'use client'
import { useTabsWithQueryParams } from '~/features/ui/useTabsWithQueryParams'
import { Children, isValidElement, useState, type PropsWithChildren, type ReactNode } from 'react'
import {
cn,
TabsFolderCorner,
TabsFolderIndicator,
TabsList,
Tabs as TabsRoot,
TabsTrigger,
} from 'ui'
interface CodeTabPanelProps {
id: string
label?: string
icon?: ReactNode
}
interface CodeTabsProps {
value?: string
onValueChange?: (value: string) => void
queryGroup?: string
}
export function NamedCodeBlock({ name, children }: PropsWithChildren<{ name: string }>) {
return (
{name}
{children}
)
}
export function CodeTabs({
children,
value,
onValueChange,
queryGroup,
}: PropsWithChildren) {
const tabs = Children.toArray(children).filter(isValidElement)
const { queryTab, onTabSelected } = useTabsWithQueryParams({
tabIds: tabs.map((tab) => tab.props.id),
queryGroup,
})
const [selected, setSelected] = useState(tabs[0]?.props.id)
const activeTab = value ?? queryTab ?? selected
const handleValueChange = (next: string) => {
setSelected(next)
onTabSelected(next)
onValueChange?.(next)
}
return (
{tabs.map((tab) => (
{tab.props.icon}
{tab.props.label ?? tab.props.id}
))}
{children}
)
}