"use client"; import { ChevronRight } from "lucide-react"; import Link from "next/link"; import type React from "react"; import { useCallback, useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Drawer, DrawerContent, DrawerHandle, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer"; import { Separator } from "@/components/ui/separator"; import { cn } from "@/lib/utils"; export interface RoutedSectionItem { value: string; label: string; href: string; icon?: React.ReactNode; } export interface RoutedSectionGroup { value: string; label: string; icon?: React.ReactNode; items: RoutedSectionItem[]; } interface RoutedSectionShellProps { title: string; items: RoutedSectionItem[]; activeValue: string; selectedLabel: string; children: React.ReactNode; groups?: RoutedSectionGroup[]; mobileNav?: "scroll" | "drawer"; contentClassName?: string; desktopNav?: boolean; } function findActiveGroupValue(groups: RoutedSectionGroup[], activeValue: string): string | null { return ( groups.find((group) => group.items.some((item) => item.value === activeValue))?.value ?? null ); } function SectionNavLink({ item, activeValue, onNavigate, }: { item: RoutedSectionItem; activeValue: string; onNavigate?: () => void; }) { const isActive = activeValue === item.value; return ( {item.icon} {item.label} ); } function SectionNavGroup({ group, activeValue, isExpanded, onToggle, onNavigate, }: { group: RoutedSectionGroup; activeValue: string; isExpanded: boolean; onToggle: () => void; onNavigate?: () => void; }) { return (
{group.items.map((item) => ( ))}
); } export function RoutedSectionShell({ title, items, activeValue, selectedLabel, children, groups = [], mobileNav = "scroll", contentClassName, desktopNav = true, }: RoutedSectionShellProps) { const [tabScrollPos, setTabScrollPos] = useState<"start" | "middle" | "end">("start"); const [drawerOpen, setDrawerOpen] = useState(false); const [expandedGroup, setExpandedGroup] = useState(() => findActiveGroupValue(groups, activeValue) ); useEffect(() => { const activeGroup = findActiveGroupValue(groups, activeValue); if (activeGroup) { setExpandedGroup(activeGroup); } }, [activeValue, groups]); const handleTabScroll = useCallback((e: React.UIEvent) => { const el = e.currentTarget; const atStart = el.scrollLeft <= 2; const atEnd = el.scrollWidth - el.scrollLeft - el.clientWidth <= 2; setTabScrollPos(atStart ? "start" : atEnd ? "end" : "middle"); }, []); const renderNav = (onNavigate?: () => void) => ( <> {items.map((item) => ( ))} {groups.length > 0 && ( <>
{groups.map((group) => ( setExpandedGroup((current) => (current === group.value ? null : group.value)) } onNavigate={onNavigate} /> ))}
)} ); return (

{title}

{desktopNav ? : null} {mobileNav === "drawer" ? ( {title} navigation ) : (
{items.map((item) => ( {item.icon} {item.label} ))}
)}
{desktopNav ? (

{selectedLabel}

) : null}
{children}
); }