"use client";
import { useCallback, useMemo, useState } from "react";
// ---------------------------------------------------------------------------
// Hook
// ---------------------------------------------------------------------------
/**
 * Headless hook for filtering and searching a set of resource templates.
 *
 * Provides category tab state, text search across name/description/tags,
 * and the filtered result set. Fully memoized — only recalculates when
 * inputs change.
 *
 * Platform builders can use this hook with their own rendering; the
 * styled `TemplateGallery` component uses it internally.
 *
 * @typeParam TData - The wizard data shape (e.g. `AgentWizardData`).
 *
 * @example
 * ```tsx
 * const { filtered, query, setQuery, activeCategory, setActiveCategory, availableCategories } =
 *   useTemplateFilter({ templates: AGENT_TEMPLATES });
 *
 * // Render your own gallery UI using `filtered`
 * ```
 */
export function useTemplateFilter(options) {
    const { templates } = options;
    const [query, setQueryRaw] = useState("");
    const [activeCategory, setActiveCategory] = useState(null);
    const setQuery = useCallback((q) => {
        setQueryRaw(q);
    }, []);
    const availableCategories = useMemo(() => {
        const seen = new Set();
        for (const t of templates) {
            seen.add(t.category);
        }
        const sorted = [...seen].sort();
        return sorted;
    }, [templates]);
    const filtered = useMemo(() => {
        let result = templates;
        if (activeCategory) {
            result = result.filter((t) => t.category === activeCategory);
        }
        const trimmed = query.trim().toLowerCase();
        if (trimmed) {
            result = result.filter((t) => {
                const haystack = [t.name, t.description, ...(t.tags ?? [])]
                    .join(" ")
                    .toLowerCase();
                return haystack.includes(trimmed);
            });
        }
        return result;
    }, [templates, activeCategory, query]);
    return useMemo(() => ({
        filtered,
        query,
        setQuery,
        activeCategory,
        setActiveCategory,
        availableCategories,
    }), [
        filtered,
        query,
        setQuery,
        activeCategory,
        setActiveCategory,
        availableCategories,
    ]);
}
//# sourceMappingURL=useTemplateFilter.js.map