"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 { PAYMENT_PORTAL, navForPayment, filterNavByBundles, } from "@/modules/payment/constants/portals"; import { usePaymentCapabilities } from "@/modules/payment/hooks/usePaymentCapabilities"; function isActive(pathname: string, href: string) { const base = href.split("?")[0]; if (base === "/payment") return pathname === "/payment"; return pathname === base || pathname.startsWith(`${base}/`); } export function PaymentPortalShell({ children, title, }: { children: React.ReactNode; title?: string; }) { const pathname = usePathname(); const { mode, toggle } = useColorMode(); const caps = usePaymentCapabilities(); const [openGroups, setOpenGroups] = useState>({}); const [mobileOpen, setMobileOpen] = useState(false); const nav = useMemo( () => filterNavByBundles(navForPayment(), caps.data?.active_bundles), [caps.data?.active_bundles] ); 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 = ( <>

تربت‌پی

{title ?? PAYMENT_PORTAL.label}

هاب تربت‌پی
); return (
{mobileOpen ? (
{sidebar}
) : null}
{PAYMENT_PORTAL.label}
{children}
); }