"use client";
import { useState } from "react";
import { Link, usePathname } from "@/i18n/navigation";
export interface NavItem { href: string; label: string }
export interface NavGroup { title: string; items: NavItem[] }
export function AdminShell({
groups,
brand,
back,
children,
}: {
groups: NavGroup[];
brand: string;
back: string;
children: React.ReactNode;
}) {
const pathname = usePathname() ?? ""; // next-intl: already without the locale prefix
const [open, setOpen] = useState(false);
const isActive = (href: string) => pathname === href || pathname.startsWith(href + "/");
const current = groups.flatMap((g) => g.items).find((i) => isActive(i.href));
return (
{/* Sidebar — pinned to the right (admin is RTL-primary). lg:translate-x-0
keeps it visible on desktop; on mobile it slides off the right edge.
(Avoid rtl:/ltr: translate variants — their [dir] selector out-specifies
lg: and would keep the panel off-screen.) */}
F
{brand}
{groups.map((g) => (
{g.title}
{g.items.map((item) => {
const active = isActive(item.href);
return (
setOpen(false)}
className={`block rounded-lg px-3 py-1.5 text-sm transition-colors ${
active
? "bg-indigo-600/15 font-medium text-indigo-300"
: "text-gray-400 hover:bg-[#161a2e] hover:text-white"
}`}
>
{item.label}
);
})}
))}
← {back}
{/* Mobile overlay */}
{open &&
setOpen(false)} />}
{/* Main column */}
setOpen(true)}
aria-label="menu"
>
{current?.label ?? brand}
{back}
{children}
);
}