"use client";
import { useMemo } from "react";
import { MODEL_REGISTRY, DEFAULT_MODEL_ID, DEFAULT_CURSOR_MODEL_ID, DISABLED_PROVIDERS, modelKey, } from "./registry";
/**
 * Data hook that exposes the platform model registry with grouping
 * and lookup helpers.
 *
 * Pure data layer — no rendering, no side effects. Platform builders
 * who want full control over rendering import this hook and build
 * their own UI.
 *
 * **Modes:**
 * - `options.harness === "cursor"` — Cursor-harness models only
 * - `options.harness === "native"` — native models, excluding disabled providers
 * - `options.harness` omitted — unified: both harnesses, excluding disabled providers
 *
 * @example
 * ```tsx
 * // Unified mode — flat picker with all models
 * const { featured, models, getByKey } = useModelRegistry();
 *
 * // Legacy single-harness mode
 * const { models, defaultModel } = useModelRegistry({ harness: "native" });
 * ```
 */
export function useModelRegistry(options) {
    const harness = options?.harness;
    return useMemo(() => {
        const isCursor = harness === "cursor";
        const isNative = harness === "native";
        const isUnified = harness === undefined;
        const defaultId = isCursor ? DEFAULT_CURSOR_MODEL_ID : DEFAULT_MODEL_ID;
        const byProvider = new Map();
        const byId = new Map();
        const byCompoundKey = new Map();
        const enabledModels = [];
        const featuredModels = [];
        let defaultModel;
        for (const model of MODEL_REGISTRY) {
            if (isCursor) {
                if (model.harness !== "cursor")
                    continue;
            }
            else if (isNative) {
                if (model.harness !== "native")
                    continue;
                if (DISABLED_PROVIDERS.has(model.provider))
                    continue;
            }
            else {
                // Unified — include both harnesses, still respect DISABLED_PROVIDERS
                if (DISABLED_PROVIDERS.has(model.provider))
                    continue;
            }
            enabledModels.push(model);
            byCompoundKey.set(modelKey(model.harness, model.modelId), model);
            if (!byId.has(model.modelId)) {
                byId.set(model.modelId, model);
            }
            const group = byProvider.get(model.provider);
            if (group) {
                group.push(model);
            }
            else {
                byProvider.set(model.provider, [model]);
            }
            if (model.modelId === defaultId) {
                defaultModel ??= model;
            }
            if (model.featured) {
                featuredModels.push(model);
            }
        }
        const providers = Array.from(byProvider.keys());
        return {
            models: enabledModels,
            byProvider: byProvider,
            defaultModel: defaultModel ?? enabledModels[0],
            getModel: (modelId) => byId.get(modelId),
            providers,
            featured: featuredModels,
            getByKey: (key) => byCompoundKey.get(key),
        };
    }, [harness]);
}
//# sourceMappingURL=useModelRegistry.js.map