import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import { getColors } from '../config/index.js';
import { BaseConfigWizard } from './base-config-wizard.js';
import { ProviderStep } from './steps/provider-step.js';
import { buildProviderConfigObject } from './validation.js';
function parseProviderConfig(raw) {
    const config = raw;
    return config?.nanocoder?.providers ?? [];
}
function ProviderSummaryItems({ items }) {
    const colors = getColors();
    if (items.length === 0) {
        return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: colors.warning, children: "No providers configured" }) }));
    }
    return (_jsxs(Box, { marginBottom: 1, flexDirection: "column", children: [_jsxs(Text, { color: colors.secondary, children: ["Providers (", items.length, "):"] }), items.map((provider, index) => (_jsxs(Text, { color: colors.success, children: ["\u2022 ", provider.name, _jsxs(Text, { children: [' ', "(", provider.models.length, ' ', provider.models.length === 1 ? 'model' : 'models', provider.models.length <= 3
                                ? `: ${provider.models.join(', ')}`
                                : '', ")"] })] }, index)))] }));
}
function ProviderCompleteExtras({ items }) {
    const colors = getColors();
    const copilotProviders = items.filter(p => p.sdkProvider === 'github-copilot');
    const codexProviders = items.filter(p => p.sdkProvider === 'chatgpt-codex');
    const localProviders = items.filter(p => !p.apiKey &&
        p.baseUrl &&
        (p.baseUrl.includes('localhost') || p.baseUrl.includes('127.0.0.1')));
    const needsAuth = copilotProviders.length > 0 || codexProviders.length > 0;
    const hasLocal = localProviders.length > 0;
    return (_jsxs(_Fragment, { children: [needsAuth && (_jsxs(Box, { marginBottom: 1, flexDirection: "column", children: [copilotProviders.length > 0 && (_jsx(Text, { color: colors.primary, children: "Run /copilot-login to auth with Copilot." })), codexProviders.length > 0 && (_jsx(Text, { color: colors.primary, children: "Run /codex-login to auth with ChatGPT/Codex." }))] })), hasLocal && (_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { children: ["Ensure your local", ' ', localProviders.length === 1 ? 'server is' : 'servers are', " running before use."] }) }))] }));
}
export function ProviderWizard({ projectDir, onComplete, onCancel, }) {
    return (_jsx(BaseConfigWizard, { title: "Provider Wizard", focusId: "config-wizard", configFileName: "agents.config.json", initialItems: [], parseConfig: parseProviderConfig, buildConfig: buildProviderConfigObject, hasItems: items => items.length > 0, renderConfigureStep: ({ items, onComplete: onItemsComplete, onBack, onDelete, configExists, }) => (_jsx(ProviderStep, { existingProviders: items, onComplete: onItemsComplete, onBack: onBack, onDelete: onDelete, configExists: configExists })), renderSummaryItems: items => _jsx(ProviderSummaryItems, { items: items }), renderCompleteExtras: items => _jsx(ProviderCompleteExtras, { items: items }), projectDir: projectDir, onComplete: onComplete, onCancel: onCancel }));
}
//# sourceMappingURL=provider-wizard.js.map