'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useState } from 'react';
import { cn } from '@/lib/utils';
const TabsContext = /*#__PURE__*/ React.createContext(null);
export function Tab({ children, className }) {
    // Tab content is rendered by Tabs parent
    return /*#__PURE__*/ _jsx("div", {
        className: className,
        children: children
    });
}
export function Tabs({ children, defaultValue, className }) {
    // Extract tab titles and content from children
    const tabs = [];
    React.Children.forEach(children, (child)=>{
        if (/*#__PURE__*/ React.isValidElement(child) && child.type === Tab) {
            tabs.push({
                title: child.props.title,
                content: child.props.children
            });
        }
    });
    const [activeTab, setActiveTab] = useState(defaultValue || tabs[0]?.title || '');
    const activeContent = tabs.find((tab)=>tab.title === activeTab)?.content;
    return /*#__PURE__*/ _jsx(TabsContext.Provider, {
        value: {
            activeTab,
            setActiveTab
        },
        children: /*#__PURE__*/ _jsxs("div", {
            className: cn('my-4', className),
            children: [
                /*#__PURE__*/ _jsx("div", {
                    className: "flex border-b border-border overflow-x-auto",
                    children: tabs.map((tab)=>/*#__PURE__*/ _jsx("button", {
                            type: "button",
                            onClick: ()=>setActiveTab(tab.title),
                            className: cn('px-4 py-2 text-sm font-medium whitespace-nowrap transition-colors', 'hover:text-foreground', 'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50', 'border-b-2 -mb-px', activeTab === tab.title ? 'border-primary text-foreground' : 'border-transparent text-muted-foreground'),
                            children: tab.title
                        }, tab.title))
                }),
                /*#__PURE__*/ _jsx("div", {
                    className: "pt-4",
                    children: activeContent
                })
            ]
        })
    });
}
