// Rôle : assemble la navigation et les sections du tableau de bord d'administration Sokko TCG. import { useEffect, useState } from "react"; import { CardsAccount, CardsDashboardLayout } from "../CardsDashboard.jsx"; import { formatRelative } from "./adminFormat.js"; import { AdminCollections } from "./AdminCollections.jsx"; import { AdminDistributions } from "./AdminDistributions.jsx"; import { AdminHistory } from "./AdminHistory.jsx"; import { AdminOverview } from "./AdminOverview.jsx"; import { AdminShop } from "./AdminShop.jsx"; import { AdminVisualLab } from "./AdminVisualLab.jsx"; import { useCatalogLookup } from "./catalogLookup.js"; import { useAdminDashboard } from "./useAdminDashboard.js"; // Les sections qui agissent sur le jeu, l'Atelier visuel à part (un bac à sable où rien n'est enregistré), puis le journal de ces actions. const ADMIN_NAVIGATION = [ [["overview", "Vue d’ensemble"], ["collections", "Collections"], ["codes", "Codes cadeaux"], ["shop", "Boutique"]], [["visual-lab", "Atelier visuel"]], [["history", "Historique"]] ]; const SECTION_IDS = new Set(ADMIN_NAVIGATION.flat().map(([id]) => id)); // Anciennes adresses conservées pour les favoris existants. const SECTION_ALIASES = { players: "overview", cards: "collections", catalog: "collections", packs: "collections", distributions: "codes", "mythic-styles": "visual-lab", "opening-effects": "visual-lab" }; function resolveAdminSection(section) { const resolved = SECTION_ALIASES[section] || section; return SECTION_IDS.has(resolved) ? resolved : "overview"; } function useNow(intervalMs) { const [now, setNow] = useState(() => Date.now()); useEffect(() => { const timer = window.setInterval(() => setNow(Date.now()), intervalMs); return () => window.clearInterval(timer); }, [intervalMs]); return now; } export function AdminPanel({ catalog, state, runMutation, busy, section, subsection = "", onCatalogChange, backLabel = "Retour au jeu", onLogout = null }) { const activeSection = resolveAdminSection(section); const lookup = useCatalogLookup(catalog); const { dashboard, loading, error, refresh } = useAdminDashboard(); const now = useNow(30_000); async function mutateCatalog(action) { const result = await runMutation(action); if (result?.catalog) { onCatalogChange?.(result.catalog); void refresh(); } return result; } // Les campagnes vivent dans les données du tableau de bord : on les recharge après chaque modification. async function mutateCampaigns(action) { const result = await runMutation(action); if (result) void refresh(); return result; } const shared = { catalog, lookup, state, dashboard, dashboardLoading: loading, refreshDashboard: refresh, runMutation, busy, now }; return
{error &&

{error}

} `#/cards/admin/${id}`} switchLink={{ href: "#/cards", label: backLabel }} busy={loading} > {activeSection === "overview" && } {activeSection === "collections" && } {activeSection === "visual-lab" && } {activeSection === "history" && } {activeSection === "codes" && } {activeSection === "shop" && }
; }