import { useState } from "react"; import { useTranslation } from "react-i18next"; import { NavLink, Outlet, useLocation, useNavigate } from "react-router-dom"; import { useAuth } from "../features/auth/AuthContext"; import "./AppLayout.scss"; import { AccountIcon, ChevronLeftIcon, CreditsIcon, DietPreferencesIcon, HouseholdIcon, PlanningIcon, RecipesIcon, SettingsIcon, ShoppingListIcon, UserPreferencesIcon, } from "./nav-icons"; /** `localStorage` key persisting {@link AppLayout}'s collapsed/expanded sidebar state across reloads. */ const SIDEBAR_COLLAPSED_KEY = "batchcooking:sidebarCollapsed"; /** * One entry in the sidebar's main nav. `key` maps to `layout.nav.` in * `locales/fr/translation.json` — adding a section is one array entry plus * one locale key, no other file to touch. */ const NAV_ITEMS = [ { to: "/", key: "planning", Icon: PlanningIcon }, { to: "/recettes", key: "recipes", Icon: RecipesIcon }, { to: "/liste-de-courses", key: "shoppingList", Icon: ShoppingListIcon }, ] as const; /** * One entry in the "Paramètres" nav, revealed by {@link SettingsMenu}. `key` * maps to `layout.settings.nav.`. */ const SETTINGS_ITEMS = [ { to: "/parametres/compte", key: "account", Icon: AccountIcon }, { to: "/parametres/preferences", key: "preferences", Icon: DietPreferencesIcon }, { to: "/parametres/foyer", key: "household", Icon: HouseholdIcon }, { to: "/parametres/preferences-utilisateur", key: "userPreferences", Icon: UserPreferencesIcon }, { to: "/parametres/credits", key: "credits", Icon: CreditsIcon }, ] as const; /** * Shell for every authenticated page: a sidebar (brand, section nav, a * collapsible "Paramètres" nav, and the account menu at the bottom) plus a * main content area rendering the matched child route via ``. * * The sidebar itself can be collapsed to an icon-only rail (see * `isCollapsed`/`SIDEBAR_COLLAPSED_KEY`) — every nav item keeps its icon * and gains a `title` tooltip, its label just hides via CSS * (`.app-sidebar.collapsed .label`, see AppLayout.scss), so collapsing is a * single class toggle on the `