// /src/app/[locale]/components/Tabs.tsx 'use client' import { usePathname } from 'next/navigation' import Link from 'next/link' import type { ReactNode, FC } from 'react' import { Children, type ReactElement } from 'react'; export type TabProps = { name: string href: string } type TabsProps = { children: ReactNode value?: string onChange?: (name: string) => void orientation?: 'horizontal' | 'vertical' className?: string tabClassName?: string } // ── add a component type that has a static Tab type TabsComponent = FC & { Tab: FC } function normalize(path: string) { if (!path) return '/' const v = path.replace(/\/+$/, '') return v === '' ? '/' : v } function isTabElement(v: unknown): v is ReactElement { if (typeof v !== 'object' || v === null) return false; if (!('props' in v)) return false; const propsUnknown = (v as { props: unknown }).props; if (typeof propsUnknown !== 'object' || propsUnknown === null) return false; const props = propsUnknown as Record; return typeof props.href === 'string' && typeof props.name === 'string'; } // implement as base function const TabsBase: FC = ({ children, value, onChange, orientation = 'horizontal', className = '', tabClassName = '' }) => { const pathname = usePathname() const rawTabs = Children.toArray(children); const tabs = rawTabs.filter(isTabElement); const isVertical = orientation === 'vertical' const current = normalize(pathname) const hrefs = tabs.map(t => normalize(t.props.href)) return ( ) } // the dummy Tab element (for nicer JSX usage) const Tab: FC = () => null // ── export Tabs with a typed static property export const Tabs: TabsComponent = Object.assign(TabsBase, { Tab })