'use client' import { useState, type ReactNode } from 'react' type Tab = { id: string label: ReactNode } type TabsProps = { tabs: Tab[] defaultTab?: string activeTab?: string onTabChange?: (id: string) => void children: ReactNode className?: string } type TabPanelProps = { id: string activeTab: string children: ReactNode } export function Tabs({ tabs, defaultTab, activeTab: controlledTab, onTabChange, children, className = '' }: TabsProps) { const [internalTab, setInternalTab] = useState(defaultTab ?? tabs[0]?.id ?? '') const activeTab = controlledTab ?? internalTab function handleTabChange(id: string) { if (!controlledTab) setInternalTab(id) onTabChange?.(id) } return (
{tabs.map((tab) => ( ))}
{children != null && (
{children}
)}
) } export function TabPanel({ id, activeTab, children }: TabPanelProps) { if (activeTab !== id) return null return
{children}
}