"use client"; import { useMemo, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { ChevronDown, Moon, Sun, Menu, X } from "lucide-react"; import { cn } from "@/lib/utils"; import { useColorMode } from "@/components/providers/ColorModeProvider"; import { Button } from "@/components/ds"; import { CRM_PORTALS, navForPortal, type CrmPortalId, } from "@/modules/crm/constants/portals"; function isActive(pathname: string, href: string) { const base = href.split("?")[0]; return pathname === base || pathname.startsWith(`${base}/`); } export function CrmPortalShell({ children, portalId, title, }: { children: React.ReactNode; portalId: CrmPortalId; title?: string; }) { const pathname = usePathname(); const { mode, toggle } = useColorMode(); const [openGroups, setOpenGroups] = useState>({}); const [mobileOpen, setMobileOpen] = useState(false); const nav = navForPortal(portalId); const portalMeta = CRM_PORTALS.find((p) => p.id === portalId); const autoOpen = useMemo(() => { const map: Record = {}; for (const g of nav) { if (g.href && isActive(pathname, g.href)) map[g.id] = true; if (g.items?.some((i) => isActive(pathname, i.href))) map[g.id] = true; } return map; }, [pathname, nav]); const expanded = { ...autoOpen, ...openGroups }; const sidebar = ( <>
تربت CRM

{title ?? portalMeta?.label}

); return (
{mobileOpen ? (
{sidebar}
) : null}
{portalMeta?.label}
{children}
); }