import a from "react";
import { MdPlayCircleOutline as s, MdStopCircle as p, MdHttp as c, MdNotifications as u, MdCallSplit as b, MdWebhook as n, MdAccountTree as h } from "react-icons/md";
import { N as d } from "./canvasTokens-CAD6G24b.js";
const m = {
  formSchema: [],
  bpmnEntry: (e) => e,
  bpmnExit: (e) => e,
  emitBpmnElements: (e) => [{ id: e, $type: "bpmn:Task" }]
};
function r(e) {
  return { ...m, ...e };
}
const T = r({
  type: "startEvent",
  label: "Start",
  icon: a.createElement(s, { size: 18, color: "#616161" }),
  matches: (e) => e === "start",
  reactFlowType: "startNode",
  emitBpmnElements: (e) => [{ id: e, $type: "bpmn:StartEvent" }],
  maxPerWorkflow: 1
}), v = r({
  type: "endEvent",
  label: "End",
  icon: a.createElement(p, { size: 18, color: "#616161" }),
  matches: (e) => e === "end" || e.startsWith("end-"),
  reactFlowType: "endNode",
  emitBpmnElements: (e) => [{ id: e, $type: "bpmn:EndEvent" }]
}), S = r({
  type: "restApi",
  label: "REST API Call",
  icon: a.createElement(c, { size: 18, color: "#546e7a" }),
  matches: (e) => e.startsWith("restApi-"),
  reactFlowType: "restApiNode",
  formSchema: [
    {
      id: "method",
      type: "select",
      label: "HTTP Method",
      required: !0,
      options: [
        { label: "GET", value: "GET" },
        { label: "POST", value: "POST" },
        { label: "PUT", value: "PUT" },
        { label: "PATCH", value: "PATCH" },
        { label: "DELETE", value: "DELETE" }
      ]
    },
    {
      id: "url",
      type: "text",
      label: "URL",
      required: !0,
      placeholder: "https://api.example.com/endpoint",
      formulaEnabled: !0
    },
    {
      id: "headers",
      type: "key-value",
      label: "Request Headers",
      placeholder: "Add headers..."
    },
    {
      id: "queryParams",
      type: "key-value",
      label: "Query Parameters",
      shouldHide: ({ values: e }) => e.method !== "GET" && e.method !== "DELETE"
    },
    {
      id: "body",
      type: "json-editor",
      label: "Request Body (JSON)",
      shouldHide: ({ values: e }) => e.method === "GET" || e.method === "DELETE"
    },
    {
      id: "responseMapping",
      type: "array",
      label: "Map Response Fields to Variables",
      children: [
        {
          id: "jsonPath",
          type: "text",
          label: "JSON Path",
          placeholder: "$.data.userId",
          required: !0
        },
        {
          id: "variableName",
          type: "text",
          label: "Variable Name",
          placeholder: "userId",
          required: !0
        }
      ]
    },
    {
      id: "timeoutMs",
      type: "number",
      label: "Timeout (ms)",
      placeholder: "5000"
    },
    {
      id: "continueOnError",
      type: "toggle",
      label: "Continue workflow on error"
    }
  ],
  bpmnEntry: (e) => `REST API Call: ${e}`,
  bpmnExit: (e) => `End REST API Call: ${e}`,
  emitBpmnElements: (e, t) => {
    const l = t;
    return [{
      id: e,
      $type: "bpmn:ServiceTask",
      name: `${l.method ?? "HTTP"} ${l.url ?? ""}`.trim()
    }];
  }
}), x = r({
  type: "notification",
  label: "Send Notification",
  icon: a.createElement(u, { size: 18, color: "#7b1fa2" }),
  matches: (e) => e.startsWith("notification-"),
  reactFlowType: "notificationNode",
  formSchema: [
    {
      id: "channel",
      type: "descriptive-select",
      label: "Notification Channel",
      required: !0,
      options: [
        { value: "email", label: "Email", description: "Send via SMTP or email provider" },
        { value: "slack", label: "Slack", description: "Post to a Slack channel or DM" },
        { value: "teams", label: "Microsoft Teams", description: "Post to a Teams channel or chat" },
        { value: "sms", label: "SMS", description: "Send a text message" },
        { value: "in-app", label: "In-App", description: "miniOrange notification center" },
        { value: "webhook", label: "Webhook", description: "POST to an external URL" }
      ]
    },
    // ── Email fields ──────────────────────────────────────────────────────────
    {
      id: "emailTo",
      type: "tags",
      label: "To",
      placeholder: "Add email address...",
      required: !0,
      shouldHide: ({ values: e }) => e.channel !== "email",
      formulaEnabled: !0
    },
    {
      id: "emailCc",
      type: "tags",
      label: "CC",
      placeholder: "Add email address...",
      shouldHide: ({ values: e }) => e.channel !== "email"
    },
    {
      id: "emailSubject",
      type: "text",
      label: "Subject",
      required: !0,
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "email"
    },
    {
      id: "emailBody",
      type: "rich-text",
      label: "Body",
      required: !0,
      shouldHide: ({ values: e }) => e.channel !== "email"
    },
    // ── Slack fields ──────────────────────────────────────────────────────────
    {
      id: "slackChannel",
      type: "text",
      label: "Channel / DM",
      required: !0,
      placeholder: "#general or @username",
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "slack"
    },
    {
      id: "slackMessage",
      type: "textarea",
      label: "Message",
      required: !0,
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "slack"
    },
    // ── Teams fields ──────────────────────────────────────────────────────────
    {
      id: "teamsWebhookUrl",
      type: "text",
      label: "Incoming Webhook URL",
      required: !0,
      placeholder: "https://...",
      shouldHide: ({ values: e }) => e.channel !== "teams"
    },
    {
      id: "teamsMessage",
      type: "textarea",
      label: "Message",
      required: !0,
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "teams"
    },
    // ── SMS fields ────────────────────────────────────────────────────────────
    {
      id: "smsTo",
      type: "text",
      label: "Phone Number",
      required: !0,
      placeholder: "+1234567890",
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "sms"
    },
    {
      id: "smsBody",
      type: "textarea",
      label: "Message",
      required: !0,
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "sms"
    },
    // ── In-App fields ─────────────────────────────────────────────────────────
    {
      id: "inAppRecipient",
      type: "text",
      label: "Recipient (User ID or Username)",
      required: !0,
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "in-app"
    },
    {
      id: "inAppTitle",
      type: "text",
      label: "Title",
      required: !0,
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "in-app"
    },
    {
      id: "inAppBody",
      type: "textarea",
      label: "Message",
      required: !0,
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "in-app"
    },
    // ── Webhook fields ────────────────────────────────────────────────────────
    {
      id: "webhookUrl",
      type: "text",
      label: "Webhook URL",
      required: !0,
      placeholder: "https://...",
      formulaEnabled: !0,
      shouldHide: ({ values: e }) => e.channel !== "webhook"
    },
    {
      id: "webhookPayload",
      type: "json-editor",
      label: "Payload (JSON)",
      shouldHide: ({ values: e }) => e.channel !== "webhook"
    },
    // ── Shared options ────────────────────────────────────────────────────────
    {
      id: "sendOnFailure",
      type: "toggle",
      label: "Also send notification on workflow failure"
    },
    {
      id: "deduplicationKey",
      type: "text",
      label: "Deduplication Key",
      placeholder: "Optional — prevents duplicate sends",
      formulaEnabled: !0
    }
  ],
  bpmnEntry: (e) => `Send Notification: ${e}`,
  bpmnExit: (e) => `End Notification: ${e}`,
  emitBpmnElements: (e, t) => [{ id: e, $type: "bpmn:SendTask", name: `Notify via ${t.channel ?? "channel"}` }]
}), y = [
  { label: "equals (=)", value: "eq" },
  { label: "not equals (≠)", value: "neq" },
  { label: "greater than (>)", value: "gt" },
  { label: "greater or equal (≥)", value: "gte" },
  { label: "less than (<)", value: "lt" },
  { label: "less or equal (≤)", value: "lte" },
  { label: "contains", value: "contains" },
  { label: "starts with", value: "startsWith" },
  { label: "ends with", value: "endsWith" },
  { label: "is empty", value: "isEmpty" },
  { label: "is not empty", value: "isNotEmpty" }
], q = r({
  type: "conditionBranch",
  label: "Condition Branch",
  icon: a.createElement(b, { size: 18, color: "#512da8" }),
  matches: (e) => e.startsWith("conditionBranch-"),
  reactFlowType: "conditionBranchNode",
  /** Initial branch labels — canvas uses these keys to initialise BranchMap on insert.
   *  Pre-seeded as Workato-style IF / ELSE IF / ELSE chain. */
  branchLabels: { branch1: "IF · Branch 1", branch2: "ELSE IF · Branch 2", default: "ELSE" },
  formSchema: [
    {
      id: "title",
      type: "text",
      label: "Node Label",
      placeholder: "e.g. Route by User Role"
    },
    {
      id: "branchConfigs",
      type: "array",
      label: "Branches",
      required: !0,
      children: [
        {
          id: "kind",
          type: "select",
          label: "Branch Type",
          required: !0,
          options: [
            { label: "IF", value: "if" },
            { label: "ELSE IF", value: "elseif" },
            { label: "ELSE", value: "else" }
          ],
          // Default for new branches is "elseif" so the chain reads correctly when
          // appended between the first IF and the trailing ELSE.
          placeholder: "elseif"
        },
        {
          id: "key",
          type: "text",
          label: "Branch Key",
          required: !0,
          placeholder: "e.g. admin (no spaces)"
        },
        {
          id: "label",
          type: "text",
          label: "Branch Label",
          required: !0,
          placeholder: "e.g. Admin Users"
        },
        {
          id: "conditions",
          type: "array",
          label: "Conditions",
          // ELSE branches have no condition by definition — hide the array.
          shouldHide: ({ values: e }) => e.kind === "else",
          children: [
            {
              id: "field",
              type: "text",
              label: "Field / Variable",
              required: !0,
              placeholder: "e.g. user.role",
              formulaEnabled: !0
            },
            {
              id: "operator",
              type: "select",
              label: "Operator",
              required: !0,
              options: y
            },
            {
              id: "value",
              type: "text",
              label: "Value",
              placeholder: "e.g. admin",
              formulaEnabled: !0,
              shouldHide: ({ values: e }) => e.operator === "isEmpty" || e.operator === "isNotEmpty"
            },
            {
              id: "logicalOperator",
              type: "select",
              label: "Combine with next",
              options: [
                { label: "AND", value: "AND" },
                { label: "OR", value: "OR" }
              ]
            }
          ]
        }
      ]
    },
    {
      id: "defaultBranch",
      type: "text",
      label: "Default Branch Key (fallback if no condition matches)",
      placeholder: "e.g. default"
    }
  ],
  bpmnEntry: (e) => `Condition Branch: ${e}`,
  bpmnExit: (e) => `End Condition Branch: ${e}`,
  emitBpmnElements: (e, t) => {
    const l = t, o = l.branchConfigs ?? [];
    return [
      { id: e, $type: "bpmn:ExclusiveGateway", name: l.title ?? "Condition Branch" },
      ...o.map((i) => ({
        id: `${e}-${i.key}`,
        $type: "bpmn:SequenceFlow",
        name: i.label
      }))
    ];
  }
}), N = r({
  type: "webhookTrigger",
  label: "Webhook Trigger",
  icon: a.createElement(n, { size: d, color: "#1565c0" }),
  matches: (e) => e.startsWith("webhookTrigger-"),
  reactFlowType: "webhookTriggerNode",
  formSchema: [
    {
      id: "endpointUrl",
      type: "text",
      label: "Endpoint URL",
      disabled: !0,
      placeholder: "Generated after saving"
    },
    {
      id: "authMethod",
      type: "select",
      label: "Authentication",
      required: !0,
      options: [
        { label: "None", value: "none" },
        { label: "API Key", value: "api-key" },
        { label: "HMAC Signature", value: "hmac" }
      ]
    },
    {
      id: "apiKeyHeader",
      type: "text",
      label: "API Key Header Name",
      placeholder: "e.g. X-API-Key",
      shouldHide: ({ values: e }) => e.authMethod !== "api-key"
    },
    {
      id: "hmacSecret",
      type: "text",
      label: "HMAC Secret",
      placeholder: "Shared secret for signature verification",
      shouldHide: ({ values: e }) => e.authMethod !== "hmac"
    },
    {
      id: "payloadDescription",
      type: "textarea",
      label: "Expected Payload Description",
      placeholder: "Describe the expected JSON payload fields..."
    }
  ],
  bpmnEntry: (e) => `Webhook Trigger: ${e}`,
  bpmnExit: (e) => `End Webhook Trigger: ${e}`,
  emitBpmnElements: (e) => [{ id: e, $type: "bpmn:StartEvent", name: "Webhook Trigger" }]
}), C = {
  triggerKey: "WEBHOOK_TRIGGER",
  label: "Incoming Webhook",
  description: "Start this workflow when an HTTP POST is received at a generated endpoint.",
  triggerCategory: "webhook",
  icon: a.createElement(n, { size: d, color: "#1565c0" })
};
function E(e = {}) {
  return r({
    type: "subWorkflow",
    label: "Sub-Workflow",
    icon: a.createElement(h, { size: 18, color: "#00695c" }),
    matches: (t) => t.startsWith("subWorkflow-"),
    reactFlowType: "subWorkflowNode",
    formSchema: [
      {
        id: "workflowId",
        type: "select",
        label: "Workflow to Call",
        required: !0,
        placeholder: "Select a workflow...",
        ...e.fetchWorkflowOptions ? { fetchOptions: e.fetchWorkflowOptions } : { options: [] }
      },
      {
        id: "workflowLabel",
        type: "text",
        label: "Display Name (optional)",
        placeholder: "Override display name shown on canvas"
      },
      {
        id: "inputMapping",
        type: "key-value",
        label: "Input Mapping",
        placeholder: "Map parent variables → sub-workflow inputs",
        formulaEnabled: !0
      },
      {
        id: "outputMapping",
        type: "key-value",
        label: "Output Mapping",
        placeholder: "Map sub-workflow outputs → parent variables"
      },
      {
        id: "waitForCompletion",
        type: "toggle",
        label: "Wait for sub-workflow to complete before continuing"
      },
      {
        id: "continueOnError",
        type: "toggle",
        label: "Continue parent workflow if sub-workflow fails"
      }
    ],
    bpmnEntry: (t) => `Sub-Workflow Call: ${t}`,
    bpmnExit: (t) => `End Sub-Workflow Call: ${t}`,
    emitBpmnElements: (t, l) => {
      const o = l;
      return [{
        id: t,
        $type: "bpmn:CallActivity",
        name: o.workflowLabel || o.workflowId || "Sub-Workflow",
        calledElement: o.workflowId
      }];
    }
  });
}
const M = E();
class f {
  constructor() {
    this.descriptors = /* @__PURE__ */ new Map();
  }
  register(t) {
    return this.descriptors.set(t.type, t), this;
  }
  forType(t) {
    return this.descriptors.get(t);
  }
  forId(t) {
    for (const l of this.descriptors.values())
      if (l.matches(t)) return l;
  }
  list() {
    return [...this.descriptors.values()];
  }
}
const H = new f();
export {
  f as NodeTypeRegistry,
  m as baseNodeDefaults,
  q as conditionBranchDescriptor,
  r as defineNode,
  v as endEventDescriptor,
  E as makeSubWorkflowDescriptor,
  H as nodeTypeRegistry,
  x as notificationDescriptor,
  S as restApiDescriptor,
  T as startEventDescriptor,
  M as subWorkflowDescriptor,
  N as webhookTriggerDescriptor,
  C as webhookTriggerTemplate
};
//# sourceMappingURL=nodeRegistry.js.map
