/** * @file Structure le layout global avec sidebar, topbar, navigation et contenu. */ import { useEffect, useRef } from "react"; import { useFullCardsReserve } from "../features/cards/cardsReserve.js"; import { Icon } from "./Icon.jsx"; import { ImportButton } from "./ImportButton.jsx"; import { Tooltip } from "./Tooltip.jsx"; /** `toolboxTargetId` : le jeu (sa toolbox liƩe) ou Sokko TCG (une toolbox au choix) dont la page ouvre le tiroir, sinon vide. */ export function Shell({ route, content, toolboxTargetId = "", drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, cardsEnabled = false, actions, onOpenAutoBackup, children }) { const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") || route.startsWith("/receive/") ? content.topbar.toolbox : route.startsWith("/games") ? content.topbar.games : route === "/library" ? content.topbar.library : route.startsWith("/cards") ? content.topbar.cards : content.topbar.dashboard; const toolboxOpen = Boolean(toolboxTargetId && drawerGameId === toolboxTargetId && drawerVisible); const toolboxLabel = toolboxOpen ? "Masquer la toolbox" : "Afficher la toolbox"; const compactSidebar = Boolean(reducedSidebar || (!compactGameLayout && toolboxOpen)); const compactToolboxVisible = Boolean(compactGameLayout && toolboxOpen); const guideTabRef = useRef(null); const toolboxTabRef = useRef(null); const wideToolboxButtonRef = useRef(null); const focusedViewControlRef = useRef(""); const previousCompactLayoutRef = useRef(compactGameLayout); useEffect(() => { const trackFocus = (event) => { if (event.target.closest?.(".compact-game-view-switch")) focusedViewControlRef.current = "compact"; else if (event.target.closest?.(".toolbox-button")) focusedViewControlRef.current = "wide"; else focusedViewControlRef.current = ""; }; document.addEventListener("focusin", trackFocus); return () => document.removeEventListener("focusin", trackFocus); }, []); useEffect(() => { const activeElement = document.activeElement; const layoutChanged = previousCompactLayoutRef.current !== compactGameLayout; previousCompactLayoutRef.current = compactGameLayout; if (layoutChanged && compactGameLayout && focusedViewControlRef.current === "wide") { (compactToolboxVisible ? toolboxTabRef.current : guideTabRef.current)?.focus(); } else if (compactGameLayout && !compactToolboxVisible && activeElement?.closest?.("#toolbox-drawer")) { guideTabRef.current?.focus(); } else if (layoutChanged && !compactGameLayout && focusedViewControlRef.current === "compact") { wideToolboxButtonRef.current?.focus(); } }, [compactGameLayout, compactToolboxVisible]); const fullCardsReserve = useFullCardsReserve(cardsEnabled); const cardsLabel = fullCardsReserve ? `${content.navigation.cards} (${content.navigation.cardsReserveFull})` : content.navigation.cards; return (