// (C) 2026 GoodData Corporation
import { useEffect, useMemo } from "react";
/**
 * Hook to manage tab visibility and effective type selection.
 */
export function usePickerTabs(itemTypes, activeType) {
    const showTabs = itemTypes.length > 1;
    const effectiveType = showTabs ? activeType : itemTypes[0];
    return { showTabs, effectiveType };
}
/**
 * Hook to ensure active type is valid when tabs are hidden.
 */
export function useEnsureActiveType(itemTypes, showTabs, setActiveType) {
    useEffect(() => {
        if (!showTabs) {
            setActiveType(itemTypes[0]);
        }
    }, [itemTypes, setActiveType, showTabs]);
}
export function useFilteredMetricItems(metricItems, searchString, effectiveType, source) {
    return useMemo(() => {
        const items = metricItems?.[source] ?? [];
        if (!searchString.trim() || effectiveType !== "metric") {
            return items;
        }
        const lowered = searchString.toLowerCase();
        return items.filter((item) => item.title.toLowerCase().includes(lowered));
    }, [effectiveType, metricItems, searchString, source]);
}
