"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { useEffect, useState } from "react";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@open-mercato/ui/primitives/dialog";
import { Button } from "@open-mercato/ui/primitives/button";
import { Input } from "@open-mercato/ui/primitives/input";
import { Textarea } from "@open-mercato/ui/primitives/textarea";
import { Checkbox } from "@open-mercato/ui/primitives/checkbox";
import { Badge } from "@open-mercato/ui/primitives/badge";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue
} from "@open-mercato/ui/primitives/select";
import { Alert, AlertDescription } from "@open-mercato/ui/primitives/alert";
import { ChevronDown, Plus, Trash2 } from "lucide-react";
import { sanitizeId } from "../lib/graph-utils.js";
import { WorkflowSelector } from "./WorkflowSelector.js";
import { JsonBuilder } from "@open-mercato/ui/backend/JsonBuilder";
import { StartPreConditionsEditor } from "./fields/StartPreConditionsEditor.js";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { useDialogKeyHandler } from "@open-mercato/ui/hooks/useDialogKeyHandler";
import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
import { isFutureIsoDateString, isValidDurationString } from "../data/validators.js";
function NodeEditDialog({ node, isOpen, onClose, onSave, onDelete }) {
  const t = useT();
  const { confirm: confirmDialog, ConfirmDialogElement } = useConfirmDialog();
  const [stepName, setStepName] = useState("");
  const [description, setDescription] = useState("");
  const [assignedTo, setAssignedTo] = useState("");
  const [assignedToRoles, setAssignedToRoles] = useState("");
  const [formKey, setFormKey] = useState("");
  const [activityType, setActivityType] = useState("");
  const [activityId, setActivityId] = useState("");
  const [timeout, setTimeout] = useState("");
  const [showAdvanced, setShowAdvanced] = useState(false);
  const [advancedConfig, setAdvancedConfig] = useState({});
  const [formFields, setFormFields] = useState([]);
  const [expandedFields, setExpandedFields] = useState(/* @__PURE__ */ new Set());
  const [isJsonSchemaFormat, setIsJsonSchemaFormat] = useState(false);
  const [assignmentRule, setAssignmentRule] = useState("");
  const [slaDuration, setSlaDuration] = useState("");
  const [escalationRules, setEscalationRules] = useState([]);
  const [subWorkflowId, setSubWorkflowId] = useState("");
  const [subWorkflowVersion, setSubWorkflowVersion] = useState("");
  const [inputMappings, setInputMappings] = useState([]);
  const [outputMappings, setOutputMappings] = useState([]);
  const [showWorkflowSelector, setShowWorkflowSelector] = useState(false);
  const [signalName, setSignalName] = useState("");
  const [signalTimeout, setSignalTimeout] = useState("");
  const [timerDuration, setTimerDuration] = useState("");
  const [timerUntil, setTimerUntil] = useState("");
  const [stepActivities, setStepActivities] = useState([]);
  const [expandedStepActivities, setExpandedStepActivities] = useState(/* @__PURE__ */ new Set());
  const [preConditions, setPreConditions] = useState([]);
  const [fieldErrors, setFieldErrors] = useState({});
  const convertJsonSchemaToFields = (schema) => {
    if (!schema || !schema.properties) return [];
    const fields = [];
    const properties = schema.properties;
    const required = schema.required || [];
    for (const [name, prop] of Object.entries(properties)) {
      const propDef = prop;
      const field = {
        name,
        type: mapJsonSchemaTypeToFieldType(propDef),
        label: propDef.title || name,
        required: required.includes(name),
        placeholder: propDef.description || void 0
      };
      if (propDef.enum) {
        field.options = propDef.enum;
      }
      if (propDef.default !== void 0) {
        field.defaultValue = String(propDef.default);
      }
      fields.push(field);
    }
    return fields;
  };
  const mapJsonSchemaTypeToFieldType = (propDef) => {
    if (propDef.enum) return "select";
    switch (propDef.type) {
      case "string":
        if (propDef.format === "email") return "email";
        if (propDef.format === "uri") return "url";
        if (propDef.format === "date") return "date";
        if (propDef.format === "time") return "time";
        if (propDef.format === "date-time") return "datetime-local";
        if (propDef.maxLength && propDef.maxLength > 200) return "textarea";
        return "text";
      case "number":
      case "integer":
        return "number";
      case "boolean":
        return "checkbox";
      default:
        return "text";
    }
  };
  useEffect(() => {
    if (node && isOpen) {
      const nodeData = node.data;
      setStepName(nodeData?.stepName || nodeData?.label || "");
      setDescription(nodeData?.description || "");
      setAssignedTo(nodeData?.assignedTo || "");
      setAssignedToRoles(nodeData?.assignedToRoles?.join(", ") || "");
      setFormKey(nodeData?.formKey || "");
      setActivityType(nodeData?.activityType || "");
      setActivityId(nodeData?.activityId || "");
      setTimeout(nodeData?.timeout || "");
      if (node.type === "userTask" && nodeData?.userTaskConfig) {
        setAssignmentRule(nodeData.userTaskConfig.assignmentRule || nodeData.assignmentRule || "");
        setSlaDuration(nodeData.userTaskConfig.slaDuration || nodeData.slaDuration || "");
        setEscalationRules(nodeData.userTaskConfig.escalationRules || nodeData.escalationRules || []);
      } else {
        setAssignmentRule("");
        setSlaDuration("");
        setEscalationRules([]);
      }
      if (node.type === "subWorkflow" && nodeData?.config) {
        setSubWorkflowId(nodeData.config.subWorkflowId || "");
        setSubWorkflowVersion(nodeData.config.version?.toString() || "");
        if (nodeData.config.inputMapping) {
          const mappings = Object.entries(nodeData.config.inputMapping).map(([key, value]) => ({
            key,
            value
          }));
          setInputMappings(mappings);
        } else {
          setInputMappings([]);
        }
        if (nodeData.config.outputMapping) {
          const mappings = Object.entries(nodeData.config.outputMapping).map(([key, value]) => ({
            key,
            value
          }));
          setOutputMappings(mappings);
        } else {
          setOutputMappings([]);
        }
      } else {
        setSubWorkflowId("");
        setSubWorkflowVersion("");
        setInputMappings([]);
        setOutputMappings([]);
      }
      if (node.type === "waitForSignal" && nodeData?.signalConfig) {
        setSignalName(nodeData.signalConfig.signalName || "");
        setSignalTimeout(nodeData.signalConfig.timeout || "PT5M");
      } else {
        setSignalName("");
        setSignalTimeout("");
      }
      if (node.type === "waitForTimer") {
        setTimerDuration(nodeData?.config?.duration || "");
        setTimerUntil(nodeData?.config?.until || "");
      } else {
        setTimerDuration("");
        setTimerUntil("");
      }
      if (node.type === "automated" && nodeData?.activities) {
        setStepActivities(nodeData.activities);
      } else if (node.type === "automated") {
        setStepActivities([]);
      }
      if (node.type === "start" && nodeData?.preConditions) {
        setPreConditions(nodeData.preConditions);
      } else if (node.type === "start") {
        setPreConditions([]);
      }
      if (nodeData?.userTaskConfig?.formSchema) {
        const schema = nodeData.userTaskConfig.formSchema;
        if (schema.fields && Array.isArray(schema.fields)) {
          setFormFields(schema.fields);
          setIsJsonSchemaFormat(false);
        } else if (schema.properties) {
          setFormFields(convertJsonSchemaToFields(schema));
          setIsJsonSchemaFormat(true);
        } else {
          setFormFields([]);
          setIsJsonSchemaFormat(false);
        }
      } else {
        setFormFields([]);
        setIsJsonSchemaFormat(false);
      }
      const advancedFields = {};
      if (nodeData?.userTaskConfig) {
        advancedFields.userTaskConfig = nodeData.userTaskConfig;
      }
      if (nodeData?.retryPolicy) {
        advancedFields.retryPolicy = nodeData.retryPolicy;
      }
      setAdvancedConfig(advancedFields);
      setExpandedFields(/* @__PURE__ */ new Set());
      setFieldErrors({});
    }
  }, [node, isOpen]);
  const addFormField = () => {
    const newField = {
      name: `field_${Date.now()}`,
      type: "text",
      label: t("workflows.form.newField"),
      required: false,
      placeholder: ""
    };
    setFormFields((prev) => [...prev, newField]);
    const newExpanded = new Set(expandedFields);
    newExpanded.add(formFields.length);
    setExpandedFields(newExpanded);
  };
  const removeFormField = async (index) => {
    const confirmed = await confirmDialog({
      title: t("workflows.confirm.removeField"),
      variant: "destructive"
    });
    if (confirmed) {
      setFormFields((prev) => prev.filter((_, i) => i !== index));
      const newExpanded = new Set(expandedFields);
      newExpanded.delete(index);
      setExpandedFields(newExpanded);
    }
  };
  const updateFormField = (index, field, value) => {
    const updated = [...formFields];
    updated[index] = { ...updated[index], [field]: value };
    setFormFields(updated);
  };
  const toggleFieldExpanded = (index) => {
    const newExpanded = new Set(expandedFields);
    if (newExpanded.has(index)) {
      newExpanded.delete(index);
    } else {
      newExpanded.add(index);
    }
    setExpandedFields(newExpanded);
  };
  const handleWorkflowSelect = (workflowId, workflow) => {
    setSubWorkflowId(workflowId);
    setSubWorkflowVersion(workflow.version.toString());
    setShowWorkflowSelector(false);
  };
  const handleSave = () => {
    if (!node) return;
    const errors = {};
    if (node.type === "waitForTimer") {
      if (timerDuration && !isValidDurationString(timerDuration)) {
        errors.timerDuration = t("workflows.validation.invalidDuration");
      }
      if (timerUntil && !isFutureIsoDateString(timerUntil)) {
        errors.timerUntil = t("workflows.validation.untilMustBeFuture");
      }
    }
    if (node.type === "waitForSignal" && signalTimeout && !isValidDurationString(signalTimeout)) {
      errors.signalTimeout = t("workflows.validation.invalidDuration");
    }
    if (Object.keys(errors).length > 0) {
      setFieldErrors(errors);
      return;
    }
    setFieldErrors({});
    const sanitizedId = sanitizeId(node.id);
    if (sanitizedId !== node.id) {
      alert(t("workflows.nodeEditor.stepIdSanitized", { from: node.id, to: sanitizedId }));
    }
    const updates = {
      stepName,
      label: stepName,
      // Keep label for backward compatibility
      description: description || void 0,
      timeout: timeout || void 0
    };
    if (node.type === "userTask") {
      updates.assignedTo = assignedTo || void 0;
      updates.assignedToRoles = assignedToRoles ? assignedToRoles.split(",").map((r) => r.trim()).filter(Boolean) : [];
      updates.formKey = formKey || void 0;
      updates.userTaskConfig = {
        ...formFields.length > 0 && {
          formSchema: {
            fields: formFields
          }
        },
        ...assignedTo && { assignedTo },
        ...assignedToRoles && { assignedToRoles: assignedToRoles.split(",").map((r) => r.trim()).filter(Boolean) },
        // Preserve advanced fields loaded from node data
        ...assignmentRule && { assignmentRule },
        ...slaDuration && { slaDuration },
        ...escalationRules && escalationRules.length > 0 && { escalationRules }
      };
    }
    if (node.type === "automated") {
      updates.activityType = activityType || void 0;
      updates.activityId = activityId || void 0;
    }
    if (node.type === "subWorkflow") {
      const config = {};
      if (subWorkflowId) {
        config.subWorkflowId = subWorkflowId;
      }
      if (subWorkflowVersion) {
        const versionNum = parseInt(subWorkflowVersion, 10);
        if (!isNaN(versionNum)) {
          config.version = versionNum;
        }
      }
      if (inputMappings.length > 0) {
        config.inputMapping = inputMappings.filter((m) => m.key && m.value).reduce((acc, m) => ({ ...acc, [m.key]: m.value }), {});
      }
      if (outputMappings.length > 0) {
        config.outputMapping = outputMappings.filter((m) => m.key && m.value).reduce((acc, m) => ({ ...acc, [m.key]: m.value }), {});
      }
      if (Object.keys(config).length > 0) {
        updates.config = config;
      }
    }
    if (node.type === "waitForSignal") {
      const config = {};
      if (signalName) {
        config.signalName = signalName;
      }
      if (signalTimeout) {
        config.timeout = signalTimeout;
      }
      if (Object.keys(config).length > 0) {
        updates.signalConfig = config;
      }
    }
    if (node.type === "waitForTimer") {
      const config = {};
      if (timerDuration) {
        config.duration = timerDuration;
      } else if (timerUntil) {
        config.until = timerUntil;
      }
      updates.config = Object.keys(config).length > 0 ? config : void 0;
    }
    if (node.type === "automated" && stepActivities.length > 0) {
      updates.activities = stepActivities;
    }
    if (node.type === "start") {
      updates.preConditions = preConditions.filter((pc) => pc.ruleId && pc.ruleId.trim());
    }
    if (advancedConfig && Object.keys(advancedConfig).length > 0) {
      Object.assign(updates, advancedConfig);
    }
    onSave(sanitizedId, updates);
    onClose();
  };
  const handleDelete = () => {
    if (!node || !onDelete) return;
    onDelete(node.id);
  };
  const handleKeyDown = useDialogKeyHandler({ onConfirm: handleSave, onCancel: onClose });
  if (!isOpen || !node) return null;
  const nodeTypeLabel = {
    start: t("workflows.nodeTypes.start"),
    end: t("workflows.nodeTypes.end"),
    userTask: t("workflows.nodeTypes.userTask"),
    automated: t("workflows.nodeTypes.automated"),
    decision: t("workflows.nodeTypes.decision"),
    waitForSignal: t("workflows.nodeTypes.waitForSignal"),
    waitForTimer: t("workflows.nodeTypes.waitForTimer"),
    subWorkflow: t("workflows.nodeTypes.subWorkflow"),
    parallelFork: t("workflows.nodeTypes.parallelFork"),
    parallelJoin: t("workflows.nodeTypes.parallelJoin")
  }[node.type || "automated"];
  const isEditable = node.type !== "end";
  const isStartNode = node.type === "start";
  const badgeVariant = node.type === "start" ? "default" : node.type === "end" ? "secondary" : node.type === "userTask" ? "outline" : "muted";
  return /* @__PURE__ */ jsxs(Dialog, { open: isOpen, onOpenChange: onClose, children: [
    /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-2xl max-h-[90vh] overflow-y-auto", onKeyDown: handleKeyDown, children: [
      /* @__PURE__ */ jsxs(DialogHeader, { children: [
        /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
          /* @__PURE__ */ jsx(DialogTitle, { children: t("workflows.nodeEditor.title") }),
          /* @__PURE__ */ jsx(Badge, { variant: badgeVariant, children: nodeTypeLabel })
        ] }),
        /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-sm text-muted-foreground", children: [
          /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
            /* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
              t("workflows.fields.id"),
              ":"
            ] }),
            /* @__PURE__ */ jsx("code", { className: "px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-mono", children: node.id })
          ] }),
          node.data?.stepName && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
            /* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
              t("workflows.fields.name"),
              ":"
            ] }),
            /* @__PURE__ */ jsx("span", { children: node.data.stepName })
          ] })
        ] })
      ] }),
      /* @__PURE__ */ jsx("div", { className: "space-y-4", children: !isEditable ? /* @__PURE__ */ jsx(Alert, { variant: "info", children: /* @__PURE__ */ jsx(AlertDescription, { children: t("workflows.nodeEditor.endStepsNotEditable") }) }) : isStartNode ? /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
        /* @__PURE__ */ jsx(Alert, { variant: "info", children: /* @__PURE__ */ jsx(AlertDescription, { children: t("workflows.nodeEditor.startStepsInfo") }) }),
        /* @__PURE__ */ jsx(
          StartPreConditionsEditor,
          {
            value: preConditions,
            setValue: setPreConditions
          }
        )
      ] }) : /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsxs("label", { className: "block text-sm font-medium text-foreground mb-1", children: [
            t("workflows.form.stepName"),
            " *"
          ] }),
          /* @__PURE__ */ jsx(
            Input,
            {
              type: "text",
              value: stepName,
              onChange: (e) => setStepName(e.target.value),
              placeholder: t("workflows.form.placeholders.stepName"),
              autoFocus: true
            }
          ),
          /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.stepName") })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.form.description") }),
          /* @__PURE__ */ jsx(
            Textarea,
            {
              value: description,
              onChange: (e) => setDescription(e.target.value),
              placeholder: t("workflows.form.placeholders.description"),
              rows: 3
            }
          ),
          /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.description") })
        ] }),
        node.type !== "waitForSignal" && node.type !== "waitForTimer" && /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.form.timeout") }),
          /* @__PURE__ */ jsx(
            Input,
            {
              type: "text",
              value: timeout,
              onChange: (e) => setTimeout(e.target.value),
              placeholder: t("workflows.form.placeholders.timeout")
            }
          ),
          /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.timeout") })
        ] }),
        node.type === "userTask" && /* @__PURE__ */ jsxs(Fragment, { children: [
          /* @__PURE__ */ jsx("div", { className: "border-t border-border pt-4 mt-4", children: /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-3", children: t("workflows.nodeEditor.userTaskConfig") }) }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.form.assignedTo") }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "text",
                value: assignedTo,
                onChange: (e) => setAssignedTo(e.target.value),
                placeholder: t("workflows.form.placeholders.userId")
              }
            ),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.assignedTo") })
          ] }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.form.assignedToRoles") }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "text",
                value: assignedToRoles,
                onChange: (e) => setAssignedToRoles(e.target.value),
                placeholder: t("workflows.form.placeholders.roles")
              }
            ),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.assignedToRoles") })
          ] }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.form.formKey") }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "text",
                value: formKey,
                onChange: (e) => setFormKey(e.target.value),
                placeholder: t("workflows.form.placeholders.formKey")
              }
            ),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.formKey") })
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "border-t border-border pt-4 mt-4", children: [
            /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
              /* @__PURE__ */ jsxs("div", { children: [
                /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground", children: t("workflows.form.formFields", { count: formFields.length }) }),
                /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.formFields") })
              ] }),
              /* @__PURE__ */ jsxs(
                Button,
                {
                  type: "button",
                  size: "sm",
                  onClick: addFormField,
                  children: [
                    /* @__PURE__ */ jsx(Plus, { className: "size-3 mr-1" }),
                    t("workflows.form.addField")
                  ]
                }
              )
            ] }),
            isJsonSchemaFormat && /* @__PURE__ */ jsx(Alert, { variant: "info", className: "mb-3", children: /* @__PURE__ */ jsx(AlertDescription, { children: t("workflows.nodeEditor.jsonSchemaFormat") }) }),
            formFields.length === 0 && /* @__PURE__ */ jsx("div", { className: "p-4 text-center text-sm text-muted-foreground bg-muted rounded-lg border border-border", children: t("workflows.nodeEditor.noFormFields") }),
            /* @__PURE__ */ jsx("div", { className: "space-y-2", children: formFields.map((field, index) => {
              const isExpanded = expandedFields.has(index);
              return /* @__PURE__ */ jsxs("div", { className: "border border-border rounded-lg bg-muted", children: [
                /* @__PURE__ */ jsxs(
                  Button,
                  {
                    type: "button",
                    variant: "ghost",
                    onClick: () => toggleFieldExpanded(index),
                    className: "h-auto w-full justify-between rounded-t-lg px-4 py-3 text-left hover:bg-muted/80",
                    children: [
                      /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                        /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
                          /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold text-foreground", children: field.label || field.name }),
                          /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: field.type }),
                          field.required && /* @__PURE__ */ jsx(Badge, { variant: "destructive", className: "text-xs", children: t("workflows.form.required") })
                        ] }),
                        /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground mt-1", children: [
                          "Field name: ",
                          /* @__PURE__ */ jsx("code", { className: "bg-background px-1 rounded", children: field.name })
                        ] })
                      ] }),
                      /* @__PURE__ */ jsx(
                        ChevronDown,
                        {
                          className: `size-5 text-muted-foreground transition-transform ${isExpanded ? "rotate-180" : ""}`
                        }
                      )
                    ]
                  }
                ),
                isExpanded && /* @__PURE__ */ jsxs("div", { className: "px-4 pb-4 space-y-3 border-t border-border bg-background", children: [
                  /* @__PURE__ */ jsxs("div", { className: "pt-3", children: [
                    /* @__PURE__ */ jsxs("label", { className: "block text-xs font-medium text-foreground mb-1", children: [
                      t("workflows.form.fieldName"),
                      " *"
                    ] }),
                    /* @__PURE__ */ jsx(
                      Input,
                      {
                        type: "text",
                        size: "sm",
                        value: field.name,
                        onChange: (e) => updateFormField(index, "name", e.target.value),
                        placeholder: t("workflows.form.placeholders.fieldName")
                      }
                    ),
                    /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.fieldName") })
                  ] }),
                  /* @__PURE__ */ jsxs("div", { children: [
                    /* @__PURE__ */ jsxs("label", { className: "block text-xs font-medium text-foreground mb-1", children: [
                      t("workflows.form.fieldLabel"),
                      " *"
                    ] }),
                    /* @__PURE__ */ jsx(
                      Input,
                      {
                        type: "text",
                        size: "sm",
                        value: field.label,
                        onChange: (e) => updateFormField(index, "label", e.target.value),
                        placeholder: t("workflows.form.placeholders.fieldLabel")
                      }
                    ),
                    /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.fieldLabel") })
                  ] }),
                  /* @__PURE__ */ jsxs("div", { children: [
                    /* @__PURE__ */ jsxs("label", { className: "block text-xs font-medium text-foreground mb-1", children: [
                      t("workflows.form.fieldType"),
                      " *"
                    ] }),
                    /* @__PURE__ */ jsxs(
                      Select,
                      {
                        value: field.type,
                        onValueChange: (value) => updateFormField(index, "type", value),
                        children: [
                          /* @__PURE__ */ jsx(SelectTrigger, { size: "sm", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
                          /* @__PURE__ */ jsxs(SelectContent, { children: [
                            /* @__PURE__ */ jsx(SelectItem, { value: "text", children: t("workflows.form.fieldTypes.text") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "number", children: t("workflows.form.fieldTypes.number") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "email", children: t("workflows.form.fieldTypes.email") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "tel", children: t("workflows.form.fieldTypes.tel") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "url", children: t("workflows.form.fieldTypes.url") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "textarea", children: t("workflows.form.fieldTypes.textarea") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "select", children: t("workflows.form.fieldTypes.select") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "radio", children: t("workflows.form.fieldTypes.radio") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "checkbox", children: t("workflows.form.fieldTypes.checkbox") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "date", children: t("workflows.form.fieldTypes.date") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "time", children: t("workflows.form.fieldTypes.time") }),
                            /* @__PURE__ */ jsx(SelectItem, { value: "datetime-local", children: t("workflows.form.fieldTypes.datetime-local") })
                          ] })
                        ]
                      }
                    )
                  ] }),
                  /* @__PURE__ */ jsxs("div", { children: [
                    /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-foreground mb-1", children: t("workflows.form.placeholder") }),
                    /* @__PURE__ */ jsx(
                      Input,
                      {
                        type: "text",
                        size: "sm",
                        value: field.placeholder || "",
                        onChange: (e) => updateFormField(index, "placeholder", e.target.value),
                        placeholder: t("workflows.form.placeholders.placeholder")
                      }
                    )
                  ] }),
                  /* @__PURE__ */ jsxs("div", { children: [
                    /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-foreground mb-1", children: t("workflows.form.defaultValue") }),
                    /* @__PURE__ */ jsx(
                      Input,
                      {
                        type: "text",
                        size: "sm",
                        value: field.defaultValue || "",
                        onChange: (e) => updateFormField(index, "defaultValue", e.target.value),
                        placeholder: t("workflows.form.placeholders.defaultValue")
                      }
                    )
                  ] }),
                  (field.type === "select" || field.type === "radio") && /* @__PURE__ */ jsxs("div", { children: [
                    /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-foreground mb-1", children: t("workflows.form.options") }),
                    /* @__PURE__ */ jsx(
                      Input,
                      {
                        type: "text",
                        size: "sm",
                        value: field.options?.join(", ") || "",
                        onChange: (e) => updateFormField(index, "options", e.target.value.split(",").map((o) => o.trim()).filter(Boolean)),
                        placeholder: t("workflows.form.placeholders.options")
                      }
                    ),
                    /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.options") })
                  ] }),
                  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 text-xs font-medium text-foreground", children: [
                    /* @__PURE__ */ jsx(
                      Checkbox,
                      {
                        checked: field.required,
                        onCheckedChange: (checked) => updateFormField(index, "required", checked === true)
                      }
                    ),
                    t("workflows.form.requiredField")
                  ] }) }),
                  /* @__PURE__ */ jsx("div", { className: "border-t border-border pt-3", children: /* @__PURE__ */ jsxs(
                    Button,
                    {
                      type: "button",
                      variant: "destructive",
                      size: "sm",
                      onClick: () => removeFormField(index),
                      children: [
                        /* @__PURE__ */ jsx(Trash2, { className: "size-4 mr-1" }),
                        t("workflows.form.removeField")
                      ]
                    }
                  ) })
                ] })
              ] }, index);
            }) })
          ] })
        ] }),
        node.type === "automated" && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", { className: "border-t border-border pt-4 mt-4", children: [
          /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
            /* @__PURE__ */ jsxs("div", { children: [
              /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground", children: t("workflows.form.stepActivities", { count: stepActivities.length }) }),
              /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.activities") })
            ] }),
            /* @__PURE__ */ jsxs(
              Button,
              {
                type: "button",
                size: "sm",
                onClick: () => {
                  setStepActivities([
                    ...stepActivities,
                    {
                      activityId: `activity_${stepActivities.length + 1}`,
                      activityName: `${t("workflows.activities.singular")} ${stepActivities.length + 1}`,
                      activityType: "CALL_API",
                      config: {},
                      async: false
                    }
                  ]);
                },
                children: [
                  /* @__PURE__ */ jsx(Plus, { className: "size-3 mr-1" }),
                  t("workflows.form.addActivity")
                ]
              }
            )
          ] }),
          stepActivities.length === 0 && /* @__PURE__ */ jsx("div", { className: "p-4 text-center text-sm text-muted-foreground bg-muted rounded-lg border border-border", children: t("workflows.nodeEditor.noActivities") }),
          /* @__PURE__ */ jsx("div", { className: "space-y-2", children: stepActivities.map((activity, index) => {
            const isExpanded = expandedStepActivities.has(index);
            return /* @__PURE__ */ jsxs("div", { className: "border border-border rounded-lg bg-muted", children: [
              /* @__PURE__ */ jsxs(
                Button,
                {
                  type: "button",
                  variant: "ghost",
                  onClick: () => {
                    const newExpanded = new Set(expandedStepActivities);
                    if (isExpanded) {
                      newExpanded.delete(index);
                    } else {
                      newExpanded.add(index);
                    }
                    setExpandedStepActivities(newExpanded);
                  },
                  className: "h-auto w-full justify-between rounded-t-lg px-4 py-3 text-left hover:bg-muted/80",
                  children: [
                    /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                      /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
                        /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold text-foreground", children: activity.activityName || activity.activityId || `Activity ${index + 1}` }),
                        /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: activity.activityType }),
                        activity.async && /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs", children: t("workflows.form.async") })
                      ] }),
                      /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground mt-1", children: [
                        "ID: ",
                        /* @__PURE__ */ jsx("code", { className: "bg-background px-1 rounded", children: activity.activityId })
                      ] })
                    ] }),
                    /* @__PURE__ */ jsx(
                      ChevronDown,
                      {
                        className: `size-5 text-muted-foreground transition-transform ${isExpanded ? "rotate-180" : ""}`
                      }
                    )
                  ]
                }
              ),
              isExpanded && /* @__PURE__ */ jsxs("div", { className: "px-4 pb-4 space-y-3 border-t border-border bg-background", children: [
                /* @__PURE__ */ jsxs("div", { className: "pt-3", children: [
                  /* @__PURE__ */ jsxs("label", { className: "block text-xs font-medium text-foreground mb-1", children: [
                    t("workflows.form.activityId"),
                    " *"
                  ] }),
                  /* @__PURE__ */ jsx(
                    Input,
                    {
                      type: "text",
                      size: "sm",
                      value: activity.activityId,
                      onChange: (e) => {
                        const updated = [...stepActivities];
                        updated[index].activityId = e.target.value;
                        setStepActivities(updated);
                      },
                      placeholder: t("workflows.form.placeholders.activityId")
                    }
                  )
                ] }),
                /* @__PURE__ */ jsxs("div", { children: [
                  /* @__PURE__ */ jsxs("label", { className: "block text-xs font-medium text-foreground mb-1", children: [
                    t("workflows.form.activityName"),
                    " *"
                  ] }),
                  /* @__PURE__ */ jsx(
                    Input,
                    {
                      type: "text",
                      size: "sm",
                      value: activity.activityName || "",
                      onChange: (e) => {
                        const updated = [...stepActivities];
                        updated[index].activityName = e.target.value;
                        setStepActivities(updated);
                      },
                      placeholder: t("workflows.form.placeholders.activityName")
                    }
                  )
                ] }),
                /* @__PURE__ */ jsxs("div", { children: [
                  /* @__PURE__ */ jsxs("label", { className: "block text-xs font-medium text-foreground mb-1", children: [
                    t("workflows.form.activityType"),
                    " *"
                  ] }),
                  /* @__PURE__ */ jsxs(
                    Select,
                    {
                      value: activity.activityType,
                      onValueChange: (value) => {
                        const updated = [...stepActivities];
                        updated[index].activityType = value;
                        setStepActivities(updated);
                      },
                      children: [
                        /* @__PURE__ */ jsx(SelectTrigger, { size: "sm", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
                        /* @__PURE__ */ jsxs(SelectContent, { children: [
                          /* @__PURE__ */ jsx(SelectItem, { value: "SEND_EMAIL", children: t("workflows.activities.types.SEND_EMAIL") }),
                          /* @__PURE__ */ jsx(SelectItem, { value: "CALL_API", children: t("workflows.activities.types.CALL_API") }),
                          /* @__PURE__ */ jsx(SelectItem, { value: "UPDATE_ENTITY", children: t("workflows.activities.types.UPDATE_ENTITY") }),
                          /* @__PURE__ */ jsx(SelectItem, { value: "EMIT_EVENT", children: t("workflows.activities.types.EMIT_EVENT") }),
                          /* @__PURE__ */ jsx(SelectItem, { value: "CALL_WEBHOOK", children: t("workflows.activities.types.CALL_WEBHOOK") }),
                          /* @__PURE__ */ jsx(SelectItem, { value: "EXECUTE_FUNCTION", children: t("workflows.activities.types.EXECUTE_FUNCTION") }),
                          /* @__PURE__ */ jsx(SelectItem, { value: "WAIT", children: t("workflows.activities.types.WAIT") })
                        ] })
                      ]
                    }
                  )
                ] }),
                /* @__PURE__ */ jsxs("div", { children: [
                  /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-foreground mb-1", children: t("workflows.form.timeout") }),
                  /* @__PURE__ */ jsx(
                    Input,
                    {
                      type: "text",
                      size: "sm",
                      value: activity.timeoutMs || "",
                      onChange: (e) => {
                        const updated = [...stepActivities];
                        updated[index].timeoutMs = e.target.value ? parseInt(e.target.value) : void 0;
                        setStepActivities(updated);
                      },
                      placeholder: t("workflows.form.placeholders.timeoutMs")
                    }
                  ),
                  /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.timeoutMs") })
                ] }),
                /* @__PURE__ */ jsxs("div", { className: "border border-border rounded-lg p-3 bg-muted", children: [
                  /* @__PURE__ */ jsx("label", { className: "block text-xs font-semibold text-foreground mb-2", children: t("workflows.form.retryPolicy") }),
                  /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-2", children: [
                    /* @__PURE__ */ jsxs("div", { children: [
                      /* @__PURE__ */ jsx("label", { className: "block text-xs text-muted-foreground mb-1", children: t("workflows.form.maxAttempts") }),
                      /* @__PURE__ */ jsx(
                        Input,
                        {
                          type: "number",
                          size: "sm",
                          value: activity.retryPolicy?.maxAttempts || 1,
                          onChange: (e) => {
                            const updated = [...stepActivities];
                            if (!updated[index].retryPolicy) updated[index].retryPolicy = {};
                            updated[index].retryPolicy.maxAttempts = parseInt(e.target.value) || 1;
                            setStepActivities(updated);
                          },
                          min: "1",
                          max: "10"
                        }
                      )
                    ] }),
                    /* @__PURE__ */ jsxs("div", { children: [
                      /* @__PURE__ */ jsx("label", { className: "block text-xs text-muted-foreground mb-1", children: t("workflows.form.initialInterval") }),
                      /* @__PURE__ */ jsx(
                        Input,
                        {
                          type: "number",
                          size: "sm",
                          value: activity.retryPolicy?.initialIntervalMs || 1e3,
                          onChange: (e) => {
                            const updated = [...stepActivities];
                            if (!updated[index].retryPolicy) updated[index].retryPolicy = {};
                            updated[index].retryPolicy.initialIntervalMs = parseInt(e.target.value) || 1e3;
                            setStepActivities(updated);
                          }
                        }
                      )
                    ] }),
                    /* @__PURE__ */ jsxs("div", { children: [
                      /* @__PURE__ */ jsx("label", { className: "block text-xs text-muted-foreground mb-1", children: t("workflows.form.backoffCoefficient") }),
                      /* @__PURE__ */ jsx(
                        Input,
                        {
                          type: "number",
                          size: "sm",
                          step: "0.1",
                          value: activity.retryPolicy?.backoffCoefficient || 2,
                          onChange: (e) => {
                            const updated = [...stepActivities];
                            if (!updated[index].retryPolicy) updated[index].retryPolicy = {};
                            updated[index].retryPolicy.backoffCoefficient = parseFloat(e.target.value) || 2;
                            setStepActivities(updated);
                          }
                        }
                      )
                    ] }),
                    /* @__PURE__ */ jsxs("div", { children: [
                      /* @__PURE__ */ jsx("label", { className: "block text-xs text-muted-foreground mb-1", children: t("workflows.form.maxInterval") }),
                      /* @__PURE__ */ jsx(
                        Input,
                        {
                          type: "number",
                          size: "sm",
                          value: activity.retryPolicy?.maxIntervalMs || 6e4,
                          onChange: (e) => {
                            const updated = [...stepActivities];
                            if (!updated[index].retryPolicy) updated[index].retryPolicy = {};
                            updated[index].retryPolicy.maxIntervalMs = parseInt(e.target.value) || 6e4;
                            setStepActivities(updated);
                          }
                        }
                      )
                    ] })
                  ] })
                ] }),
                /* @__PURE__ */ jsx("div", { className: "flex gap-4", children: /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [
                  /* @__PURE__ */ jsx(
                    Checkbox,
                    {
                      checked: activity.async || false,
                      onCheckedChange: (checked) => {
                        const updated = [...stepActivities];
                        updated[index].async = checked === true;
                        setStepActivities(updated);
                      }
                    }
                  ),
                  /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("workflows.form.executeAsync") })
                ] }) }),
                activity.activityType === "WAIT" && /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
                  /* @__PURE__ */ jsxs("div", { children: [
                    /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-foreground mb-1", children: t("workflows.activities.waitDuration") }),
                    /* @__PURE__ */ jsx(
                      Input,
                      {
                        size: "sm",
                        type: "text",
                        value: activity.config?.duration || "",
                        onChange: (e) => {
                          const updated = [...stepActivities];
                          updated[index].config = { ...updated[index].config, duration: e.target.value, until: void 0 };
                          setStepActivities(updated);
                        },
                        placeholder: t("workflows.activities.waitDurationPlaceholder")
                      }
                    ),
                    /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.activities.waitDurationDescription") })
                  ] }),
                  /* @__PURE__ */ jsx("div", { className: "text-xs text-center text-muted-foreground", children: t("workflows.activities.waitOr") }),
                  /* @__PURE__ */ jsxs("div", { children: [
                    /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-foreground mb-1", children: t("workflows.activities.waitUntil") }),
                    /* @__PURE__ */ jsx(
                      Input,
                      {
                        size: "sm",
                        type: "datetime-local",
                        value: activity.config?.until ? activity.config.until.slice(0, 16) : "",
                        onChange: (e) => {
                          const updated = [...stepActivities];
                          updated[index].config = { ...updated[index].config, until: e.target.value ? new Date(e.target.value).toISOString() : void 0, duration: void 0 };
                          setStepActivities(updated);
                        }
                      }
                    ),
                    /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.activities.waitUntilDescription") })
                  ] })
                ] }),
                activity.activityType !== "WAIT" && /* @__PURE__ */ jsxs("div", { children: [
                  /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-foreground mb-1", children: t("workflows.form.configuration") }),
                  /* @__PURE__ */ jsx(
                    JsonBuilder,
                    {
                      value: activity.config || {},
                      onChange: (config) => {
                        const updated = [...stepActivities];
                        updated[index].config = config;
                        setStepActivities(updated);
                      }
                    }
                  ),
                  /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.activityConfig") })
                ] }),
                /* @__PURE__ */ jsx("div", { className: "pt-3 border-t border-border", children: /* @__PURE__ */ jsxs(
                  Button,
                  {
                    type: "button",
                    variant: "destructive",
                    size: "sm",
                    onClick: () => {
                      setStepActivities(stepActivities.filter((_, i) => i !== index));
                      const newExpanded = new Set(expandedStepActivities);
                      newExpanded.delete(index);
                      setExpandedStepActivities(newExpanded);
                    },
                    children: [
                      /* @__PURE__ */ jsx(Trash2, { className: "size-3 mr-1" }),
                      t("workflows.form.deleteActivity")
                    ]
                  }
                ) })
              ] })
            ] }, index);
          }) })
        ] }) }),
        node.type === "subWorkflow" && /* @__PURE__ */ jsxs(Fragment, { children: [
          /* @__PURE__ */ jsx("div", { className: "border-t border-border pt-4 mt-4", children: /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-3", children: t("workflows.form.subWorkflowConfig") }) }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsxs("label", { className: "block text-sm font-medium text-foreground mb-1", children: [
              t("workflows.form.workflowToInvoke"),
              " *"
            ] }),
            /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
              /* @__PURE__ */ jsx(
                Input,
                {
                  type: "text",
                  value: subWorkflowId,
                  onChange: (e) => setSubWorkflowId(e.target.value),
                  placeholder: t("workflows.form.placeholders.subWorkflowId"),
                  className: "flex-1",
                  readOnly: true
                }
              ),
              /* @__PURE__ */ jsx(
                Button,
                {
                  type: "button",
                  variant: "outline",
                  onClick: () => setShowWorkflowSelector(true),
                  children: t("workflows.form.browse")
                }
              )
            ] }),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.subWorkflowId") })
          ] }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.form.version") }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "number",
                value: subWorkflowVersion,
                onChange: (e) => setSubWorkflowVersion(e.target.value),
                placeholder: t("workflows.form.placeholders.version")
              }
            ),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.subWorkflowVersion") })
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "border-t border-border pt-4 mt-4", children: [
            /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
              /* @__PURE__ */ jsxs("div", { children: [
                /* @__PURE__ */ jsx("h4", { className: "text-sm font-semibold text-foreground", children: t("workflows.form.inputMapping", { count: inputMappings.length }) }),
                /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.inputMapping") })
              ] }),
              /* @__PURE__ */ jsxs(
                Button,
                {
                  type: "button",
                  size: "sm",
                  onClick: () => setInputMappings((prev) => [...prev, { key: "", value: "" }]),
                  children: [
                    /* @__PURE__ */ jsx(Plus, { className: "size-3 mr-1" }),
                    t("workflows.form.addMapping")
                  ]
                }
              )
            ] }),
            inputMappings.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground italic", children: t("workflows.nodeEditor.noInputMappings") }) : /* @__PURE__ */ jsx("div", { className: "space-y-2", children: inputMappings.map((mapping, index) => /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-start", children: [
              /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                /* @__PURE__ */ jsx(
                  Input,
                  {
                    type: "text",
                    value: mapping.key,
                    onChange: (e) => {
                      const newMappings = [...inputMappings];
                      newMappings[index].key = e.target.value;
                      setInputMappings(newMappings);
                    },
                    placeholder: t("workflows.form.placeholders.childKey")
                  }
                ),
                /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.childKey") })
              ] }),
              /* @__PURE__ */ jsx("span", { className: "text-muted-foreground mt-2", children: "\u2192" }),
              /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                /* @__PURE__ */ jsx(
                  Input,
                  {
                    type: "text",
                    value: mapping.value,
                    onChange: (e) => {
                      const newMappings = [...inputMappings];
                      newMappings[index].value = e.target.value;
                      setInputMappings(newMappings);
                    },
                    placeholder: t("workflows.form.placeholders.parentPath")
                  }
                ),
                /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.parentPath") })
              ] }),
              /* @__PURE__ */ jsx(
                Button,
                {
                  type: "button",
                  size: "sm",
                  variant: "ghost",
                  onClick: () => {
                    setInputMappings((prev) => prev.filter((_, i) => i !== index));
                  },
                  className: "mt-1",
                  children: /* @__PURE__ */ jsx(Trash2, { className: "size-3" })
                }
              )
            ] }, index)) })
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "border-t border-border pt-4 mt-4", children: [
            /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
              /* @__PURE__ */ jsxs("div", { children: [
                /* @__PURE__ */ jsx("h4", { className: "text-sm font-semibold text-foreground", children: t("workflows.form.outputMapping", { count: outputMappings.length }) }),
                /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.outputMapping") })
              ] }),
              /* @__PURE__ */ jsxs(
                Button,
                {
                  type: "button",
                  size: "sm",
                  onClick: () => setOutputMappings((prev) => [...prev, { key: "", value: "" }]),
                  children: [
                    /* @__PURE__ */ jsx(Plus, { className: "size-3 mr-1" }),
                    t("workflows.form.addMapping")
                  ]
                }
              )
            ] }),
            outputMappings.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground italic", children: t("workflows.nodeEditor.noOutputMappings") }) : /* @__PURE__ */ jsx("div", { className: "space-y-2", children: outputMappings.map((mapping, index) => /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-start", children: [
              /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                /* @__PURE__ */ jsx(
                  Input,
                  {
                    type: "text",
                    value: mapping.key,
                    onChange: (e) => {
                      const newMappings = [...outputMappings];
                      newMappings[index].key = e.target.value;
                      setOutputMappings(newMappings);
                    },
                    placeholder: t("workflows.form.placeholders.parentKey")
                  }
                ),
                /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.parentKey") })
              ] }),
              /* @__PURE__ */ jsx("span", { className: "text-muted-foreground mt-2", children: "\u2190" }),
              /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                /* @__PURE__ */ jsx(
                  Input,
                  {
                    type: "text",
                    value: mapping.value,
                    onChange: (e) => {
                      const newMappings = [...outputMappings];
                      newMappings[index].value = e.target.value;
                      setOutputMappings(newMappings);
                    },
                    placeholder: t("workflows.form.placeholders.childPath")
                  }
                ),
                /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: t("workflows.form.descriptions.childPath") })
              ] }),
              /* @__PURE__ */ jsx(
                Button,
                {
                  type: "button",
                  size: "sm",
                  variant: "ghost",
                  onClick: () => {
                    setOutputMappings((prev) => prev.filter((_, i) => i !== index));
                  },
                  className: "mt-1",
                  children: /* @__PURE__ */ jsx(Trash2, { className: "size-3" })
                }
              )
            ] }, index)) })
          ] })
        ] }),
        node.type === "waitForSignal" && /* @__PURE__ */ jsxs(Fragment, { children: [
          /* @__PURE__ */ jsx("div", { className: "border-t border-border pt-4 mt-4", children: /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-3", children: t("workflows.form.signalConfig") }) }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsxs("label", { className: "block text-sm font-medium text-foreground mb-1", children: [
              t("workflows.form.signalName"),
              " *"
            ] }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "text",
                value: signalName,
                onChange: (e) => setSignalName(e.target.value),
                placeholder: t("workflows.form.placeholders.signalName")
              }
            ),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.signalName") })
          ] }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.form.timeout") }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "text",
                value: signalTimeout,
                onChange: (e) => {
                  setSignalTimeout(e.target.value);
                  if (fieldErrors.signalTimeout) {
                    const next = { ...fieldErrors };
                    delete next.signalTimeout;
                    setFieldErrors(next);
                  }
                },
                placeholder: t("workflows.form.placeholders.signalTimeout"),
                "aria-invalid": fieldErrors.signalTimeout ? true : void 0
              }
            ),
            fieldErrors.signalTimeout ? /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive mt-1", children: fieldErrors.signalTimeout }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.signalTimeout") })
          ] })
        ] }),
        node.type === "waitForTimer" && /* @__PURE__ */ jsxs(Fragment, { children: [
          /* @__PURE__ */ jsx("div", { className: "border-t border-border pt-4 mt-4", children: /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-3", children: t("workflows.steps.types.WAIT_FOR_TIMER") }) }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.activities.waitDuration") }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "text",
                value: timerDuration,
                onChange: (e) => {
                  setTimerDuration(e.target.value);
                  if (e.target.value) setTimerUntil("");
                  if (fieldErrors.timerDuration) {
                    const next = { ...fieldErrors };
                    delete next.timerDuration;
                    setFieldErrors(next);
                  }
                },
                placeholder: t("workflows.activities.waitDurationPlaceholder"),
                "aria-invalid": fieldErrors.timerDuration ? true : void 0
              }
            ),
            fieldErrors.timerDuration ? /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive mt-1", children: fieldErrors.timerDuration }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.activities.waitDurationDescription") })
          ] }),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-foreground mb-1", children: t("workflows.activities.waitUntil") }),
            /* @__PURE__ */ jsx(
              Input,
              {
                type: "datetime-local",
                value: timerUntil ? timerUntil.slice(0, 16) : "",
                min: new Date(Date.now() - (/* @__PURE__ */ new Date()).getTimezoneOffset() * 6e4).toISOString().slice(0, 16),
                onChange: (e) => {
                  const next = e.target.value ? new Date(e.target.value).toISOString() : "";
                  setTimerUntil(next);
                  if (next) setTimerDuration("");
                  if (fieldErrors.timerUntil) {
                    const nextErrors = { ...fieldErrors };
                    delete nextErrors.timerUntil;
                    setFieldErrors(nextErrors);
                  }
                },
                "aria-invalid": fieldErrors.timerUntil ? true : void 0
              }
            ),
            fieldErrors.timerUntil ? /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive mt-1", children: fieldErrors.timerUntil }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.activities.waitUntilDescription") })
          ] })
        ] }),
        /* @__PURE__ */ jsxs("div", { className: "border-t border-border pt-4 mt-4", children: [
          /* @__PURE__ */ jsxs(
            Button,
            {
              type: "button",
              variant: "ghost",
              onClick: () => setShowAdvanced(!showAdvanced),
              className: "h-auto w-full justify-between px-0 py-0 text-left hover:bg-transparent",
              children: [
                /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground", children: t("workflows.form.advancedConfiguration") }),
                /* @__PURE__ */ jsx(
                  ChevronDown,
                  {
                    className: `size-5 transition-transform ${showAdvanced ? "rotate-180" : ""}`
                  }
                )
              ]
            }
          ),
          showAdvanced && /* @__PURE__ */ jsxs("div", { className: "mt-3", children: [
            /* @__PURE__ */ jsx(
              JsonBuilder,
              {
                value: advancedConfig,
                onChange: setAdvancedConfig
              }
            ),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: t("workflows.form.descriptions.advancedConfig") })
          ] })
        ] })
      ] }) }),
      /* @__PURE__ */ jsxs(DialogFooter, { className: "flex justify-between", children: [
        onDelete && /* @__PURE__ */ jsxs(
          Button,
          {
            type: "button",
            variant: "destructive",
            onClick: handleDelete,
            children: [
              /* @__PURE__ */ jsx(Trash2, { className: "size-4" }),
              t("workflows.form.deleteStep")
            ]
          }
        ),
        /* @__PURE__ */ jsxs("div", { className: "flex gap-2 ml-auto", children: [
          /* @__PURE__ */ jsx(
            Button,
            {
              type: "button",
              variant: "outline",
              onClick: onClose,
              children: t("workflows.actions.cancel")
            }
          ),
          isEditable && /* @__PURE__ */ jsx(
            Button,
            {
              type: "button",
              onClick: handleSave,
              children: t("workflows.actions.saveChanges")
            }
          )
        ] })
      ] })
    ] }),
    node?.type === "subWorkflow" && /* @__PURE__ */ jsx(
      WorkflowSelector,
      {
        isOpen: showWorkflowSelector,
        onClose: () => setShowWorkflowSelector(false),
        onSelect: handleWorkflowSelect,
        excludeWorkflowIds: [],
        title: t("workflows.dialogs.selectSubWorkflow"),
        description: t("workflows.dialogs.selectSubWorkflowDescription"),
        onlyEnabled: true
      }
    ),
    ConfirmDialogElement
  ] });
}
export {
  NodeEditDialog
};
//# sourceMappingURL=NodeEditDialog.js.map
