import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { Pane } from "../../design/Pane.js";
import { ProgressBar } from "../../design/ProgressBar.js";
import { SelectList } from "../../design/SelectList.js";
import { agentMarkdownFilename } from "../agentFileUtils.js";
import { generateAgentMarkdown } from "../generateAgent.js";
import { validateAgentDraft } from "../validateAgent.js";
import { AGENT_CREATION_STEPS } from "./types.js";
export function createAgentWizardModel(input) {
    const activeIndex = Math.max(0, AGENT_CREATION_STEPS.findIndex((step) => step.id === (input.activeStep ?? "method")));
    const validation = validateAgentDraft(input.state);
    const activeStep = AGENT_CREATION_STEPS[activeIndex] ?? AGENT_CREATION_STEPS[0];
    const progress = (activeIndex + 1) / AGENT_CREATION_STEPS.length;
    return {
        activeIndex,
        activeStep: activeStep.id,
        progress,
        title: `Create agent: ${activeStep.title}`,
        subtitle: activeStep.detail,
        stepOptions: AGENT_CREATION_STEPS.map((step, index) => ({
            id: step.id,
            label: step.title,
            detail: step.detail,
            selected: index === activeIndex,
            tone: index < activeIndex ? "success" : index === activeIndex ? "brand" : "muted",
        })),
        ready: validation.ok,
        filename: agentMarkdownFilename(input.state.name),
        markdownPreview: generateAgentMarkdown(input.state).split(/\r?\n/).slice(0, 10),
        warnings: validation.warnings,
        errors: validation.errors,
    };
}
export function CreateAgentWizard(props) {
    const model = createAgentWizardModel(props);
    return (_jsx(Pane, { width: props.width, title: model.title, tone: model.ready ? "success" : "brand", children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "gray", children: model.subtitle }), _jsx(ProgressBar, { ratio: model.progress, width: Math.max(10, props.width - 4), filledTone: "brand" }), _jsx(SelectList, { options: model.stepOptions, selectedIndex: model.activeIndex, visibleCount: 6, width: Math.max(24, props.width - 4) }), _jsxs(Box, { marginTop: 1, children: [_jsxs(Text, { color: model.ready ? "green" : "yellow", children: [model.ready ? "ready" : "needs input", " "] }), _jsx(Text, { color: "gray", children: model.filename })] })] }) }));
}
