{"version":3,"file":"workflowUtilities.mjs","names":["UnitStateType","UnitTypeEnums","DateTime","formatDateToLocaleString","getWorkflowTaskIconByActionType","type","iconName","Rest","Sms","Mail","Scene","getWorkflowTaskStateIconByStateType","Initial","Started","Completed","Cancelled","Failed","getWorkflowTaskStateIconColorByStateType","color","SELECTABLE_NODE_TYPES","transformWorkflowPlayTree","node","label","name","expanded","startedAt","DATETIME_SHORT","updatedNode","id","parentId","isExpanded","isSelectable","includes","properties","defaultIcon","conditionalIcon","state","nodeLabel","nodeSubLabel","description","interruptPages","playSceneId","endedAt","dueDate","variables","sms","templateData","to","from","body","email","subject","text","html","children","child","updatedChild","push","updateWorkflowPlayNodeState","nodeId","nodeState","length"],"sources":["../../../src/utilities/workflow/workflowUtilities.js"],"sourcesContent":["import { UnitStateType, UnitTypeEnums } from '../../enums/workflowEnums';\nimport { DateTime } from 'luxon';\nimport { formatDateToLocaleString } from '../input/DateUtilities';\n\nexport const getWorkflowTaskIconByActionType = (type) => {\n  let iconName = 'ClipboardListIcon';\n  switch (type) {\n    case UnitTypeEnums.Rest:\n      iconName = 'CloudImportExportIcon';\n      break;\n    case UnitTypeEnums.Sms:\n      iconName = 'MessageFillIcon';\n      break;\n    case UnitTypeEnums.Mail:\n      iconName = 'MailSolidIcon';\n      break;\n    case UnitTypeEnums.Scene:\n      iconName = 'ReleaseGateIcon';\n      break;\n    default:\n      break;\n  }\n  return iconName;\n};\n\nexport const getWorkflowTaskStateIconByStateType = (type) => {\n  let iconName = '';\n  switch (type) {\n    case UnitStateType.Initial:\n      iconName = 'StopwatchIcon';\n      break;\n    case UnitStateType.Started:\n      iconName = 'ProgressLoopOuterIcon';\n      break;\n    case UnitStateType.Completed:\n      iconName = 'CheckMarkIcon';\n      break;\n    case UnitStateType.Cancelled:\n      iconName = 'CancelIcon';\n      break;\n    case UnitStateType.Failed:\n    default:\n      iconName = 'ErrorBadgeIcon';\n      break;\n  }\n  return iconName;\n};\n\nexport const getWorkflowTaskStateIconColorByStateType = (type) => {\n  let color = '';\n  switch (type) {\n    case UnitStateType.Initial:\n      color = '#ffa726';\n      break;\n    case UnitStateType.Started:\n      color = '#29b6f6';\n      break;\n    case UnitStateType.Completed:\n      color = '#66bb6a';\n      break;\n    case UnitStateType.Cancelled:\n      color = '#f44336';\n      break;\n    case UnitStateType.Failed:\n    default:\n      color = '#f44336';\n      break;\n  }\n  return color;\n};\n\nconst SELECTABLE_NODE_TYPES = [\n  UnitTypeEnums.Sms,\n  UnitTypeEnums.Mail,\n  UnitTypeEnums.Scene\n];\n\nexport const transformWorkflowPlayTree = (node) => {\n  if (!node) return null;\n  const label = node.name || '';\n  const expanded = 'expanded';\n  const startedAt = node.startedAt\n    ? formatDateToLocaleString(node.startedAt, DateTime.DATETIME_SHORT)\n    : null;\n\n  const updatedNode = {\n    id: node.id,\n    parentId: node.parentId,\n    isExpanded: expanded,\n    isSelectable: !!node.type && SELECTABLE_NODE_TYPES.includes(node.type),\n    properties: {\n      defaultIcon: {\n        type: '',\n        name: getWorkflowTaskIconByActionType(node.type),\n        color: ''\n      },\n      conditionalIcon: {\n        type: '',\n        name: !!node.type && getWorkflowTaskStateIconByStateType(node.state),\n        color:\n          !!node.type && getWorkflowTaskStateIconColorByStateType(node.state)\n      },\n      nodeLabel: label,\n      nodeSubLabel: node.parentId ? node.description : startedAt || '',\n      state: node.state,\n      type: node.type,\n      interruptPages: node.interruptPages,\n      playSceneId: node.playSceneId,\n      startedAt: node.startedAt,\n      endedAt: node.endedAt,\n      dueDate: node.dueDate,\n      variables: node.variables,\n      sms:\n        node.type === UnitTypeEnums.Sms\n          ? {\n              templateData: node.templateData,\n              to: node.to,\n              from: node.from,\n              body: node.body\n            }\n          : null,\n      email:\n        node.type === UnitTypeEnums.Mail\n          ? {\n              templateData: node.templateData,\n              to: node.to,\n              from: node.from,\n              subject: node.subject,\n              text: node.text,\n              html: node.html\n            }\n          : null\n    },\n    children: []\n  };\n\n  for (const child of node.children) {\n    const updatedChild = transformWorkflowPlayTree(child);\n    if (updatedChild) {\n      updatedNode.children.push(updatedChild);\n    }\n  }\n\n  return updatedNode;\n};\n\nexport const updateWorkflowPlayNodeState = (node, nodeId, nodeState) => {\n  if (!node) return null;\n\n  // Check if the current node matches the nodeId\n  if (node.id === nodeId) {\n    node.properties.state = nodeState;\n    node.properties.defaultIcon = {\n      type: '',\n      name: getWorkflowTaskIconByActionType(node.properties.type),\n      color: ''\n    };\n    node.properties.conditionalIcon = {\n      type: '',\n      name:\n        !!node.properties.type &&\n        getWorkflowTaskStateIconByStateType(nodeState),\n      color:\n        !!node.properties.type &&\n        getWorkflowTaskStateIconColorByStateType(nodeState)\n    };\n    return node; // Return the updated node\n  }\n\n  // Recursively check and update children nodes if any\n  if (node.children && node.children.length) {\n    for (const child of node.children) {\n      const updatedChild = updateWorkflowPlayNodeState(\n        child,\n        nodeId,\n        nodeState\n      );\n      if (updatedChild) {\n        return node; // Return the updated node\n      }\n    }\n  }\n\n  return null; // If no matching nodeId is found\n};\n"],"mappings":";;;;AAIA,MAAaI,mCAAmCC,SAAS;CACvD,IAAIC,WAAW;AACf,SAAQD,MAAR;EACE,KAAKJ,cAAcM;AACjBD,cAAW;AACX;EACF,KAAKL,cAAcO;AACjBF,cAAW;AACX;EACF,KAAKL,cAAcQ;AACjBH,cAAW;AACX;EACF,KAAKL,cAAcS;AACjBJ,cAAW;AACX;EACF,QACE;;AAEJ,QAAOA;;AAGT,MAAaK,uCAAuCN,SAAS;CAC3D,IAAIC,WAAW;AACf,SAAQD,MAAR;EACE,KAAKL,cAAcY;AACjBN,cAAW;AACX;EACF,KAAKN,cAAca;AACjBP,cAAW;AACX;EACF,KAAKN,cAAcc;AACjBR,cAAW;AACX;EACF,KAAKN,cAAce;AACjBT,cAAW;AACX;EACF,KAAKN,cAAcgB;EACnB;AACEV,cAAW;AACX;;AAEJ,QAAOA;;AAGT,MAAaW,4CAA4CZ,SAAS;CAChE,IAAIa,QAAQ;AACZ,SAAQb,MAAR;EACE,KAAKL,cAAc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