"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useState, useEffect, createContext, useContext } from "react";
import { getStoredUser } from "@/src/lib/auth";
import Logo from "@/src/utils/logo";
import BrandIcon from "@/src/utils/brandIcon";
//ــــــــــــــ Drawer Context
const DrawerCtx = createContext<{
open: boolean;
setOpen: (v: boolean) => void;
}>({ open: false, setOpen: () => {} });
export function useSidebarDrawer() {
return useContext(DrawerCtx);
}
export function SidebarProvider({ children }: { children: React.ReactNode }) {
const [open, setOpen] = useState(false);
return (
{children}
);
}
/* ══════════════════════════════════════════
Nav items
══════════════════════════════════════════ */
const navSections = [
{
label: "الرئيسية",
items: [
{ href: "/dashboard", label: "Dashboard", icon: "ti-layout-dashboard", permission: "read-dashboard" },
{ href: "/dashboard/users", label: "Users", icon: "ti-users", permission: "read-user" },
],
},
{
label: "الأسطول",
items: [
{ href: "/dashboard/cars", label: "Cars", icon: "ti-car", permission: "read-car" },
{ href: "/dashboard/drivers", label: "Drivers", icon: "ti-steering-wheel", permission: "read-driver" },
{ href: "/dashboard/trips", label: "Trips", icon: "ti-route", permission: "read-trip" },
],
},
{
label: "العمليات",
items: [
{ href: "/dashboard/orders", label: "Orders", icon: "ti-package", permission: "read-order" },
{ href: "/dashboard/clients", label: "Clients", icon: "ti-users-group", permission: "read-client" },
{ href: "/dashboard/branches", label: "Branches", icon: "ti-building", permission: "read-branch" },
{ href: "/dashboard/roles", label: "Roles", icon: "ti-shield", permission: "read-role" },
{ href: "/dashboard/audit", label: "Audit", icon: "ti-clipboard-list", permission: "read-audit" },
],
},
];
/* ══════════════════════════════════════════
Brand Icon
══════════════════════════════════════════ */
export function BrandIconButton({ onClick }: { onClick: () => void }) {
return (
);
}
const GRAD = "linear-gradient(175deg, #1E3A8A 0%, #1D4ED8 60%, #1565C0 100%)";
/* ══════════════════════════════════════════
Sidebar
⚠️ NO display property in any inline style here
globals.css controls ALL display with !important
══════════════════════════════════════════ */
export function Sidebar() {
const pathname = usePathname();
const user = getStoredUser();
const permissions = user?.permissions ?? navSections.flatMap(s => s.items.map(i => i.permission));
const { open, setOpen } = useSidebarDrawer();
useEffect(() => { setOpen(false); }, [pathname, setOpen]);
useEffect(() => {
document.body.style.overflow = open ? "hidden" : "";
return () => { document.body.style.overflow = ""; };
}, [open]);
return (
<>
{/* ══ 1. Full sidebar — lg+ ══*/}
{/* ══ 2. Compact rail */}
{/* mobile drower*/}
{/* open drower*/}
{open && (
setOpen(false)}
aria-hidden="true"
style={{
position: "fixed",
top: 0, left: 0, right: 0, bottom: 0,
background: "rgba(0,0,0,0.5)",
zIndex: 40,
}}
/>
)}
{/* Drawer panel */}
>
);
}
/* ══════════════════════════════════════════
SidebarContent
══════════════════════════════════════════ */
function SidebarContent({
pathname, permissions, user, compact,
}: {
pathname: string;
permissions: string[];
user: ReturnType
;
compact: boolean;
}) {
return (
<>
{compact ? : }
{compact ? (
{(user?.name ?? user?.userName ?? "—").slice(0, 1)}
) : (
{user?.name ?? user?.userName ?? "—"}
{user?.role ?? "Signed in"}
)}
>
);
}