import { jsx as _jsx } from "react/jsx-runtime";
import { useState } from 'react';
import { ItemSelector, } from '../components/item-selector.js';
import { loadAllProviderConfigs } from '../config/mcp-config-loader.js';
export default function ModelSelector({ currentProvider, currentModel, onModelSelect, onCancel, }) {
    // Flat list of every model across every configured provider. The option
    // value is the entry's index, so a selection maps back to its
    // (provider, model) pair without encoding a delimiter into the value.
    const [entries] = useState(() => loadAllProviderConfigs().flatMap(provider => (provider.models ?? []).map(model => ({
        provider: provider.name,
        model,
    }))));
    const items = entries.map((entry, index) => ({
        label: `${entry.model} (${entry.provider})${entry.provider === currentProvider && entry.model === currentModel
            ? ' (current)'
            : ''}`,
        value: String(index),
    }));
    const error = entries.length === 0
        ? 'No models available. Please check your configuration.'
        : null;
    return (_jsx(ItemSelector, { title: "Select a Model", items: items, onSelect: value => {
            const entry = entries[Number(value)];
            if (entry) {
                onModelSelect(entry.provider, entry.model);
            }
        }, onCancel: onCancel, error: error, errorTitle: "Model Selection - Error", errorHint: "Make sure your providers are properly configured." }));
}
//# sourceMappingURL=model-selector.js.map