"use client"; import React from "react"; import Link from "next/link"; import { useParams, usePathname } from "next/navigation"; import { cn } from "@app/lib/cn"; import { CornerDownRight } from "lucide-react"; interface SidebarNavItem { href: string; title: string; icon?: React.ReactNode; children?: SidebarNavItem[]; } interface SidebarNavProps extends React.HTMLAttributes { items: SidebarNavItem[]; disabled?: boolean; } export function SidebarNav({ className, items, disabled = false, ...props }: SidebarNavProps) { const pathname = usePathname(); const params = useParams(); const orgId = params.orgId as string; const niceId = params.niceId as string; const resourceId = params.resourceId as string; const userId = params.userId as string; function hydrateHref(val: string): string { return val .replace("{orgId}", orgId) .replace("{niceId}", niceId) .replace("{resourceId}", resourceId) .replace("{userId}", userId); } function renderItems(items: SidebarNavItem[]) { return items.map((item) => { const hydratedHref = hydrateHref(item.href); const isActive = pathname.startsWith(hydratedHref); return (
e.preventDefault() : undefined} tabIndex={disabled ? -1 : undefined} aria-disabled={disabled} > {item.icon && {item.icon}} {item.title} {item.children && (
{item.children.map((child) => { const hydratedChildHref = hydrateHref(child.href); const isChildActive = pathname.startsWith(hydratedChildHref) && !pathname.includes("create"); return ( e.preventDefault() : undefined} tabIndex={disabled ? -1 : undefined} aria-disabled={disabled} > {child.icon && {child.icon}} {child.title} ); })}
)}
); }); } return ( ); }