"use client"; import React from "react"; import Link from "next/link"; import { useParams, usePathname } from "next/navigation"; import { cn } from "@app/lib/cn"; import { Badge } from "@app/components/ui/badge"; import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext"; import { useTranslations } from "next-intl"; export type HorizontalTabs = Array<{ title: string; href: string; icon?: React.ReactNode; showProfessional?: boolean; }>; interface HorizontalTabsProps { children: React.ReactNode; items: HorizontalTabs; disabled?: boolean; } export function HorizontalTabs({ children, items, disabled = false }: HorizontalTabsProps) { const pathname = usePathname(); const params = useParams(); const { licenseStatus, isUnlocked } = useLicenseStatusContext(); const t = useTranslations(); 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) .replace("{clientId}", params.clientId as string) .replace("{apiKeyId}", params.apiKeyId as string); } return (
{items.map((item) => { const hydratedHref = hydrateHref(item.href); const isActive = pathname.startsWith(hydratedHref) && !pathname.includes("create"); const isProfessional = item.showProfessional && !isUnlocked(); const isDisabled = disabled || (isProfessional && !isUnlocked()); return ( { if (isDisabled) { e.preventDefault(); } }} tabIndex={isDisabled ? -1 : undefined} aria-disabled={isDisabled} >
{item.icon && item.icon} {item.title} {isProfessional && ( {t('licenseBadge')} )}
); })}
{children}
); }