"use client"; import React from "react"; import Link from "next/link"; import { useParams, usePathname } from "next/navigation"; import { cn } from "@app/lib/cn"; import { buttonVariants } from "@/components/ui/button"; interface HorizontalTabsProps { children: React.ReactNode; items: Array<{ title: string; href: string; icon?: React.ReactNode; }>; disabled?: boolean; } export function HorizontalTabs({ children, items, disabled = false }: HorizontalTabsProps) { const pathname = usePathname(); const params = useParams(); function hydrateHref(href: string) { return href .replace("{orgId}", params.orgId as string) .replace("{resourceId}", params.resourceId as string) .replace("{niceId}", params.niceId as string) .replace("{userId}", params.userId as string); } return (
{items.map((item) => { const hydratedHref = hydrateHref(item.href); const isActive = pathname.startsWith(hydratedHref) && !pathname.includes("create"); return ( e.preventDefault() : undefined } tabIndex={disabled ? -1 : undefined} aria-disabled={disabled} > {item.icon ? (
{item.icon} {item.title}
) : ( item.title )} ); })}
{children}
); }