"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useCallback } from "react";
const AI_KINDS = new Set(["agent_call", "llm_call", "eval"]);
const INVOCATION_KINDS = new Set(["http_call", "grpc_call", "activity_call", "run_workflow"]);
/**
 * Runtime tab — timeout, retry, budget, and execution policies.
 *
 * Content varies by task kind category:
 * - AI kinds: model, timeout, temperature, max cost
 * - Invocation kinds: timeout
 * - Container kinds: concurrency, join policy
 *
 * @since T10 (Inspector Panel Refactor)
 */
export const RuntimeTab = memo(function RuntimeTab({ node, kindString, descriptor, onFieldChange, }) {
    const config = node.config;
    const isAi = AI_KINDS.has(kindString);
    const isInvocation = INVOCATION_KINDS.has(kindString);
    const handleChange = useCallback((field, value) => onFieldChange(field, value), [onFieldChange]);
    return (_jsxs("div", { className: "flex flex-col gap-4 px-3 py-3", children: [isAi && (_jsx(AgentRuntimeSection, { config: config, kindString: kindString, onChange: handleChange })), isInvocation && (_jsx(TimeoutSection, { config: config, kindString: kindString, onChange: handleChange })), kindString === "fork" && (_jsx(ForkRuntimeSection, { config: config, onChange: handleChange })), kindString === "for_each" && (_jsx(ForEachRuntimeSection, { config: config, onChange: handleChange })), !isAi && !isInvocation && kindString !== "fork" && kindString !== "for_each" && (_jsx("p", { className: "text-xs text-[var(--stgm-muted-foreground,#737373)]", children: "No runtime settings available for this task kind." }))] }));
});
// ---------------------------------------------------------------------------
// Agent/LLM runtime
// ---------------------------------------------------------------------------
function AgentRuntimeSection({ config, kindString, onChange, }) {
    const nestedConfig = (config.config ?? {});
    const handleNestedChange = useCallback((field, value) => {
        onChange("config", { ...nestedConfig, [field]: value === "" ? undefined : value });
    }, [nestedConfig, onChange]);
    return (_jsxs("section", { className: "flex flex-col gap-3", children: [_jsx(SectionLabel, { children: "Execution" }), kindString === "agent_call" && (_jsx(FieldRow, { label: "Model", hint: "Override agent default model", children: _jsx("input", { type: "text", value: typeof nestedConfig.model === "string" ? nestedConfig.model : "", onChange: (e) => handleNestedChange("model", e.target.value || undefined), placeholder: "Agent default", className: inputClass }) })), _jsx(FieldRow, { label: "Timeout", hint: "Seconds before the task is cancelled", children: _jsx("input", { type: "number", value: typeof nestedConfig.timeout === "number" ? nestedConfig.timeout : "", onChange: (e) => handleNestedChange("timeout", e.target.value ? parseInt(e.target.value, 10) : undefined), placeholder: "300", min: 1, max: 3600, className: inputClass }) }), kindString === "agent_call" && (_jsx(FieldRow, { label: "Temperature", hint: "0.0 (deterministic) to 1.0 (creative)", children: _jsx("input", { type: "number", value: typeof nestedConfig.temperature === "number" ? nestedConfig.temperature : "", onChange: (e) => handleNestedChange("temperature", e.target.value ? parseFloat(e.target.value) : undefined), placeholder: "0.7", min: 0, max: 1, step: 0.1, className: inputClass }) })), _jsx(FieldRow, { label: "Max cost", hint: "Per-task cost cap in micro-USD", children: _jsx("input", { type: "number", value: typeof nestedConfig.max_cost_micros === "number" ? nestedConfig.max_cost_micros : "", onChange: (e) => handleNestedChange("max_cost_micros", e.target.value ? parseInt(e.target.value, 10) : undefined), placeholder: "No limit", min: 0, className: inputClass }) })] }));
}
// ---------------------------------------------------------------------------
// Timeout section (invocation kinds)
// ---------------------------------------------------------------------------
function TimeoutSection({ config, kindString, onChange, }) {
    const fieldName = kindString === "http_call" ? "timeout_seconds" : "timeout";
    const currentValue = config[fieldName];
    return (_jsxs("section", { className: "flex flex-col gap-3", children: [_jsx(SectionLabel, { children: "Execution" }), _jsx(FieldRow, { label: "Timeout", hint: "Seconds before the request is cancelled", children: _jsx("input", { type: "number", value: typeof currentValue === "number" ? currentValue : "", onChange: (e) => onChange(fieldName, e.target.value ? parseInt(e.target.value, 10) : undefined), placeholder: "30", min: 1, className: inputClass }) })] }));
}
// ---------------------------------------------------------------------------
// Fork runtime
// ---------------------------------------------------------------------------
function ForkRuntimeSection({ config, onChange, }) {
    const compete = config.compete === true;
    return (_jsxs("section", { className: "flex flex-col gap-3", children: [_jsx(SectionLabel, { children: "Join policy" }), _jsxs("label", { className: "flex cursor-pointer items-center gap-2", children: [_jsx("input", { type: "checkbox", checked: compete, onChange: (e) => onChange("compete", e.target.checked || undefined), className: "h-4 w-4 rounded border-[var(--stgm-border,#d4d4d8)] text-[var(--stgm-primary,#6366f1)]" }), _jsx("span", { className: "text-xs text-[var(--stgm-foreground,#1a1a2e)]", children: "Compete mode (first branch wins)" })] }), _jsx("p", { className: "text-[10px] text-[var(--stgm-muted-foreground,#737373)]", children: compete
                    ? "The join resumes when any branch completes. Other branches are cancelled."
                    : "The join waits for all branches to complete before continuing." })] }));
}
// ---------------------------------------------------------------------------
// ForEach runtime
// ---------------------------------------------------------------------------
function ForEachRuntimeSection({ config, onChange, }) {
    return (_jsxs("section", { className: "flex flex-col gap-3", children: [_jsx(SectionLabel, { children: "Iteration" }), _jsx(FieldRow, { label: "Collection", hint: "Expression that produces the items to iterate", children: _jsx("input", { type: "text", value: typeof config.collection === "string" ? config.collection : "", onChange: (e) => onChange("collection", e.target.value || undefined), placeholder: '${ $context.items }', className: inputClass }) })] }));
}
// ---------------------------------------------------------------------------
// Shared
// ---------------------------------------------------------------------------
const inputClass = "w-full rounded-md border border-[var(--stgm-border,#d4d4d8)] bg-[var(--stgm-background,#fff)] px-2 py-1.5 text-xs text-[var(--stgm-foreground,#1a1a2e)] placeholder:text-[var(--stgm-muted-foreground,#a3a3a3)] focus:outline-none focus:ring-1 focus:ring-[var(--stgm-ring,#3b82f6)]";
function SectionLabel({ children }) {
    return (_jsx("h4", { className: "text-[11px] font-semibold uppercase tracking-wide text-[var(--stgm-muted-foreground,#737373)]", children: children }));
}
function FieldRow({ label, hint, children, }) {
    return (_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("label", { className: "text-[11px] font-medium text-[var(--stgm-foreground,#1a1a2e)]", children: label }), hint && (_jsx("p", { className: "text-[10px] leading-tight text-[var(--stgm-muted-foreground,#737373)]", children: hint })), children] }));
}
//# sourceMappingURL=RuntimeTab.js.map