"use client";
import { useCallback, useMemo, useState } from "react";
/**
 * Internal hook that manages tab state for detail view components.
 *
 * Implements the uncontrolled-by-default / controlled-when-specified
 * pattern (DD-T05A-001):
 * - When both `activeTab` and `onTabChange` are provided, the component
 *   operates in controlled mode (consumer owns the state).
 * - Otherwise, the component manages its own internal tab state.
 *
 * Single-tab suppression (DD-T05A-002):
 * - When only one tab exists (no additionalTabs), `effectiveTabs` is
 *   `undefined` so the consumer skips rendering the tab bar entirely.
 */
export function useDetailTabs({ builtInTabs, additionalTabs, activeTab, onTabChange, defaultTab, }) {
    const isControlled = activeTab !== undefined && onTabChange !== undefined;
    const allTabs = useMemo(() => {
        if (!additionalTabs || additionalTabs.length === 0)
            return builtInTabs;
        return [...builtInTabs, ...additionalTabs];
    }, [builtInTabs, additionalTabs]);
    const initialTab = defaultTab ?? builtInTabs[0]?.id ?? "";
    const [internalTab, setInternalTab] = useState(initialTab);
    const effectiveActiveTab = isControlled ? activeTab : internalTab;
    const effectiveOnTabChange = useCallback((tabId) => {
        if (isControlled) {
            onTabChange(tabId);
        }
        else {
            setInternalTab(tabId);
        }
    }, [isControlled, onTabChange]);
    const effectiveTabs = allTabs.length > 1 ? allTabs : undefined;
    const activeAdditionalTab = useMemo(() => {
        if (!additionalTabs)
            return undefined;
        return additionalTabs.find((t) => t.id === effectiveActiveTab);
    }, [additionalTabs, effectiveActiveTab]);
    return {
        effectiveTabs,
        effectiveActiveTab,
        effectiveOnTabChange,
        activeAdditionalTab,
    };
}
//# sourceMappingURL=useDetailTabs.js.map