"use client"; import { Icon } from "@iconify/react"; import { AnimatePresence, motion, useReducedMotion } from "framer-motion"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; import { iconArchive, iconChart, iconCloseSquare, iconDashboard, iconDelivery, iconHamburgerMenu, iconStorefrontFill, iconUserPlus, iconUsersGroup, iconWalletMoney, } from "../../_core/icons"; import { useSessionUser } from "../../_core/hooks/use-session-user"; import { OperatingDayControl } from "./operating-day-control"; import { UserMenu } from "./user-menu"; const NAV_ITEMS = [ { href: "/admin", label: "Panel", icon: iconDashboard }, { href: "/admin/inventario", label: "Inventario", icon: iconArchive }, { href: "/admin/proveedores", label: "Proveedores", icon: iconDelivery }, { href: "/admin/clientes", label: "Clientes", icon: iconUserPlus }, { href: "/admin/reportes", label: "Reportes", icon: iconChart }, { href: "/admin/usuarios", label: "Usuarios", icon: iconUsersGroup }, ] as const; function isActive(pathname: string, href: string) { if (href === "/admin") return pathname === "/admin"; return pathname.startsWith(href); } export function AdminShell({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const { user, logout } = useSessionUser(); const reduceMotion = useReducedMotion(); const [menuOpen, setMenuOpen] = useState(false); const [prevPathname, setPrevPathname] = useState(pathname); if (pathname !== prevPathname) { setPrevPathname(pathname); setMenuOpen(false); } useEffect(() => { if (!menuOpen) return; function onKeyDown(e: KeyboardEvent) { if (e.key === "Escape") setMenuOpen(false); } document.addEventListener("keydown", onKeyDown); return () => document.removeEventListener("keydown", onKeyDown); }, [menuOpen]); if (!user) return null; const activeItem = NAV_ITEMS.find((item) => isActive(pathname, item.href)); const navList = ( ); return (
{/* Unified header */}

PDV

Panel administrativo

{activeItem?.label ?? "Panel"}

{/* Sidebar (desktop) */}
{children}
{/* Mobile drawer */} {menuOpen && ( <> setMenuOpen(false)} aria-hidden="true" />
PDV Admin
{navList}
)}
); }