'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { AlertTriangle } from 'lucide-react';
import { useId } from 'react';
import { SettingsCard, SettingsToggleRow } from './components.js';
import { capabilityLabel, effectiveFeatureModel, isModelCompatible } from './featureModel.js';
const SELECT_CLASS = 'w-full rounded-md border border-border bg-input-background px-3 py-2 text-sm text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-60';
/**
 * Global AI feature toggles with per-feature model routing. Each switch persists
 * (via the Save bar) to the shared `ai.features.*` flags; the optional model
 * picker overrides which model that feature uses (otherwise it inherits the
 * default). Enforcement across modules lands in a later phase; here we surface
 * and store the operator's intent.
 */
export function AiFeaturesCard({ features, models, defaultModelId, canEdit, onToggle, onSetFeatureModel, }) {
    return (_jsx(SettingsCard, { title: "AI Features", description: "Turn individual AI-powered features on or off, and optionally route each to a specific model.", children: features.length === 0 ? (_jsx("p", { className: "text-muted-foreground text-sm", children: "No AI features are available." })) : (_jsx("div", { className: "divide-border divide-y", children: features.map((f) => (_jsx(FeatureRow, { feature: f, models: models, defaultModelId: defaultModelId, canEdit: canEdit, onToggle: onToggle, onSetFeatureModel: onSetFeatureModel }, f.key))) })) }));
}
function FeatureRow({ feature, models, defaultModelId, canEdit, onToggle, onSetFeatureModel, }) {
    const selectId = useId();
    const required = feature.requiredCapabilities ?? [];
    const effective = effectiveFeatureModel(feature.modelId, defaultModelId, required, models);
    const defaultModel = models.find((m) => m.id === defaultModelId || m.providerModelId === defaultModelId);
    const hasModels = models.length > 0;
    const defaultLabel = defaultModel
        ? `Use default (${defaultModel.displayName})`
        : 'Use default model';
    return (_jsxs("div", { className: "py-4 first:pt-0 last:pb-0", children: [_jsx(SettingsToggleRow, { label: feature.label, description: feature.description, checked: feature.enabled, disabled: !canEdit, onChange: (v) => onToggle(feature.key, v) }), feature.enabled && (_jsxs("div", { className: "mt-3 pl-0", children: [_jsx("label", { htmlFor: selectId, className: "text-muted-foreground mb-1 block text-sm", children: "Model" }), hasModels ? (_jsxs("select", { id: selectId, value: feature.modelId ?? '', disabled: !canEdit, onChange: (e) => onSetFeatureModel(feature.key, e.target.value), className: SELECT_CLASS, children: [_jsx("option", { value: "", children: defaultLabel }), models.map((m) => {
                                const compatible = isModelCompatible(m, required);
                                return (_jsxs("option", { value: m.id, disabled: !compatible, children: [m.displayName, m.status === 'unavailable' ? ' (unavailable)' : '', m.status !== 'unavailable' && !compatible ? ' (incompatible)' : ''] }, m.id));
                            })] })) : (_jsx("p", { className: "text-muted-foreground text-sm", children: "Connect a provider and refresh models to route this feature." })), hasModels && !effective.isOverride && (_jsx("p", { className: "text-muted-foreground mt-1 text-sm", children: effective.model
                            ? `Uses the default model (${effective.model.displayName}).`
                            : 'No default model selected yet — set one in the AI Assistant card above.' })), hasModels && effective.missingCapabilities.length > 0 && (_jsxs("p", { className: "text-warning mt-1.5 flex items-start gap-1.5 text-sm", role: "status", children: [_jsx(AlertTriangle, { size: 14, className: "mt-0.5 shrink-0", "aria-hidden": "true" }), "This model can't do", ' ', effective.missingCapabilities.map(capabilityLabel).join(', '), ", which this feature needs. Pick a compatible model."] }))] }))] }));
}
//# sourceMappingURL=AiFeaturesCard.js.map