import { useState } from "react";
import { NavLink, Outlet } from "react-router-dom";
import { Button, cn } from "../ui/index.js";
import { api } from "../lib/api.js";
import { useSession } from "../lib/session.js";
import {
ActivityIcon,
CloseIcon,
FolderIcon,
HardDriveIcon,
ImageIcon,
LogoutIcon,
MenuIcon,
SearchNavIcon,
SettingsIcon,
ShieldIcon,
TrashIcon,
} from "./icons.js";
interface NavItem {
to: string;
label: string;
icon: typeof FolderIcon;
}
const NAV: NavItem[] = [
{ to: "/files", label: "Fichiers", icon: FolderIcon },
{ to: "/search", label: "Recherche", icon: SearchNavIcon },
{ to: "/gallery", label: "Galerie", icon: ImageIcon },
{ to: "/trash", label: "Corbeille", icon: TrashIcon },
];
const ADMIN_NAV: NavItem[] = [
{ to: "/admin/comptes", label: "Comptes", icon: ShieldIcon },
{ to: "/admin/stockage", label: "Stockage", icon: HardDriveIcon },
{ to: "/admin/audit", label: "Journal", icon: ActivityIcon },
];
const ACCOUNT_NAV: NavItem = { to: "/profile", label: "Mon compte", icon: SettingsIcon };
const initials = (first: string, last: string): string =>
`${first.charAt(0)}${last.charAt(0)}`.toUpperCase() || "?";
const navClass = ({ isActive }: { isActive: boolean }) =>
cn(
"flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors",
isActive
? "bg-accent/10 text-accent"
: "text-muted-foreground hover:bg-surface-hover hover:text-foreground",
);
export const AppShell = () => {
const { user, logout } = useSession();
const [menuOpen, setMenuOpen] = useState(false);
if (!user) return null;
const isAdmin = user.role_slug === "admin";
const allNav = [...NAV, ...(isAdmin ? ADMIN_NAV : []), ACCOUNT_NAV];
const brand = (
CoHaiSe
Cloud
{user.first_name} {user.last_name}
{user.role_name}