"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from "react";
import { cn } from "@stigmer/theme";
import { getUserMessage } from "@stigmer/sdk";
import { serializeAgentInputYaml } from "../../library/serialize-resource-yaml.js";
/**
 * Wizard step 3: Review and create.
 *
 * Shows a summary card with key configuration details and a full
 * YAML preview of the agent that will be created. The "Create" action
 * is in the WizardNav footer, not in this component.
 */
export function ReviewStep({ org, data, isCreating, error, }) {
    const agentInput = useMemo(() => buildAgentInput(org, data), [org, data]);
    const yamlPreview = useMemo(() => serializeAgentInputYaml(agentInput), [agentInput]);
    return (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsxs("div", { children: [_jsx("h2", { className: "text-lg font-semibold text-foreground", children: "Review & Create" }), _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: "Review the agent configuration below, then create it." })] }), _jsx("div", { className: "rounded-lg border border-border p-4", children: _jsxs("dl", { className: "grid gap-x-6 gap-y-3 text-sm sm:grid-cols-2", children: [_jsx(SummaryItem, { label: "Name", value: data.name }), _jsx(SummaryItem, { label: "Slug", value: data.slug, mono: true }), _jsx(SummaryItem, { label: "Organization", value: org, mono: true }), _jsx(SummaryItem, { label: "Visibility", value: data.visibility === "public" ? "Public" : "Private" }), data.description && (_jsx(SummaryItem, { label: "Description", value: data.description, className: "sm:col-span-2" })), data.instructions && (_jsx(SummaryItem, { label: "Instructions", value: truncate(data.instructions, 120), className: "sm:col-span-2" })), _jsx(SummaryItem, { label: "MCP Servers", value: data.mcpServerUsages.length > 0
                                ? `${data.mcpServerUsages.length} configured`
                                : "None" }), _jsx(SummaryItem, { label: "Skills", value: data.skillRefs.length > 0
                                ? `${data.skillRefs.length} attached`
                                : "None" }), data.env.length > 0 && (_jsx(SummaryItem, { label: "Env Variables", value: `${data.env.length} declared` }))] }) }), _jsxs("div", { className: "space-y-2", children: [_jsx("h3", { className: "text-xs font-medium uppercase tracking-wider text-muted-foreground", children: "YAML Preview" }), _jsx("div", { className: "max-h-80 overflow-auto rounded-lg border border-border bg-muted-faint", children: _jsx("pre", { className: "p-4 font-mono text-xs leading-relaxed text-foreground", children: yamlPreview }) })] }), error && (_jsxs("div", { className: "rounded-md border border-destructive bg-muted-faint px-4 py-3", role: "alert", children: [_jsx("p", { className: "text-sm font-medium text-destructive", children: "Failed to create agent" }), _jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: getUserMessage(error) })] })), isCreating && (_jsx("p", { className: "text-sm text-muted-foreground", "aria-live": "polite", children: "Creating agent\u2026" }))] }));
}
// ---------------------------------------------------------------------------
// Summary item
// ---------------------------------------------------------------------------
function SummaryItem({ label, value, mono, className, }) {
    return (_jsxs("div", { className: className, children: [_jsx("dt", { className: "text-xs text-muted-foreground", children: label }), _jsx("dd", { className: cn("mt-0.5 text-sm text-foreground", mono && "font-mono"), children: value })] }));
}
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function truncate(text, maxLength) {
    if (text.length <= maxLength)
        return text;
    return text.slice(0, maxLength) + "…";
}
/**
 * Transforms wizard data into the SDK `AgentInput` shape for submission.
 * Exported for reuse by `AgentCreationWizard`.
 */
export function buildAgentInput(org, data) {
    const input = {
        name: data.name.trim(),
        org,
        ...(data.slug && { slug: data.slug }),
        ...(data.description && { description: data.description.trim() }),
        ...(data.iconUrl && { iconUrl: data.iconUrl.trim() }),
        ...(data.instructions && { instructions: data.instructions }),
    };
    if (data.mcpServerUsages.length > 0) {
        input.mcpServerUsages = data.mcpServerUsages;
    }
    if (data.skillRefs.length > 0) {
        input.skillRefs = data.skillRefs;
    }
    if (data.env.length > 0) {
        const env = {};
        for (const entry of data.env) {
            if (!entry.key)
                continue;
            env[entry.key] = {
                ...(entry.isSecret && { isSecret: true }),
                ...(entry.description && { description: entry.description }),
                ...(entry.optional && { optional: true }),
            };
        }
        if (Object.keys(env).length > 0) {
            input.env = env;
        }
    }
    return input;
}
//# sourceMappingURL=ReviewStep.js.map