import { D as re, F as oe, a as ae, b as ie, c as le, I as ue, O as ce, T as de, V as pe, d as fe, e as me, f as Ee, g as ge, h as ye, i as he, j as ve, k as Te, E as we, l as be, m as Ne, n as Se, o as Re, p as De, q as Fe, r as Ie, s as Ce, t as xe, u as Ae, v as $e, w as Oe, x as _e, y as ke, z as Pe, A as je, B as We, C as Le } from "./index-B-D9UuLO.js";
import { F as Be, S as Ve, a as Me, u as ze } from "./SchemaBuilderDrawer-BP7aZgFe.js";
import "react/jsx-runtime";
import "react";
import "@mui/material";
import "react-icons/md";
import { NodeTypeRegistry as He, baseNodeDefaults as Je, conditionBranchDescriptor as Ke, defineNode as Ye, endEventDescriptor as Ge, makeSubWorkflowDescriptor as Xe, nodeTypeRegistry as Qe, notificationDescriptor as Ze, restApiDescriptor as et, startEventDescriptor as tt, subWorkflowDescriptor as nt, webhookTriggerDescriptor as st, webhookTriggerTemplate as rt } from "./nodeRegistry.js";
import { TemplateRegistry as at, templateRegistry as it } from "./templateRegistry.js";
import { F as ut, a as ct, S as dt, F as pt, W as ft, b as mt, c as Et, o as gt, u as yt, w as ht } from "./templateSkeletons-f-XQQvyE.js";
import { d as Tt } from "./messages-CO299wPN.js";
import { l as bt, s as Nt } from "./bpmn-CtfWDaOY.js";
import { A as Rt, b as Dt, E as Ft, c as It, F as Ct, R as xt, S as At, T as $t, W as Ot, e as _t } from "./GatewayBranchEdge-CrgczPYJ.js";
class W {
  constructor() {
    this.channels = /* @__PURE__ */ new Map();
  }
  register(t, n) {
    this.channels.set(t, n);
  }
  get(t) {
    return this.channels.get(t);
  }
  list() {
    return Array.from(this.channels.entries()).map(([t, n]) => ({ key: t, ...n }));
  }
  has(t) {
    return this.channels.has(t);
  }
}
const Z = new W();
function ee(e) {
  const {
    currentNodeId: t,
    nodes: n,
    getParents: o,
    getOutputSchema: a,
    nodePath: s,
    nodeLabel: d,
    getNodeId: i = (g) => g.id
  } = e, l = n.find((g) => i(g) === t);
  if (!l) return [];
  const f = L(l, n, o, i), h = [];
  for (const g of f) {
    const v = a(g);
    if (!v || v.length === 0) continue;
    const w = s(g);
    h.push({
      label: d ? d(g) : w,
      items: v.map((r) => _(r, w))
    });
  }
  return h;
}
function L(e, t, n, o) {
  const a = /* @__PURE__ */ new Set(), s = [], d = [...n(e, t)];
  for (; d.length > 0; ) {
    const i = d.shift(), l = o(i);
    a.has(l) || (a.add(l), s.push(i), d.push(...n(i, t)));
  }
  return s;
}
function _(e, t) {
  const n = `${t}.${e.key}`, o = e.description ?? (e.sample !== void 0 && e.sample !== null ? String(e.sample) : void 0), a = { label: e.label, path: n };
  return o !== void 0 && (a.description = o), e.children && e.children.length > 0 && (a.children = e.children.map((s) => _(s, n))), a;
}
const I = {
  triggerToCategory: {
    END_USER_CREATION: "END_USER_CREATION",
    END_USER_UPDATION: "END_USER_UPDATION",
    DELETE_DORMANT_ACCOUNT: "DELETE_DORMANT_ACCOUNT",
    NOTIFY_EXPIRED_PASSWORD: "NOTIFY_EXPIRED_PASSWORD"
  },
  schedulerEventTypes: ["DELETE_DORMANT_ACCOUNT", "NOTIFY_EXPIRED_PASSWORD"],
  conditionPathPrefix: "startEvent.endUser",
  defaultWorkflowCategory: "END_USER_CREATION",
  endEventIds: {
    success: "endEventSuccess",
    failure: "endEventFailure",
    rejected: "endEventRejected"
  },
  endEventNames: {
    success: "Task Completed successfully",
    failure: "User Not Created",
    rejected: "Approval Rejected"
  },
  startEventId: "startEvent"
}, U = /* @__PURE__ */ new Set([
  "start",
  "end",
  "triggerFixed",
  "addTrigger",
  "addStep"
]), B = (e) => !!e && !U.has(String(e.kind ?? ""));
function S(e, t) {
  return e == null ? "" : String(e).replace(
    /\$\{(\w+)\}/g,
    (n, o) => Object.prototype.hasOwnProperty.call(t, o) ? String(t[o]) : n
  );
}
function V(e, t) {
  var s, d, i, l, f;
  if (!e || typeof e != "object") return "";
  const { from: n, key: o, value: a } = e;
  return n === "literal" ? a === void 0 ? "" : String(a) : n === "task" ? String(((s = t.task) == null ? void 0 : s[o ?? ""]) ?? "") : n === "ctx" ? String(((d = t.ctx) == null ? void 0 : d[o ?? ""]) ?? "") : n === "slot" ? String(((i = t.slot) == null ? void 0 : i[o ?? ""]) ?? "") : n === "formData" ? String(((f = (l = t.slot) == null ? void 0 : l.formData) == null ? void 0 : f[o ?? ""]) ?? "") : "";
}
function M(e, t) {
  var o, a, s;
  const n = e == null ? void 0 : e.source;
  if (!n) return "";
  if (n.type === "literal")
    return typeof n.value == "string" ? n.value : JSON.stringify(n.value ?? "");
  if (n.type === "json" || n.type === "taskConfig") {
    const d = n.shape || {}, i = {};
    return Object.keys(d).forEach((l) => {
      i[l] = V(d[l], t);
    }), JSON.stringify(i);
  }
  if (n.type === "formData") {
    if (n.passthrough) {
      const d = new Set(n.exclude || []), i = {}, l = ((o = t.slot) == null ? void 0 : o.formData) ?? {};
      return Object.keys(l).forEach((f) => {
        d.has(f) || (i[f] = l[f]);
      }), JSON.stringify(i);
    }
    return String(((s = (a = t.slot) == null ? void 0 : a.formData) == null ? void 0 : s[n.key ?? ""]) ?? "");
  }
  return "";
}
function z(e, t) {
  if (!(!e || typeof e != "object" || !t))
    return t.split(".").reduce((n, o) => {
      if (!(n == null || typeof n != "object"))
        return n[o];
    }, e);
}
function q(e, t, n) {
  var w;
  const o = e.operatorMap || {}, a = e.valuesField || "groups", s = (r) => {
    const m = o[String((r == null ? void 0 : r.operator) ?? "")] ?? "==", u = `${n}.${(r == null ? void 0 : r.key) ?? (r == null ? void 0 : r.field) ?? ""}`, E = `'${String((r == null ? void 0 : r.value) ?? "")}'`;
    return m.startsWith(".") ? `${u}${m}(${E})` : m.startsWith("!.") ? `!${u}${m.slice(1)}(${E})` : `${u} ${m} ${E}`;
  }, d = (r) => {
    var T, p;
    const m = Array.isArray(r) ? r : [];
    if (m.length === 0) return null;
    const u = m.map(s), y = ((T = m[0]) == null ? void 0 : T.connector) === "or" || ((p = m[0]) == null ? void 0 : p.logicalOperator) === "OR" ? "||" : "&&";
    return u.join(` ${y} `);
  }, i = [];
  let l = 1;
  const f = (r, m) => {
    i.push({
      id: `rule${l}`,
      inputEntries: [
        {
          id: `rule${l}InputEntry1`,
          text: r ? `\${(${r})}` : ""
        }
      ],
      outputEntries: [
        {
          id: `rule${l}OutputEntry1`,
          text: `"${m}"`
        }
      ]
    }), l += 1;
  }, h = Array.isArray((w = t == null ? void 0 : t.formData) == null ? void 0 : w.groupBlocks) ? t.formData.groupBlocks : [];
  if (h.length > 0)
    return h.forEach((r) => {
      const m = Array.isArray(r == null ? void 0 : r[a]) ? r[a] : [], u = d(r == null ? void 0 : r.conditions);
      m.forEach((E) => f(u, E));
    }), i;
  const g = (t == null ? void 0 : t.formData) ?? {}, v = g._conditionConfig ?? g.conditionConfig;
  return v && typeof v == "object" && Object.keys(v).forEach((r) => {
    const m = v[r], u = d(m), E = Object.prototype.hasOwnProperty.call(g, r) ? g[r] : z(g, r);
    Array.isArray(E) ? E.forEach((y) => {
      const T = typeof y == "object" && y !== null ? y.value ?? y.label ?? y : y;
      f(u, T);
    }) : E != null && E !== "" ? f(u, E) : u && f(u, "");
  }), i;
}
function H(e, t, n) {
  return {
    mappings: [],
    name: e.tableName,
    decision: {
      id: e.tableName,
      name: e.tableName,
      decisionTable: {
        id: `decisionTable_${e.tableName}`,
        hitPolicy: e.hitPolicy || "FIRST",
        inputs: [
          {
            id: `input_${e.tableName}`,
            inputExpression: {
              id: `inputExpr_${e.tableName}`,
              typeRef: "string",
              text: e.inputExpr
            }
          }
        ],
        outputs: (e.outputs || []).map((o) => ({
          id: o.id,
          label: o.label,
          typeRef: o.typeRef || "string",
          name: o.name
        })),
        rules: q(e, t, n)
      }
    }
  };
}
function J(e, t, n, o) {
  var E, y, T;
  const a = (E = t == null ? void 0 : t.ui) == null ? void 0 : E.bpmnEmit;
  if (!a)
    return {
      serviceTasks: [
        {
          id: e.id,
          name: (t == null ? void 0 : t.name) || e.descriptorType,
          configuration: Array.isArray(t == null ? void 0 : t.configuration) ? t.configuration : [],
          input: e.formData || {}
        }
      ],
      gateways: [],
      callActivities: [],
      templateFlows: [],
      dmn: null,
      bpmnEntry: e.id,
      bpmnExit: e.id,
      outgoingConditions: {},
      endsNeeded: /* @__PURE__ */ new Set()
    };
  const s = {
    id: e.id,
    endFailure: o.endEventIds.failure,
    endRejected: o.endEventIds.rejected,
    endSuccess: o.endEventIds.success
  }, d = { task: t, slot: e, ctx: n }, i = (a.serviceTasks || []).map((p) => ({
    id: S(p.idTemplate, s),
    name: p.name,
    flowableClass: p.flowableClass,
    extensionElements: {
      fields: (p.extensionFields || []).map((b) => ({
        name: b.name,
        stringValue: M(b, d)
      }))
    }
  }));
  let l = null;
  const f = [];
  a.gateway && (l = S(a.gateway.idTemplate, s), s.gateway = l, f.push({ id: l, name: a.gateway.name }));
  const h = /* @__PURE__ */ new Set(), g = (a.templateFlows || []).map((p) => {
    const b = S(p.from, s), N = S(p.to, s);
    return N === o.endEventIds.failure && h.add(o.endEventIds.failure), N === o.endEventIds.rejected && h.add(o.endEventIds.rejected), {
      id: p.idTemplate ? S(p.idTemplate, s) : `${b}-to-${N}`,
      sourceRef: b,
      targetRef: N,
      conditionExpression: p.condition ? S(p.condition, s) : null
    };
  }), v = [], w = a.dmnEmit ? H(a.dmnEmit, e, o.conditionPathPrefix) : null, r = ((y = i[0]) == null ? void 0 : y.id) ?? e.id, m = l ?? ((T = i[i.length - 1]) == null ? void 0 : T.id) ?? e.id, u = {};
  return Object.keys(a.outgoingConditions || {}).forEach((p) => {
    u[p] = S(
      a.outgoingConditions[p],
      s
    );
  }), {
    serviceTasks: i,
    gateways: f,
    callActivities: v,
    templateFlows: g,
    dmn: w,
    bpmnEntry: r,
    bpmnExit: m,
    outgoingConditions: u,
    endsNeeded: h
  };
}
function te(e) {
  var C, x, A, $;
  const { state: t, tasksByKey: n, context: o, config: a } = e, s = {
    ...I,
    ...a ?? {},
    triggerToCategory: { ...I.triggerToCategory, ...(a == null ? void 0 : a.triggerToCategory) ?? {} },
    schedulerEventTypes: (a == null ? void 0 : a.schedulerEventTypes) ?? I.schedulerEventTypes,
    endEventIds: { ...I.endEventIds, ...(a == null ? void 0 : a.endEventIds) ?? {} },
    endEventNames: { ...I.endEventNames, ...(a == null ? void 0 : a.endEventNames) ?? {} }
  }, d = Array.isArray(t == null ? void 0 : t.slots) ? t.slots : [], i = d.find((c) => c.kind === "triggerFixed"), l = (C = i == null ? void 0 : i.nodeData) == null ? void 0 : C.eventType, f = ((x = i == null ? void 0 : i.nodeData) == null ? void 0 : x.type) || "event", h = (A = i == null ? void 0 : i.nodeData) == null ? void 0 : A.sources, g = Array.isArray(h) ? h.map(
    (c) => typeof c == "string" ? c : (c == null ? void 0 : c.value) ?? (c == null ? void 0 : c.key) ?? ""
  ).filter(Boolean) : [], v = s.triggerToCategory[l ?? ""] ?? s.defaultWorkflowCategory, r = !!l && s.schedulerEventTypes.includes(l) ? ["SCHEDULER"] : g, u = d.filter(B).map((c) => ({
    slot: c,
    emit: J(c, n[c.descriptorType ?? ""] ?? {}, o, s)
  })), E = [], y = [], T = [], p = [], b = [], N = /* @__PURE__ */ new Set();
  u.forEach(({ emit: c }) => {
    E.push(...c.serviceTasks), y.push(...c.gateways), T.push(...c.callActivities), p.push(...c.templateFlows), c.dmn && b.push(c.dmn), c.endsNeeded.forEach((D) => N.add(D));
  });
  const R = [];
  if (u.length > 0) {
    R.push({
      id: `${s.startEventId}-to-${u[0].emit.bpmnEntry}`,
      sourceRef: s.startEventId,
      targetRef: u[0].emit.bpmnEntry,
      conditionExpression: null
    });
    for (let D = 0; D < u.length - 1; D += 1) {
      const F = u[D].emit, O = u[D + 1].emit, j = F.outgoingConditions.success ?? F.outgoingConditions.pass ?? F.outgoingConditions.approved ?? null;
      R.push({
        id: `${F.bpmnExit}-to-${O.bpmnEntry}`,
        sourceRef: F.bpmnExit,
        targetRef: O.bpmnEntry,
        conditionExpression: j
      });
    }
    const c = u[u.length - 1].emit;
    R.push({
      id: `${c.bpmnExit}-to-${s.endEventIds.success}`,
      sourceRef: c.bpmnExit,
      targetRef: s.endEventIds.success,
      conditionExpression: null
    });
  } else
    R.push({
      id: `${s.startEventId}-to-${s.endEventIds.success}`,
      sourceRef: s.startEventId,
      targetRef: s.endEventIds.success,
      conditionExpression: null
    });
  const k = [
    {
      id: s.endEventIds.success,
      name: s.endEventNames.success,
      executionListener: null
    },
    ...N.has(s.endEventIds.failure) ? [{ id: s.endEventIds.failure, name: s.endEventNames.failure }] : [],
    ...N.has(s.endEventIds.rejected) ? [{ id: s.endEventIds.rejected, name: s.endEventNames.rejected }] : []
  ], P = {
    id: s.startEventId,
    name: "Start",
    ...f === "event" ? {
      messageEventDefinition: {
        messageRef: `msg_${(l || "EVENT").toLowerCase()}_${r.length > 0 ? r.join("_").toLowerCase() : "default"}_${o.customerKey}`
      }
    } : {}
  };
  return {
    canvasState: {
      slots: d,
      branches: (t == null ? void 0 : t.branches) ?? {}
    },
    bpmn: {
      customerId: `${o.customerKey}`,
      workflowCategory: v,
      sources: r,
      process: {
        name: o.workflowName,
        isExecutable: "true"
      },
      startEvent: P,
      endEvent: k,
      sequenceFlows: [...R, ...p],
      exclusiveGateways: y,
      serviceTasks: E,
      callActivities: T
    },
    ...f === "event" ? {
      message: {
        id: `msg_${(l || "event").toLowerCase()}_${r.length > 0 ? r.join("_").toLowerCase() : "default"}_${o.customerKey}`,
        name: `msg_${(l || "event").toLowerCase()}_${r.length > 0 ? r.join("_").toLowerCase() : "default"}_${o.customerKey}`
      },
      dmns: b
    } : {
      eventConfig: [
        {
          eventType: l,
          config: {
            type: l,
            ...(($ = i == null ? void 0 : i.nodeData) == null ? void 0 : $.scheduler) ?? {}
          }
        }
      ]
    }
  };
}
export {
  Rt as ActionNode,
  Dt as ApprovalNode,
  re as DynamicFormRenderer,
  Ft as EdgeWithPlusLabel,
  It as EndNode,
  oe as FF,
  Be as FIELD_TYPE_OPTIONS,
  Ct as FilterNode,
  ut as FlowForgeCanvas,
  ct as FlowForgeHeader,
  ae as FlowForgeRegistry,
  ie as FlowForm,
  le as FormulaInput,
  ue as InfiniteSelectField,
  He as NodeTypeRegistry,
  ce as OptionsResolversProvider,
  xt as RestApiNode,
  Ve as SchemaBuilder,
  Me as SchemaBuilderDrawer,
  At as StartNode,
  dt as SubWorkflowPreviewDrawer,
  de as TablePickerField,
  at as TemplateRegistry,
  $t as TriggerNode,
  pe as VariablePicker,
  fe as VariablePickerProvider,
  Ot as WebhookTriggerNode,
  pt as WorkflowCanvas,
  ft as WorkflowExecutionHistory,
  mt as WorkflowTemplateLibrary,
  Et as accessRequestSkeleton,
  me as astHasRefs,
  Ee as astToTokens,
  Je as baseNodeDefaults,
  te as buildBackendPayload,
  ge as buildEvaluationPayload,
  ye as buildFieldConfig,
  he as buildFormulaPath,
  ve as buildSelectStyles,
  Te as buildValidationSchema,
  ee as buildVariableGroups,
  _t as builtInNodeTypes,
  Ke as conditionBranchDescriptor,
  we as dataSourceRegistry,
  Tt as defaultFlowForgeMessages,
  Ye as defineNode,
  Ge as endEventDescriptor,
  be as errorTextStyle,
  Ne as extractLabel,
  Se as fieldRegistry,
  Re as hasFormulaTokens,
  De as helperTextStyle,
  Fe as inputStyle,
  Ie as isFormula,
  bt as loadWorkflowFromBpmn,
  Xe as makeSubWorkflowDescriptor,
  Qe as nodeTypeRegistry,
  Z as notificationChannelRegistry,
  Ze as notificationDescriptor,
  gt as offboardingSkeleton,
  Ce as parseToAST,
  et as restApiDescriptor,
  Nt as saveWorkflowToBpmn,
  xe as serializeAST,
  Ae as serializeASTAsConfig,
  $e as serializeConditionExpressions,
  tt as startEventDescriptor,
  Oe as stripFormulaTokens,
  nt as subWorkflowDescriptor,
  it as templateRegistry,
  _e as tokenize,
  ke as unwrapFormula,
  Pe as useDynamicOptions,
  ze as useFlowForm,
  je as useOptionsResolvers,
  We as useVariablePickerContext,
  yt as userOnboardingSkeleton,
  ht as webhookIntegrationSkeleton,
  st as webhookTriggerDescriptor,
  rt as webhookTriggerTemplate,
  Le as wrapFormula
};
//# sourceMappingURL=index.js.map
