@nyaruka/temba-components 0.156.2 → 0.156.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2822,34 +2822,36 @@ const{I:Rc}=rt,Nc=t=>t,Bc=()=>document.createComment(""),Fc=(t,e,i)=>{const o=t.
2822
2822
  text-align: center;
2823
2823
  font-size: 11px;
2824
2824
  color: #8e8e93;
2825
+ max-width: 100%;
2826
+ overflow: hidden;
2825
2827
  }
2826
2828
 
2827
2829
  .event .webhook-event {
2828
2830
  display: inline-flex;
2829
- align-items: center;
2831
+ align-items: flex-start;
2830
2832
  gap: 6px;
2833
+ max-width: 100%;
2834
+ min-width: 0;
2831
2835
  }
2832
2836
 
2833
- .event .webhook-event-log-link {
2834
- all: unset;
2835
- display: inline-flex;
2836
- align-items: center;
2837
- justify-content: center;
2838
- color: #9ca3af;
2839
- cursor: pointer;
2840
- line-height: 1;
2841
- border-radius: 4px;
2842
- transition: color var(--animation-time, 200ms) ease;
2837
+ .event .webhook-event-text {
2838
+ overflow: hidden;
2839
+ display: -webkit-box;
2840
+ -webkit-line-clamp: 2;
2841
+ -webkit-box-orient: vertical;
2842
+ word-break: break-all;
2843
+ min-width: 0;
2844
+ padding: 4px 0;
2843
2845
  }
2844
2846
 
2845
- .event .webhook-event-log-link:hover,
2846
- .event .webhook-event-log-link:focus-visible {
2847
- color: var(--color-primary-dark, #007aff);
2847
+ .event .webhook-event-url {
2848
+ color: inherit;
2849
+ text-decoration: underline;
2850
+ cursor: pointer;
2848
2851
  }
2849
2852
 
2850
- .event .webhook-event-log-link:focus-visible {
2851
- outline: 1px solid currentColor;
2852
- outline-offset: 2px;
2853
+ .event .webhook-event-url:hover {
2854
+ text-decoration: none;
2853
2855
  }
2854
2856
 
2855
2857
  .event p {
@@ -3146,7 +3148,7 @@ const{I:Rc}=rt,Nc=t=>t,Bc=()=>document.createComment(""),Fc=(t,e,i)=>{const o=t.
3146
3148
  Started somebody else in <strong>${e.name}</strong>
3147
3149
  </div>`:null})(t);break;case Jc.RESTHOOK_CALLED:i=(t=>H`<div>
3148
3150
  Triggered flow event <strong>${t.resthook}</strong>
3149
- </div>`)(t);break;case Jc.WEBHOOK_CALLED:i=(t=>H`<div>Called <strong>${t.url}</strong></div>`)(t);break;case Jc.SERVICE_CALLED:i=(t=>{const e=t.service;return"classifier"===e?H`<div>Called classifier</div>`:H`<div>Called <strong>${e}</strong></div>`})(t);break;case Jc.TICKET_ASSIGNEE_CHANGED:i=(t=>t._user?t.assignee?H`<div>
3151
+ </div>`)(t);break;case Jc.WEBHOOK_CALLED:i=(t=>{const e=t.url&&t.url.length>50?t.url.slice(0,50)+"...":t.url;return H`<div>Called <strong>${e}</strong></div>`})(t);break;case Jc.SERVICE_CALLED:i=(t=>{const e=t.service;return"classifier"===e?H`<div>Called classifier</div>`:H`<div>Called <strong>${e}</strong></div>`})(t);break;case Jc.TICKET_ASSIGNEE_CHANGED:i=(t=>t._user?t.assignee?H`<div>
3150
3152
  <strong>${t._user.name}</strong> assigned this ticket to
3151
3153
  <strong>${t.assignee.name}</strong>
3152
3154
  </div>`:H`<div>
@@ -8791,7 +8793,7 @@ background: #ccc;
8791
8793
  ${this.renderUploader()}
8792
8794
  </div>
8793
8795
  </div>
8794
- </div>`}}t([mt({type:String,attribute:!1})],cu.prototype,"endpoint",void 0),t([mt({type:Boolean})],cu.prototype,"pendingDrop",void 0),t([mt({type:Boolean})],cu.prototype,"ignoreDrops",void 0),t([mt({type:String})],cu.prototype,"icon",void 0),t([mt({type:String})],cu.prototype,"accept",void 0),t([mt({type:Number})],cu.prototype,"max",void 0),t([mt({type:Array})],cu.prototype,"attachments",void 0),t([mt({type:Boolean,attribute:!1})],cu.prototype,"uploading",void 0);let hu="dev";try{hu="0.156.2"}catch(t){}const uu=hu,pu="undefined"!=typeof navigator&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function mu(t){return 0!==t.button||!(!pu||!t.ctrlKey)}function gu(t){if(t.dependency){const e=t.dependency.name||t.dependency.key;return`Cannot find a ${t.dependency.type} for ${e}`}return t.description}function fu(t){const e=20*Math.round(t/20);return Math.max(e,0)}const vu="font-family:SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;font-size:0.95em",bu={[Vd.ExpressionPrefix]:`color:${dc.expression};font-weight:600;${vu}`,[Vd.Identifier]:`color:${dc.expression};${vu}`,[Vd.FunctionName]:`color:${dc.fn};font-weight:900;${vu}`,[Vd.StringLiteral]:`color:${dc.string};${vu}`,[Vd.NumberLiteral]:`color:${dc.number};${vu}`,[Vd.Keyword]:`color:${dc.keyword};${vu}`,[Vd.Operator]:`color:${dc.operator};${vu}`,[Vd.ContextRef]:`color:${dc.expression};${vu}`,[Vd.Separator]:`color:${dc.operator};${vu}`,[Vd.Arrow]:`color:${dc.operator};${vu}`,[Vd.Bracket]:`color:${dc.operator};${vu}`,[Vd.Paren]:`color:${dc.paren};${vu}`,[Vd.Whitespace]:vu},yu=[[/claude|anthropic/i,"anthropic"],[/gpt|openai|o1|o3|o4/i,"openai"],[/gemini|google/i,"gemini"],[/azure|microsoft/i,"azure"],[/deepseek/i,"deepseek"]],xu=(t,e=!1)=>{const i=Qd(t||"",e?Nd:Rd),o=[];for(const t of i){const e=!!bu[t.type],i=o[o.length-1];i&&i.isExpr===e?i.tokens.push(t):o.push({isExpr:e,tokens:[t]})}const n=t=>{const e=bu[t.type];if(!e){const e=t.text.split("\n");return H`${e.map((t,e)=>H`${e>0?H`<br />`:null}${t}`)}`}const i=t.text.split("\n");return H`${i.map((t,i)=>H`${i>0?H`<br />`:null}${t?H`<span style="${e}">${t}</span>`:null}`)}`};return H`${o.map(t=>{const e=H`${t.tokens.map(n)}`;return t.isExpr?H`<span style="hyphens:none">${e}</span>`:e})}`},wu=(t,e,i=3)=>H`<div
8796
+ </div>`}}t([mt({type:String,attribute:!1})],cu.prototype,"endpoint",void 0),t([mt({type:Boolean})],cu.prototype,"pendingDrop",void 0),t([mt({type:Boolean})],cu.prototype,"ignoreDrops",void 0),t([mt({type:String})],cu.prototype,"icon",void 0),t([mt({type:String})],cu.prototype,"accept",void 0),t([mt({type:Number})],cu.prototype,"max",void 0),t([mt({type:Array})],cu.prototype,"attachments",void 0),t([mt({type:Boolean,attribute:!1})],cu.prototype,"uploading",void 0);let hu="dev";try{hu="0.156.3"}catch(t){}const uu=hu,pu="undefined"!=typeof navigator&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function mu(t){return 0!==t.button||!(!pu||!t.ctrlKey)}function gu(t){if(t.dependency){const e=t.dependency.name||t.dependency.key;return`Cannot find a ${t.dependency.type} for ${e}`}return t.description}function fu(t){const e=20*Math.round(t/20);return Math.max(e,0)}const vu="font-family:SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;font-size:0.95em",bu={[Vd.ExpressionPrefix]:`color:${dc.expression};font-weight:600;${vu}`,[Vd.Identifier]:`color:${dc.expression};${vu}`,[Vd.FunctionName]:`color:${dc.fn};font-weight:900;${vu}`,[Vd.StringLiteral]:`color:${dc.string};${vu}`,[Vd.NumberLiteral]:`color:${dc.number};${vu}`,[Vd.Keyword]:`color:${dc.keyword};${vu}`,[Vd.Operator]:`color:${dc.operator};${vu}`,[Vd.ContextRef]:`color:${dc.expression};${vu}`,[Vd.Separator]:`color:${dc.operator};${vu}`,[Vd.Arrow]:`color:${dc.operator};${vu}`,[Vd.Bracket]:`color:${dc.operator};${vu}`,[Vd.Paren]:`color:${dc.paren};${vu}`,[Vd.Whitespace]:vu},yu=[[/claude|anthropic/i,"anthropic"],[/gpt|openai|o1|o3|o4/i,"openai"],[/gemini|google/i,"gemini"],[/azure|microsoft/i,"azure"],[/deepseek/i,"deepseek"]],xu=(t,e=!1)=>{const i=Qd(t||"",e?Nd:Rd),o=[];for(const t of i){const e=!!bu[t.type],i=o[o.length-1];i&&i.isExpr===e?i.tokens.push(t):o.push({isExpr:e,tokens:[t]})}const n=t=>{const e=bu[t.type];if(!e){const e=t.text.split("\n");return H`${e.map((t,e)=>H`${e>0?H`<br />`:null}${t}`)}`}const i=t.text.split("\n");return H`${i.map((t,i)=>H`${i>0?H`<br />`:null}${t?H`<span style="${e}">${t}</span>`:null}`)}`};return H`${o.map(t=>{const e=H`${t.tokens.map(n)}`;return t.isExpr?H`<span style="hyphens:none">${e}</span>`:e})}`},wu=(t,e,i=3)=>H`<div
8795
8797
  style="display: -webkit-box; -webkit-line-clamp: ${i}; -webkit-box-orient: vertical; overflow: hidden; word-wrap: break-word; overflow-wrap: break-word; hyphens: auto;"
8796
8798
  title="${e}"
8797
8799
  >
@@ -8837,8 +8839,8 @@ background: #ccc;
8837
8839
  </div>`:null}
8838
8840
  ${wu(xu(e.text,!0),e.text)}
8839
8841
  </div>
8840
- </div>`},form:{recipients:{type:"select",label:"Recipients",helpText:"Select the contacts or groups to receive the broadcast",multi:!0,searchable:!0,endpoint:"/contact/omnibox/?types=gc",queryParam:"search",valueKey:"id",nameKey:"name",placeholder:"Search for contacts or groups...",required:!0,expressions:"session"},text:{type:"message-editor",label:"Message",helpText:"Enter the message to send with optional attachments. You can use expressions like @contact.name",required:!0,evaluated:!0,placeholder:"Type your message here...",maxAttachments:10,accept:"",endpoint:"/api/v2/media.json",counter:"temba-charcount",gsm:!0,autogrow:!0},template:{type:"template-editor",endpoint:"/api/internal/templates.json"}},layout:["recipients","text",{type:"accordion",sections:[{label:"WhatsApp Template",collapsed:!0,localizable:!1,getValueCount:t=>!!t.template,items:["template"]}]}],toFormData:t=>({uuid:t.uuid,recipients:[...(t.contacts||[]).map(t=>({id:t.uuid,name:t.name,type:"contact"})),...(t.groups||[]).map(t=>({id:t.uuid,name:t.name,type:"group"})),...(t.legacy_vars||[]).map(t=>({id:t,name:t,type:"expression"}))],text:t.text||"",attachments:t.attachments||[],template:t.template||null,template_variables:t.template_variables||[]}),fromFormData:t=>{const e=t.recipients||[],i=e.filter(t=>"contact"===t.type||!t.type&&!t.expression&&t.id).map(t=>({uuid:t.id,name:t.name})),o=e.filter(t=>"group"===t.type).map(t=>({uuid:t.id,name:t.name})),n=e.filter(t=>"expression"===t.type||t.expression).map(t=>t.value||t.name||t.id),s={uuid:t.uuid,type:"send_broadcast",text:t.text||"",contacts:i,groups:o,attachments:t.attachments||[]};return n.length>0&&(s.legacy_vars=n),0===s.attachments.length&&delete s.attachments,t.template&&(s.template=t.template,s.template_variables=t.template_variables||[]),s},sanitize:t=>{t.text&&"string"==typeof t.text&&(t.text=t.text.trim())}},Qu={name:"Save Flow Result",group:qu.save,flowTypes:[Ru,Pu,Nu],render:(t,e)=>wu(H`Set <strong>${e.name}</strong> to
8841
- ${xu(e.value,!0)}`,`Set ${e.name} to ${e.value}`),form:{name:{type:"select",label:"Result Name",helpText:"Select an existing result name or type a new one",required:!0,placeholder:"Select or enter result name...",createArbitraryOption:(t,e)=>!e.some(e=>e.value.toLowerCase()===t.toLowerCase()||e.name.toLowerCase()===t.toLowerCase())&&t.trim().length>0?{value:t,name:t}:null,searchable:!0,clearable:!1,getDynamicOptions:()=>{const t=Ed();return t?t.getState().getFlowResults().map(t=>({value:t.name,name:t.name})):[]}},value:{type:"textarea",label:"Value",helpText:"The value to save for this result (can use expressions)",required:!1,evaluated:!0,placeholder:"Enter value..."},category:{type:"text",label:"Category",helpText:"Optional category for this result",required:!1,placeholder:"Enter category..."}},layout:["name","value","category"],toFormData:t=>({uuid:t.uuid,name:t.name?[{name:t.name,value:t.name}]:null,value:t.value||"",category:t.category||""}),fromFormData:t=>{let e=t.name||"";return Array.isArray(e)&&e.length>0&&(e=e[0]),"object"==typeof e&&e.value&&(e=e.value),"object"==typeof e&&e.name&&(e=e.name),{uuid:t.uuid,type:"set_run_result",name:String(e),value:t.value||"",category:t.category||""}}},Ju={image:"Image",audio:"Audio",video:"Video",application:"Document"},tp={name:"Send Message",group:qu.send,flowTypes:[Ru,Pu,Nu],hideFromActions:!0,render:(t,e)=>{var i;const o=Dc(e.text);return H`
8842
+ </div>`},form:{recipients:{type:"select",label:"Recipients",helpText:"Select the contacts or groups to receive the broadcast",multi:!0,searchable:!0,endpoint:"/contact/omnibox/?types=gc",queryParam:"search",valueKey:"id",nameKey:"name",placeholder:"Search for contacts or groups...",required:!0,expressions:"session"},text:{type:"message-editor",label:"Message",helpText:"Enter the message to send with optional attachments. You can use expressions like @contact.name",required:!0,evaluated:!0,placeholder:"Type your message here...",maxLength:640,maxAttachments:10,accept:"",endpoint:"/api/v2/media.json",counter:"temba-charcount",gsm:!0,autogrow:!0},template:{type:"template-editor",endpoint:"/api/internal/templates.json"}},layout:["recipients","text",{type:"accordion",sections:[{label:"WhatsApp Template",collapsed:!0,localizable:!1,getValueCount:t=>!!t.template,items:["template"]}]}],toFormData:t=>({uuid:t.uuid,recipients:[...(t.contacts||[]).map(t=>({id:t.uuid,name:t.name,type:"contact"})),...(t.groups||[]).map(t=>({id:t.uuid,name:t.name,type:"group"})),...(t.legacy_vars||[]).map(t=>({id:t,name:t,type:"expression"}))],text:t.text||"",attachments:t.attachments||[],template:t.template||null,template_variables:t.template_variables||[]}),fromFormData:t=>{const e=t.recipients||[],i=e.filter(t=>"contact"===t.type||!t.type&&!t.expression&&t.id).map(t=>({uuid:t.id,name:t.name})),o=e.filter(t=>"group"===t.type).map(t=>({uuid:t.id,name:t.name})),n=e.filter(t=>"expression"===t.type||t.expression).map(t=>t.value||t.name||t.id),s={uuid:t.uuid,type:"send_broadcast",text:t.text||"",contacts:i,groups:o,attachments:t.attachments||[]};return n.length>0&&(s.legacy_vars=n),0===s.attachments.length&&delete s.attachments,t.template&&(s.template=t.template,s.template_variables=t.template_variables||[]),s},sanitize:t=>{t.text&&"string"==typeof t.text&&(t.text=t.text.trim())},localizable:["text","attachments"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};return e.text&&Array.isArray(e.text)?i.text=e.text[0]||"":i.text="",e.attachments&&Array.isArray(e.attachments)?i.attachments=e.attachments:i.attachments=[],i},fromLocalizationFormData:(t,e)=>{const i={};t.text&&""!==t.text.trim()&&t.text!==e.text&&(i.text=[t.text]);const o=(t.attachments||[]).filter(t=>t&&""!==t.trim());return o.length>0&&JSON.stringify(o)!==JSON.stringify(e.attachments||[])&&(i.attachments=o),i}},Qu={name:"Save Flow Result",group:qu.save,flowTypes:[Ru,Pu,Nu],render:(t,e)=>wu(H`Set <strong>${e.name}</strong> to
8843
+ ${xu(e.value,!0)}`,`Set ${e.name} to ${e.value}`),form:{name:{type:"select",label:"Result Name",helpText:"Select an existing result name or type a new one",required:!0,placeholder:"Select or enter result name...",createArbitraryOption:(t,e)=>!e.some(e=>e.value.toLowerCase()===t.toLowerCase()||e.name.toLowerCase()===t.toLowerCase())&&t.trim().length>0?{value:t,name:t}:null,searchable:!0,clearable:!1,getDynamicOptions:()=>{const t=Ed();return t?t.getState().getFlowResults().map(t=>({value:t.name,name:t.name})):[]}},value:{type:"textarea",label:"Value",helpText:"The value to save for this result (can use expressions)",required:!1,evaluated:!0,placeholder:"Enter value..."},category:{type:"text",label:"Category",helpText:"Optional category for this result",required:!1,maxLength:36,placeholder:"Enter category..."}},layout:["name","value","category"],toFormData:t=>({uuid:t.uuid,name:t.name?[{name:t.name,value:t.name}]:null,value:t.value||"",category:t.category||""}),fromFormData:t=>{let e=t.name||"";return Array.isArray(e)&&e.length>0&&(e=e[0]),"object"==typeof e&&e.value&&(e=e.value),"object"==typeof e&&e.name&&(e=e.name),{uuid:t.uuid,type:"set_run_result",name:String(e),value:t.value||"",category:t.category||""}}},Ju={image:"Image",audio:"Audio",video:"Video",application:"Document"},tp={name:"Send Message",group:qu.send,flowTypes:[Ru,Pu,Nu],hideFromActions:!0,render:(t,e)=>{var i;const o=Dc(e.text);return H`
8842
8844
  ${e.template?H`<div
8843
8845
  style="border: 1px solid #7dc8bc;padding: 0.5em;margin-bottom: 0.5em;border-radius: 4px; display:flex;align-items: flex-start;background: #f0faf7;color: #128C7E;font-size: 0.85em;"
8844
8846
  >
@@ -8858,12 +8860,12 @@ background: #ccc;
8858
8860
  ${(null===(i=e.quick_replies||[])||void 0===i?void 0:i.length)>0?H`<div class="quick-replies">
8859
8861
  ${(e.quick_replies||[]).map(t=>H`<div class="quick-reply">${t}</div>`)}
8860
8862
  </div>`:null}
8861
- `},form:{text:{type:"message-editor",label:"Message",helpText:"Enter the message to send with optional attachments. You can use expressions like @contact.name",required:!0,evaluated:!0,placeholder:"Type your message here...",maxAttachments:10,accept:"",endpoint:"/api/v2/media.json",counter:"temba-charcount",gsm:!0,autogrow:!0},quick_replies:{type:"select",options:[],multi:!0,tags:!0,searchable:!0,placeholder:"Add quick replies...",maxItems:10,evaluated:!0},template:{type:"template-editor",endpoint:"/api/internal/templates.json"},runtime_attachments:{type:"array",itemLabel:"Attachment",sortable:!0,maxItems:10,isEmptyItem:t=>!t.expression||""===t.expression.trim(),itemConfig:{type:{type:"select",width:"140px",options:[{value:"image",name:"Image"},{value:"audio",name:"Audio"},{value:"video",name:"Video"},{value:"application",name:"Document"}],required:!0,searchable:!1},expression:{type:"text",placeholder:"Expression (e.g. @contact.photo)",required:!0,evaluated:!0}}}},layout:["text",{type:"accordion",sections:[{label:"Quick Replies",collapsed:!0,getValueCount:t=>{var e;return(null===(e=t.quick_replies)||void 0===e?void 0:e.length)||0},items:["quick_replies"]},{label:"WhatsApp Template",collapsed:!0,localizable:!1,getValueCount:t=>!!t.template,items:["template"]},{label:"Runtime Attachments",collapsed:!0,getValueCount:t=>{var e;return(null===(e=t.runtime_attachments)||void 0===e?void 0:e.filter(t=>t&&t.expression&&""!==t.expression.trim()).length)||0},items:["runtime_attachments"]}]}],toFormData:t=>{const e=[],i=[];return t.attachments&&Array.isArray(t.attachments)&&t.attachments.forEach(t=>{if("string"==typeof t&&t.includes(":")){const o=t.indexOf(":"),n=t.substring(0,o),s=t.substring(o+1);n.includes("/")?i.push(t):e.push({type:{name:Ju[n]||Pe(n),value:n},expression:s})}}),{uuid:t.uuid,text:t.text||"",attachments:i,runtime_attachments:e,quick_replies:(t.quick_replies||[]).map(t=>({name:t,value:t})),template:t.template||null,template_variables:t.template_variables||[]}},fromFormData:t=>{const e={uuid:t.uuid,type:"send_msg",text:t.text||"",attachments:[],quick_replies:(t.quick_replies||[]).map(t=>"string"==typeof t?t:t.value||t.name||t)},i=t.attachments||[],o=(t.runtime_attachments||[]).filter(t=>t&&t.type&&t.expression).map(t=>`${t.type[0].value}:${t.expression}`);return e.attachments=[...i,...o],0===e.quick_replies.length&&delete e.quick_replies,t.template&&(e.template=t.template,e.template_variables=t.template_variables||[]),e},sanitize:t=>{t.text&&"string"==typeof t.text&&(t.text=t.text.trim())},validate:t=>{const e={},i=t.attachments||[],o=(t.runtime_attachments||[]).filter(t=>t&&t.expression&&""!==t.expression.trim());return i.length+o.length>10&&(o.length>0&&(e.runtime_attachments="Each message can only have up to 10 attachments"),i.length>0&&(e.text="Each message can only have up to 10 total attachments")),{valid:0===Object.keys(e).length,errors:e}},localizable:["text","quick_replies","attachments"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};e.text&&Array.isArray(e.text)?i.text=e.text[0]||"":i.text="",e.attachments&&Array.isArray(e.attachments)&&(i.attachments=e.attachments),e.quick_replies&&Array.isArray(e.quick_replies)&&(i.quick_replies=e.quick_replies.map(t=>({name:t,value:t})));const o=[],n=[];return i.attachments&&Array.isArray(i.attachments)&&i.attachments.forEach(t=>{if("string"==typeof t&&t.includes(":")){const e=t.indexOf(":"),i=t.substring(0,e),s=t.substring(e+1);i.includes("/")?n.push(t):o.push({type:{name:Ju[i]||Pe(i),value:i},expression:s})}}),i.attachments=n,i.runtime_attachments=o,i},fromLocalizationFormData:(t,e)=>{const i={};t.text&&""!==t.text.trim()&&t.text!==e.text&&(i.text=[t.text]);const o=(t.quick_replies||[]).map(t=>"string"==typeof t?t:t.value||t.name||t).filter(t=>t&&""!==t.trim());o.length>0&&JSON.stringify(o)!==JSON.stringify(e.quick_replies||[])&&(i.quick_replies=o);const n=[...(t.attachments||[]).filter(t=>t&&""!==t.trim()),...(t.runtime_attachments||[]).filter(t=>t&&t.type&&t.expression&&""!==t.expression.trim()).map(t=>`${t.type[0].value}:${t.expression}`)];return n.length>0&&JSON.stringify(n)!==JSON.stringify(e.attachments||[])&&(i.attachments=n),i}},ep={name:"Send Email",group:qu.broadcast,flowTypes:[Ru,Pu,Nu],render:(t,e)=>H`<div>
8863
+ `},form:{text:{type:"message-editor",label:"Message",helpText:"Enter the message to send with optional attachments. You can use expressions like @contact.name",required:!0,evaluated:!0,placeholder:"Type your message here...",maxLength:1e4,maxAttachments:10,accept:"",endpoint:"/api/v2/media.json",counter:"temba-charcount",gsm:!0,autogrow:!0},quick_replies:{type:"select",options:[],multi:!0,tags:!0,searchable:!0,placeholder:"Add quick replies...",maxItems:10,evaluated:!0},template:{type:"template-editor",endpoint:"/api/internal/templates.json"},runtime_attachments:{type:"array",itemLabel:"Attachment",sortable:!0,maxItems:10,isEmptyItem:t=>!t.expression||""===t.expression.trim(),itemConfig:{type:{type:"select",width:"140px",options:[{value:"image",name:"Image"},{value:"audio",name:"Audio"},{value:"video",name:"Video"},{value:"application",name:"Document"}],required:!0,searchable:!1},expression:{type:"text",placeholder:"Expression (e.g. @contact.photo)",required:!0,evaluated:!0}}}},layout:["text",{type:"accordion",sections:[{label:"Quick Replies",collapsed:!0,getValueCount:t=>{var e;return(null===(e=t.quick_replies)||void 0===e?void 0:e.length)||0},items:["quick_replies"]},{label:"WhatsApp Template",collapsed:!0,localizable:!1,getValueCount:t=>!!t.template,items:["template"]},{label:"Runtime Attachments",collapsed:!0,getValueCount:t=>{var e;return(null===(e=t.runtime_attachments)||void 0===e?void 0:e.filter(t=>t&&t.expression&&""!==t.expression.trim()).length)||0},items:["runtime_attachments"]}]}],toFormData:t=>{const e=[],i=[];return t.attachments&&Array.isArray(t.attachments)&&t.attachments.forEach(t=>{if("string"==typeof t&&t.includes(":")){const o=t.indexOf(":"),n=t.substring(0,o),s=t.substring(o+1);n.includes("/")?i.push(t):e.push({type:{name:Ju[n]||Pe(n),value:n},expression:s})}}),{uuid:t.uuid,text:t.text||"",attachments:i,runtime_attachments:e,quick_replies:(t.quick_replies||[]).map(t=>({name:t,value:t})),template:t.template||null,template_variables:t.template_variables||[]}},fromFormData:t=>{const e={uuid:t.uuid,type:"send_msg",text:t.text||"",attachments:[],quick_replies:(t.quick_replies||[]).map(t=>"string"==typeof t?t:t.value||t.name||t)},i=t.attachments||[],o=(t.runtime_attachments||[]).filter(t=>t&&t.type&&t.expression).map(t=>`${t.type[0].value}:${t.expression}`);return e.attachments=[...i,...o],0===e.quick_replies.length&&delete e.quick_replies,t.template&&(e.template=t.template,e.template_variables=t.template_variables||[]),e},sanitize:t=>{t.text&&"string"==typeof t.text&&(t.text=t.text.trim())},validate:t=>{const e={},i=t.attachments||[],o=(t.runtime_attachments||[]).filter(t=>t&&t.expression&&""!==t.expression.trim());return i.length+o.length>10&&(o.length>0&&(e.runtime_attachments="Each message can only have up to 10 attachments"),i.length>0&&(e.text="Each message can only have up to 10 total attachments")),{valid:0===Object.keys(e).length,errors:e}},localizable:["text","quick_replies","attachments"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};e.text&&Array.isArray(e.text)?i.text=e.text[0]||"":i.text="",e.attachments&&Array.isArray(e.attachments)&&(i.attachments=e.attachments),e.quick_replies&&Array.isArray(e.quick_replies)&&(i.quick_replies=e.quick_replies.map(t=>({name:t,value:t})));const o=[],n=[];return i.attachments&&Array.isArray(i.attachments)&&i.attachments.forEach(t=>{if("string"==typeof t&&t.includes(":")){const e=t.indexOf(":"),i=t.substring(0,e),s=t.substring(e+1);i.includes("/")?n.push(t):o.push({type:{name:Ju[i]||Pe(i),value:i},expression:s})}}),i.attachments=n,i.runtime_attachments=o,i},fromLocalizationFormData:(t,e)=>{const i={};t.text&&""!==t.text.trim()&&t.text!==e.text&&(i.text=[t.text]);const o=(t.quick_replies||[]).map(t=>"string"==typeof t?t:t.value||t.name||t).filter(t=>t&&""!==t.trim());o.length>0&&JSON.stringify(o)!==JSON.stringify(e.quick_replies||[])&&(i.quick_replies=o);const n=[...(t.attachments||[]).filter(t=>t&&""!==t.trim()),...(t.runtime_attachments||[]).filter(t=>t&&t.type&&t.expression&&""!==t.expression.trim()).map(t=>`${t.type[0].value}:${t.expression}`)];return n.length>0&&JSON.stringify(n)!==JSON.stringify(e.attachments||[])&&(i.attachments=n),i}},ep={name:"Send Email",group:qu.broadcast,flowTypes:[Ru,Pu,Nu],render:(t,e)=>H`<div>
8862
8864
  <div>${ku(e.addresses,ko.email,!0)}</div>
8863
8865
  <div style="margin-top: 0.5em">
8864
8866
  ${wu(xu(e.subject,!0),e.subject)}
8865
8867
  </div>
8866
- </div>`,form:{addresses:{type:"select",label:"Recipients",multi:!0,searchable:!0,placeholder:"Enter email addresses...",emails:!0,expressions:"session"},subject:{type:"text",label:"Subject",required:!0,evaluated:!0,placeholder:"Enter email subject",maxLength:255},body:{type:"textarea",required:!0,evaluated:!0,minHeight:175}},fromFormData:t=>({uuid:t.uuid,type:"send_email",addresses:t.addresses.map(t=>t.value),subject:t.subject,body:t.body}),validate:t=>{const e={};return t.addresses&&0!==t.addresses.length||(e.addresses="At least one recipient email address is required"),{valid:0===Object.keys(e).length,errors:e}}},ip={name:"Start Flow",group:qu.broadcast,flowTypes:[Ru,Pu,Nu],render:(t,e)=>{let i=H``;if(e.create_contact)i=H`Create a new contact`;else if(e.contact_query)i=H`${xu(e.contact_query,!0)}`;else{const t=[...(e.groups||[]).map(t=>({name:t.name,icon:ko.group,uuid:t.uuid,eventType:Io.GroupClicked})),...(e.contacts||[]).map(t=>({name:t.name,icon:ko.contacts,uuid:t.uuid,eventType:Io.ContactClicked})),...(e.legacy_vars||[]).map(t=>({name:t,icon:ko.contacts,content:xu(t,!0)}))];i=H`${Cu(t)}`}return H`
8868
+ </div>`,form:{addresses:{type:"select",label:"Recipients",multi:!0,searchable:!0,placeholder:"Enter email addresses...",emails:!0,expressions:"session"},subject:{type:"text",label:"Subject",required:!0,evaluated:!0,placeholder:"Enter email subject",maxLength:1e3},body:{type:"textarea",required:!0,evaluated:!0,maxLength:1e4,minHeight:175}},fromFormData:t=>({uuid:t.uuid,type:"send_email",addresses:t.addresses.map(t=>t.value),subject:t.subject,body:t.body}),localizable:["subject","body"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};return e.subject&&Array.isArray(e.subject)?i.subject=e.subject[0]||"":i.subject="",e.body&&Array.isArray(e.body)?i.body=e.body[0]||"":i.body="",i},fromLocalizationFormData:(t,e)=>{const i={};return t.subject&&""!==t.subject.trim()&&t.subject!==e.subject&&(i.subject=[t.subject]),t.body&&""!==t.body.trim()&&t.body!==e.body&&(i.body=[t.body]),i},validate:t=>{const e={};return t.addresses&&0!==t.addresses.length||(e.addresses="At least one recipient email address is required"),{valid:0===Object.keys(e).length,errors:e}}},ip={name:"Start Flow",group:qu.broadcast,flowTypes:[Ru,Pu,Nu],render:(t,e)=>{let i=H``;if(e.create_contact)i=H`Create a new contact`;else if(e.contact_query)i=H`${xu(e.contact_query,!0)}`;else{const t=[...(e.groups||[]).map(t=>({name:t.name,icon:ko.group,uuid:t.uuid,eventType:Io.GroupClicked})),...(e.contacts||[]).map(t=>({name:t.name,icon:ko.contacts,uuid:t.uuid,eventType:Io.ContactClicked})),...(e.legacy_vars||[]).map(t=>({name:t,icon:ko.contacts,content:xu(t,!0)}))];i=H`${Cu(t)}`}return H`
8867
8869
  <div>
8868
8870
  <div>${i}</div>
8869
8871
  <div style="margin-top: 0.5em">
@@ -8906,7 +8908,7 @@ background: #ccc;
8906
8908
  </div>
8907
8909
  `}
8908
8910
  </div>`:null}
8909
- `;var i},form:{text:{type:"textarea",label:"Message",required:!0,evaluated:!0,placeholder:"Enter message to speak...",minHeight:80},audio_url:{type:"media",label:"Recording",required:!1,accept:"audio/*",optionalLink:"Add a recording"}},layout:["text","audio_url"],toFormData:t=>({uuid:t.uuid,text:t.text||"",audio_url:t.audio_url||""}),fromFormData:t=>{const e={uuid:t.uuid,type:"say_msg",text:t.text||""};return t.audio_url&&""!==t.audio_url.trim()&&(e.audio_url=t.audio_url.trim()),e},sanitize:t=>{t.text&&"string"==typeof t.text&&(t.text=t.text.trim())},localizable:["text","audio_url"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};return e.text&&Array.isArray(e.text)?i.text=e.text[0]||"":i.text="",e.audio_url&&Array.isArray(e.audio_url)?i.audio_url=e.audio_url[0]||"":i.audio_url="",i},fromLocalizationFormData:(t,e)=>{const i={};return t.text&&""!==t.text.trim()&&t.text!==e.text&&(i.text=[t.text]),t.audio_url&&""!==t.audio_url.trim()&&t.audio_url!==e.audio_url&&(i.audio_url=[t.audio_url]),i}},pp={name:"Play Recording",group:qu.send,flowTypes:[Ru],render:(t,e)=>H`
8911
+ `;var i},form:{text:{type:"textarea",label:"Message",required:!0,evaluated:!0,placeholder:"Enter message to speak...",maxLength:1e4,minHeight:80},audio_url:{type:"media",label:"Recording",required:!1,accept:"audio/*",optionalLink:"Add a recording"}},layout:["text","audio_url"],toFormData:t=>({uuid:t.uuid,text:t.text||"",audio_url:t.audio_url||""}),fromFormData:t=>{const e={uuid:t.uuid,type:"say_msg",text:t.text||""};return t.audio_url&&""!==t.audio_url.trim()&&(e.audio_url=t.audio_url.trim()),e},sanitize:t=>{t.text&&"string"==typeof t.text&&(t.text=t.text.trim())},localizable:["text","audio_url"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};return e.text&&Array.isArray(e.text)?i.text=e.text[0]||"":i.text="",e.audio_url&&Array.isArray(e.audio_url)?i.audio_url=e.audio_url[0]||"":i.audio_url="",i},fromLocalizationFormData:(t,e)=>{const i={};return t.text&&""!==t.text.trim()&&t.text!==e.text&&(i.text=[t.text]),t.audio_url&&""!==t.audio_url.trim()&&t.audio_url!==e.audio_url&&(i.audio_url=[t.audio_url]),i}},pp={name:"Play Recording",group:qu.send,flowTypes:[Ru],render:(t,e)=>H`
8910
8912
  <div style="display: flex; align-items: center; gap: 0.3em;">
8911
8913
  <temba-icon name="recording" size="1"></temba-icon>
8912
8914
  <div
@@ -8916,12 +8918,12 @@ background: #ccc;
8916
8918
  ${xu(e.audio_url||"",!0)}
8917
8919
  </div>
8918
8920
  </div>
8919
- `,form:{audio_url:{type:"text",label:"Recording URL",required:!0,evaluated:!0}},layout:["audio_url"],toFormData:t=>({uuid:t.uuid,audio_url:t.audio_url||""}),fromFormData:t=>({uuid:t.uuid,type:"play_audio",audio_url:(t.audio_url||"").trim()}),localizable:["audio_url"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};return e.audio_url&&Array.isArray(e.audio_url)?i.audio_url=e.audio_url[0]||"":i.audio_url="",i},fromLocalizationFormData:(t,e)=>{const i={};return t.audio_url&&""!==t.audio_url.trim()&&t.audio_url!==e.audio_url&&(i.audio_url=[t.audio_url]),i}};function mp(t){const e=Sd.getState().flowDefinition;return!!e&&("messaging_background"===e.type&&"message"===t.type)}const gp={name:"Enter a Flow",group:qu.trigger,hideFromActions:!0,flowTypes:[Ru,Pu,Nu],render:(t,e)=>H`${$u([e.flow],"flow")}`,toFormData:t=>({uuid:t.uuid,flow:t.flow?[t.flow]:[]}),form:{flow:{type:"select",required:!0,placeholder:"Select a flow...",helpText:"The contact will enter this flow and not return",endpoint:"/api/v2/flows.json",valueKey:"uuid",nameKey:"name",shouldExclude:mp}},layout:["flow"],fromFormData:t=>{const e=t.flow[0];return{uuid:t.uuid,type:"enter_flow",terminal:!0,flow:{uuid:e.uuid||e.value,name:e.name}}}},fp={ARS:{code:"ARS",name:"Argentine Peso"},AUD:{code:"AUD",name:"Australian Dollar"},BIF:{code:"BIF",name:"Burundi Franc"},BRL:{code:"BRL",name:"Brazilian Real"},CAD:{code:"CAD",name:"Canadian Dollar"},CDF:{code:"CDF",name:"Congolese Franc"},CLP:{code:"CLP",name:"Chilean Peso"},COP:{code:"COP",name:"Colombian Peso"},DJF:{code:"DJF",name:"Djibouti Franc"},DOP:{code:"DOP",name:"Dominican Peso"},DZD:{code:"DZD",name:"Algerian Dinar"},EUR:{code:"EUR",name:"Euro"},GBP:{code:"GBP",name:"Pound Sterling"},GHS:{code:"GHS",name:"Ghana Cedi"},GNF:{code:"GNF",name:"Guinean Franc"},KES:{code:"KES",name:"Kenyan Shilling"},LBP:{code:"LBP",name:"Lebanese Pound"},LKR:{code:"LKR",name:"Sri Lanka Rupee"},LRD:{code:"LRD",name:"Liberian Dollar"},MWK:{code:"MWK",name:"Malawian Kwacha"},MXN:{code:"MXN",name:"Mexican Peso"},MZN:{code:"MZN",name:"Mozambican Metical"},NAD:{code:"NAD",name:"Namibian Dollar"},NGN:{code:"NGN",name:"Nigerian Naira"},PEN:{code:"PEN",name:"Peruvian Sol"},PHP:{code:"PHP",name:"Philippine Peso"},RWF:{code:"RWF",name:"Rwandan Franc"},SZL:{code:"SZL",name:"Swazi Lilangeni"},TZS:{code:"TZS",name:"Tanzanian Shilling"},UGX:{code:"UGX",name:"Ugandan Shilling"},USD:{code:"USD",name:"US Dollar"},XAF:{code:"XAF",name:"Central African CFA Franc"},XOF:{code:"XOF",name:"West African CFA Franc"},ZAR:{code:"ZAR",name:"South African Rand"},ZMW:{code:"ZMW",name:"Zambian Kwacha"}},vp=Object.values(fp).map(t=>({value:t.code,name:`${t.name} (${t.code})`})),bp=[{type:"has_any_word",name:"has any of the words",operands:1},{type:"has_all_words",name:"has all of the words",operands:1},{type:"has_phrase",name:"has the phrase",operands:1},{type:"has_only_phrase",name:"has only the phrase",operands:1},{type:"has_beginning",name:"starts with",operands:1},{type:"has_text",name:"has some text",operands:0,categoryName:"Has Text"},{type:"has_number",name:"has a number",operands:0,categoryName:"Has Number"},{type:"has_number_between",name:"has a number between",operands:2},{type:"has_number_lt",name:"has a number below",operands:1},{type:"has_number_lte",name:"has a number at or below",operands:1},{type:"has_number_eq",name:"has a number equal to",operands:1},{type:"has_number_gte",name:"has a number at or above",operands:1},{type:"has_number_gt",name:"has a number above",operands:1},{type:"has_date",name:"has a date",operands:0,categoryName:"Has Date"},{type:"has_date_lt",name:"has a date before",operands:1},{type:"has_date_eq",name:"has a date equal to",operands:1},{type:"has_date_gt",name:"has a date after",operands:1},{type:"has_time",name:"has a time",operands:0,categoryName:"Has Time"},{type:"has_phone",name:"has a phone number",operands:0,categoryName:"Has Phone"},{type:"has_email",name:"has an email",operands:0,categoryName:"Has Email"},{type:"has_state",name:"has state",operands:0,categoryName:"Has State",filter:"locations"},{type:"has_district",name:"has district",operands:1,categoryName:"Has District",filter:"locations"},{type:"has_ward",name:"has ward",operands:2,categoryName:"Has Ward",filter:"locations"},{type:"has_group",name:"is in the group",operands:1,visibility:"hidden"},{type:"has_category",name:"has the category",operands:0,visibility:"hidden"},{type:"has_error",name:"has an error",operands:0,categoryName:"Has Error",visibility:"hidden"},{type:"has_value",name:"is not empty",operands:0,categoryName:"Not Empty",visibility:"hidden"},{type:"has_pattern",name:"matches regex",operands:1}],yp=t=>bp.filter(e=>"hidden"!==e.visibility&&(!e.filter||!!t&&t.includes(e.filter))),xp=new Set(["has_beginning","has_number","has_number_between","has_number_lt","has_number_lte","has_number_eq","has_number_gte","has_number_gt","has_pattern"]),wp=t=>bp.find(e=>e.type===t),_p=t=>t.map(t=>({value:t.type,name:t.name})),kp={type:"text",required:!1,placeholder:"(optional)",helpText:"The name to use to reference this result in the flow"},Cp={type:"checkbox",label:"Require rules to be localized",helpText:"Each language must specify its own rules for this node"},Sp={type:"checkbox",label:"Require categories to be localized",helpText:t=>{var e;const i=null===(e=t.result_name)||void 0===e?void 0:e.trim();if(i){return`Only enable if you plan to use @results.${i.toLowerCase().replace(/\s+/g,"_")}.category_localized`}return"Only enable if you plan to use category_localized in your expressions for this result"},conditions:{visible:t=>!!t.result_name}},Ap={label:"Save Result",localizable:!1,items:["result_name"],collapsed:t=>!(t._isNew&&t.result_name),getValueCount:t=>!!t.result_name},$p={type:"accordion",multi:!0,sections:[Ap,{label:"Localization",localizable:!1,items:["localizeRules","localizeCategories"],collapsed:!0,getValueCount:t=>!(!t.localizeRules&&!t.localizeCategories)}]},Ep={type:"accordion",multi:!0,sections:[Ap]};function Tp(t,e){var i,o;const n=(null===(i=t.router)||void 0===i?void 0:i.categories)||[],s={};n.forEach(t=>{const i=t.uuid,o=e[i];s[i]={originalName:t.name,localizedName:o&&o.name?Array.isArray(o.name)?o.name[0]||"":o.name:""}});const r=(null===(o=t.router)||void 0===o?void 0:o.cases)||[],a={};return r.forEach(t=>{var i,o;if(!(null===(i=t.arguments)||void 0===i?void 0:i.length)||!t.arguments.some(t=>t))return;const n=e[t.uuid],s=(null===(o=wp(t.type))||void 0===o?void 0:o.name)||t.type;a[t.uuid]={operatorName:s,originalArguments:[...t.arguments],localizedArguments:(null==n?void 0:n.arguments)?[...n.arguments]:t.arguments.map(()=>"")}}),{categories:s,rules:a}}function Dp(t,e){const i={};return t.categories&&Object.keys(t.categories).forEach(e=>{var o,n;const s=t.categories[e],r=(null===(o=s.localizedName)||void 0===o?void 0:o.trim())||"",a=(null===(n=s.originalName)||void 0===n?void 0:n.trim())||"";r&&r!==a&&(i[e]={name:[r]})}),t.rules&&Object.keys(t.rules).forEach(e=>{const o=t.rules[e],n=o.localizedArguments||[],s=o.originalArguments||[],r=n.some((t,e)=>(null==t?void 0:t.trim())&&t.trim()!==(s[e]||""));r&&(i[e]={arguments:n.map(t=>(null==t?void 0:t.trim())||"")})}),i}const Mp={type:"split_by_airtime",name:"Send Airtime",group:qu.services,flowTypes:[Ru,Pu,Nu],features:[Fu],showAsAction:!0,form:{amounts:{type:"array",label:"Airtime Amounts",helpText:"Define the currencies and amounts to transfer",required:!0,itemLabel:"Amount",sortable:!1,minItems:1,maxItems:10,isEmptyItem:t=>!t.currency||!t.amount||""===t.amount.trim(),itemConfig:{currency:{type:"select",placeholder:"Select a currency",required:!0,options:vp,searchable:!0,multi:!1,width:"200px"},amount:{type:"text",placeholder:"Amount",required:!0}}},result_name:kp},layout:["amounts","result_name"],validate:t=>{const e={};if(t.amounts&&Array.isArray(t.amounts)){const i=t.amounts.filter(t=>(null==t?void 0:t.currency)&&(null==t?void 0:t.amount)&&""!==t.amount.trim());if(0===i.length)return e.amounts="At least one currency and amount is required",{valid:!1,errors:e};const o=new Set,n=[];i.forEach(t=>{var e;const i=Array.isArray(t.currency)&&t.currency.length>0?t.currency[0].value:"string"==typeof t.currency?t.currency:null===(e=t.currency)||void 0===e?void 0:e.value;o.has(i)?n.push(i):o.add(i)}),n.length>0&&(e.amounts=`Duplicate currencies found: ${n.join(", ")}`);for(const t of i){const i=t.amount.trim();if(isNaN(Number(i))||Number(i)<=0)return e.amounts="All amounts must be valid positive numbers",{valid:!1,errors:e}}}else e.amounts="At least one currency and amount is required";return{valid:0===Object.keys(e).length,errors:e}},render:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"transfer_airtime"===t.type);if(!i||!i.amounts)return H`<div class="body">Configure airtime transfer</div>`;const o=i.amounts,n=Object.keys(o);if(0===n.length)return H`<div class="body">Configure airtime transfer</div>`;const s=n[0],r=o[s],a=n.length-1;return H`
8921
+ `,form:{audio_url:{type:"text",label:"Recording URL",required:!0,evaluated:!0}},layout:["audio_url"],toFormData:t=>({uuid:t.uuid,audio_url:t.audio_url||""}),fromFormData:t=>({uuid:t.uuid,type:"play_audio",audio_url:(t.audio_url||"").trim()}),localizable:["audio_url"],toLocalizationFormData:(t,e)=>{const i={uuid:t.uuid};return e.audio_url&&Array.isArray(e.audio_url)?i.audio_url=e.audio_url[0]||"":i.audio_url="",i},fromLocalizationFormData:(t,e)=>{const i={};return t.audio_url&&""!==t.audio_url.trim()&&t.audio_url!==e.audio_url&&(i.audio_url=[t.audio_url]),i}};function mp(t){const e=Sd.getState().flowDefinition;return!!e&&("messaging_background"===e.type&&"message"===t.type)}const gp={name:"Enter a Flow",group:qu.trigger,hideFromActions:!0,flowTypes:[Ru,Pu,Nu],render:(t,e)=>H`${$u([e.flow],"flow")}`,toFormData:t=>({uuid:t.uuid,flow:t.flow?[t.flow]:[]}),form:{flow:{type:"select",required:!0,placeholder:"Select a flow...",helpText:"The contact will enter this flow and not return",endpoint:"/api/v2/flows.json",valueKey:"uuid",nameKey:"name",shouldExclude:mp}},layout:["flow"],fromFormData:t=>{const e=t.flow[0];return{uuid:t.uuid,type:"enter_flow",terminal:!0,flow:{uuid:e.uuid||e.value,name:e.name}}}},fp={ARS:{code:"ARS",name:"Argentine Peso"},AUD:{code:"AUD",name:"Australian Dollar"},BIF:{code:"BIF",name:"Burundi Franc"},BRL:{code:"BRL",name:"Brazilian Real"},CAD:{code:"CAD",name:"Canadian Dollar"},CDF:{code:"CDF",name:"Congolese Franc"},CLP:{code:"CLP",name:"Chilean Peso"},COP:{code:"COP",name:"Colombian Peso"},DJF:{code:"DJF",name:"Djibouti Franc"},DOP:{code:"DOP",name:"Dominican Peso"},DZD:{code:"DZD",name:"Algerian Dinar"},EUR:{code:"EUR",name:"Euro"},GBP:{code:"GBP",name:"Pound Sterling"},GHS:{code:"GHS",name:"Ghana Cedi"},GNF:{code:"GNF",name:"Guinean Franc"},KES:{code:"KES",name:"Kenyan Shilling"},LBP:{code:"LBP",name:"Lebanese Pound"},LKR:{code:"LKR",name:"Sri Lanka Rupee"},LRD:{code:"LRD",name:"Liberian Dollar"},MWK:{code:"MWK",name:"Malawian Kwacha"},MXN:{code:"MXN",name:"Mexican Peso"},MZN:{code:"MZN",name:"Mozambican Metical"},NAD:{code:"NAD",name:"Namibian Dollar"},NGN:{code:"NGN",name:"Nigerian Naira"},PEN:{code:"PEN",name:"Peruvian Sol"},PHP:{code:"PHP",name:"Philippine Peso"},RWF:{code:"RWF",name:"Rwandan Franc"},SZL:{code:"SZL",name:"Swazi Lilangeni"},TZS:{code:"TZS",name:"Tanzanian Shilling"},UGX:{code:"UGX",name:"Ugandan Shilling"},USD:{code:"USD",name:"US Dollar"},XAF:{code:"XAF",name:"Central African CFA Franc"},XOF:{code:"XOF",name:"West African CFA Franc"},ZAR:{code:"ZAR",name:"South African Rand"},ZMW:{code:"ZMW",name:"Zambian Kwacha"}},vp=Object.values(fp).map(t=>({value:t.code,name:`${t.name} (${t.code})`})),bp=[{type:"has_any_word",name:"has any of the words",operands:1},{type:"has_all_words",name:"has all of the words",operands:1},{type:"has_phrase",name:"has the phrase",operands:1},{type:"has_only_phrase",name:"has only the phrase",operands:1},{type:"has_beginning",name:"starts with",operands:1},{type:"has_text",name:"has some text",operands:0,categoryName:"Has Text"},{type:"has_number",name:"has a number",operands:0,categoryName:"Has Number"},{type:"has_number_between",name:"has a number between",operands:2},{type:"has_number_lt",name:"has a number below",operands:1},{type:"has_number_lte",name:"has a number at or below",operands:1},{type:"has_number_eq",name:"has a number equal to",operands:1},{type:"has_number_gte",name:"has a number at or above",operands:1},{type:"has_number_gt",name:"has a number above",operands:1},{type:"has_date",name:"has a date",operands:0,categoryName:"Has Date"},{type:"has_date_lt",name:"has a date before",operands:1},{type:"has_date_eq",name:"has a date equal to",operands:1},{type:"has_date_gt",name:"has a date after",operands:1},{type:"has_time",name:"has a time",operands:0,categoryName:"Has Time"},{type:"has_phone",name:"has a phone number",operands:0,categoryName:"Has Phone"},{type:"has_email",name:"has an email",operands:0,categoryName:"Has Email"},{type:"has_state",name:"has state",operands:0,categoryName:"Has State",filter:"locations"},{type:"has_district",name:"has district",operands:1,categoryName:"Has District",filter:"locations"},{type:"has_ward",name:"has ward",operands:2,categoryName:"Has Ward",filter:"locations"},{type:"has_group",name:"is in the group",operands:1,visibility:"hidden"},{type:"has_category",name:"has the category",operands:0,visibility:"hidden"},{type:"has_error",name:"has an error",operands:0,categoryName:"Has Error",visibility:"hidden"},{type:"has_value",name:"is not empty",operands:0,categoryName:"Not Empty",visibility:"hidden"},{type:"has_pattern",name:"matches regex",operands:1}],yp=t=>bp.filter(e=>"hidden"!==e.visibility&&(!e.filter||!!t&&t.includes(e.filter))),xp=new Set(["has_beginning","has_number","has_number_between","has_number_lt","has_number_lte","has_number_eq","has_number_gte","has_number_gt","has_pattern"]),wp=t=>bp.find(e=>e.type===t),_p=t=>t.map(t=>({value:t.type,name:t.name})),kp={type:"text",required:!1,maxLength:64,placeholder:"(optional)",helpText:"The name to use to reference this result in the flow"},Cp={type:"checkbox",label:"Require rules to be localized",helpText:"Each language must specify its own rules for this node"},Sp={type:"checkbox",label:"Require categories to be localized",helpText:t=>{var e;const i=null===(e=t.result_name)||void 0===e?void 0:e.trim();if(i){return`Only enable if you plan to use @results.${i.toLowerCase().replace(/\s+/g,"_")}.category_localized`}return"Only enable if you plan to use category_localized in your expressions for this result"},conditions:{visible:t=>!!t.result_name}},Ap={label:"Save Result",localizable:!1,items:["result_name"],collapsed:t=>!(t._isNew&&t.result_name),getValueCount:t=>!!t.result_name},$p={type:"accordion",multi:!0,sections:[Ap,{label:"Localization",localizable:!1,items:["localizeRules","localizeCategories"],collapsed:!0,getValueCount:t=>!(!t.localizeRules&&!t.localizeCategories)}]},Ep={type:"accordion",multi:!0,sections:[Ap]};function Tp(t,e){var i,o;const n=(null===(i=t.router)||void 0===i?void 0:i.categories)||[],s={};n.forEach(t=>{const i=t.uuid,o=e[i];s[i]={originalName:t.name,localizedName:o&&o.name?Array.isArray(o.name)?o.name[0]||"":o.name:""}});const r=(null===(o=t.router)||void 0===o?void 0:o.cases)||[],a={};return r.forEach(t=>{var i,o;if(!(null===(i=t.arguments)||void 0===i?void 0:i.length)||!t.arguments.some(t=>t))return;const n=e[t.uuid],s=(null===(o=wp(t.type))||void 0===o?void 0:o.name)||t.type;a[t.uuid]={operatorName:s,originalArguments:[...t.arguments],localizedArguments:(null==n?void 0:n.arguments)?[...n.arguments]:t.arguments.map(()=>"")}}),{categories:s,rules:a}}function Dp(t,e){const i={};return t.categories&&Object.keys(t.categories).forEach(e=>{var o,n;const s=t.categories[e],r=(null===(o=s.localizedName)||void 0===o?void 0:o.trim())||"",a=(null===(n=s.originalName)||void 0===n?void 0:n.trim())||"";r&&r!==a&&(i[e]={name:[r]})}),t.rules&&Object.keys(t.rules).forEach(e=>{const o=t.rules[e],n=o.localizedArguments||[],s=o.originalArguments||[],r=n.some((t,e)=>(null==t?void 0:t.trim())&&t.trim()!==(s[e]||""));r&&(i[e]={arguments:n.map(t=>(null==t?void 0:t.trim())||"")})}),i}const Mp={type:"split_by_airtime",name:"Send Airtime",group:qu.services,flowTypes:[Ru,Pu,Nu],features:[Fu],showAsAction:!0,form:{amounts:{type:"array",label:"Airtime Amounts",helpText:"Define the currencies and amounts to transfer",required:!0,itemLabel:"Amount",sortable:!1,minItems:1,maxItems:10,isEmptyItem:t=>!t.currency||!t.amount||""===t.amount.trim(),itemConfig:{currency:{type:"select",placeholder:"Select a currency",required:!0,options:vp,searchable:!0,multi:!1,width:"200px"},amount:{type:"text",placeholder:"Amount",required:!0}}},result_name:kp},layout:["amounts","result_name"],validate:t=>{const e={};if(t.amounts&&Array.isArray(t.amounts)){const i=t.amounts.filter(t=>(null==t?void 0:t.currency)&&(null==t?void 0:t.amount)&&""!==t.amount.trim());if(0===i.length)return e.amounts="At least one currency and amount is required",{valid:!1,errors:e};const o=new Set,n=[];i.forEach(t=>{var e;const i=Array.isArray(t.currency)&&t.currency.length>0?t.currency[0].value:"string"==typeof t.currency?t.currency:null===(e=t.currency)||void 0===e?void 0:e.value;o.has(i)?n.push(i):o.add(i)}),n.length>0&&(e.amounts=`Duplicate currencies found: ${n.join(", ")}`);for(const t of i){const i=t.amount.trim();if(isNaN(Number(i))||Number(i)<=0)return e.amounts="All amounts must be valid positive numbers",{valid:!1,errors:e}}}else e.amounts="At least one currency and amount is required";return{valid:0===Object.keys(e).length,errors:e}},render:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"transfer_airtime"===t.type);if(!i||!i.amounts)return H`<div class="body">Configure airtime transfer</div>`;const o=i.amounts,n=Object.keys(o);if(0===n.length)return H`<div class="body">Configure airtime transfer</div>`;const s=n[0],r=o[s],a=n.length-1;return H`
8920
8922
  <div class="body">
8921
8923
  ${s}
8922
8924
  ${r}${a>0?H` <span style="color: #999;">+${a} more</span>`:""}
8923
8925
  </div>
8924
- `},toFormData:t=>{var e,i;const o=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"transfer_airtime"===t.type),n=[];return o&&o.amounts&&Object.entries(o.amounts).forEach(([t,e])=>{var i;n.push({currency:[{value:t,name:(null===(i=fp[t])||void 0===i?void 0:i.name)?`${fp[t].name} (${t})`:t}],amount:String(e)})}),{uuid:t.uuid,amounts:n,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o,n;const s={};t.amounts&&Array.isArray(t.amounts)&&t.amounts.forEach(t=>{var e;if(!(null==t?void 0:t.currency)||!(null==t?void 0:t.amount)||""===t.amount.trim())return;let i;if(Array.isArray(t.currency)&&t.currency.length>0)i=t.currency[0].value;else if("string"==typeof t.currency)i=t.currency;else{if(!(null===(e=t.currency)||void 0===e?void 0:e.value))return;i=t.currency.value}const o=parseFloat(t.amount.trim());!isNaN(o)&&o>0&&(s[i]=o)});const r=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"transfer_airtime"===t.type),a={type:"transfer_airtime",uuid:(null==r?void 0:r.uuid)||Xt(),amounts:s},l=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],d=e.exits||[],c=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:h,exits:u}=Me("@locals._new_transfer",{type:"has_text",arguments:[]},l,d,c),p={...h};return t.result_name&&""!==t.result_name.trim()&&(p.result_name=t.result_name.trim()),{uuid:e.uuid,actions:[a],router:p,exits:u}},localizable:"categories",nonTranslatableCategories:"all",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},zp=t=>{if("string"==typeof t)return t.trim();if(Array.isArray(t)&&t.length>0){const e=t[0];if(e&&"object"==typeof e&&e.value)return e.value.trim()}else if(t&&"object"==typeof t&&t.value)return t.value.trim();return""},Ip=t=>{const e=zp(t.operator);if(!e||!t.category||""===t.category.trim())return!0;const i=wp(e);return i&&1===i.operands?!t.value1||""===t.value1.trim():!(!i||2!==i.operands)&&(!t.value1||""===t.value1.trim()||!t.value2||""===t.value2.trim())},Lp=t=>{const e=zp(t.operator),i=wp(e);return!i||i.operands>=1},Op=t=>{const e=zp(t.operator),i=wp(e);return!!i&&2===i.operands},Pp=t=>{const e=zp(t.operator);return"has_district"===e||"has_ward"===e?"State":""},Rp=t=>"has_ward"===zp(t.operator)?"District":"",Np=()=>({operator:{type:"select",required:!0,multi:!1,options:[],getDynamicOptions:()=>{const t=Sd.getState().features;return _p(yp(t))},flavor:"xsmall",width:"220px"},value1:{type:"text",placeholder:Pp,evaluated:!0,flavor:"xsmall",conditions:{visible:Lp}},value2:{type:"text",placeholder:Rp,evaluated:!0,flavor:"xsmall",conditions:{visible:Op}},category:{type:"text",placeholder:"Category",required:!0,maxWidth:"120px",flavor:"xsmall"}}),Bp=t=>(t.rules||[]).filter(t=>{const e=zp(null==t?void 0:t.operator);if(!e||!(null==t?void 0:t.category)||""===e||""===t.category.trim())return!1;const i=wp(e);return i&&1===i.operands?(null==t?void 0:t.value1)&&""!==t.value1.trim():!i||2!==i.operands||(null==t?void 0:t.value1)&&""!==t.value1.trim()&&(null==t?void 0:t.value2)&&""!==t.value2.trim()}).map(t=>{const e=zp(t.operator),i=wp(e),o=t.value1?t.value1.trim():"",n=t.value2?t.value2.trim():"";let s="";return s=i&&1===i.operands?o:(i&&i.operands,""),{operator:e,value:s,value1:o,value2:n,category:t.category.trim()}}),Fp=t=>{var e,i;const o=[];return(null===(e=t.router)||void 0===e?void 0:e.cases)&&(null===(i=t.router)||void 0===i?void 0:i.categories)&&t.router.cases.forEach(e=>{const i=t.router.categories.find(t=>t.uuid===e.category_uuid);if(i&&(n=i.name,!["No Response","Other","All Responses","Timeout"].includes(n))){const t=wp(e.type),n=t?t.name:e.type;let s="",r="";t&&0===t.operands?(s="",r=""):t&&1===t.operands?(s=e.arguments.join(" "),r=""):t&&2===t.operands?(s=e.arguments[0]||"",r=e.arguments[1]||""):(s=e.arguments.join(" "),r=""),o.push({operator:{value:e.type,name:n},value1:s,value2:r,category:i.name})}var n}),o};const qp=(t,e="Define rules to categorize responses")=>({type:"array",helpText:e,itemLabel:"Rule",minItems:0,maxItems:100,sortable:!0,maintainEmptyItem:!0,isEmptyItem:Ip,onItemChange:(t,e,i,o)=>{const n=[...o],s={...n[t]};s[e]=i;const r=o[t]||{},a=zp("operator"===e?r.operator:s.operator),l=zp(s.operator),d=Le(a,wp,"value1"===e?r.value1:s.value1,"value2"===e?r.value2:s.value2),c=Le(l,wp,s.value1,s.value2);return(!s.category||""===s.category.trim()||s.category===d)&&c&&(s.category=c),n[t]=s,n},createEmptyItem:t=>{const e=Sd.getState().features,i=_p(yp(e)),o=[...t].reverse().find(t=>{const e=zp(t.operator),i=e?wp(e):void 0;return i&&i.operands>=1&&"locations"!==i.filter}),n=i.filter(t=>{const e=wp(t.value);return!e||"locations"!==e.filter}),s=o?zp(o.operator):null,r=s?i.find(t=>t.value===s):n[0];return r?{operator:[{...r}]}:{}},itemConfig:{...Np(),operator:{...Np().operator,options:t}}}),Up={name:{id:"name",name:"Name",type:"property"},language:{id:"language",name:"Language",type:"property"},status:{id:"status",name:"Status",type:"property"},channel:{id:"channel",name:"Channel",type:"property"}},jp={type:"split_by_contact_field",name:"Split by Contact Field",group:Uu.split,flowTypes:[Ru,Pu,Nu],dialogSize:"large",form:{field:{type:"select",required:!0,searchable:!0,clearable:!1,endpoint:"/api/v2/fields.json",valueKey:"key",nameKey:"name",placeholder:"Select a field...",options:[...Object.values(Up).map(t=>({value:t.id,name:t.name,type:t.type})),...Tu.filter(t=>!t.excludeFromSplit).map(t=>({value:t.scheme,name:t.path,type:"scheme"}))]},rules:qp(_p(yp()),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:["field","rules",$p],validate:t=>{const e={};return t.field&&0!==t.field.length||(e.field="A field is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s;const r={...(null===(i=null==e?void 0:e.config)||void 0===i?void 0:i.operand)||Up.name};"field"===r.type?r.key||(r.key=r.id):r.value||(r.value=r.id);const a=Fp(t);return{uuid:t.uuid,field:[r],rules:a,result_name:(null===(o=t.router)||void 0===o?void 0:o.result_name)||"",localizeRules:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeRules)||!1,localizeCategories:(null===(s=null==e?void 0:e.config)||void 0===s?void 0:s.localizeCategories)||!1}},fromFormData:(t,e)=>{var i,o,n;const s=null===(i=t.field)||void 0===i?void 0:i[0];if(!s)return e;const r=(t=>{if("scheme"===t.type)return`@(default(urn_parts(urns.${t.id||t.value}).path, ""))`;return"property"===t.type?`@contact.${t.id||t.value}`:`@fields.${t.key||t.id||t.value}`})(s),a=Bp(t),l=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],d=e.exits||[],c=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:h,exits:u}=Oe(r,a,wp,l,d,c),p={...h};return t.result_name&&""!==t.result_name.trim()&&(p.result_name=t.result_name.trim()),{...e,router:p,exits:u}},toUIConfig:t=>{var e;const i=null===(e=t.field)||void 0===e?void 0:e[0];if(!i)return{};let o=i.id||i.value||i.key;"scheme"===i.type&&(o=i.value||i.id);let n=i.type;"property"!==n&&"scheme"!==n&&(n="field");const s={operand:{id:o,name:i.name||i.label,type:n}};return s.localizeRules=!!t.localizeRules,s.localizeCategories=!!t.result_name&&!!t.localizeCategories,s},renderTitle:(t,e)=>H`<div>Split by ${e.config.operand.name}</div>`,localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Wp={type:"split_by_expression",name:"Split by Expression",group:Uu.split,flowTypes:[Ru,Pu,Nu],dialogSize:"large",form:{operand:{type:"text",label:"Expression",helpText:"The expression to evaluate and split on",required:!0,evaluated:!0,placeholder:"@fields.age"},rules:qp(_p(yp()),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:["operand","rules",$p],validate:t=>{const e={};return t.operand&&""!==t.operand.trim()||(e.operand="Expression is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s;const r=Fp(t);return{uuid:t.uuid,operand:(null===(i=t.router)||void 0===i?void 0:i.operand)||"@input.text",rules:r,result_name:(null===(o=t.router)||void 0===o?void 0:o.result_name)||"",localizeRules:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeRules)||!1,localizeCategories:(null===(s=null==e?void 0:e.config)||void 0===s?void 0:s.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n;const s=Bp(t),r=(null===(i=t.operand)||void 0===i?void 0:i.trim())||"@input.text",a=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],l=e.exits||[],d=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:c,exits:h}=Oe(r,s,wp,a,l,d),u={...c};return t.result_name&&""!==t.result_name.trim()&&(u.result_name=t.result_name.trim()),{...e,router:u,exits:h}},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Hp={type:"split_by_groups",name:"Split by Group",group:Uu.split,flowTypes:[Ru,Pu,Nu],form:{groups:{type:"select",label:"Groups",helpText:"Select the groups to split contacts by. Contacts will be routed based on their group membership.",required:!0,options:[],multi:!0,searchable:!0,endpoint:"/api/v2/groups.json",valueKey:"uuid",nameKey:"name",placeholder:"Search for groups...",allowCreate:!0,createArbitraryOption:(t,e)=>!e.find(e=>e.name.toLowerCase().trim()===t.toLowerCase().trim())&&t.trim()?{name:t.trim(),arbitrary:!0}:null},result_name:kp},layout:["groups",Ep],validate:t=>{const e={};return t.groups&&Array.isArray(t.groups)&&0!==t.groups.length||(e.groups="At least one group is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:t=>{var e,i;const o=[];return(null===(e=t.router)||void 0===e?void 0:e.cases)&&t.router.cases.forEach(t=>{var e;"has_group"===t.type&&(null===(e=t.arguments)||void 0===e?void 0:e.length)>=2&&o.push({uuid:t.arguments[0],name:t.arguments[1]})}),{uuid:t.uuid,groups:o,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(t.groups||[]).filter(t=>(null==t?void 0:t.uuid)||(null==t?void 0:t.arbitrary)).map(t=>({uuid:t.uuid||Xt(),name:t.name})),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=((t,e=[],i=[],o=[],n="")=>{const s=[],r=[],a=[];t.forEach(t=>{const n=e.find(e=>e.name===t.name),l=n?i.find(t=>t.uuid===n.exit_uuid):null,d=o.find(e=>{var i;return(null===(i=e.arguments)||void 0===i?void 0:i[0])===t.uuid}),c=(null==l?void 0:l.uuid)||Xt(),h=(null==n?void 0:n.uuid)||Xt(),u=(null==d?void 0:d.uuid)||Xt();s.push({uuid:h,name:t.name,exit_uuid:c}),r.push({uuid:c,destination_uuid:(null==l?void 0:l.destination_uuid)||null}),a.push({uuid:u,type:"has_group",arguments:[t.uuid,t.name],category_uuid:h})});const l=e.find(e=>"Other"===e.name&&!t.some(t=>t.name===e.name)),d=l?i.find(t=>t.uuid===l.exit_uuid):null,c=(null==d?void 0:d.uuid)||Xt(),h=(null==l?void 0:l.uuid)||Xt();return s.push({uuid:h,name:"Other",exit_uuid:c}),r.push({uuid:c,destination_uuid:(null==d?void 0:d.destination_uuid)||null}),{router:{type:"switch",cases:a,categories:s,default_category_uuid:h,operand:"@contact.groups",result_name:n},exits:r}})(n,s,r,a,t.result_name||"");return{uuid:e.uuid,actions:e.actions||[],router:l,exits:d}},router:{type:"switch",operand:"@contact.groups"},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Vp={type:"split_by_random",name:"Random Split",group:Uu.split,flowTypes:[Ru,Pu,Nu],form:{categories:{type:"array",helpText:"Define the buckets to randomly split contacts into",required:!0,itemLabel:"Bucket",sortable:!0,minItems:2,maxItems:10,isEmptyItem:t=>!t.name||""===t.name.trim(),itemConfig:{name:{type:"text",placeholder:"Bucket name",required:!0}}}},layout:["categories"],validate:t=>{const e={};if(t.categories&&Array.isArray(t.categories)){const i=t.categories.filter(t=>(null==t?void 0:t.name)&&""!==t.name.trim());i.length<2&&(e.categories="At least 2 buckets are required for random split");const o=[],n=new Map;if(i.forEach(t=>{const e=t.name.trim().toLowerCase();n.has(e)||n.set(e,[]),n.get(e).push(t.name.trim())}),n.forEach(t=>{t.length>1&&o.push(...t)}),o.length>0){const t=[...new Set(o)];e.categories=`Duplicate bucket names found: ${t.join(", ")}`}}return{valid:0===Object.keys(e).length,errors:e}},toFormData:t=>{var e,i;const o=(null===(i=null===(e=t.router)||void 0===e?void 0:e.categories)||void 0===i?void 0:i.map(t=>({name:t.name})))||[];return{uuid:t.uuid,categories:o}},fromFormData:(t,e)=>{var i;const o=(t.categories||[]).filter(t=>{var e;return null===(e=null==t?void 0:t.name)||void 0===e?void 0:e.trim()}).map(t=>t.name.trim()),n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],{router:r,exits:a}=((t,e=[],i=[])=>{const o=[],n=[];return t.forEach(t=>{const s=e.find(e=>e.name===t),r=s?i.find(t=>t.uuid===s.exit_uuid):null,a=(null==r?void 0:r.uuid)||Xt(),l=(null==s?void 0:s.uuid)||Xt();o.push({uuid:l,name:t,exit_uuid:a}),n.push({uuid:a,destination_uuid:(null==r?void 0:r.destination_uuid)||null})}),{router:{type:"random",categories:o},exits:n}})(o,n,s);return{uuid:e.uuid,actions:e.actions||[],router:r,exits:a}},router:{type:"random"},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Zp=[{value:"0",name:"first result"},{value:"1",name:"second result"},{value:"2",name:"third result"},{value:"3",name:"fourth result"},{value:"4",name:"fifth result"},{value:"5",name:"sixth result"},{value:"6",name:"seventh result"},{value:"7",name:"eighth result"},{value:"8",name:"ninth result"},{value:"9",name:"tenth result"},{value:"10",name:"11th result"},{value:"11",name:"12th result"},{value:"12",name:"13th result"},{value:"13",name:"14th result"},{value:"14",name:"15th result"},{value:"15",name:"16th result"},{value:"16",name:"17th result"},{value:"17",name:"18th result"},{value:"18",name:"19th result"},{value:"19",name:"20th result"}],Yp=[{value:"",name:"Don't delimit result"},{value:" ",name:"Delimited by spaces"},{value:".",name:"Delimited by periods"},{value:"+",name:"Delimited by plusses"}],Kp={type:"split_by_run_result",name:"Split by Result",aliases:["split_by_run_result_delimited"],group:Uu.split,flowTypes:[Ru,Pu,Nu],dialogSize:"large",form:{result:{type:"select",required:!0,searchable:!1,clearable:!1,placeholder:"Select a result...",getDynamicOptions:()=>{const t=Ed();return t?t.getState().getFlowResults().map(t=>({value:t.key,name:t.name})):[]},valueKey:"value",nameKey:"name"},delimit_by:{type:"select",required:!1,searchable:!1,clearable:!1,options:Yp,valueKey:"value",nameKey:"name",maxWidth:"180px"},delimit_index:{type:"select",required:!1,searchable:!1,clearable:!1,options:Zp,valueKey:"value",nameKey:"name",maxWidth:"140px",conditions:{visible:t=>{var e,i;const o=null===(i=null===(e=t.delimit_by)||void 0===e?void 0:e[0])||void 0===i?void 0:i.value;return void 0!==o&&""!==o}}},rules:qp(_p(yp()),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:[{type:"row",label:"Flow Result",helpText:"Select a flow result and optionally delimit it to split on a specific part",items:["result","delimit_by","delimit_index"]},"rules",$p],validate:t=>{const e={};return t.result&&0!==t.result.length||(e.result="A flow result is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s,r;const a=null===(i=null==e?void 0:e.config)||void 0===i?void 0:i.operand,l=a?{...a,value:a.value||a.id}:null,d=Fp(t),c=((null===(o=t.router)||void 0===o?void 0:o.operand)||"").match(/field\(results\.[\w]+,\s*(\d+),\s*"(.+?)"\)/),h=null!==c,u=h?parseInt(c[1],10):0,p=h?c[2]:"";return{uuid:t.uuid,result:l?[l]:[],delimit_by:h?[Yp.find(t=>t.value===p)]:[Yp[0]],delimit_index:h?[Zp.find(t=>t.value===String(u))]:[Zp[0]],rules:d,result_name:(null===(n=t.router)||void 0===n?void 0:n.result_name)||"",localizeRules:(null===(s=null==e?void 0:e.config)||void 0===s?void 0:s.localizeRules)||!1,localizeCategories:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeCategories)||!1}},fromFormData:(t,e)=>{var i,o,n,s,r,a,l,d;const c=null===(i=t.result)||void 0===i?void 0:i[0];if(!c)return e;let h;const u=c.value||c.id,p=null===(n=null===(o=t.delimit_by)||void 0===o?void 0:o[0])||void 0===n?void 0:n.value;if(void 0!==p&&""!==p){h=`@(field(results.${u}, ${null!==(a=null===(r=null===(s=t.delimit_index)||void 0===s?void 0:s[0])||void 0===r?void 0:r.value)&&void 0!==a?a:"0"}, "${p}"))`}else h=`@results.${u}`;const m=Bp(t),g=(null===(l=e.router)||void 0===l?void 0:l.categories)||[],f=e.exits||[],v=(null===(d=e.router)||void 0===d?void 0:d.cases)||[],{router:b,exits:y}=Oe(h,m,wp,g,f,v),x={...b};return t.result_name&&""!==t.result_name.trim()&&(x.result_name=t.result_name.trim()),{...e,router:x,exits:y}},toUIConfig:t=>{var e,i,o,n,s,r;const a=null===(e=t.result)||void 0===e?void 0:e[0];if(!a)return{};const l={operand:{id:a.value,name:a.name,type:"result"}},d=null===(o=null===(i=t.delimit_by)||void 0===i?void 0:i[0])||void 0===o?void 0:o.value,c=void 0!==d&&""!==d;return c&&(l.index=parseInt(null!==(r=null===(s=null===(n=t.delimit_index)||void 0===n?void 0:n[0])||void 0===s?void 0:s.value)&&void 0!==r?r:"0",10),l.delimiter=d),l.type=c?"split_by_run_result_delimited":"split_by_run_result",l.localizeRules=!!t.localizeRules,l.localizeCategories=!!t.result_name&&!!t.localizeCategories,l},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Gp={type:"split_by_scheme",name:"Split by URN Type",group:Uu.split,flowTypes:[Ru,Pu,Nu],form:{schemes:{type:"select",label:"Channel Types",helpText:"The contact's URN is the address they used to reach you such as their phone number or a Facebook ID. Select which URN types to split by.",required:!0,options:Tu.map(t=>({value:t.scheme,name:t.name})),multi:!0,searchable:!0,placeholder:"Select the channels to split by..."},result_name:kp},layout:["schemes",Ep],validate:t=>{const e={};return t.schemes&&Array.isArray(t.schemes)&&0!==t.schemes.length||(e.schemes="At least one channel type is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:t=>{var e,i;const o=[];return(null===(e=t.router)||void 0===e?void 0:e.cases)&&t.router.cases.forEach(t=>{var e;"has_only_phrase"===t.type&&(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&o.push(t.arguments[0])}),{uuid:t.uuid,schemes:o.map(t=>{const e=Tu.find(e=>e.scheme===t);return{value:t,name:(null==e?void 0:e.name)||t}}),result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(t.schemes||[]).filter(t=>t).map(t=>"string"==typeof t?t:t.value),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=((t,e=[],i=[],o=[],n="")=>{const s=[],r=[],a=[];t.forEach(t=>{const n=Tu.find(e=>e.scheme===t),l=(null==n?void 0:n.name)||t,d=e.find(t=>t.name===l),c=d?i.find(t=>t.uuid===d.exit_uuid):null,h=o.find(e=>{var i;return(null===(i=e.arguments)||void 0===i?void 0:i[0])===t}),u=(null==c?void 0:c.uuid)||Xt(),p=(null==d?void 0:d.uuid)||Xt(),m=(null==h?void 0:h.uuid)||Xt();s.push({uuid:p,name:l,exit_uuid:u}),r.push({uuid:u,destination_uuid:(null==c?void 0:c.destination_uuid)||null}),a.push({uuid:m,type:"has_only_phrase",arguments:[t],category_uuid:p})});const l=e.find(e=>{const i=t.some(t=>{const i=Tu.find(e=>e.scheme===t);return(null==i?void 0:i.name)===e.name});return"Other"===e.name&&!i}),d=l?i.find(t=>t.uuid===l.exit_uuid):null,c=(null==d?void 0:d.uuid)||Xt(),h=(null==l?void 0:l.uuid)||Xt();return s.push({uuid:h,name:"Other",exit_uuid:c}),r.push({uuid:c,destination_uuid:(null==d?void 0:d.destination_uuid)||null}),{router:{type:"switch",cases:a,categories:s,default_category_uuid:h,operand:"@(urn_parts(contact.urn).scheme)",result_name:n},exits:r}})(n,s,r,a,t.result_name||"");return{uuid:e.uuid,actions:e.actions||[],router:l,exits:d}},router:{type:"switch",operand:"@(urn_parts(contact.urn).scheme)"},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Xp={type:"split_by_subflow",name:"Enter a Flow",group:qu.trigger,flowTypes:[Ru,Pu,Nu],showAsAction:!0,form:{flow:{type:"select",required:!0,searchable:!0,placeholder:"Select a flow...",helpText:"Once the subflow is complete or expires, the contact will return here",endpoint:"/api/v2/flows.json",valueKey:"uuid",nameKey:"name",shouldExclude:mp},params:{type:"key-value",keyPlaceholder:"Parameter name",valuePlaceholder:"Value",minRows:0,readOnlyKeys:!0,dependsOn:["flow"],conditions:{visible:t=>{const e=t.params;return Array.isArray(e)?e.length>0:!(!e||"object"!=typeof e)&&Object.keys(e).length>0}},computeValue:(t,e)=>{var i;const o=Array.isArray(t.flow)&&t.flow.length>0?t.flow[0]:null;if(!(null===(i=null==o?void 0:o.parent_refs)||void 0===i?void 0:i.length))return[];const n={};return Array.isArray(e)?e.forEach(t=>{t.key&&(n[t.key]=t.value||"")}):e&&"object"==typeof e&&Object.entries(e).forEach(([t,e])=>{n[t]="string"==typeof e?e:""}),o.parent_refs.map(t=>({key:t,value:n[t]||""}))}}},layout:["flow",{type:"accordion",sections:[{label:"Parameters",collapsed:!1,getValueCount:t=>{const e=t.params;return Array.isArray(e)?e.filter(t=>t.value&&""!==t.value.trim()).length:e&&"object"==typeof e?Object.values(e).filter(t=>"string"==typeof t&&""!==t.trim()).length:0},items:["params"]}]}],resolveFormData:async t=>{var e;const i=Array.isArray(t.flow)&&t.flow.length>0?t.flow[0]:null;if(!(null==i?void 0:i.uuid))return t;if(i.parent_refs)return t;try{const o=await fetch(`/api/v2/flows.json?uuid=${i.uuid}`),n=null===(e=(await o.json()).results)||void 0===e?void 0:e[0];if(null==n?void 0:n.parent_refs){const e={...i,parent_refs:n.parent_refs};return{...t,flow:[e]}}}catch(t){}return t},render:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"enter_flow"===t.type);return H`
8926
+ `},toFormData:t=>{var e,i;const o=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"transfer_airtime"===t.type),n=[];return o&&o.amounts&&Object.entries(o.amounts).forEach(([t,e])=>{var i;n.push({currency:[{value:t,name:(null===(i=fp[t])||void 0===i?void 0:i.name)?`${fp[t].name} (${t})`:t}],amount:String(e)})}),{uuid:t.uuid,amounts:n,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o,n;const s={};t.amounts&&Array.isArray(t.amounts)&&t.amounts.forEach(t=>{var e;if(!(null==t?void 0:t.currency)||!(null==t?void 0:t.amount)||""===t.amount.trim())return;let i;if(Array.isArray(t.currency)&&t.currency.length>0)i=t.currency[0].value;else if("string"==typeof t.currency)i=t.currency;else{if(!(null===(e=t.currency)||void 0===e?void 0:e.value))return;i=t.currency.value}const o=parseFloat(t.amount.trim());!isNaN(o)&&o>0&&(s[i]=o)});const r=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"transfer_airtime"===t.type),a={type:"transfer_airtime",uuid:(null==r?void 0:r.uuid)||Xt(),amounts:s},l=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],d=e.exits||[],c=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:h,exits:u}=Me("@locals._new_transfer",{type:"has_text",arguments:[]},l,d,c),p={...h};return t.result_name&&""!==t.result_name.trim()&&(p.result_name=t.result_name.trim()),{uuid:e.uuid,actions:[a],router:p,exits:u}},localizable:"categories",nonTranslatableCategories:"all",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},zp=t=>{if("string"==typeof t)return t.trim();if(Array.isArray(t)&&t.length>0){const e=t[0];if(e&&"object"==typeof e&&e.value)return e.value.trim()}else if(t&&"object"==typeof t&&t.value)return t.value.trim();return""},Ip=t=>{const e=zp(t.operator);if(!e||!t.category||""===t.category.trim())return!0;const i=wp(e);return i&&1===i.operands?!t.value1||""===t.value1.trim():!(!i||2!==i.operands)&&(!t.value1||""===t.value1.trim()||!t.value2||""===t.value2.trim())},Lp=t=>{const e=zp(t.operator),i=wp(e);return!i||i.operands>=1},Op=t=>{const e=zp(t.operator),i=wp(e);return!!i&&2===i.operands},Pp=t=>{const e=zp(t.operator);return"has_district"===e||"has_ward"===e?"State":""},Rp=t=>"has_ward"===zp(t.operator)?"District":"",Np=()=>({operator:{type:"select",required:!0,multi:!1,options:[],getDynamicOptions:()=>{const t=Sd.getState().features;return _p(yp(t))},flavor:"xsmall",width:"220px"},value1:{type:"text",placeholder:Pp,evaluated:!0,flavor:"xsmall",conditions:{visible:Lp}},value2:{type:"text",placeholder:Rp,evaluated:!0,flavor:"xsmall",conditions:{visible:Op}},category:{type:"text",placeholder:"Category",required:!0,maxLength:36,maxWidth:"120px",flavor:"xsmall"}}),Bp=t=>(t.rules||[]).filter(t=>{const e=zp(null==t?void 0:t.operator);if(!e||!(null==t?void 0:t.category)||""===e||""===t.category.trim())return!1;const i=wp(e);return i&&1===i.operands?(null==t?void 0:t.value1)&&""!==t.value1.trim():!i||2!==i.operands||(null==t?void 0:t.value1)&&""!==t.value1.trim()&&(null==t?void 0:t.value2)&&""!==t.value2.trim()}).map(t=>{const e=zp(t.operator),i=wp(e),o=t.value1?t.value1.trim():"",n=t.value2?t.value2.trim():"";let s="";return s=i&&1===i.operands?o:(i&&i.operands,""),{operator:e,value:s,value1:o,value2:n,category:t.category.trim()}}),Fp=t=>{var e,i;const o=[];return(null===(e=t.router)||void 0===e?void 0:e.cases)&&(null===(i=t.router)||void 0===i?void 0:i.categories)&&t.router.cases.forEach(e=>{const i=t.router.categories.find(t=>t.uuid===e.category_uuid);if(i&&(n=i.name,!["No Response","Other","All Responses","Timeout"].includes(n))){const t=wp(e.type),n=t?t.name:e.type;let s="",r="";t&&0===t.operands?(s="",r=""):t&&1===t.operands?(s=e.arguments.join(" "),r=""):t&&2===t.operands?(s=e.arguments[0]||"",r=e.arguments[1]||""):(s=e.arguments.join(" "),r=""),o.push({operator:{value:e.type,name:n},value1:s,value2:r,category:i.name})}var n}),o};const qp=(t,e="Define rules to categorize responses")=>({type:"array",helpText:e,itemLabel:"Rule",minItems:0,maxItems:100,sortable:!0,maintainEmptyItem:!0,isEmptyItem:Ip,onItemChange:(t,e,i,o)=>{const n=[...o],s={...n[t]};s[e]=i;const r=o[t]||{},a=zp("operator"===e?r.operator:s.operator),l=zp(s.operator),d=Le(a,wp,"value1"===e?r.value1:s.value1,"value2"===e?r.value2:s.value2),c=Le(l,wp,s.value1,s.value2);return(!s.category||""===s.category.trim()||s.category===d)&&c&&(s.category=c),n[t]=s,n},createEmptyItem:t=>{const e=Sd.getState().features,i=_p(yp(e)),o=[...t].reverse().find(t=>{const e=zp(t.operator),i=e?wp(e):void 0;return i&&i.operands>=1&&"locations"!==i.filter}),n=i.filter(t=>{const e=wp(t.value);return!e||"locations"!==e.filter}),s=o?zp(o.operator):null,r=s?i.find(t=>t.value===s):n[0];return r?{operator:[{...r}]}:{}},itemConfig:{...Np(),operator:{...Np().operator,options:t}}}),Up={name:{id:"name",name:"Name",type:"property"},language:{id:"language",name:"Language",type:"property"},status:{id:"status",name:"Status",type:"property"},channel:{id:"channel",name:"Channel",type:"property"}},jp={type:"split_by_contact_field",name:"Split by Contact Field",group:Uu.split,flowTypes:[Ru,Pu,Nu],dialogSize:"large",form:{field:{type:"select",required:!0,searchable:!0,clearable:!1,endpoint:"/api/v2/fields.json",valueKey:"key",nameKey:"name",placeholder:"Select a field...",options:[...Object.values(Up).map(t=>({value:t.id,name:t.name,type:t.type})),...Tu.filter(t=>!t.excludeFromSplit).map(t=>({value:t.scheme,name:t.path,type:"scheme"}))]},rules:qp(_p(yp()),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:["field","rules",$p],validate:t=>{const e={};return t.field&&0!==t.field.length||(e.field="A field is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s;const r={...(null===(i=null==e?void 0:e.config)||void 0===i?void 0:i.operand)||Up.name};"field"===r.type?r.key||(r.key=r.id):r.value||(r.value=r.id);const a=Fp(t);return{uuid:t.uuid,field:[r],rules:a,result_name:(null===(o=t.router)||void 0===o?void 0:o.result_name)||"",localizeRules:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeRules)||!1,localizeCategories:(null===(s=null==e?void 0:e.config)||void 0===s?void 0:s.localizeCategories)||!1}},fromFormData:(t,e)=>{var i,o,n;const s=null===(i=t.field)||void 0===i?void 0:i[0];if(!s)return e;const r=(t=>{if("scheme"===t.type)return`@(default(urn_parts(urns.${t.id||t.value}).path, ""))`;return"property"===t.type?`@contact.${t.id||t.value}`:`@fields.${t.key||t.id||t.value}`})(s),a=Bp(t),l=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],d=e.exits||[],c=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:h,exits:u}=Oe(r,a,wp,l,d,c),p={...h};return t.result_name&&""!==t.result_name.trim()&&(p.result_name=t.result_name.trim()),{...e,router:p,exits:u}},toUIConfig:t=>{var e;const i=null===(e=t.field)||void 0===e?void 0:e[0];if(!i)return{};let o=i.id||i.value||i.key;"scheme"===i.type&&(o=i.value||i.id);let n=i.type;"property"!==n&&"scheme"!==n&&(n="field");const s={operand:{id:o,name:i.name||i.label,type:n}};return s.localizeRules=!!t.localizeRules,s.localizeCategories=!!t.result_name&&!!t.localizeCategories,s},renderTitle:(t,e)=>H`<div>Split by ${e.config.operand.name}</div>`,localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Wp={type:"split_by_expression",name:"Split by Expression",group:Uu.split,flowTypes:[Ru,Pu,Nu],dialogSize:"large",form:{operand:{type:"text",label:"Expression",helpText:"The expression to evaluate and split on",required:!0,evaluated:!0,placeholder:"@fields.age"},rules:qp(_p(yp()),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:["operand","rules",$p],validate:t=>{const e={};return t.operand&&""!==t.operand.trim()||(e.operand="Expression is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s;const r=Fp(t);return{uuid:t.uuid,operand:(null===(i=t.router)||void 0===i?void 0:i.operand)||"@input.text",rules:r,result_name:(null===(o=t.router)||void 0===o?void 0:o.result_name)||"",localizeRules:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeRules)||!1,localizeCategories:(null===(s=null==e?void 0:e.config)||void 0===s?void 0:s.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n;const s=Bp(t),r=(null===(i=t.operand)||void 0===i?void 0:i.trim())||"@input.text",a=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],l=e.exits||[],d=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:c,exits:h}=Oe(r,s,wp,a,l,d),u={...c};return t.result_name&&""!==t.result_name.trim()&&(u.result_name=t.result_name.trim()),{...e,router:u,exits:h}},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Hp={type:"split_by_groups",name:"Split by Group",group:Uu.split,flowTypes:[Ru,Pu,Nu],form:{groups:{type:"select",label:"Groups",helpText:"Select the groups to split contacts by. Contacts will be routed based on their group membership.",required:!0,options:[],multi:!0,searchable:!0,endpoint:"/api/v2/groups.json",valueKey:"uuid",nameKey:"name",placeholder:"Search for groups...",allowCreate:!0,createArbitraryOption:(t,e)=>!e.find(e=>e.name.toLowerCase().trim()===t.toLowerCase().trim())&&t.trim()?{name:t.trim(),arbitrary:!0}:null},result_name:kp},layout:["groups",Ep],validate:t=>{const e={};return t.groups&&Array.isArray(t.groups)&&0!==t.groups.length||(e.groups="At least one group is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:t=>{var e,i;const o=[];return(null===(e=t.router)||void 0===e?void 0:e.cases)&&t.router.cases.forEach(t=>{var e;"has_group"===t.type&&(null===(e=t.arguments)||void 0===e?void 0:e.length)>=2&&o.push({uuid:t.arguments[0],name:t.arguments[1]})}),{uuid:t.uuid,groups:o,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(t.groups||[]).filter(t=>(null==t?void 0:t.uuid)||(null==t?void 0:t.arbitrary)).map(t=>({uuid:t.uuid||Xt(),name:t.name})),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=((t,e=[],i=[],o=[],n="")=>{const s=[],r=[],a=[];t.forEach(t=>{const n=e.find(e=>e.name===t.name),l=n?i.find(t=>t.uuid===n.exit_uuid):null,d=o.find(e=>{var i;return(null===(i=e.arguments)||void 0===i?void 0:i[0])===t.uuid}),c=(null==l?void 0:l.uuid)||Xt(),h=(null==n?void 0:n.uuid)||Xt(),u=(null==d?void 0:d.uuid)||Xt();s.push({uuid:h,name:t.name,exit_uuid:c}),r.push({uuid:c,destination_uuid:(null==l?void 0:l.destination_uuid)||null}),a.push({uuid:u,type:"has_group",arguments:[t.uuid,t.name],category_uuid:h})});const l=e.find(e=>"Other"===e.name&&!t.some(t=>t.name===e.name)),d=l?i.find(t=>t.uuid===l.exit_uuid):null,c=(null==d?void 0:d.uuid)||Xt(),h=(null==l?void 0:l.uuid)||Xt();return s.push({uuid:h,name:"Other",exit_uuid:c}),r.push({uuid:c,destination_uuid:(null==d?void 0:d.destination_uuid)||null}),{router:{type:"switch",cases:a,categories:s,default_category_uuid:h,operand:"@contact.groups",result_name:n},exits:r}})(n,s,r,a,t.result_name||"");return{uuid:e.uuid,actions:e.actions||[],router:l,exits:d}},router:{type:"switch",operand:"@contact.groups"},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Vp={type:"split_by_random",name:"Random Split",group:Uu.split,flowTypes:[Ru,Pu,Nu],form:{categories:{type:"array",helpText:"Define the buckets to randomly split contacts into",required:!0,itemLabel:"Bucket",sortable:!0,minItems:2,maxItems:10,isEmptyItem:t=>!t.name||""===t.name.trim(),itemConfig:{name:{type:"text",placeholder:"Bucket name",required:!0}}}},layout:["categories"],validate:t=>{const e={};if(t.categories&&Array.isArray(t.categories)){const i=t.categories.filter(t=>(null==t?void 0:t.name)&&""!==t.name.trim());i.length<2&&(e.categories="At least 2 buckets are required for random split");const o=[],n=new Map;if(i.forEach(t=>{const e=t.name.trim().toLowerCase();n.has(e)||n.set(e,[]),n.get(e).push(t.name.trim())}),n.forEach(t=>{t.length>1&&o.push(...t)}),o.length>0){const t=[...new Set(o)];e.categories=`Duplicate bucket names found: ${t.join(", ")}`}}return{valid:0===Object.keys(e).length,errors:e}},toFormData:t=>{var e,i;const o=(null===(i=null===(e=t.router)||void 0===e?void 0:e.categories)||void 0===i?void 0:i.map(t=>({name:t.name})))||[];return{uuid:t.uuid,categories:o}},fromFormData:(t,e)=>{var i;const o=(t.categories||[]).filter(t=>{var e;return null===(e=null==t?void 0:t.name)||void 0===e?void 0:e.trim()}).map(t=>t.name.trim()),n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],{router:r,exits:a}=((t,e=[],i=[])=>{const o=[],n=[];return t.forEach(t=>{const s=e.find(e=>e.name===t),r=s?i.find(t=>t.uuid===s.exit_uuid):null,a=(null==r?void 0:r.uuid)||Xt(),l=(null==s?void 0:s.uuid)||Xt();o.push({uuid:l,name:t,exit_uuid:a}),n.push({uuid:a,destination_uuid:(null==r?void 0:r.destination_uuid)||null})}),{router:{type:"random",categories:o},exits:n}})(o,n,s);return{uuid:e.uuid,actions:e.actions||[],router:r,exits:a}},router:{type:"random"},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Zp=[{value:"0",name:"first result"},{value:"1",name:"second result"},{value:"2",name:"third result"},{value:"3",name:"fourth result"},{value:"4",name:"fifth result"},{value:"5",name:"sixth result"},{value:"6",name:"seventh result"},{value:"7",name:"eighth result"},{value:"8",name:"ninth result"},{value:"9",name:"tenth result"},{value:"10",name:"11th result"},{value:"11",name:"12th result"},{value:"12",name:"13th result"},{value:"13",name:"14th result"},{value:"14",name:"15th result"},{value:"15",name:"16th result"},{value:"16",name:"17th result"},{value:"17",name:"18th result"},{value:"18",name:"19th result"},{value:"19",name:"20th result"}],Yp=[{value:"",name:"Don't delimit result"},{value:" ",name:"Delimited by spaces"},{value:".",name:"Delimited by periods"},{value:"+",name:"Delimited by plusses"}],Kp={type:"split_by_run_result",name:"Split by Result",aliases:["split_by_run_result_delimited"],group:Uu.split,flowTypes:[Ru,Pu,Nu],dialogSize:"large",form:{result:{type:"select",required:!0,searchable:!1,clearable:!1,placeholder:"Select a result...",getDynamicOptions:()=>{const t=Ed();return t?t.getState().getFlowResults().map(t=>({value:t.key,name:t.name})):[]},valueKey:"value",nameKey:"name"},delimit_by:{type:"select",required:!1,searchable:!1,clearable:!1,options:Yp,valueKey:"value",nameKey:"name",maxWidth:"180px"},delimit_index:{type:"select",required:!1,searchable:!1,clearable:!1,options:Zp,valueKey:"value",nameKey:"name",maxWidth:"140px",conditions:{visible:t=>{var e,i;const o=null===(i=null===(e=t.delimit_by)||void 0===e?void 0:e[0])||void 0===i?void 0:i.value;return void 0!==o&&""!==o}}},rules:qp(_p(yp()),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:[{type:"row",label:"Flow Result",helpText:"Select a flow result and optionally delimit it to split on a specific part",items:["result","delimit_by","delimit_index"]},"rules",$p],validate:t=>{const e={};return t.result&&0!==t.result.length||(e.result="A flow result is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s,r;const a=null===(i=null==e?void 0:e.config)||void 0===i?void 0:i.operand,l=a?{...a,value:a.value||a.id}:null,d=Fp(t),c=((null===(o=t.router)||void 0===o?void 0:o.operand)||"").match(/field\(results\.[\w]+,\s*(\d+),\s*"(.+?)"\)/),h=null!==c,u=h?parseInt(c[1],10):0,p=h?c[2]:"";return{uuid:t.uuid,result:l?[l]:[],delimit_by:h?[Yp.find(t=>t.value===p)]:[Yp[0]],delimit_index:h?[Zp.find(t=>t.value===String(u))]:[Zp[0]],rules:d,result_name:(null===(n=t.router)||void 0===n?void 0:n.result_name)||"",localizeRules:(null===(s=null==e?void 0:e.config)||void 0===s?void 0:s.localizeRules)||!1,localizeCategories:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeCategories)||!1}},fromFormData:(t,e)=>{var i,o,n,s,r,a,l,d;const c=null===(i=t.result)||void 0===i?void 0:i[0];if(!c)return e;let h;const u=c.value||c.id,p=null===(n=null===(o=t.delimit_by)||void 0===o?void 0:o[0])||void 0===n?void 0:n.value;if(void 0!==p&&""!==p){h=`@(field(results.${u}, ${null!==(a=null===(r=null===(s=t.delimit_index)||void 0===s?void 0:s[0])||void 0===r?void 0:r.value)&&void 0!==a?a:"0"}, "${p}"))`}else h=`@results.${u}`;const m=Bp(t),g=(null===(l=e.router)||void 0===l?void 0:l.categories)||[],f=e.exits||[],v=(null===(d=e.router)||void 0===d?void 0:d.cases)||[],{router:b,exits:y}=Oe(h,m,wp,g,f,v),x={...b};return t.result_name&&""!==t.result_name.trim()&&(x.result_name=t.result_name.trim()),{...e,router:x,exits:y}},toUIConfig:t=>{var e,i,o,n,s,r;const a=null===(e=t.result)||void 0===e?void 0:e[0];if(!a)return{};const l={operand:{id:a.value,name:a.name,type:"result"}},d=null===(o=null===(i=t.delimit_by)||void 0===i?void 0:i[0])||void 0===o?void 0:o.value,c=void 0!==d&&""!==d;return c&&(l.index=parseInt(null!==(r=null===(s=null===(n=t.delimit_index)||void 0===n?void 0:n[0])||void 0===s?void 0:s.value)&&void 0!==r?r:"0",10),l.delimiter=d),l.type=c?"split_by_run_result_delimited":"split_by_run_result",l.localizeRules=!!t.localizeRules,l.localizeCategories=!!t.result_name&&!!t.localizeCategories,l},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Gp={type:"split_by_scheme",name:"Split by URN Type",group:Uu.split,flowTypes:[Ru,Pu,Nu],form:{schemes:{type:"select",label:"Channel Types",helpText:"The contact's URN is the address they used to reach you such as their phone number or a Facebook ID. Select which URN types to split by.",required:!0,options:Tu.map(t=>({value:t.scheme,name:t.name})),multi:!0,searchable:!0,placeholder:"Select the channels to split by..."},result_name:kp},layout:["schemes",Ep],validate:t=>{const e={};return t.schemes&&Array.isArray(t.schemes)&&0!==t.schemes.length||(e.schemes="At least one channel type is required"),{valid:0===Object.keys(e).length,errors:e}},toFormData:t=>{var e,i;const o=[];return(null===(e=t.router)||void 0===e?void 0:e.cases)&&t.router.cases.forEach(t=>{var e;"has_only_phrase"===t.type&&(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&o.push(t.arguments[0])}),{uuid:t.uuid,schemes:o.map(t=>{const e=Tu.find(e=>e.scheme===t);return{value:t,name:(null==e?void 0:e.name)||t}}),result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(t.schemes||[]).filter(t=>t).map(t=>"string"==typeof t?t:t.value),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=((t,e=[],i=[],o=[],n="")=>{const s=[],r=[],a=[];t.forEach(t=>{const n=Tu.find(e=>e.scheme===t),l=(null==n?void 0:n.name)||t,d=e.find(t=>t.name===l),c=d?i.find(t=>t.uuid===d.exit_uuid):null,h=o.find(e=>{var i;return(null===(i=e.arguments)||void 0===i?void 0:i[0])===t}),u=(null==c?void 0:c.uuid)||Xt(),p=(null==d?void 0:d.uuid)||Xt(),m=(null==h?void 0:h.uuid)||Xt();s.push({uuid:p,name:l,exit_uuid:u}),r.push({uuid:u,destination_uuid:(null==c?void 0:c.destination_uuid)||null}),a.push({uuid:m,type:"has_only_phrase",arguments:[t],category_uuid:p})});const l=e.find(e=>{const i=t.some(t=>{const i=Tu.find(e=>e.scheme===t);return(null==i?void 0:i.name)===e.name});return"Other"===e.name&&!i}),d=l?i.find(t=>t.uuid===l.exit_uuid):null,c=(null==d?void 0:d.uuid)||Xt(),h=(null==l?void 0:l.uuid)||Xt();return s.push({uuid:h,name:"Other",exit_uuid:c}),r.push({uuid:c,destination_uuid:(null==d?void 0:d.destination_uuid)||null}),{router:{type:"switch",cases:a,categories:s,default_category_uuid:h,operand:"@(urn_parts(contact.urn).scheme)",result_name:n},exits:r}})(n,s,r,a,t.result_name||"");return{uuid:e.uuid,actions:e.actions||[],router:l,exits:d}},router:{type:"switch",operand:"@(urn_parts(contact.urn).scheme)"},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},Xp={type:"split_by_subflow",name:"Enter a Flow",group:qu.trigger,flowTypes:[Ru,Pu,Nu],showAsAction:!0,form:{flow:{type:"select",required:!0,searchable:!0,placeholder:"Select a flow...",helpText:"Once the subflow is complete or expires, the contact will return here",endpoint:"/api/v2/flows.json",valueKey:"uuid",nameKey:"name",shouldExclude:mp},params:{type:"key-value",keyPlaceholder:"Parameter name",valuePlaceholder:"Value",minRows:0,readOnlyKeys:!0,dependsOn:["flow"],conditions:{visible:t=>{const e=t.params;return Array.isArray(e)?e.length>0:!(!e||"object"!=typeof e)&&Object.keys(e).length>0}},computeValue:(t,e)=>{var i;const o=Array.isArray(t.flow)&&t.flow.length>0?t.flow[0]:null;if(!(null===(i=null==o?void 0:o.parent_refs)||void 0===i?void 0:i.length))return[];const n={};return Array.isArray(e)?e.forEach(t=>{t.key&&(n[t.key]=t.value||"")}):e&&"object"==typeof e&&Object.entries(e).forEach(([t,e])=>{n[t]="string"==typeof e?e:""}),o.parent_refs.map(t=>({key:t,value:n[t]||""}))}}},layout:["flow",{type:"accordion",sections:[{label:"Parameters",collapsed:!1,getValueCount:t=>{const e=t.params;return Array.isArray(e)?e.filter(t=>t.value&&""!==t.value.trim()).length:e&&"object"==typeof e?Object.values(e).filter(t=>"string"==typeof t&&""!==t.trim()).length:0},items:["params"]}]}],resolveFormData:async t=>{var e;const i=Array.isArray(t.flow)&&t.flow.length>0?t.flow[0]:null;if(!(null==i?void 0:i.uuid))return t;if(i.parent_refs)return t;try{const o=await fetch(`/api/v2/flows.json?uuid=${i.uuid}`),n=null===(e=(await o.json()).results)||void 0===e?void 0:e[0];if(null==n?void 0:n.parent_refs){const e={...i,parent_refs:n.parent_refs};return{...t,flow:[e]}}}catch(t){}return t},render:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"enter_flow"===t.type);return H`
8925
8927
  <div class="body">
8926
8928
  ${(null==i?void 0:i.flow)?$u([i.flow],"flow"):null}
8927
8929
  </div>
@@ -8940,7 +8942,7 @@ background: #ccc;
8940
8942
  </div>
8941
8943
  `},form:{llm:{type:"select",label:"LLM",required:!0,options:[],endpoint:"/api/internal/llms.json",searchable:!0,valueKey:"uuid",nameKey:"name",placeholder:"Select an LLM..."},input:{type:"text",label:"Input",helpText:"The input the AI will process",required:!0,evaluated:!0,placeholder:"@input"},instructions:{type:"textarea",label:"Instructions",helpText:"Tell the AI what to do with the input. The result can be referenced as **`@locals._llm_output`**",required:!0,evaluated:!0,placeholder:"Enter instructions for the AI model...",minHeight:130}},layout:["llm","input","instructions"],toFormData:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"call_llm"===t.type);return{uuid:t.uuid,llm:(null==i?void 0:i.llm)?[i.llm]:[],input:(null==i?void 0:i.input)||"@input",instructions:(null==i?void 0:i.instructions)||""}},fromFormData:(t,e)=>{var i,o,n;const s=Array.isArray(t.llm)&&t.llm.length>0?t.llm[0]:null,r=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),a={type:"call_llm",uuid:(null==r?void 0:r.uuid)||Xt(),llm:s?{uuid:s.uuid||s.value,name:s.name}:{uuid:"",name:""},input:t.input||"@input",instructions:t.instructions||"",output_local:"_llm_output"},l=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],d=e.exits||[],c=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:h,exits:u}=Me("@locals._llm_output",{type:"has_text",arguments:[]},l,d,c);return{uuid:e.uuid,actions:[a],router:h,exits:u}},localizable:"categories",nonTranslatableCategories:"all",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},sm={type:"split_by_llm_categorize",name:"Split by AI",group:qu.services,flowTypes:[],features:[Bu],form:{llm:{type:"select",label:"LLM",helpText:"Select the LLM to use for categorization",required:!0,endpoint:"/api/internal/llms.json",valueKey:"uuid",nameKey:"name",placeholder:"Select an LLM..."},input:{type:"text",label:"Input",helpText:"The input to categorize (usually @input)",required:!0,evaluated:!0,placeholder:"@input"},categories:{type:"array",helpText:"Define the categories for classification",required:!0,sortable:!0,itemLabel:"Category",minItems:1,maxItems:10,isEmptyItem:t=>!t.name||""===t.name.trim(),itemConfig:{name:{type:"text",placeholder:"Category name",required:!0}}}},layout:["llm","input","categories"],validate:t=>{const e={};if(t.categories&&Array.isArray(t.categories)){const i=t.categories.filter(t=>(null==t?void 0:t.name)&&""!==t.name.trim()),o=[],n=new Map;if(i.forEach(t=>{const e=t.name.trim().toLowerCase();n.has(e)||n.set(e,[]),n.get(e).push(t.name.trim())}),n.forEach(t=>{t.length>1&&o.push(...t)}),o.length>0){const t=[...new Set(o)];e.categories=`Duplicate category names found: ${t.join(", ")}`}}return{valid:0===Object.keys(e).length,errors:e}},render:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"call_llm"===t.type);return H`
8942
8944
  <div class="body">Categorize with ${i.llm.name}</div>
8943
- `},toFormData:t=>{var e,i,o;const n=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"call_llm"===t.type),s=(null===(o=null===(i=t.router)||void 0===i?void 0:i.categories)||void 0===o?void 0:o.filter(t=>"Other"!==t.name&&"Failure"!==t.name).map(t=>({name:t.name})))||[];return{uuid:t.uuid,llm:(null==n?void 0:n.llm)?[n.llm]:[],input:(null==n?void 0:n.input)||"@input",categories:s}},fromFormData:(t,e)=>{var i,o,n;const s=Array.isArray(t.llm)&&t.llm.length>0?t.llm[0]:null,r=(t.categories||[]).filter(t=>{var e;return null===(e=null==t?void 0:t.name)||void 0===e?void 0:e.trim()}).map(t=>t.name.trim()),a=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),l={type:"call_llm",uuid:(null==a?void 0:a.uuid)||Xt(),llm:s?{uuid:s.uuid||s.value,name:s.name}:{uuid:"",name:""},instructions:'@(prompt("categorize", slice(node.categories, 0, -2)))',input:t.input||"@input",output_local:"_llm_output"},d=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],c=e.exits||[],h=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:u,exits:p}=((t,e,i,o=[],n=[],s=[])=>{const r=[],a=[],l=[];e.forEach(t=>{const e=De({name:t,existingCategories:o,existingExits:n,existingCases:s,caseConfig:i(t)});r.push(e.category),a.push(e.exit),e.case&&l.push(e.case)});const d=De({name:"Other",existingCategories:o,existingExits:n});r.push(d.category),a.push(d.exit);const c=De({name:"Failure",existingCategories:o,existingExits:n,existingCases:s,caseConfig:{type:"has_only_text",arguments:["<ERROR>"]}});return r.push(c.category),a.push(c.exit),c.case&&l.push(c.case),{router:{type:"switch",categories:r,default_category_uuid:d.category.uuid,operand:t,cases:l},exits:a}})("@locals._llm_output",r,t=>({type:"has_only_text",arguments:[t]}),d,c,h);return{uuid:e.uuid,actions:[l],router:u,exits:p}},localizable:"categories",nonTranslatableCategories:["Failure"],toLocalizationFormData:Tp,fromLocalizationFormData:Dp},rm={type:"wait_for_audio",name:"Make Recording",group:Uu.wait,flowTypes:[Ru],form:{result_name:{type:"text",label:"Result Name",required:!1,placeholder:"(optional)",helpText:"The name to use to reference this result in the flow"}},layout:["result_name"],toFormData:t=>{var e;return{uuid:t.uuid,result_name:(null===(e=t.router)||void 0===e?void 0:e.result_name)||""}},fromFormData:(t,e)=>{var i;const o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],n=e.exits||[];let s,r=o.find(t=>"All Responses"===t.name);if(r)s=n.find(t=>t.uuid===r.exit_uuid)||{uuid:r.exit_uuid,destination_uuid:null};else{const t=Xt();r={uuid:Xt(),name:"All Responses",exit_uuid:t},s={uuid:t,destination_uuid:null}}const a={type:"switch",operand:"@input",default_category_uuid:r.uuid,cases:[],categories:[r],wait:{type:"msg",hint:{type:"audio"}}};return t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim()),{...e,router:a,exits:[s]}},localizable:"categories",nonTranslatableCategories:"all",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},am=["Answered","No Answer","Busy","Failed"],lm=[{type:"has_only_text",arguments:["answered"],categoryName:"Answered"},{type:"has_only_text",arguments:["no_answer"],categoryName:"No Answer"},{type:"has_only_text",arguments:["busy"],categoryName:"Busy"}],dm={type:"wait_for_dial",name:"Redirect Call",group:Uu.wait,flowTypes:[Ru],router:{type:"switch",defaultCategory:"Failed",rules:lm.map(t=>({type:t.type,arguments:t.arguments,categoryName:t.categoryName}))},form:{phone:{type:"text",label:"Phone Number",required:!0,evaluated:!0,placeholder:"Phone number or expression"},dial_limit_seconds:{type:"text",label:"Dial Limit (seconds)",required:!1,placeholder:"60"},call_limit_seconds:{type:"text",label:"Call Limit (seconds)",required:!1,placeholder:"7200"},result_name:kp},layout:["phone",{type:"row",items:["dial_limit_seconds","call_limit_seconds"]},"result_name"],toFormData:t=>{var e,i;const o=null===(e=t.router)||void 0===e?void 0:e.wait;return{uuid:t.uuid,phone:(null==o?void 0:o.phone)||"",dial_limit_seconds:(null==o?void 0:o.dial_limit_seconds)?String(o.dial_limit_seconds):"",call_limit_seconds:(null==o?void 0:o.call_limit_seconds)?String(o.call_limit_seconds):"",result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const t of am){const e=n.find(e=>e.name===t);if(e){a.push(e);const t=s.find(t=>t.uuid===e.exit_uuid);l.push(t||{uuid:e.exit_uuid,destination_uuid:null})}else{const e=Xt();a.push({uuid:Xt(),name:t,exit_uuid:e}),l.push({uuid:e,destination_uuid:null})}}for(const t of lm){const e=a.find(e=>e.name===t.categoryName);if(!e)continue;const i=r.find(e=>{var i;return e.type===t.type&&(null===(i=e.arguments)||void 0===i?void 0:i[0])===t.arguments[0]});d.push({uuid:(null==i?void 0:i.uuid)||Xt(),type:t.type,arguments:t.arguments,category_uuid:e.uuid})}const c=a.find(t=>"Failed"===t.name),h=(t.phone||"").trim(),u=parseInt(t.dial_limit_seconds,10),p=parseInt(t.call_limit_seconds,10),m={type:"dial",phone:h};!isNaN(u)&&u>0&&(m.dial_limit_seconds=u),!isNaN(p)&&p>0&&(m.call_limit_seconds=p);const g={type:"switch",operand:'@(default(resume.dial.status, ""))',default_category_uuid:null==c?void 0:c.uuid,cases:d,categories:a,wait:m};return t.result_name&&""!==t.result_name.trim()&&(g.result_name=t.result_name.trim()),{...e,router:g,exits:l}},localizable:"categories",nonTranslatableCategories:"all",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},cm={type:"wait_for_digits",name:"Wait for Digits",group:Uu.wait,flowTypes:[Ru],dialogSize:"large",form:{rules:qp(_p(bp.filter(t=>xp.has(t.type))),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:[{type:"text",text:"Rules match against all digits pressed by the caller followed by the # sign."},"rules",$p],validate:t=>({valid:!0,errors:{}}),toFormData:(t,e)=>{var i,o,n;const s=Fp(t);return{uuid:t.uuid,rules:s,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||"",localizeRules:(null===(o=null==e?void 0:e.config)||void 0===o?void 0:o.localizeRules)||!1,localizeCategories:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=Bp(t),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=Oe("@input.text",n,wp,s,r,a),c={...l,wait:{type:"msg",hint:{type:"digits"}}};return t.result_name&&""!==t.result_name.trim()&&(c.result_name=t.result_name.trim()),{...e,router:c,exits:d}},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},hm=["1","2","3","4","5","6","7","8","9","0"];function um(t){return`digit_${t}`}const pm={type:"wait_for_menu",name:"Wait for Menu",group:Uu.wait,flowTypes:[Ru],form:{...Object.fromEntries(hm.map(t=>[um(t),{type:"text",required:!1,placeholder:"",flavor:"xsmall"}])),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:[{type:"row",items:["digit_1","digit_2","digit_3"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_1:"1",digit_2:"2",digit_3:"3"}},{type:"row",items:["digit_4","digit_5","digit_6"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_4:"4",digit_5:"5",digit_6:"6"}},{type:"row",items:["digit_7","digit_8","digit_9"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_7:"7",digit_8:"8",digit_9:"9"}},{type:"row",items:[{type:"spacer"},"digit_0",{type:"spacer"}],gap:"2rem",inlineLabels:{digit_0:"0"}},$p],toFormData:(t,e)=>{var i,o,n,s,r,a;const l={uuid:t.uuid,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""};for(const t of hm)l[um(t)]="";if((null===(o=t.router)||void 0===o?void 0:o.cases)&&(null===(n=t.router)||void 0===n?void 0:n.categories))for(const e of t.router.cases)if("has_number_eq"===e.type&&(null===(s=e.arguments)||void 0===s?void 0:s[0])){const i=e.arguments[0],o=t.router.categories.find(t=>t.uuid===e.category_uuid);o&&hm.includes(i)&&(l[um(i)]=o.name)}return l.localizeRules=(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,l.localizeCategories=(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1,l},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const e of hm){const i=(t[um(e)]||"").trim();if(!i)continue;let o=a.find(t=>t.name===i);if(!o){const t=n.find(t=>t.name===i);if(t){o=t;const e=s.find(e=>e.uuid===t.exit_uuid);a.push(o),l.push(e||{uuid:t.exit_uuid,destination_uuid:null})}else{const t=Xt();o={uuid:Xt(),name:i,exit_uuid:t},a.push(o),l.push({uuid:t,destination_uuid:null})}}const c=r.find(t=>{var i;return"has_number_eq"===t.type&&(null===(i=t.arguments)||void 0===i?void 0:i[0])===e});d.push({uuid:(null==c?void 0:c.uuid)||Xt(),type:"has_number_eq",arguments:[e],category_uuid:o.uuid})}const c=n.find(t=>"Other"===t.name);let h;if(c){h=c;const t=s.find(t=>t.uuid===c.exit_uuid);l.push(t||{uuid:c.exit_uuid,destination_uuid:null})}else{const t=Xt();h={uuid:Xt(),name:"Other",exit_uuid:t},l.push({uuid:t,destination_uuid:null})}a.push(h);const u={type:"switch",operand:"@input.text",default_category_uuid:h.uuid,cases:d,categories:a,wait:{type:"msg",hint:{type:"digits",count:1}}};return t.result_name&&""!==t.result_name.trim()&&(u.result_name=t.result_name.trim()),{...e,router:u,exits:l}},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},mm=[{value:"60",name:"1 minute"},{value:"120",name:"2 minutes"},{value:"180",name:"3 minutes"},{value:"240",name:"4 minutes"},{value:"300",name:"5 minutes"},{value:"600",name:"10 minutes"},{value:"900",name:"15 minutes"},{value:"1800",name:"30 minutes"},{value:"3600",name:"1 hour"},{value:"7200",name:"2 hours"},{value:"10800",name:"3 hours"},{value:"21600",name:"6 hours"},{value:"43200",name:"12 hours"},{value:"64800",name:"18 hours"},{value:"86400",name:"1 day"},{value:"172800",name:"2 days"},{value:"259200",name:"3 days"},{value:"604800",name:"1 week"}],gm=(t,e=[],i=[],o=[])=>{const{router:n,exits:s}=Oe("@input.text",t,wp,e,i,o),r=e.find(t=>"No Response"===t.name||"Timeout"===t.name);if(r){const t=i.find(t=>t.uuid===r.exit_uuid);t&&(n.categories.push(r),s.push({uuid:t.uuid,destination_uuid:t.destination_uuid||null}))}return{router:n,exits:s}},fm={type:"wait_for_response",name:"Wait for Response",group:Uu.wait,flowTypes:[Pu],hideFromSplits:!0,dialogSize:"large",form:{rules:qp(_p(yp()),"If the message from the contact..."),timeout_enabled:{type:"checkbox",label:t=>t.timeout_enabled?"Continue when there is no response for":"Continue when there is no response..",labelPadding:"4px 8px"},timeout_duration:{type:"select",placeholder:"5 minutes",multi:!1,maxWidth:"130px",flavor:"xsmall",options:mm,conditions:{visible:t=>!0===t.timeout_enabled}},result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:["rules",$p],gutter:[{type:"row",items:["timeout_enabled","timeout_duration"],gap:"0.5rem"}],validate:t=>{const e={};return{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s,r,a;const l=Fp(t),d=null===(n=null===(o=null===(i=t.router)||void 0===i?void 0:i.wait)||void 0===o?void 0:o.timeout)||void 0===n?void 0:n.seconds;let c=mm.find(t=>t.value===String(d));return c||(c={value:"300",name:"5 minutes"}),{uuid:t.uuid,rules:l,timeout_enabled:!!d,timeout_duration:c,result_name:(null===(s=t.router)||void 0===s?void 0:s.result_name)||"",localizeRules:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,localizeCategories:(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n,s,r,a,l,d;const c=Bp(t);if(0===c.length){let o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[];const n=[...e.exits||[]];if(t.timeout_enabled){let t=o.find(t=>"No Response"===t.name);if(!t){const e=Xt();t={uuid:Xt(),name:"No Response",exit_uuid:e},o=[...o,t],n.find(t=>t.uuid===e)||n.push({uuid:e,destination_uuid:null})}}else o=o.filter(t=>"No Response"!==t.name);const{router:s,exits:r}=gm([],o,n,[]),a={...s,cases:[]};t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim());const l={type:"msg"};if(t.timeout_enabled){let e;e=t.timeout_duration?Array.isArray(t.timeout_duration)&&t.timeout_duration.length>0?parseInt(t.timeout_duration[0].value,10):"string"==typeof t.timeout_duration?parseInt(t.timeout_duration,10):t.timeout_duration&&"object"==typeof t.timeout_duration&&t.timeout_duration.value?parseInt(t.timeout_duration.value,10):300:300,(isNaN(e)||e<=0)&&(e=300);const i=a.categories.find(t=>"No Response"===t.name);i&&(l.timeout={seconds:e,category_uuid:i.uuid})}return a.wait=l,{...e,router:a,exits:r}}const h=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],u=e.exits||[],p=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:m,exits:g}=gm(c,h,u,p),f={...m};t.result_name&&""!==t.result_name.trim()&&(f.result_name=t.result_name.trim());const v={type:"msg"};try{if(t.timeout_enabled){let i;if(t.timeout_duration)try{i=parseInt(t.timeout_duration[0].value,10)}catch(t){i=300}const o=null===(r=null===(s=e.router)||void 0===s?void 0:s.categories)||void 0===r?void 0:r.find(t=>"No Response"===t.name),n=o||{uuid:Xt(),name:"No Response",exit_uuid:Xt()};if(v.timeout={seconds:i,category_uuid:n.uuid},!(null===(a=m.categories)||void 0===a?void 0:a.some(t=>"No Response"===t.name))&&(m.categories=m.categories||[],m.categories.push(n),!g.some(t=>t.uuid===n.exit_uuid))){const t={uuid:n.exit_uuid,destination_uuid:(null==o?void 0:o.exit_uuid)&&(null===(d=null===(l=e.exits)||void 0===l?void 0:l.find(t=>t.uuid===o.exit_uuid))||void 0===d?void 0:d.destination_uuid)||null};g.push(t)}}else if(m.categories){const t=m.categories.findIndex(t=>"No Response"===t.name);if(-1!==t){const e=m.categories[t];m.categories.splice(t,1);const i=g.findIndex(t=>t.uuid===e.exit_uuid);-1!==i&&g.splice(i,1)}}}catch(t){console.error("Error processing timeout configuration:",t)}return f.wait=v,{...e,router:f,exits:g}},localizable:"categories",nonTranslatableCategories:["Timeout"],toLocalizationFormData:Tp,fromLocalizationFormData:Dp},vm=bm({say_msg:up,play_audio:pp,set_contact_field:Zu,send_broadcast:Xu,set_run_result:Qu,send_msg:tp,send_email:ep,start_session:ip,set_contact_name:op,add_contact_groups:np,remove_contact_groups:sp,set_contact_channel:Yu,set_contact_language:Ku,set_contact_status:Gu,add_contact_urn:Vu,add_input_labels:Hu,request_optin:rp,enter_flow:gp});function bm(t){const e={...t};return Object.values(t).forEach(t=>{t.aliases&&t.aliases.forEach(i=>{e[i]=t})}),e}const ym=bm({execute_actions:{type:"execute_actions"},split_by_contact_field:jp,split_by_expression:Wp,split_by_groups:Hp,split_by_llm:nm,split_by_llm_categorize:sm,split_by_random:Vp,split_by_run_result:Kp,split_by_scheme:Gp,split_by_subflow:Xp,split_by_ticket:Qp,split_by_webhook:im,split_by_resthook:om,wait_for_menu:pm,wait_for_digits:cm,wait_for_audio:rm,wait_for_dial:dm,wait_for_response:fm,split_by_airtime:Mp,terminal:{type:"terminal"}}),xm=60,wm=20;function _m(t,e,i,o){if(0===t.length)return{};const n=new Set(t.map(t=>t.uuid)),s=new Map,r=new Map;for(const e of t){const t=new Set,i=[];for(const o of e.exits)if(o.destination_uuid&&n.has(o.destination_uuid)&&!t.has(o.destination_uuid)){t.add(o.destination_uuid),i.push(o.destination_uuid);const n=r.get(o.destination_uuid)||[];n.push(e.uuid),r.set(o.destination_uuid,n)}s.set(e.uuid,i)}const a=function(t,e){const i=new Set,o=new Set,n=new Set;function s(t){o.add(t),n.add(t);for(const r of e.get(t)||[])o.has(r)?i.add(`${t}->${r}`):n.has(r)||s(r);o.delete(t)}return s(t),i}(i,s),l=function(t,e,i,o,n){const s=new Map;s.set(t,0);const r=new Map;for(const t of e)r.set(t.uuid,0);for(const[t,e]of i)for(const i of e)n.has(`${t}->${i}`)||r.set(i,(r.get(i)||0)+1);const a=[];for(const[t,e]of r)0===e&&(a.push(t),s.has(t)||s.set(t,0));for(;a.length>0;){const t=a.shift(),e=s.get(t);for(const o of i.get(t)||[]){if(n.has(`${t}->${o}`))continue;const i=e+1;(!s.has(o)||i>s.get(o))&&s.set(o,i);const l=r.get(o)-1;r.set(o,l),0===l&&a.push(o)}}const l=e.filter(t=>!s.has(t.uuid));if(l.length>0){let t=Math.max(...Array.from(s.values()),-1)+2;for(const e of l)s.set(e.uuid,t),t++}return s}(i,t,s,0,a),d=new Map;for(const[t,e]of l){const i=d.get(e)||[];i.push(t),d.set(e,i)}const c=Array.from(d.keys()).sort((t,e)=>t-e);!function(t,e,i,o){const n=new Map;for(const s of t){const r=e.get(s);if(s===t[0]){r.forEach((t,e)=>n.set(t,e));continue}const a=r.map(t=>{const e=(i.get(t)||[]).filter(t=>{const e=o.get(t);return void 0!==e&&e<s});if(0===e.length)return{uuid:t,value:1/0};const r=e.reduce((t,e)=>{var i;return t+(null!==(i=n.get(e))&&void 0!==i?i:0)},0);return{uuid:t,value:r/e.length}});a.sort((t,e)=>t.value-e.value);const l=a.map(t=>t.uuid);e.set(s,l),l.forEach((t,e)=>n.set(t,e))}}(c,d,r,l);const h=new Map;for(const e of t)h.set(e.uuid,o(e.uuid));return function(t,e,i,o,n,s){var r,a,l,d;const c={};let h=0;for(const u of t){const p=km(e.get(u),i);for(const e of p){const p=fu(h);if(u===t[0]){let t=0;for(const o of e){const e=o===s?p:p+40;c[o]={left:fu(t),top:e},t+=((null===(r=i.get(o))||void 0===r?void 0:r.width)||200)+xm}}else{let t=0;for(const o of e)t+=(null===(a=i.get(o))||void 0===a?void 0:a.width)||200;t+=xm*(e.length-1);const s=[];for(const t of e){const e=(o.get(t)||[]).filter(t=>{const e=n.get(t);return void 0!==e&&e<u});for(const t of e){const e=c[t];if(e){const o=(null===(l=i.get(t))||void 0===l?void 0:l.width)||200;s.push(e.left+o/2)}}}let r;if(s.length>0){const e=(Math.min(...s)+Math.max(...s))/2;r=Math.max(0,e-t/2)}else r=0;let h=r;for(const t of e){const e=(null===(d=i.get(t))||void 0===d?void 0:d.width)||200;c[t]={left:fu(h),top:p},h=fu(h)+e+xm}}const m=Math.max(...e.map(t=>{var e;return(null===(e=i.get(t))||void 0===e?void 0:e.height)||100}));h=p+m+80}}const u=c[s];if(u){const t=u.left,e=u.top;for(const i of Object.keys(c))c[i]={left:fu(Math.max(0,c[i].left-t)),top:fu(Math.max(0,c[i].top-e))}}return c}(c,d,h,r,l,i)}function km(t,e){var i;const o=[];let n=[],s=0;for(const r of t){const t=(null===(i=e.get(r))||void 0===i?void 0:i.width)||200,a=n.length>0?xm+t:t;n.length>0&&s+a>1200?(o.push(n),n=[r],s=t):(n.push(r),s+=a)}return n.length>0&&o.push(n),o}function Cm(t,e,i,o,n){for(const s of n)if(t<s.left+s.width+wm&&t+i+wm>s.left&&e<s.top+s.height+wm&&e+o+wm>s.top)return!0;return!1}class Sm extends Be{constructor(){super(...arguments),this.color="#6B7280",this.order=0,this.top=100,this.hidden=!1,this.saving=!1,this.active=!1}static get styles(){return a`
8945
+ `},toFormData:t=>{var e,i,o;const n=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"call_llm"===t.type),s=(null===(o=null===(i=t.router)||void 0===i?void 0:i.categories)||void 0===o?void 0:o.filter(t=>"Other"!==t.name&&"Failure"!==t.name).map(t=>({name:t.name})))||[];return{uuid:t.uuid,llm:(null==n?void 0:n.llm)?[n.llm]:[],input:(null==n?void 0:n.input)||"@input",categories:s}},fromFormData:(t,e)=>{var i,o,n;const s=Array.isArray(t.llm)&&t.llm.length>0?t.llm[0]:null,r=(t.categories||[]).filter(t=>{var e;return null===(e=null==t?void 0:t.name)||void 0===e?void 0:e.trim()}).map(t=>t.name.trim()),a=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),l={type:"call_llm",uuid:(null==a?void 0:a.uuid)||Xt(),llm:s?{uuid:s.uuid||s.value,name:s.name}:{uuid:"",name:""},instructions:'@(prompt("categorize", slice(node.categories, 0, -2)))',input:t.input||"@input",output_local:"_llm_output"},d=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],c=e.exits||[],h=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:u,exits:p}=((t,e,i,o=[],n=[],s=[])=>{const r=[],a=[],l=[];e.forEach(t=>{const e=De({name:t,existingCategories:o,existingExits:n,existingCases:s,caseConfig:i(t)});r.push(e.category),a.push(e.exit),e.case&&l.push(e.case)});const d=De({name:"Other",existingCategories:o,existingExits:n});r.push(d.category),a.push(d.exit);const c=De({name:"Failure",existingCategories:o,existingExits:n,existingCases:s,caseConfig:{type:"has_only_text",arguments:["<ERROR>"]}});return r.push(c.category),a.push(c.exit),c.case&&l.push(c.case),{router:{type:"switch",categories:r,default_category_uuid:d.category.uuid,operand:t,cases:l},exits:a}})("@locals._llm_output",r,t=>({type:"has_only_text",arguments:[t]}),d,c,h);return{uuid:e.uuid,actions:[l],router:u,exits:p}},localizable:"categories",nonTranslatableCategories:["Failure"],toLocalizationFormData:Tp,fromLocalizationFormData:Dp},rm={type:"wait_for_audio",name:"Make Recording",group:Uu.wait,flowTypes:[Ru],form:{result_name:{type:"text",label:"Result Name",required:!1,maxLength:64,placeholder:"(optional)",helpText:"The name to use to reference this result in the flow"}},layout:["result_name"],toFormData:t=>{var e;return{uuid:t.uuid,result_name:(null===(e=t.router)||void 0===e?void 0:e.result_name)||""}},fromFormData:(t,e)=>{var i;const o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],n=e.exits||[];let s,r=o.find(t=>"All Responses"===t.name);if(r)s=n.find(t=>t.uuid===r.exit_uuid)||{uuid:r.exit_uuid,destination_uuid:null};else{const t=Xt();r={uuid:Xt(),name:"All Responses",exit_uuid:t},s={uuid:t,destination_uuid:null}}const a={type:"switch",operand:"@input",default_category_uuid:r.uuid,cases:[],categories:[r],wait:{type:"msg",hint:{type:"audio"}}};return t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim()),{...e,router:a,exits:[s]}},localizable:"categories",nonTranslatableCategories:"all",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},am=["Answered","No Answer","Busy","Failed"],lm=[{type:"has_only_text",arguments:["answered"],categoryName:"Answered"},{type:"has_only_text",arguments:["no_answer"],categoryName:"No Answer"},{type:"has_only_text",arguments:["busy"],categoryName:"Busy"}],dm={type:"wait_for_dial",name:"Redirect Call",group:Uu.wait,flowTypes:[Ru],router:{type:"switch",defaultCategory:"Failed",rules:lm.map(t=>({type:t.type,arguments:t.arguments,categoryName:t.categoryName}))},form:{phone:{type:"text",label:"Phone Number",required:!0,evaluated:!0,placeholder:"Phone number or expression"},dial_limit_seconds:{type:"text",label:"Dial Limit (seconds)",required:!1,placeholder:"60"},call_limit_seconds:{type:"text",label:"Call Limit (seconds)",required:!1,placeholder:"7200"},result_name:kp},layout:["phone",{type:"row",items:["dial_limit_seconds","call_limit_seconds"]},"result_name"],toFormData:t=>{var e,i;const o=null===(e=t.router)||void 0===e?void 0:e.wait;return{uuid:t.uuid,phone:(null==o?void 0:o.phone)||"",dial_limit_seconds:(null==o?void 0:o.dial_limit_seconds)?String(o.dial_limit_seconds):"",call_limit_seconds:(null==o?void 0:o.call_limit_seconds)?String(o.call_limit_seconds):"",result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const t of am){const e=n.find(e=>e.name===t);if(e){a.push(e);const t=s.find(t=>t.uuid===e.exit_uuid);l.push(t||{uuid:e.exit_uuid,destination_uuid:null})}else{const e=Xt();a.push({uuid:Xt(),name:t,exit_uuid:e}),l.push({uuid:e,destination_uuid:null})}}for(const t of lm){const e=a.find(e=>e.name===t.categoryName);if(!e)continue;const i=r.find(e=>{var i;return e.type===t.type&&(null===(i=e.arguments)||void 0===i?void 0:i[0])===t.arguments[0]});d.push({uuid:(null==i?void 0:i.uuid)||Xt(),type:t.type,arguments:t.arguments,category_uuid:e.uuid})}const c=a.find(t=>"Failed"===t.name),h=(t.phone||"").trim(),u=parseInt(t.dial_limit_seconds,10),p=parseInt(t.call_limit_seconds,10),m={type:"dial",phone:h};!isNaN(u)&&u>0&&(m.dial_limit_seconds=u),!isNaN(p)&&p>0&&(m.call_limit_seconds=p);const g={type:"switch",operand:'@(default(resume.dial.status, ""))',default_category_uuid:null==c?void 0:c.uuid,cases:d,categories:a,wait:m};return t.result_name&&""!==t.result_name.trim()&&(g.result_name=t.result_name.trim()),{...e,router:g,exits:l}},localizable:"categories",nonTranslatableCategories:"all",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},cm={type:"wait_for_digits",name:"Wait for Digits",group:Uu.wait,flowTypes:[Ru],dialogSize:"large",form:{rules:qp(_p(bp.filter(t=>xp.has(t.type))),""),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:[{type:"text",text:"Rules match against all digits pressed by the caller followed by the # sign."},"rules",$p],validate:t=>({valid:!0,errors:{}}),toFormData:(t,e)=>{var i,o,n;const s=Fp(t);return{uuid:t.uuid,rules:s,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||"",localizeRules:(null===(o=null==e?void 0:e.config)||void 0===o?void 0:o.localizeRules)||!1,localizeCategories:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=Bp(t),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=Oe("@input.text",n,wp,s,r,a),c={...l,wait:{type:"msg",hint:{type:"digits"}}};return t.result_name&&""!==t.result_name.trim()&&(c.result_name=t.result_name.trim()),{...e,router:c,exits:d}},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},hm=["1","2","3","4","5","6","7","8","9","0"];function um(t){return`digit_${t}`}const pm={type:"wait_for_menu",name:"Wait for Menu",group:Uu.wait,flowTypes:[Ru],form:{...Object.fromEntries(hm.map(t=>[um(t),{type:"text",required:!1,placeholder:"",flavor:"xsmall"}])),result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:[{type:"row",items:["digit_1","digit_2","digit_3"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_1:"1",digit_2:"2",digit_3:"3"}},{type:"row",items:["digit_4","digit_5","digit_6"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_4:"4",digit_5:"5",digit_6:"6"}},{type:"row",items:["digit_7","digit_8","digit_9"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_7:"7",digit_8:"8",digit_9:"9"}},{type:"row",items:[{type:"spacer"},"digit_0",{type:"spacer"}],gap:"2rem",inlineLabels:{digit_0:"0"}},$p],toFormData:(t,e)=>{var i,o,n,s,r,a;const l={uuid:t.uuid,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""};for(const t of hm)l[um(t)]="";if((null===(o=t.router)||void 0===o?void 0:o.cases)&&(null===(n=t.router)||void 0===n?void 0:n.categories))for(const e of t.router.cases)if("has_number_eq"===e.type&&(null===(s=e.arguments)||void 0===s?void 0:s[0])){const i=e.arguments[0],o=t.router.categories.find(t=>t.uuid===e.category_uuid);o&&hm.includes(i)&&(l[um(i)]=o.name)}return l.localizeRules=(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,l.localizeCategories=(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1,l},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const e of hm){const i=(t[um(e)]||"").trim();if(!i)continue;let o=a.find(t=>t.name===i);if(!o){const t=n.find(t=>t.name===i);if(t){o=t;const e=s.find(e=>e.uuid===t.exit_uuid);a.push(o),l.push(e||{uuid:t.exit_uuid,destination_uuid:null})}else{const t=Xt();o={uuid:Xt(),name:i,exit_uuid:t},a.push(o),l.push({uuid:t,destination_uuid:null})}}const c=r.find(t=>{var i;return"has_number_eq"===t.type&&(null===(i=t.arguments)||void 0===i?void 0:i[0])===e});d.push({uuid:(null==c?void 0:c.uuid)||Xt(),type:"has_number_eq",arguments:[e],category_uuid:o.uuid})}const c=n.find(t=>"Other"===t.name);let h;if(c){h=c;const t=s.find(t=>t.uuid===c.exit_uuid);l.push(t||{uuid:c.exit_uuid,destination_uuid:null})}else{const t=Xt();h={uuid:Xt(),name:"Other",exit_uuid:t},l.push({uuid:t,destination_uuid:null})}a.push(h);const u={type:"switch",operand:"@input.text",default_category_uuid:h.uuid,cases:d,categories:a,wait:{type:"msg",hint:{type:"digits",count:1}}};return t.result_name&&""!==t.result_name.trim()&&(u.result_name=t.result_name.trim()),{...e,router:u,exits:l}},localizable:"categories",toLocalizationFormData:Tp,fromLocalizationFormData:Dp},mm=[{value:"60",name:"1 minute"},{value:"120",name:"2 minutes"},{value:"180",name:"3 minutes"},{value:"240",name:"4 minutes"},{value:"300",name:"5 minutes"},{value:"600",name:"10 minutes"},{value:"900",name:"15 minutes"},{value:"1800",name:"30 minutes"},{value:"3600",name:"1 hour"},{value:"7200",name:"2 hours"},{value:"10800",name:"3 hours"},{value:"21600",name:"6 hours"},{value:"43200",name:"12 hours"},{value:"64800",name:"18 hours"},{value:"86400",name:"1 day"},{value:"172800",name:"2 days"},{value:"259200",name:"3 days"},{value:"604800",name:"1 week"}],gm=(t,e=[],i=[],o=[])=>{const{router:n,exits:s}=Oe("@input.text",t,wp,e,i,o),r=e.find(t=>"No Response"===t.name||"Timeout"===t.name);if(r){const t=i.find(t=>t.uuid===r.exit_uuid);t&&(n.categories.push(r),s.push({uuid:t.uuid,destination_uuid:t.destination_uuid||null}))}return{router:n,exits:s}},fm={type:"wait_for_response",name:"Wait for Response",group:Uu.wait,flowTypes:[Pu],hideFromSplits:!0,dialogSize:"large",form:{rules:qp(_p(yp()),"If the message from the contact..."),timeout_enabled:{type:"checkbox",label:t=>t.timeout_enabled?"Continue when there is no response for":"Continue when there is no response..",labelPadding:"4px 8px"},timeout_duration:{type:"select",placeholder:"5 minutes",multi:!1,maxWidth:"130px",flavor:"xsmall",options:mm,conditions:{visible:t=>!0===t.timeout_enabled}},result_name:kp,localizeRules:Cp,localizeCategories:Sp},layout:["rules",$p],gutter:[{type:"row",items:["timeout_enabled","timeout_duration"],gap:"0.5rem"}],validate:t=>{const e={};return{valid:0===Object.keys(e).length,errors:e}},toFormData:(t,e)=>{var i,o,n,s,r,a;const l=Fp(t),d=null===(n=null===(o=null===(i=t.router)||void 0===i?void 0:i.wait)||void 0===o?void 0:o.timeout)||void 0===n?void 0:n.seconds;let c=mm.find(t=>t.value===String(d));return c||(c={value:"300",name:"5 minutes"}),{uuid:t.uuid,rules:l,timeout_enabled:!!d,timeout_duration:c,result_name:(null===(s=t.router)||void 0===s?void 0:s.result_name)||"",localizeRules:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,localizeCategories:(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n,s,r,a,l,d;const c=Bp(t);if(0===c.length){let o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[];const n=[...e.exits||[]];if(t.timeout_enabled){let t=o.find(t=>"No Response"===t.name);if(!t){const e=Xt();t={uuid:Xt(),name:"No Response",exit_uuid:e},o=[...o,t],n.find(t=>t.uuid===e)||n.push({uuid:e,destination_uuid:null})}}else o=o.filter(t=>"No Response"!==t.name);const{router:s,exits:r}=gm([],o,n,[]),a={...s,cases:[]};t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim());const l={type:"msg"};if(t.timeout_enabled){let e;e=t.timeout_duration?Array.isArray(t.timeout_duration)&&t.timeout_duration.length>0?parseInt(t.timeout_duration[0].value,10):"string"==typeof t.timeout_duration?parseInt(t.timeout_duration,10):t.timeout_duration&&"object"==typeof t.timeout_duration&&t.timeout_duration.value?parseInt(t.timeout_duration.value,10):300:300,(isNaN(e)||e<=0)&&(e=300);const i=a.categories.find(t=>"No Response"===t.name);i&&(l.timeout={seconds:e,category_uuid:i.uuid})}return a.wait=l,{...e,router:a,exits:r}}const h=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],u=e.exits||[],p=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:m,exits:g}=gm(c,h,u,p),f={...m};t.result_name&&""!==t.result_name.trim()&&(f.result_name=t.result_name.trim());const v={type:"msg"};try{if(t.timeout_enabled){let i;if(t.timeout_duration)try{i=parseInt(t.timeout_duration[0].value,10)}catch(t){i=300}const o=null===(r=null===(s=e.router)||void 0===s?void 0:s.categories)||void 0===r?void 0:r.find(t=>"No Response"===t.name),n=o||{uuid:Xt(),name:"No Response",exit_uuid:Xt()};if(v.timeout={seconds:i,category_uuid:n.uuid},!(null===(a=m.categories)||void 0===a?void 0:a.some(t=>"No Response"===t.name))&&(m.categories=m.categories||[],m.categories.push(n),!g.some(t=>t.uuid===n.exit_uuid))){const t={uuid:n.exit_uuid,destination_uuid:(null==o?void 0:o.exit_uuid)&&(null===(d=null===(l=e.exits)||void 0===l?void 0:l.find(t=>t.uuid===o.exit_uuid))||void 0===d?void 0:d.destination_uuid)||null};g.push(t)}}else if(m.categories){const t=m.categories.findIndex(t=>"No Response"===t.name);if(-1!==t){const e=m.categories[t];m.categories.splice(t,1);const i=g.findIndex(t=>t.uuid===e.exit_uuid);-1!==i&&g.splice(i,1)}}}catch(t){console.error("Error processing timeout configuration:",t)}return f.wait=v,{...e,router:f,exits:g}},localizable:"categories",nonTranslatableCategories:["Timeout"],toLocalizationFormData:Tp,fromLocalizationFormData:Dp},vm=bm({say_msg:up,play_audio:pp,set_contact_field:Zu,send_broadcast:Xu,set_run_result:Qu,send_msg:tp,send_email:ep,start_session:ip,set_contact_name:op,add_contact_groups:np,remove_contact_groups:sp,set_contact_channel:Yu,set_contact_language:Ku,set_contact_status:Gu,add_contact_urn:Vu,add_input_labels:Hu,request_optin:rp,enter_flow:gp});function bm(t){const e={...t};return Object.values(t).forEach(t=>{t.aliases&&t.aliases.forEach(i=>{e[i]=t})}),e}const ym=bm({execute_actions:{type:"execute_actions"},split_by_contact_field:jp,split_by_expression:Wp,split_by_groups:Hp,split_by_llm:nm,split_by_llm_categorize:sm,split_by_random:Vp,split_by_run_result:Kp,split_by_scheme:Gp,split_by_subflow:Xp,split_by_ticket:Qp,split_by_webhook:im,split_by_resthook:om,wait_for_menu:pm,wait_for_digits:cm,wait_for_audio:rm,wait_for_dial:dm,wait_for_response:fm,split_by_airtime:Mp,terminal:{type:"terminal"}}),xm=60,wm=20;function _m(t,e,i,o){if(0===t.length)return{};const n=new Set(t.map(t=>t.uuid)),s=new Map,r=new Map;for(const e of t){const t=new Set,i=[];for(const o of e.exits)if(o.destination_uuid&&n.has(o.destination_uuid)&&!t.has(o.destination_uuid)){t.add(o.destination_uuid),i.push(o.destination_uuid);const n=r.get(o.destination_uuid)||[];n.push(e.uuid),r.set(o.destination_uuid,n)}s.set(e.uuid,i)}const a=function(t,e){const i=new Set,o=new Set,n=new Set;function s(t){o.add(t),n.add(t);for(const r of e.get(t)||[])o.has(r)?i.add(`${t}->${r}`):n.has(r)||s(r);o.delete(t)}return s(t),i}(i,s),l=function(t,e,i,o,n){const s=new Map;s.set(t,0);const r=new Map;for(const t of e)r.set(t.uuid,0);for(const[t,e]of i)for(const i of e)n.has(`${t}->${i}`)||r.set(i,(r.get(i)||0)+1);const a=[];for(const[t,e]of r)0===e&&(a.push(t),s.has(t)||s.set(t,0));for(;a.length>0;){const t=a.shift(),e=s.get(t);for(const o of i.get(t)||[]){if(n.has(`${t}->${o}`))continue;const i=e+1;(!s.has(o)||i>s.get(o))&&s.set(o,i);const l=r.get(o)-1;r.set(o,l),0===l&&a.push(o)}}const l=e.filter(t=>!s.has(t.uuid));if(l.length>0){let t=Math.max(...Array.from(s.values()),-1)+2;for(const e of l)s.set(e.uuid,t),t++}return s}(i,t,s,0,a),d=new Map;for(const[t,e]of l){const i=d.get(e)||[];i.push(t),d.set(e,i)}const c=Array.from(d.keys()).sort((t,e)=>t-e);!function(t,e,i,o){const n=new Map;for(const s of t){const r=e.get(s);if(s===t[0]){r.forEach((t,e)=>n.set(t,e));continue}const a=r.map(t=>{const e=(i.get(t)||[]).filter(t=>{const e=o.get(t);return void 0!==e&&e<s});if(0===e.length)return{uuid:t,value:1/0};const r=e.reduce((t,e)=>{var i;return t+(null!==(i=n.get(e))&&void 0!==i?i:0)},0);return{uuid:t,value:r/e.length}});a.sort((t,e)=>t.value-e.value);const l=a.map(t=>t.uuid);e.set(s,l),l.forEach((t,e)=>n.set(t,e))}}(c,d,r,l);const h=new Map;for(const e of t)h.set(e.uuid,o(e.uuid));return function(t,e,i,o,n,s){var r,a,l,d;const c={};let h=0;for(const u of t){const p=km(e.get(u),i);for(const e of p){const p=fu(h);if(u===t[0]){let t=0;for(const o of e){const e=o===s?p:p+40;c[o]={left:fu(t),top:e},t+=((null===(r=i.get(o))||void 0===r?void 0:r.width)||200)+xm}}else{let t=0;for(const o of e)t+=(null===(a=i.get(o))||void 0===a?void 0:a.width)||200;t+=xm*(e.length-1);const s=[];for(const t of e){const e=(o.get(t)||[]).filter(t=>{const e=n.get(t);return void 0!==e&&e<u});for(const t of e){const e=c[t];if(e){const o=(null===(l=i.get(t))||void 0===l?void 0:l.width)||200;s.push(e.left+o/2)}}}let r;if(s.length>0){const e=(Math.min(...s)+Math.max(...s))/2;r=Math.max(0,e-t/2)}else r=0;let h=r;for(const t of e){const e=(null===(d=i.get(t))||void 0===d?void 0:d.width)||200;c[t]={left:fu(h),top:p},h=fu(h)+e+xm}}const m=Math.max(...e.map(t=>{var e;return(null===(e=i.get(t))||void 0===e?void 0:e.height)||100}));h=p+m+80}}const u=c[s];if(u){const t=u.left,e=u.top;for(const i of Object.keys(c))c[i]={left:fu(Math.max(0,c[i].left-t)),top:fu(Math.max(0,c[i].top-e))}}return c}(c,d,h,r,l,i)}function km(t,e){var i;const o=[];let n=[],s=0;for(const r of t){const t=(null===(i=e.get(r))||void 0===i?void 0:i.width)||200,a=n.length>0?xm+t:t;n.length>0&&s+a>1200?(o.push(n),n=[r],s=t):(n.push(r),s+=a)}return n.length>0&&o.push(n),o}function Cm(t,e,i,o,n){for(const s of n)if(t<s.left+s.width+wm&&t+i+wm>s.left&&e<s.top+s.height+wm&&e+o+wm>s.top)return!0;return!1}class Sm extends Be{constructor(){super(...arguments),this.color="#6B7280",this.order=0,this.top=100,this.hidden=!1,this.saving=!1,this.active=!1}static get styles(){return a`
8944
8946
  .tab.hidden {
8945
8947
  transform: translateX(calc(100% + var(--floating-tab-clip, 0px)));
8946
8948
  }
@@ -9300,6 +9302,9 @@ background: #ccc;
9300
9302
 
9301
9303
  .router .body {
9302
9304
  padding: 0.75em;
9305
+ }
9306
+
9307
+ .router .body > div {
9303
9308
  max-width: 180px;
9304
9309
  }
9305
9310
 
@@ -9307,7 +9312,32 @@ background: #ccc;
9307
9312
  font-weight: 500;
9308
9313
  display: inline-block;
9309
9314
  }
9310
-
9315
+
9316
+ .router {
9317
+ display: flex;
9318
+ flex-direction: column;
9319
+ }
9320
+
9321
+ .rules-count {
9322
+ position: absolute;
9323
+ right: 4px;
9324
+ top: 50%;
9325
+ transform: translateY(-50%);
9326
+ background: #fff8dc;
9327
+ border-radius: 10px;
9328
+ min-width: 18px;
9329
+ height: 18px;
9330
+ padding: 0 5px;
9331
+ font-size: 11px;
9332
+ font-weight: 600;
9333
+ color: #333;
9334
+ display: flex;
9335
+ align-items: center;
9336
+ justify-content: center;
9337
+ line-height: 1;
9338
+ box-sizing: border-box;
9339
+ }
9340
+
9311
9341
  .exit-wrapper {
9312
9342
  display: flex;
9313
9343
  justify-content: center;
@@ -9482,9 +9512,9 @@ background: #ccc;
9482
9512
  >
9483
9513
 
9484
9514
  </div>
9485
- </div>`}renderNodeTitle(t,e,i,o=!1){var n,s;const r=t.group?(null===(n=ju[t.group])||void 0===n?void 0:n.color)||(null===(s=Wu[t.group])||void 0===s?void 0:s.color):"#aaaaaa";return H`<div
9515
+ </div>`}renderNodeTitle(t,e,i,o=!1){var n,s;const r=t.group?(null===(n=ju[t.group])||void 0===n?void 0:n.color)||(null===(s=Wu[t.group])||void 0===s?void 0:s.color):"#aaaaaa",a=this.getUntranslatedRulesCount();return H`<div
9486
9516
  class="cn-title ${o?"removing":""}"
9487
- style="background:${r}"
9517
+ style="background:${r}; position: relative;"
9488
9518
  >
9489
9519
  <div class="title-spacer"></div>
9490
9520
  <div class="name">
@@ -9497,6 +9527,7 @@ background: #ccc;
9497
9527
  >
9498
9528
 
9499
9529
  </div>
9530
+ ${a>0?H`<div class="rules-count">${a}</div>`:null}
9500
9531
  </div>`}renderDropPlaceholder(){var t;const e=(null===(t=this.externalDragInfo)||void 0===t?void 0:t.actionHeight)||60;return H`<div
9501
9532
  class="action sortable drop-placeholder"
9502
9533
  style="height: ${e}px; background: #f3f4f6; border: 2px dashed #d1d5db; border-radius: var(--curvature);"
@@ -9526,7 +9557,7 @@ background: #ccc;
9526
9557
 
9527
9558
  </div>
9528
9559
  ${e.type}
9529
- </div>`}renderActionsWithPlaceholder(){if(!this.externalDragInfo)return this.node.actions.map((t,e)=>this.renderAction(this.node,t,e));const t=[];for(let e=0;e<this.node.actions.length;e++)e===this.externalDragInfo.dropIndex&&t.push(this.renderDropPlaceholder()),t.push(this.renderAction(this.node,this.node.actions[e],e));return this.externalDragInfo.dropIndex>=this.node.actions.length&&t.push(this.renderDropPlaceholder()),t}renderRouter(t,e){if(ym[e.type])return H`<div class="router" style="position: relative;">
9560
+ </div>`}renderActionsWithPlaceholder(){if(!this.externalDragInfo)return this.node.actions.map((t,e)=>this.renderAction(this.node,t,e));const t=[];for(let e=0;e<this.node.actions.length;e++)e===this.externalDragInfo.dropIndex&&t.push(this.renderDropPlaceholder()),t.push(this.renderAction(this.node,this.node.actions[e],e));return this.externalDragInfo.dropIndex>=this.node.actions.length&&t.push(this.renderDropPlaceholder()),t}getUntranslatedRulesCount(){var t,e,i,o,n,s;if(!this.isTranslating||!(null===(e=null===(t=this.ui)||void 0===t?void 0:t.config)||void 0===e?void 0:e.localizeRules))return 0;const r=null===(o=null===(i=this.node)||void 0===i?void 0:i.router)||void 0===o?void 0:o.cases;if(!(null==r?void 0:r.length))return 0;const a=(null===(s=null===(n=this.flowDefinition)||void 0===n?void 0:n.localization)||void 0===s?void 0:s[this.languageCode])||{};return r.filter(t=>{var e,i;if(!(null===(e=t.arguments)||void 0===e?void 0:e.length)||!t.arguments.some(t=>t))return!1;const o=null===(i=a[t.uuid])||void 0===i?void 0:i.arguments;return!Array.isArray(o)||!o.some(t=>t)}).length}renderRouter(t,e){if(ym[e.type])return H`<div class="router" style="position: relative;">
9530
9561
  ${t.result_name?H`<div
9531
9562
  class="body"
9532
9563
  @mousedown=${t=>this.handleNodeMouseDown(t)}
@@ -9762,6 +9793,12 @@ background: #ccc;
9762
9793
  border: 1px solid #d7dce2;
9763
9794
  }
9764
9795
 
9796
+ .language-pill.complete {
9797
+ background: #d4f5e0;
9798
+ color: #1a7f37;
9799
+ --icon-color: #1a7f37;
9800
+ }
9801
+
9765
9802
  .language-pill-caret {
9766
9803
  margin-left: 1px;
9767
9804
  --icon-color: currentColor;
@@ -9777,6 +9814,10 @@ background: #ccc;
9777
9814
  white-space: nowrap;
9778
9815
  }
9779
9816
 
9817
+ .language-pill.complete .language-percent {
9818
+ color: #1a7f37;
9819
+ }
9820
+
9780
9821
  .toolbar-zoom-level {
9781
9822
  font-size: 12px;
9782
9823
  min-width: 40px;
@@ -10865,12 +10906,14 @@ background: #ccc;
10865
10906
  >Original</span
10866
10907
  >
10867
10908
  </div>
10868
- `}return H`
10909
+ `}const o=100===t.percent,n=o?"#d4f5e0":"",s=o?"#c0edce":"",r=o?"color:#1a7f37;":"color:#5f6b7a;";return H`
10869
10910
  <div
10870
- style="display:flex; align-items:center; justify-content:space-between; gap:8px; padding:6px 10px;"
10911
+ style="display:flex; align-items:center; justify-content:space-between; gap:8px; padding:6px 10px; ${n?`background:${n};`:""} ${o?"border-radius:4px;":""}"
10912
+ @mouseenter=${o?t=>{t.currentTarget.style.background=s}:null}
10913
+ @mouseleave=${o?t=>{t.currentTarget.style.background=n}:null}
10871
10914
  >
10872
- <span>${t.name}</span>
10873
- <span style="font-size:11px; font-weight:600; color:#5f6b7a;"
10915
+ <span style="${o?"color:#1a7f37;":""}">${t.name}</span>
10916
+ <span style="font-size:11px; font-weight:600; ${r}"
10874
10917
  >${null!==(i=t.percent)&&void 0!==i?i:0}%</span
10875
10918
  >
10876
10919
  </div>
@@ -10901,7 +10944,7 @@ background: #ccc;
10901
10944
  <div class="toolbar-language">
10902
10945
  ${this.renderToolbarTip("Change language",H`
10903
10946
  <button
10904
- class="language-pill ${a?"primary":""}"
10947
+ class="language-pill ${a?"primary":100===h?"complete":""}"
10905
10948
  id="language-btn"
10906
10949
  @click=${this.handleLanguageIconClick}
10907
10950
  aria-label="Change language"
@@ -11002,24 +11045,7 @@ background: #ccc;
11002
11045
  `)}
11003
11046
  </div>
11004
11047
  </div>
11005
- `}renderToolbarTranslationTools(t){const e=Boolean(this.viewingRevision),i=this.autoTranslating?"Stop auto translate":"Auto translate";return H`
11006
- <div class="toolbar-translation">
11007
- ${this.renderToolbarTip(i,H`
11008
- <button
11009
- class="toolbar-btn language-tool ${this.autoTranslating?"active":""}"
11010
- @click=${this.handleAutoTranslateClick}
11011
- ?disabled=${e||!this.autoTranslating&&!t}
11012
- aria-label=${i}
11013
- >
11014
- <temba-icon
11015
- name=${this.autoTranslating?"progress_spinner":ko.ai}
11016
- size="0.9"
11017
- ?spin=${this.autoTranslating}
11018
- ></temba-icon>
11019
- </button>
11020
- `)}
11021
- </div>
11022
- `}focusNode(t){const e=this.querySelector(`temba-flow-node[uuid="${t}"]`);if(!e)return;const i=this.querySelector("#editor");if(!i)return;const o=i.getBoundingClientRect(),n=o.width/2,s=o.height/2,r=e.offsetLeft+e.offsetWidth/2,a=e.offsetTop+e.offsetHeight/2,l=r*this.zoom-n,d=a*this.zoom-s;i.scrollTo({left:Math.max(0,l),top:Math.max(0,d),behavior:"smooth"})}handleSearchResultSelected(t){var e,i,o;const n=t.detail;if(n.stickyField)return void this.focusCanvasElement(`temba-sticky-note[uuid="${n.nodeUuid}"]`,n.stickyField);const s=this.definition.nodes.find(t=>t.uuid===n.nodeUuid);if(!s)return;const r=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[n.nodeUuid];if(this.showMessageTable){const t=this.querySelector("temba-message-table");null===(i=null==t?void 0:t.focusSearchResult)||void 0===i||i.call(t,n.nodeUuid,(null===(o=n.action)||void 0===o?void 0:o.uuid)||null)}else this.focusNode(n.nodeUuid);setTimeout(()=>{n.action?(this.editingAction=n.action,this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null):(this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null)},200)}focusCanvasElement(t,e){const i=this.querySelector(t);if(!i)return;const o=this.querySelector("#editor");if(!o)return;const n=o.getBoundingClientRect(),s=i.offsetLeft+i.offsetWidth/2,r=i.offsetTop+i.offsetHeight/2,a=s*this.zoom-n.width/2,l=r*this.zoom-n.height/2;o.scrollTo({left:Math.max(0,a),top:Math.max(0,l),behavior:"smooth"}),e&&setTimeout(()=>{var t;const o=null===(t=i.shadowRoot)||void 0===t?void 0:t.querySelector(`.sticky-${e}`);o&&o.focus()},300)}isReadOnly(){return null!==this.viewingRevision||this.isTranslating}render(){var t,e;const i=H`<style>
11048
+ `}renderToolbarTranslationTools(t){return H``}focusNode(t){const e=this.querySelector(`temba-flow-node[uuid="${t}"]`);if(!e)return;const i=this.querySelector("#editor");if(!i)return;const o=i.getBoundingClientRect(),n=o.width/2,s=o.height/2,r=e.offsetLeft+e.offsetWidth/2,a=e.offsetTop+e.offsetHeight/2,l=r*this.zoom-n,d=a*this.zoom-s;i.scrollTo({left:Math.max(0,l),top:Math.max(0,d),behavior:"smooth"})}handleSearchResultSelected(t){var e,i,o;const n=t.detail;if(n.stickyField)return void this.focusCanvasElement(`temba-sticky-note[uuid="${n.nodeUuid}"]`,n.stickyField);const s=this.definition.nodes.find(t=>t.uuid===n.nodeUuid);if(!s)return;const r=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[n.nodeUuid];if(this.showMessageTable){const t=this.querySelector("temba-message-table");null===(i=null==t?void 0:t.focusSearchResult)||void 0===i||i.call(t,n.nodeUuid,(null===(o=n.action)||void 0===o?void 0:o.uuid)||null)}else this.focusNode(n.nodeUuid);setTimeout(()=>{n.action?(this.editingAction=n.action,this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null):(this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null)},200)}focusCanvasElement(t,e){const i=this.querySelector(t);if(!i)return;const o=this.querySelector("#editor");if(!o)return;const n=o.getBoundingClientRect(),s=i.offsetLeft+i.offsetWidth/2,r=i.offsetTop+i.offsetHeight/2,a=s*this.zoom-n.width/2,l=r*this.zoom-n.height/2;o.scrollTo({left:Math.max(0,a),top:Math.max(0,l),behavior:"smooth"}),e&&setTimeout(()=>{var t;const o=null===(t=i.shadowRoot)||void 0===t?void 0:t.querySelector(`.sticky-${e}`);o&&o.focus()},300)}isReadOnly(){return null!==this.viewingRevision||this.isTranslating}render(){var t,e;const i=H`<style>
11023
11049
  ${r(Pm.styles.cssText)}
11024
11050
  ${r(Mm.styles.cssText)}
11025
11051
  </style>`,o=(null===(e=null===(t=this.definition)||void 0===t?void 0:t._ui)||void 0===e?void 0:e.stickies)||{},n=this.definition&&this.definition.nodes.length>0&&this.definition.nodes.some(t=>{var e;return!(null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid])});return H`${i} ${this.renderIssuesWindow()}
@@ -13174,7 +13200,7 @@ const ak=(t,e)=>{const i=t._$AN;if(void 0===i)return!1;for(const t of i)t._$AO?.
13174
13200
  <div class="original-value">
13175
13201
  <div class="original-value-content">${i}</div>
13176
13202
  </div>
13177
- `:H``}renderFieldContent(t,e,i,o){const n=this.isTranslating?{...e,required:!1}:e;return vk.renderField(t,n,i,{errors:o,onChange:i=>{var o,n;if(t&&"key-value"===e.type){const e=i;e.detail&&this.handleNewFieldChange(t,e.detail.value)}else if(t&&"array"===e.type)this.handleNewFieldChange(t,i.target.value);else if(t&&"message-editor"===e.type)this.handleMessageEditorChange(t,i);else if(t&&"media"===e.type){const e=(null===(n=null===(o=i.target.attachments)||void 0===o?void 0:o[0])||void 0===n?void 0:n.url)||"";this.handleNewFieldChange(t,e)}else t&&"template-editor"===e.type?this.handleTemplateEditorChange(t,i):this.handleFormFieldChange(t,i)},showLabel:!0,formData:this.formData,additionalData:{attachments:this.formData.attachments||[],template_variables:this.formData.template_variables||[]}})}handleGroupToggle(t){this.groupCollapseState={...this.groupCollapseState,[t]:!this.groupCollapseState[t]}}handleGroupMouseEnter(t){this.groupHoverState={...this.groupHoverState,[t]:!0}}handleGroupMouseLeave(t){this.groupHoverState={...this.groupHoverState,[t]:!1}}expandGroupsWithErrors(t){const e=this.getConfig();if(!(null==e?void 0:e.layout))return;const i=new Set(Object.keys(t));this.expandGroupsWithErrorsRecursive(e.layout,i)}expandGroupsWithErrorsRecursive(t,e){t.forEach(t=>{if("object"==typeof t&&"group"===t.type){this.collectFieldsFromItems(t.items).some(t=>e.has(t))&&(this.groupCollapseState={...this.groupCollapseState,[t.label]:!1}),this.expandGroupsWithErrorsRecursive(t.items,e)}else"object"==typeof t&&"row"===t.type?this.expandGroupsWithErrorsRecursive(t.items,e):"object"==typeof t&&"accordion"===t.type&&t.sections.forEach(t=>{this.collectFieldsFromItems(t.items).some(t=>e.has(t))&&(this.groupCollapseState={...this.groupCollapseState,[`accordion:${t.label}`]:!1}),this.expandGroupsWithErrorsRecursive(t.items,e)})})}renderLayoutItem(t,e,i){if("string"==typeof t)return this.renderLayoutItem({type:"field",field:t},e,i);switch(t.type){case"field":if(e.form[t.field]&&!i.has(t.field)){i.add(t.field);const o=e.form[t.field];return o.optionalLink?this.renderOptionalField(t.field,o,this.formData[t.field]):this.renderNewField(t.field,o,this.formData[t.field])}return H``;case"row":return this.renderRow(t,e,i);case"group":return this.renderGroup(t,e,i);case"accordion":return this.renderAccordion(t,e,i);case"spacer":default:return H``;case"text":return H`<div class="form-text">${t.text}</div>`}}renderRow(t,e,i){const{items:o,gap:n="1rem",label:s,helpText:r,inlineLabels:a,marginBottom:l}=t,d=this.collectFieldsFromItems(o).filter(t=>{var i;return null===(i=e.form)||void 0===i?void 0:i[t]}).filter(t=>{const i=e.form[t];return this.isFieldVisible(t,i)});if(0===d.length)return H``;const c=new Map;d.forEach(t=>{const i=e.form[t];i.maxWidth?c.set(t,`flex: 0 0 ${i.maxWidth};`):c.set(t,"flex: 1 1 0;")});const h=H`
13203
+ `:H``}renderFieldContent(t,e,i,o){const n=this.isTranslating?{...e,required:!1}:e;return vk.renderField(t,n,i,{errors:o,onChange:i=>{var o,n;if(t&&"key-value"===e.type){const e=i;e.detail&&this.handleNewFieldChange(t,e.detail.value)}else if(t&&"array"===e.type)this.handleNewFieldChange(t,i.target.value);else if(t&&"message-editor"===e.type)this.handleMessageEditorChange(t,i);else if(t&&"media"===e.type){const e=(null===(n=null===(o=i.target.attachments)||void 0===o?void 0:o[0])||void 0===n?void 0:n.url)||"";this.handleNewFieldChange(t,e)}else t&&"template-editor"===e.type?this.handleTemplateEditorChange(t,i):this.handleFormFieldChange(t,i)},showLabel:!0,formData:this.formData,additionalData:{attachments:this.formData.attachments||[],template_variables:this.formData.template_variables||[]}})}handleGroupToggle(t){this.groupCollapseState={...this.groupCollapseState,[t]:!this.groupCollapseState[t]}}handleGroupMouseEnter(t){this.groupHoverState={...this.groupHoverState,[t]:!0}}handleGroupMouseLeave(t){this.groupHoverState={...this.groupHoverState,[t]:!1}}expandGroupsWithErrors(t){const e=this.getConfig();if(!(null==e?void 0:e.layout))return;const i=new Set(Object.keys(t));this.expandGroupsWithErrorsRecursive(e.layout,i)}expandGroupsWithErrorsRecursive(t,e){t.forEach(t=>{if("object"==typeof t&&"group"===t.type){this.collectFieldsFromItems(t.items).some(t=>e.has(t))&&(this.groupCollapseState={...this.groupCollapseState,[t.label]:!1}),this.expandGroupsWithErrorsRecursive(t.items,e)}else"object"==typeof t&&"row"===t.type?this.expandGroupsWithErrorsRecursive(t.items,e):"object"==typeof t&&"accordion"===t.type&&t.sections.forEach(t=>{this.collectFieldsFromItems(t.items).some(t=>e.has(t))&&(this.groupCollapseState={...this.groupCollapseState,[`accordion:${t.label}`]:!1}),this.expandGroupsWithErrorsRecursive(t.items,e)})})}renderLayoutItem(t,e,i){if("string"==typeof t)return this.renderLayoutItem({type:"field",field:t},e,i);switch(t.type){case"field":if(this.isTranslating&&Array.isArray(e.localizable)&&!e.localizable.includes(t.field))return i.add(t.field),H``;if(e.form[t.field]&&!i.has(t.field)){i.add(t.field);const o=e.form[t.field];return o.optionalLink?this.renderOptionalField(t.field,o,this.formData[t.field]):this.renderNewField(t.field,o,this.formData[t.field])}return H``;case"row":return this.renderRow(t,e,i);case"group":return this.renderGroup(t,e,i);case"accordion":return this.renderAccordion(t,e,i);case"spacer":default:return H``;case"text":return H`<div class="form-text">${t.text}</div>`}}renderRow(t,e,i){const{items:o,gap:n="1rem",label:s,helpText:r,inlineLabels:a,marginBottom:l}=t,d=this.collectFieldsFromItems(o).filter(t=>{var i;return null===(i=e.form)||void 0===i?void 0:i[t]}).filter(t=>{const i=e.form[t];return this.isFieldVisible(t,i)});if(0===d.length)return H``;const c=new Map;d.forEach(t=>{const i=e.form[t];i.maxWidth?c.set(t,`flex: 0 0 ${i.maxWidth};`):c.set(t,"flex: 1 1 0;")});const h=H`
13178
13204
  <div
13179
13205
  class="form-row"
13180
13206
  style="display: flex; gap: ${n};${l?` margin-bottom: ${l};`:""}"
@@ -13256,9 +13282,9 @@ const ak=(t,e)=>{const i=t._$AN;if(void 0===i)return!1;for(const t of i)t._$AO?.
13256
13282
  </temba-accordion>
13257
13283
  `}handleAccordionSectionToggle(t){const e=t.detail.label,i=t.detail.collapsed,o=`accordion:${e}`;this.groupCollapseState={...this.groupCollapseState,[o]:i}}collectFieldsFromItems(t){const e=[];return t.forEach(t=>{"string"==typeof t?e.push(t):"field"===t.type?e.push(t.field):"row"===t.type||"group"===t.type?e.push(...this.collectFieldsFromItems(t.items)):"accordion"===t.type&&t.sections.forEach(t=>{e.push(...this.collectFieldsFromItems(t.items))})}),e}renderFieldRow(t,e){return this.renderRow(t,e,new Set)}renderFieldGroup(t,e){return this.renderGroup(t,e,new Set)}handleNewFieldChange(t,e){if(this.formData={...this.formData,[t]:e},this.errors[t]){const e={...this.errors};delete e[t],this.errors=e}this.updateGroupCollapseStates(),this.requestUpdate()}handleTemplateEditorChange(t,e){const i=e.detail;this.formData={...this.formData,[t]:i.template?{uuid:i.template.uuid,name:i.template.name}:null,template_variables:i.variables||[]},this.updateGroupCollapseStates(),this.requestUpdate()}handleMessageEditorChange(t,e){const i=e.target;if(this.formData={...this.formData,[t]:i.value,attachments:i.attachments||[]},this.errors[t]){const e={...this.errors};delete e[t],delete e.attachments,this.errors=e}this.requestUpdate()}renderFields(){const t=this.getConfig();if(!t)return H` <div>No configuration available</div> `;if(this.isTranslating&&"categories"===t.localizable&&(this.formData.categories||this.formData.rules))return this.renderLocalizationTable();if(t.form){if(t.layout){const e=new Set,i=new Set;if(t.gutter){this.collectFieldsFromItems(t.gutter).forEach(t=>i.add(t))}return H`
13258
13284
  ${t.layout.map(i=>this.renderLayoutItem(i,t,e))}
13259
- ${Object.entries(t.form).map(([t,o])=>e.has(t)||i.has(t)?H``:this.renderNewField(t,o,this.formData[t]))}
13285
+ ${Object.entries(t.form).map(([o,n])=>e.has(o)||i.has(o)||this.isTranslating&&Array.isArray(t.localizable)&&!t.localizable.includes(o)?H``:this.renderNewField(o,n,this.formData[o]))}
13260
13286
  `}return H`
13261
- ${Object.entries(t.form).map(([t,e])=>this.renderNewField(t,e,this.formData[t]))}
13287
+ ${Object.entries(t.form).map(([e,i])=>this.isTranslating&&Array.isArray(t.localizable)&&!t.localizable.includes(e)?H``:this.renderNewField(e,i,this.formData[e]))}
13262
13288
  `}return this.action?H` <div>No form configuration available for this action</div> `:H` <div>No form configuration available for this node</div> `}renderGutter(){const t=this.getConfig();if(!(null==t?void 0:t.gutter)||0===t.gutter.length)return H``;if(this.isTranslating&&"categories"===t.localizable)return H``;const e=new Set;return H`
13263
13289
  <div class="gutter-fields">
13264
13290
  ${t.gutter.map(i=>this.renderLayoutItem(i,t,e))}
@@ -14858,17 +14884,17 @@ const ak=(t,e)=>{const i=t._$AN;if(void 0===i)return!1;for(const t of i)t._$AO?.
14858
14884
  font-size: 13px;
14859
14885
  }
14860
14886
  `}resetAttachmentIndices(){this.imageIndex=2,this.videoIndex=0,this.audioIndex=0,this.locationIndex=0}get sizeConfig(){return zk[this.size]||zk.medium}get windowWidth(){const t=this.sizeConfig;return t.contextWidth+t.phoneWidth+t.optionPaneWidth+t.optionPaneGap+t.contextOffset}get leftBoundaryMargin(){const t=this.sizeConfig;return t.contextWidth+t.contextOffset}get contextClosedLeft(){const t=this.sizeConfig;return t.contextWidth+t.contextOffset-t.phoneWidth}connectedCallback(){super.connectedCallback()}firstUpdated(t){super.firstUpdated(t),this.refreshChat(),this.setupCustomScrollbar()}refreshChat(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("temba-chat");return e!==this.chat&&(this.chat=e),this.chat&&this.events.length>0&&(this.chat.addMessages(this.events,null,!0),this.events=[]),this.chat}setupCustomScrollbar(){var t,e,i;const o=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("temba-chat"),n=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(".custom-scrollbar-container"),s=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelector(".custom-scrollbar-content");o&&n&&s&&o.updateComplete.then(()=>{var t;const e=null===(t=o.shadowRoot)||void 0===t?void 0:t.querySelector(".scroll");if(!e)return;let i=!1;e.addEventListener("scroll",()=>{if(!i){i=!0;const t=n.scrollHeight-n.clientHeight-Math.abs(e.scrollTop);n.scrollTop=t,requestAnimationFrame(()=>i=!1)}}),n.addEventListener("scroll",()=>{if(!i){i=!0;const t=n.scrollHeight-n.clientHeight-n.scrollTop;e.scrollTop=-t,requestAnimationFrame(()=>i=!1)}});const r=()=>{const t=e.scrollHeight-e.clientHeight,i=n.clientHeight;if(t<=0)return void(s.style.height="100%");const o=t+i;s.style.height=`${o}px`,Math.abs(e.scrollTop)<5&&(n.scrollTop=n.scrollHeight)};new MutationObserver(r).observe(e,{childList:!0,subtree:!0,attributes:!0});new ResizeObserver(r).observe(e),r()})}willUpdate(t){super.willUpdate(t),t.has("flow")&&this.flow&&(this.endpoint=`/flow/simulate/${this.flow}/`)}updated(t){super.updated(t),(t.has("currentQuickReplies")||t.has("keyboardVisible")||t.has("attachmentMenuOpen"))&&this.updateBottomInputHeight(),t.has("attachmentMenuOpen")&&(this.attachmentMenuOpen?(this.boundClickOutsideHandler||(this.boundClickOutsideHandler=this.handleClickOutsideAttachmentMenu.bind(this)),setTimeout(()=>{document.addEventListener("click",this.boundClickOutsideHandler)},0)):this.boundClickOutsideHandler&&document.removeEventListener("click",this.boundClickOutsideHandler)),t.has("size")?requestAnimationFrame(()=>{var t,e;const i=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("phone-window");if(i){const t=this.previousWindowWidth||i.width,o=i.left+t,n=this.sizeConfig,s=this.windowWidth;this.previousWindowWidth=s,i.width=s,i.leftBoundaryMargin=this.leftBoundaryMargin,i.topBoundaryMargin=n.windowPadding,i.bottomBoundaryMargin=n.windowPadding;let r=o-s;const a=20,l=a-this.leftBoundaryMargin,d=window.innerWidth-s-a+i.rightBoundaryMargin;r=Math.max(l,Math.min(r,d)),i.left=r;const c=null===(e=i.shadowRoot)||void 0===e?void 0:e.querySelector(".window"),h=(null==c?void 0:c.offsetHeight)||n.phoneTotalHeight,u=Math.max(a-n.windowPadding,window.innerHeight-h-a+n.windowPadding);i.top=Math.max(a-n.windowPadding,Math.min(i.top,u))}}):this.previousWindowWidth||(this.previousWindowWidth=this.windowWidth)}disconnectedCallback(){super.disconnectedCallback(),this.boundClickOutsideHandler&&document.removeEventListener("click",this.boundClickOutsideHandler)}handleTabClick(){this.isVisible?this.handleClose():this.handleShow()}async handleShow(){var t,e;this.shadowRoot.getElementById("phone-window").show(),this.isVisible=!0,Ed().getState().setSimulatorActive(!0),this.refreshChat(),this.session||(await(null===(e=(t=Ed().getState()).flushSave)||void 0===e?void 0:e.call(t)),this.startFlow())}async startFlow(){const t=(new Date).toISOString(),e=Sd.getState().languageCode;e&&(this.contact={...this.contact,language:e}),this.contact={...this.contact,created_on:t};const i={contact:this.contact,trigger:{type:"manual",triggered_on:t,flow:{uuid:this.flow,name:"New Chat"},params:{}}};try{const t=await ue(this.endpoint,i);this.updateRunContext(t.json)}catch(e){console.error("Failed to start simulation:",e);const i={uuid:Jt(),type:"error",created_on:new Date(t),_rendered:{html:H`<p>Failed to start simulation</p>`,type:Yc.Error}};this.refreshChat(),this.chat?this.chat.addMessages([i],null,!0):this.events=[...this.events,i]}}updateRunContext(t,e){var i;const o=[];if(e&&(e.uuid||(e.uuid=Jt()),"string"==typeof e.created_on&&(e.created_on=new Date(e.created_on)),o.push(e)),t.session&&(this.session=t.session,t.contact&&(this.contact=t.contact)),t.context&&(this.context=t.context),this.currentQuickReplies=[],t.events&&t.events.length>0)for(const e of t.events){if("msg_received"===e.type)continue;if(("msg_created"===e.type||"ivr_created"===e.type)&&!e.msg)continue;const t={...e,uuid:e.uuid||Jt(),created_on:"string"==typeof e.created_on?new Date(e.created_on):e.created_on};this.prerenderEvent(t),"msg_created"===t.type&&(null===(i=t.msg)||void 0===i?void 0:i.quick_replies)&&(this.currentQuickReplies=t.msg.quick_replies);const n="msg_created"===t.type||"ivr_created"===t.type,s=t.msg;if(n){const t=s.text&&s.text.trim().length>0,e=s.attachments&&s.attachments.length>0;if(!t&&!e)continue}else if(!t._rendered)continue;o.push(t)}this.refreshChat(),this.chat?this.chat.addMessages(o,null,!0):this.events=[...this.events,...o],this.sprinting=!1,this.requestUpdate(),this.scrollToBottom(),this.updateActivity()}updateActivity(){if(!this.session)return;const t={},e={};for(const i of this.session.runs){if(i.path)for(let e=0;e<i.path.length-1;e++){const o=i.path[e],n=i.path[e+1];if(o.exit_uuid&&n.node_uuid){const e=o.exit_uuid+":"+n.node_uuid;t[e]=(t[e]||0)+1}}if(("active"===i.status||"waiting"===i.status)&&i.path&&i.path.length>0){const t=i.path[i.path.length-1];t&&t.node_uuid&&(e[t.node_uuid]=(e[t.node_uuid]||0)+1)}}Ed().getState().updateSimulatorActivity({segments:t,nodes:e}),this.following&&this.fireFollowEvent()}fireFollowEvent(){var t;if(!this.session||!this.session.runs||0===this.session.runs.length)return;let e=this.session.runs.find(t=>"active"===t.status||"waiting"===t.status);if(e||(e=this.session.runs.find(t=>"completed"===t.status)),e&&e.path&&e.path.length>0){const i=e.path[e.path.length-1];i&&i.node_uuid&&this.fireCustomEvent(Io.FollowSimulation,{flowUuid:(null===(t=e.flow)||void 0===t?void 0:t.uuid)||this.flow,nodeUuid:i.node_uuid})}}scrollToBottom(){if(this.chat)return this.chat.scrollToBottom(),void setTimeout(()=>{var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".message-input input");e&&e.focus()},50);setTimeout(()=>{var t,e;const i=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".phone-screen");i&&(i.scrollTop=i.scrollHeight),this.previousEventCount=this.events.length;const o=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(".message-input input");o&&o.focus()},50)}prerenderEvent(t){if(t._rendered||t.type===Jc.MSG_CREATED||t.type===Jc.MSG_RECEIVED)return;if("error"===t.type||"failure"===t.type)return void(t._rendered={html:ih(t,!0),type:Yc.Error});if("warning"===t.type)return void(t._rendered={html:ih(t,!0),type:Yc.Note});const e=ih(t,!0);if(e){const i=t.type===Jc.WEBHOOK_CALLED&&this.hasWebhookDetails(t)?H`<div class="webhook-event">
14861
- <div class="webhook-event-text">${e}</div>
14862
- <button
14863
- type="button"
14864
- data-webhook-details="true"
14865
- class="webhook-event-log-link"
14866
- title="View webhook call details"
14867
- aria-label="View webhook call details"
14868
- @click=${e=>this.handleWebhookDetailsClick(t,e)}
14869
- >
14870
- <temba-icon name="log" size="0.8"></temba-icon>
14871
- </button>
14887
+ <div class="webhook-event-text">
14888
+ Called
14889
+ <a
14890
+ href="#"
14891
+ class="webhook-event-url"
14892
+ data-webhook-details="true"
14893
+ title="View webhook call details"
14894
+ @click=${e=>{e.preventDefault(),this.handleWebhookDetailsClick(t,e)}}
14895
+ >${((t,e=50)=>t&&t.length>e?t.slice(0,e)+"…":t)(t.url)}</a
14896
+ >
14897
+ </div>
14872
14898
  </div>`:e;t._rendered={html:i,type:Yc.Inline}}}handleClose(){this.shadowRoot.getElementById("phone-window").handleClose(),this.isVisible=!1,this.closeWebhookDetails(),Ed().getState().setSimulatorActive(!1)}async handleReset(){var t,e,i;this.events=[],this.session=null,this.context=null,this.inputValue="",this.sprinting=!1,this.previousEventCount=0,this.currentQuickReplies=[],this.closeWebhookDetails(),this.refreshChat(),this.chat&&this.chat.reset(),Ed().getState().updateSimulatorActivity({segments:{},nodes:{}});const o=Sd.getState().languageCode;this.contact={uuid:"fb3787ab-2eda-48a0-a2bc-e2ddadec1286",urns:["tel:+12065551212"],fields:{},groups:[],language:o||(null===(t=this.definition)||void 0===t?void 0:t.language)||"eng",status:"active",created_on:(new Date).toISOString()},await(null===(i=(e=Ed().getState()).flushSave)||void 0===i?void 0:i.call(e)),this.startFlow()}handleToggleFollow(){this.following=!this.following}handleCycleSize(){const t=["small","medium","large"],e=(t.indexOf(this.size)+1)%t.length;this.size=t[e]}handleToggleContextExplorer(){this.contextExplorerOpen=!this.contextExplorerOpen,this.contextExplorerOpen&&requestAnimationFrame(()=>{var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("phone-window");if(e){const t=20-this.sizeConfig.contextOffset;e.left<t&&(e.left=t)}})}togglePath(t){this.expandedPaths.has(t)?this.expandedPaths.delete(t):this.expandedPaths.add(t),this.requestUpdate()}isExpandable(t){if(null===t||"object"!=typeof t)return!1;if(Array.isArray(t))return t.length>0;return Object.keys(t).filter(t=>"__default__"!==t).length>0}renderContextValue(t){return null==t?"":"boolean"==typeof t||"number"==typeof t||"string"==typeof t?H`<span class="context-value">${t}</span>`:Array.isArray(t)?H`<span class="context-value">[${t.length}]</span>`:""}buildExpression(t){return`@${t}`}async handleCopyExpression(t,e){e.stopPropagation();const i=this.buildExpression(t);try{await navigator.clipboard.writeText(i),this.copiedExpression=i,setTimeout(()=>{this.copiedExpression=""},2e3)}catch(t){console.error("Failed to copy expression:",t)}}handleToggleShowAllKeys(){this.showAllKeys=!this.showAllKeys,this.toastMessage=this.showAllKeys?"Showing all keys":"Filtering out keys without values",setTimeout(()=>{this.toastMessage=""},2e3)}renderContextTree(t,e=""){if(!t||"object"!=typeof t)return H``;let i=Array.isArray(t)?t.map((t,e)=>[String(e),t]):Object.entries(t).filter(([t])=>"__default__"!==t);return this.showAllKeys||(i=i.filter(([,t])=>!!this.isExpandable(t)||null!=t&&("boolean"==typeof t||"number"==typeof t||"string"==typeof t||Array.isArray(t)))),H`${i.map(([t,i])=>{const o=e?`${e}.${t}`:t,n=this.expandedPaths.has(o),s=this.isExpandable(i);let r=i;return s&&!Array.isArray(i)&&null!==i&&"object"==typeof i&&"__default__"in i&&(r=i.__default__),H`
14873
14899
  <div>
14874
14900
  <div
@@ -15117,7 +15143,7 @@ const ak=(t,e)=>{const i=t._$AN;if(void 0===i)return!1;for(const t of i)t._$AO?.
15117
15143
  .active=${this.isVisible}
15118
15144
  @temba-button-clicked=${this.handleTabClick}
15119
15145
  ></temba-floating-tab>
15120
- `}}t([Ad(Sd,t=>t.flowDefinition)],Ik.prototype,"definition",void 0),t([Ad(Sd,t=>t.viewingRevision)],Ik.prototype,"viewingRevision",void 0),t([mt({type:String})],Ik.prototype,"flow",void 0),t([mt({type:String})],Ik.prototype,"endpoint",void 0),t([mt({type:Number})],Ik.prototype,"animationTime",void 0),t([ke("simulator","small",{validate:t=>t in zk})],Ik.prototype,"size",void 0),t([mt({type:Array})],Ik.prototype,"events",void 0),t([mt({type:Object})],Ik.prototype,"session",void 0),t([mt({type:Object})],Ik.prototype,"context",void 0),t([mt({type:Object})],Ik.prototype,"contact",void 0),t([mt({type:Boolean})],Ik.prototype,"sprinting",void 0),t([mt({type:String})],Ik.prototype,"inputValue",void 0),t([ke("simulator",!0)],Ik.prototype,"following",void 0),t([ke("simulator",!1)],Ik.prototype,"contextExplorerOpen",void 0),t([mt({type:Object})],Ik.prototype,"expandedPaths",void 0),t([mt({type:String})],Ik.prototype,"copiedExpression",void 0),t([mt({type:String})],Ik.prototype,"toastMessage",void 0),t([mt({type:Boolean})],Ik.prototype,"showAllKeys",void 0),t([mt({type:Array})],Ik.prototype,"currentQuickReplies",void 0),t([mt({type:Boolean})],Ik.prototype,"isVisible",void 0),t([mt({type:Boolean})],Ik.prototype,"attachmentMenuOpen",void 0),t([mt({type:Boolean})],Ik.prototype,"webhookDetailsOpen",void 0),t([mt({attribute:!1})],Ik.prototype,"webhookDetailsEvent",void 0);const Lk={yellow:{border:"#facc15",fill:"#fcd94d",text:"#713f12"},blue:{border:"#3b82f6",fill:"#6ca1f8",text:"#fff"},pink:{border:"#ec4899",fill:"#f17ab7",text:"#fff"},green:{border:"#10b981",fill:"#48ca9d",text:"#fff"},gray:{border:"#6b7280",fill:"#8f949f",text:"#fff"}};function Ok(t){var e,i,o,n,s,r,a,l,d,c,h;const u=[];switch(t.type){case"send_msg":{const i=t;i.text&&u.push(i.text),i.quick_replies&&u.push(...i.quick_replies),(null===(e=i.template)||void 0===e?void 0:e.name)&&u.push(i.template.name);break}case"send_email":{const e=t;e.subject&&u.push(e.subject),e.body&&u.push(e.body),e.addresses&&u.push(...e.addresses);break}case"send_broadcast":{const e=t;e.text&&u.push(e.text),e.groups&&u.push(...e.groups.map(t=>t.name)),e.contacts&&u.push(...e.contacts.map(t=>t.name)),(null===(i=e.template)||void 0===i?void 0:i.name)&&u.push(e.template.name);break}case"say_msg":{const e=t;e.text&&u.push(e.text);break}case"play_audio":{const e=t;e.audio_url&&u.push(e.audio_url);break}case"set_contact_name":{const e=t;e.name&&u.push(e.name);break}case"set_contact_field":{const e=t;(null===(o=e.field)||void 0===o?void 0:o.name)&&u.push(e.field.name),e.value&&u.push(e.value);break}case"set_contact_language":{const e=t;e.language&&u.push(e.language);break}case"set_contact_status":{const e=t;e.status&&u.push(e.status);break}case"set_contact_channel":{const e=t;(null===(n=e.channel)||void 0===n?void 0:n.name)&&u.push(e.channel.name);break}case"add_contact_urn":{const e=t;e.path&&u.push(e.path);break}case"add_contact_groups":{const e=t;e.groups&&u.push(...e.groups.map(t=>t.name));break}case"remove_contact_groups":{const e=t;e.groups&&u.push(...e.groups.map(t=>t.name));break}case"add_input_labels":{const e=t;e.labels&&u.push(...e.labels.map(t=>t.name));break}case"set_run_result":{const e=t;e.name&&u.push(e.name),e.value&&u.push(e.value),e.category&&u.push(e.category);break}case"enter_flow":{const e=t;(null===(s=e.flow)||void 0===s?void 0:s.name)&&u.push(e.flow.name);break}case"start_session":{const e=t;(null===(r=e.flow)||void 0===r?void 0:r.name)&&u.push(e.flow.name),e.groups&&u.push(...e.groups.map(t=>t.name)),e.contacts&&u.push(...e.contacts.map(t=>t.name));break}case"request_optin":{const e=t;(null===(a=e.optin)||void 0===a?void 0:a.name)&&u.push(e.optin.name);break}case"call_webhook":{const e=t;e.url&&u.push(e.url),e.body&&u.push(e.body);break}case"call_resthook":{const e=t;e.resthook&&u.push(e.resthook);break}case"call_llm":{const e=t;(null===(l=e.llm)||void 0===l?void 0:l.name)&&u.push(e.llm.name),e.instructions&&u.push(e.instructions),e.input&&u.push(e.input);break}case"call_classifier":{const e=t;(null===(d=e.classifier)||void 0===d?void 0:d.name)&&u.push(e.classifier.name),e.input&&u.push(e.input);break}case"open_ticket":{const e=t;(null===(c=e.topic)||void 0===c?void 0:c.name)&&u.push(e.topic.name),e.subject&&u.push(e.subject),e.body&&u.push(e.body),(null===(h=e.assignee)||void 0===h?void 0:h.name)&&u.push(e.assignee.name);break}}return u}function Pk(t){const e=[];return t.text&&e.push(t.text),t.quick_replies&&e.push(...t.quick_replies),e}function Rk(t,e,i){var o,n,s,r,a,l;const d=[];if((null===(o=t.router)||void 0===o?void 0:o.operand)&&d.push(t.router.operand),(null===(n=t.router)||void 0===n?void 0:n.result_name)&&d.push(t.router.result_name),null===(s=t.router)||void 0===s?void 0:s.categories)for(const e of t.router.categories)e.name&&"Other"!==e.name&&"All Responses"!==e.name&&d.push(Fk(e.uuid,e.name,i));if(null===(r=t.router)||void 0===r?void 0:r.cases)for(const e of t.router.cases)if(e.arguments)for(const t of e.arguments)t&&d.push(t);return(null===(l=null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.operand)||void 0===l?void 0:l.name)&&d.push(e.config.operand.name),d}function Nk(t,e){var i,o,n;return(null==t?void 0:t.group)?(null===(i=ju[t.group])||void 0===i?void 0:i.color)||"#aaaaaa":(null==e?void 0:e.group)&&((null===(o=ju[e.group])||void 0===o?void 0:o.color)||(null===(n=Wu[e.group])||void 0===n?void 0:n.color))||"#aaaaaa"}function Bk(t,e){return(null==t?void 0:t.name)?t.name:(null==e?void 0:e.name)?e.name:"Unknown"}function Fk(t,e,i){const o=null==i?void 0:i[t];return(null==o?void 0:o.name)&&Array.isArray(o.name)&&o.name[0]?o.name[0]:e}class qk extends dt{constructor(){super(...arguments),this.open=!1,this.definition=null,this.languageCode="",this.scope="flow",this.includeCategories=!1,this.searchQuery="",this.results=[],this.highlightedIndex=0}show(){this.open=!0,this.searchQuery="",this.results=[],this.highlightedIndex=0,this.updateComplete.then(()=>{var t,e;null===(t=this.inputEl)||void 0===t||t.focus(),null===(e=this.inputEl)||void 0===e||e.select()})}hide(){this.open=!1,this.searchQuery="",this.results=[]}handleInput(t){const e=t.target;this.searchQuery=e.value,this.performSearch(),this.highlightedIndex=0}handleKeyDown(t){return"Escape"===t.key?(t.preventDefault(),void this.hide()):"ArrowDown"===t.key||t.ctrlKey&&"n"===t.key?(t.preventDefault(),void(this.results.length>0&&(this.highlightedIndex=(this.highlightedIndex+1)%this.results.length))):"ArrowUp"===t.key||t.ctrlKey&&"p"===t.key?(t.preventDefault(),void(this.results.length>0&&(this.highlightedIndex=(this.highlightedIndex-1+this.results.length)%this.results.length))):"Enter"===t.key?(t.preventDefault(),void(this.results.length>0&&this.selectResult(this.results[this.highlightedIndex]))):void 0}handleBackdropClick(){this.hide()}selectResult(t){this.hide(),this.dispatchEvent(new CustomEvent("temba-search-result-selected",{detail:t,bubbles:!0,composed:!0}))}performSearch(){var t;if(!this.definition||!this.searchQuery.trim())return void(this.results=[]);const e=this.searchQuery.toLowerCase(),i=this.languageCode&&this.languageCode!==this.definition.language?null===(t=this.definition.localization)||void 0===t?void 0:t[this.languageCode]:void 0;"table"!==this.scope?this.results=this.performFlowSearch(e,i):this.results=this.performTableSearch(e,i)}performFlowSearch(t,e){var i,o;const n=[];for(const o of this.definition.nodes){const s=null===(i=this.definition._ui)||void 0===i?void 0:i.nodes[o.uuid],r=(null==s?void 0:s.type)||"execute_actions";if("execute_actions"===r){if(o.actions)for(const i of o.actions){const s=vm[i.type],r=Ok(Ou(i,null==e?void 0:e[i.uuid]));for(const e of r){const r=e.toLowerCase().indexOf(t);if(-1!==r){n.push({nodeUuid:o.uuid,action:i,typeName:Bk(s,void 0),color:Nk(s,void 0),fullText:e,matchStart:r,matchLength:t.length});break}}}}else{const i=ym[r],a=Rk(o,s,e);if(o.actions)for(const t of o.actions){const i=Ou(t,null==e?void 0:e[t.uuid]);a.push(...Ok(i))}for(const e of a){const s=e.toLowerCase().indexOf(t);if(-1!==s){n.push({nodeUuid:o.uuid,action:null,typeName:Bk(void 0,i),color:Nk(void 0,i),fullText:e,matchStart:s,matchLength:t.length});break}}}}const s=(null===(o=this.definition._ui)||void 0===o?void 0:o.stickies)||{};for(const[e,i]of Object.entries(s)){const o=[];i.title&&o.push({text:i.title,field:"title"}),i.body&&o.push({text:i.body,field:"body"});for(const{text:s,field:r}of o){const o=s.toLowerCase().indexOf(t);if(-1!==o){const a=Lk[i.color]||Lk.yellow;n.push({nodeUuid:e,action:null,typeName:"Sticky Note",color:a.fill,borderColor:a.border,textColor:a.text,fullText:s,matchStart:o,matchLength:t.length,stickyField:r});break}}}return n}performTableSearch(t,e){var i,o,n,s;const r=[];for(const a of this.definition.nodes){const l=null===(i=this.definition._ui)||void 0===i?void 0:i.nodes[a.uuid],d=(null==l?void 0:l.type)||"execute_actions";if(a.actions)for(const i of a.actions){if("send_msg"!==i.type)continue;const o=vm[i.type],n=Pk(Ou(i,null==e?void 0:e[i.uuid]));for(const e of n){const n=e.toLowerCase().indexOf(t);if(-1!==n){r.push({nodeUuid:a.uuid,action:i,typeName:Bk(o,void 0),color:Nk(o,void 0),fullText:e,matchStart:n,matchLength:t.length});break}}}if(this.includeCategories&&(null===(n=null===(o=a.router)||void 0===o?void 0:o.categories)||void 0===n?void 0:n.length)&&"categories"===(null===(s=ym[d])||void 0===s?void 0:s.localizable)){const i=$m(d,a.router.categories);if(!i.length)continue;const o=ym[d],n=i.map(t=>Fk(t.uuid,t.name,e));for(const e of n){const i=e.toLowerCase().indexOf(t);if(-1!==i){r.push({nodeUuid:a.uuid,action:null,typeName:Bk(void 0,o),color:Nk(void 0,o),fullText:e,matchStart:i,matchLength:t.length});break}}}}return r}renderMatchText(t){const{matchStart:e,matchLength:i}=t,o=e+i,n=t.fullText.replace(/\n/g," "),s=n.length-o<30?50:20,r=Math.max(0,e-s),a=r>0?"…":"",l=n.slice(r,e),d=n.slice(e,o),c=n.slice(o);return H`${a}${l}<mark>${d}</mark>${c}`}updated(t){var e;if(t.has("highlightedIndex")){const t=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(".result-item.highlighted");null==t||t.scrollIntoView({block:"nearest"})}}render(){const t="table"===this.scope?"Search this table":"Search this flow";return H`
15146
+ `}}t([Ad(Sd,t=>t.flowDefinition)],Ik.prototype,"definition",void 0),t([Ad(Sd,t=>t.viewingRevision)],Ik.prototype,"viewingRevision",void 0),t([mt({type:String})],Ik.prototype,"flow",void 0),t([mt({type:String})],Ik.prototype,"endpoint",void 0),t([mt({type:Number})],Ik.prototype,"animationTime",void 0),t([ke("simulator","small",{validate:t=>t in zk})],Ik.prototype,"size",void 0),t([mt({type:Array})],Ik.prototype,"events",void 0),t([mt({type:Object})],Ik.prototype,"session",void 0),t([mt({type:Object})],Ik.prototype,"context",void 0),t([mt({type:Object})],Ik.prototype,"contact",void 0),t([mt({type:Boolean})],Ik.prototype,"sprinting",void 0),t([mt({type:String})],Ik.prototype,"inputValue",void 0),t([ke("simulator",!0)],Ik.prototype,"following",void 0),t([ke("simulator",!1)],Ik.prototype,"contextExplorerOpen",void 0),t([mt({type:Object})],Ik.prototype,"expandedPaths",void 0),t([mt({type:String})],Ik.prototype,"copiedExpression",void 0),t([mt({type:String})],Ik.prototype,"toastMessage",void 0),t([mt({type:Boolean})],Ik.prototype,"showAllKeys",void 0),t([mt({type:Array})],Ik.prototype,"currentQuickReplies",void 0),t([mt({type:Boolean})],Ik.prototype,"isVisible",void 0),t([mt({type:Boolean})],Ik.prototype,"attachmentMenuOpen",void 0),t([mt({type:Boolean})],Ik.prototype,"webhookDetailsOpen",void 0),t([mt({attribute:!1})],Ik.prototype,"webhookDetailsEvent",void 0);const Lk={yellow:{border:"#facc15",fill:"#fcd94d",text:"#713f12"},blue:{border:"#3b82f6",fill:"#6ca1f8",text:"#fff"},pink:{border:"#ec4899",fill:"#f17ab7",text:"#fff"},green:{border:"#10b981",fill:"#48ca9d",text:"#fff"},gray:{border:"#6b7280",fill:"#8f949f",text:"#fff"}};function Ok(t){var e,i,o,n,s,r,a,l,d,c,h;const u=[];switch(t.type){case"send_msg":{const i=t;i.text&&u.push(i.text),i.quick_replies&&u.push(...i.quick_replies),(null===(e=i.template)||void 0===e?void 0:e.name)&&u.push(i.template.name);break}case"send_email":{const e=t;e.subject&&u.push(e.subject),e.body&&u.push(e.body),e.addresses&&u.push(...e.addresses);break}case"send_broadcast":{const e=t;e.text&&u.push(e.text),e.groups&&u.push(...e.groups.map(t=>t.name)),e.contacts&&u.push(...e.contacts.map(t=>t.name)),(null===(i=e.template)||void 0===i?void 0:i.name)&&u.push(e.template.name);break}case"say_msg":{const e=t;e.text&&u.push(e.text);break}case"play_audio":{const e=t;e.audio_url&&u.push(e.audio_url);break}case"set_contact_name":{const e=t;e.name&&u.push(e.name);break}case"set_contact_field":{const e=t;(null===(o=e.field)||void 0===o?void 0:o.name)&&u.push(e.field.name),e.value&&u.push(e.value);break}case"set_contact_language":{const e=t;e.language&&u.push(e.language);break}case"set_contact_status":{const e=t;e.status&&u.push(e.status);break}case"set_contact_channel":{const e=t;(null===(n=e.channel)||void 0===n?void 0:n.name)&&u.push(e.channel.name);break}case"add_contact_urn":{const e=t;e.path&&u.push(e.path);break}case"add_contact_groups":{const e=t;e.groups&&u.push(...e.groups.map(t=>t.name));break}case"remove_contact_groups":{const e=t;e.groups&&u.push(...e.groups.map(t=>t.name));break}case"add_input_labels":{const e=t;e.labels&&u.push(...e.labels.map(t=>t.name));break}case"set_run_result":{const e=t;e.name&&u.push(e.name),e.value&&u.push(e.value),e.category&&u.push(e.category);break}case"enter_flow":{const e=t;(null===(s=e.flow)||void 0===s?void 0:s.name)&&u.push(e.flow.name);break}case"start_session":{const e=t;(null===(r=e.flow)||void 0===r?void 0:r.name)&&u.push(e.flow.name),e.groups&&u.push(...e.groups.map(t=>t.name)),e.contacts&&u.push(...e.contacts.map(t=>t.name));break}case"request_optin":{const e=t;(null===(a=e.optin)||void 0===a?void 0:a.name)&&u.push(e.optin.name);break}case"call_webhook":{const e=t;e.url&&u.push(e.url),e.body&&u.push(e.body);break}case"call_resthook":{const e=t;e.resthook&&u.push(e.resthook);break}case"call_llm":{const e=t;(null===(l=e.llm)||void 0===l?void 0:l.name)&&u.push(e.llm.name),e.instructions&&u.push(e.instructions),e.input&&u.push(e.input);break}case"call_classifier":{const e=t;(null===(d=e.classifier)||void 0===d?void 0:d.name)&&u.push(e.classifier.name),e.input&&u.push(e.input);break}case"open_ticket":{const e=t;(null===(c=e.topic)||void 0===c?void 0:c.name)&&u.push(e.topic.name),e.subject&&u.push(e.subject),e.body&&u.push(e.body),(null===(h=e.assignee)||void 0===h?void 0:h.name)&&u.push(e.assignee.name);break}}return u}function Pk(t){const e=[],i=vm[t.type];if(!(null==i?void 0:i.localizable))return e;const o=t;for(const t of i.localizable){const i=o[t];if("string"==typeof i&&i.trim())e.push(i);else if(Array.isArray(i))for(const t of i)"string"==typeof t&&t.trim()&&e.push(t)}return e}function Rk(t,e,i){var o,n,s,r,a,l;const d=[];if((null===(o=t.router)||void 0===o?void 0:o.operand)&&d.push(t.router.operand),(null===(n=t.router)||void 0===n?void 0:n.result_name)&&d.push(t.router.result_name),null===(s=t.router)||void 0===s?void 0:s.categories)for(const e of t.router.categories)e.name&&"Other"!==e.name&&"All Responses"!==e.name&&d.push(Fk(e.uuid,e.name,i));if(null===(r=t.router)||void 0===r?void 0:r.cases)for(const e of t.router.cases)if(e.arguments)for(const t of e.arguments)t&&d.push(t);return(null===(l=null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.operand)||void 0===l?void 0:l.name)&&d.push(e.config.operand.name),d}function Nk(t,e){var i,o,n;return(null==t?void 0:t.group)?(null===(i=ju[t.group])||void 0===i?void 0:i.color)||"#aaaaaa":(null==e?void 0:e.group)&&((null===(o=ju[e.group])||void 0===o?void 0:o.color)||(null===(n=Wu[e.group])||void 0===n?void 0:n.color))||"#aaaaaa"}function Bk(t,e){return(null==t?void 0:t.name)?t.name:(null==e?void 0:e.name)?e.name:"Unknown"}function Fk(t,e,i){const o=null==i?void 0:i[t];return(null==o?void 0:o.name)&&Array.isArray(o.name)&&o.name[0]?o.name[0]:e}class qk extends dt{constructor(){super(...arguments),this.open=!1,this.definition=null,this.languageCode="",this.scope="flow",this.includeCategories=!1,this.searchQuery="",this.results=[],this.highlightedIndex=0}show(){this.open=!0,this.searchQuery="",this.results=[],this.highlightedIndex=0,this.updateComplete.then(()=>{var t,e;null===(t=this.inputEl)||void 0===t||t.focus(),null===(e=this.inputEl)||void 0===e||e.select()})}hide(){this.open=!1,this.searchQuery="",this.results=[]}handleInput(t){const e=t.target;this.searchQuery=e.value,this.performSearch(),this.highlightedIndex=0}handleKeyDown(t){return"Escape"===t.key?(t.preventDefault(),void this.hide()):"ArrowDown"===t.key||t.ctrlKey&&"n"===t.key?(t.preventDefault(),void(this.results.length>0&&(this.highlightedIndex=(this.highlightedIndex+1)%this.results.length))):"ArrowUp"===t.key||t.ctrlKey&&"p"===t.key?(t.preventDefault(),void(this.results.length>0&&(this.highlightedIndex=(this.highlightedIndex-1+this.results.length)%this.results.length))):"Enter"===t.key?(t.preventDefault(),void(this.results.length>0&&this.selectResult(this.results[this.highlightedIndex]))):void 0}handleBackdropClick(){this.hide()}selectResult(t){this.hide(),this.dispatchEvent(new CustomEvent("temba-search-result-selected",{detail:t,bubbles:!0,composed:!0}))}performSearch(){var t;if(!this.definition||!this.searchQuery.trim())return void(this.results=[]);const e=this.searchQuery.toLowerCase(),i=this.languageCode&&this.languageCode!==this.definition.language?null===(t=this.definition.localization)||void 0===t?void 0:t[this.languageCode]:void 0;"table"!==this.scope?this.results=this.performFlowSearch(e,i):this.results=this.performTableSearch(e,i)}performFlowSearch(t,e){var i,o;const n=[];for(const o of this.definition.nodes){const s=null===(i=this.definition._ui)||void 0===i?void 0:i.nodes[o.uuid],r=(null==s?void 0:s.type)||"execute_actions";if("execute_actions"===r){if(o.actions)for(const i of o.actions){const s=vm[i.type],r=Ok(Ou(i,null==e?void 0:e[i.uuid]));for(const e of r){const r=e.toLowerCase().indexOf(t);if(-1!==r){n.push({nodeUuid:o.uuid,action:i,typeName:Bk(s,void 0),color:Nk(s,void 0),fullText:e,matchStart:r,matchLength:t.length});break}}}}else{const i=ym[r],a=Rk(o,s,e);if(o.actions)for(const t of o.actions){const i=Ou(t,null==e?void 0:e[t.uuid]);a.push(...Ok(i))}for(const e of a){const s=e.toLowerCase().indexOf(t);if(-1!==s){n.push({nodeUuid:o.uuid,action:null,typeName:Bk(void 0,i),color:Nk(void 0,i),fullText:e,matchStart:s,matchLength:t.length});break}}}}const s=(null===(o=this.definition._ui)||void 0===o?void 0:o.stickies)||{};for(const[e,i]of Object.entries(s)){const o=[];i.title&&o.push({text:i.title,field:"title"}),i.body&&o.push({text:i.body,field:"body"});for(const{text:s,field:r}of o){const o=s.toLowerCase().indexOf(t);if(-1!==o){const a=Lk[i.color]||Lk.yellow;n.push({nodeUuid:e,action:null,typeName:"Sticky Note",color:a.fill,borderColor:a.border,textColor:a.text,fullText:s,matchStart:o,matchLength:t.length,stickyField:r});break}}}return n}performTableSearch(t,e){var i,o,n,s;const r=[];for(const a of this.definition.nodes){const l=null===(i=this.definition._ui)||void 0===i?void 0:i.nodes[a.uuid],d=(null==l?void 0:l.type)||"execute_actions";if(a.actions)for(const i of a.actions){const o=vm[i.type];if("send_msg"!==i.type&&(!(null==o?void 0:o.localizable)||0===o.localizable.length))continue;const n=Pk(i),s=Pk(Ou(i,null==e?void 0:e[i.uuid])),l=[],d=new Set;for(const t of[...n,...s])d.has(t)||(d.add(t),l.push(t));let c=!1;for(const e of l){const n=e.toLowerCase().indexOf(t);if(-1!==n){r.push({nodeUuid:a.uuid,action:i,typeName:Bk(o,void 0),color:Nk(o,void 0),fullText:e,matchStart:n,matchLength:t.length}),c=!0;break}}}if(this.includeCategories&&(null===(n=null===(o=a.router)||void 0===o?void 0:o.categories)||void 0===n?void 0:n.length)&&"categories"===(null===(s=ym[d])||void 0===s?void 0:s.localizable)){const i=$m(d,a.router.categories);if(!i.length)continue;const o=ym[d],n=i.map(t=>Fk(t.uuid,t.name,e));for(const e of n){const i=e.toLowerCase().indexOf(t);if(-1!==i){r.push({nodeUuid:a.uuid,action:null,typeName:Bk(void 0,o),color:Nk(void 0,o),fullText:e,matchStart:i,matchLength:t.length});break}}}}return r}renderMatchText(t){const{matchStart:e,matchLength:i}=t,o=e+i,n=t.fullText.replace(/\n/g," "),s=n.length-o<30?50:20,r=Math.max(0,e-s),a=r>0?"…":"",l=n.slice(r,e),d=n.slice(e,o),c=n.slice(o);return H`${a}${l}<mark>${d}</mark>${c}`}updated(t){var e;if(t.has("highlightedIndex")){const t=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(".result-item.highlighted");null==t||t.scrollIntoView({block:"nearest"})}}render(){const t="table"===this.scope?"Search this table":"Search this flow";return H`
15121
15147
  <div class="backdrop" @click=${this.handleBackdropClick}></div>
15122
15148
  <div
15123
15149
  class="search-container"
@@ -15377,6 +15403,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15377
15403
  padding: 12px 16px;
15378
15404
  border-bottom: 1px solid #f0f0f0;
15379
15405
  vertical-align: top;
15406
+ position: relative;
15380
15407
  }
15381
15408
 
15382
15409
  .message-table td.translation-td {
@@ -15456,12 +15483,27 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15456
15483
  flex: 1;
15457
15484
  }
15458
15485
 
15486
+ .message-table td.rail-td {
15487
+ padding: 8px 8px 8px 20px;
15488
+ height: 1px;
15489
+ }
15490
+
15491
+ .message-table td.rail-td::before {
15492
+ content: '';
15493
+ position: absolute;
15494
+ left: 10px;
15495
+ top: 8px;
15496
+ bottom: 8px;
15497
+ width: 4px;
15498
+ background: var(--node-rail-color, #d1d5db);
15499
+ }
15500
+
15459
15501
  .message-cell {
15460
15502
  cursor: pointer;
15461
- position: relative;
15462
- border-radius: 0 6px 6px 0;
15463
- padding: 10px 12px 10px 16px;
15464
- margin: -4px -6px;
15503
+ border-radius: 6px;
15504
+ padding: 12px 12px;
15505
+ min-height: 100%;
15506
+ box-sizing: border-box;
15465
15507
  transition: background 0.15s;
15466
15508
  word-wrap: break-word;
15467
15509
  line-height: 1.5;
@@ -15469,16 +15511,6 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15469
15511
  color: #333;
15470
15512
  }
15471
15513
 
15472
- .message-cell::before {
15473
- content: '';
15474
- position: absolute;
15475
- left: 0;
15476
- top: 0;
15477
- bottom: 0;
15478
- width: 4px;
15479
- background: var(--node-rail-color, #d1d5db);
15480
- }
15481
-
15482
15514
  .message-cell:hover {
15483
15515
  background: #f5f8ff;
15484
15516
  }
@@ -15625,6 +15657,33 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15625
15657
  background: #fff;
15626
15658
  }
15627
15659
 
15660
+ .attachments {
15661
+ display: flex;
15662
+ flex-wrap: wrap;
15663
+ gap: 4px;
15664
+ margin-top: 0.5em;
15665
+ }
15666
+
15667
+ .attachments.standalone {
15668
+ margin-top: 0;
15669
+ }
15670
+
15671
+ .attachment-icon {
15672
+ display: inline-flex;
15673
+ align-items: center;
15674
+ justify-content: center;
15675
+ width: 32px;
15676
+ height: 32px;
15677
+ border: 1px solid #d1d5db;
15678
+ border-radius: 6px;
15679
+ background: #fafafa;
15680
+ }
15681
+
15682
+ .attachment-icon temba-icon {
15683
+ --icon-size: 18px;
15684
+ --icon-color: #888;
15685
+ }
15686
+
15628
15687
  .empty-state {
15629
15688
  display: flex;
15630
15689
  align-items: center;
@@ -15635,7 +15694,46 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15635
15694
  padding: 60px 20px;
15636
15695
  text-align: center;
15637
15696
  }
15638
- `}getEntries(){var t,e,i,o,n,s,r,a,l,d,c,h,u;if(!(null===(t=this.definition)||void 0===t?void 0:t.nodes))return[];const p=[];let m=0;for(const t of this.definition.nodes){m++;for(const e of t.actions||[])"send_msg"===e.type&&p.push({kind:"message",node:t,action:e,nodeIndex:m});if(!this.isTranslating)continue;const g=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.nodes)||void 0===o?void 0:o[t.uuid],f=null==g?void 0:g.type,v=(null===(s=null===(n=this.definition)||void 0===n?void 0:n.localization)||void 0===s?void 0:s[this.languageCode])||{};let b=[];if(null===(a=null===(r=t.router)||void 0===r?void 0:r.cases)||void 0===a?void 0:a.length){const e=null===(l=null==g?void 0:g.config)||void 0===l?void 0:l.localizeRules;b=t.router.cases.filter(t=>{var e;return(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&t.arguments.some(t=>t)}).filter(t=>{var i,o;return e||(null===(o=null===(i=v[t.uuid])||void 0===i?void 0:i.arguments)||void 0===o?void 0:o.some(t=>t))}).map(t=>({uuid:t.uuid,type:t.type,arguments:[...t.arguments]}))}let y=[];if(f&&"categories"===(null===(d=ym[f])||void 0===d?void 0:d.localizable)&&(null===(h=null===(c=t.router)||void 0===c?void 0:c.categories)||void 0===h?void 0:h.length)){const e=null===(u=null==g?void 0:g.config)||void 0===u?void 0:u.localizeCategories,i=$m(f,t.router.categories);y=e?i:i.filter(t=>{var e,i;return null===(i=null===(e=v[t.uuid])||void 0===e?void 0:e.name)||void 0===i?void 0:i.some(t=>t)})}(b.length>0||y.length>0)&&p.push({kind:"localization-group",node:t,rules:b,categories:y,nodeIndex:m})}return p}focusSearchResult(t,e){const i=Array.from(this.renderRoot.querySelectorAll("tr[data-node-uuid]"));if(!i.length)return;let o=e?i.find(i=>i.dataset.nodeUuid===t&&i.dataset.actionUuid===e):i.find(e=>e.dataset.nodeUuid===t&&"category-group"===e.dataset.entryKind);o||(o=i.find(e=>e.dataset.nodeUuid===t)),null==o||o.scrollIntoView({behavior:"smooth",block:"center"})}getTranslatedText(t){var e,i,o;if(!this.isTranslating||!this.languageCode)return null;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[t];return(null==n?void 0:n.text)&&Array.isArray(n.text)&&n.text[0]||null}getTranslatedQuickReplies(t){var e,i,o;if(!this.isTranslating||!this.languageCode)return[];const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[t];return Array.isArray(null==n?void 0:n.quick_replies)?n.quick_replies.map(t=>"string"==typeof t?t.trim():"").filter(t=>t.length>0):[]}stripLeadingLineBreaks(t){return t.replace(/^(?:\r?\n)+/,"")}getTranslatedCategoryName(t){var e,i,o;if(!this.isTranslating||!this.languageCode)return null;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[t];return(null==n?void 0:n.name)?Array.isArray(n.name)?n.name[0]||null:"string"==typeof n.name?n.name:null:null}handleBaseTextClick(t){this.fireCustomEvent(Io.ActionEditRequested,{action:t.action,nodeUuid:t.node.uuid,forceBase:!0})}handleTranslationClick(t){this.fireCustomEvent(Io.ActionEditRequested,{action:t.action,nodeUuid:t.node.uuid})}handleBaseGroupClick(t){var e,i,o;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.nodes)||void 0===o?void 0:o[t.node.uuid];n&&this.fireCustomEvent(Io.NodeEditRequested,{node:t.node,nodeUI:n,forceBase:!0})}handleGroupTranslationClick(t){var e,i,o;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.nodes)||void 0===o?void 0:o[t.node.uuid];n&&this.fireCustomEvent(Io.NodeEditRequested,{node:t.node,nodeUI:n})}getGroupTranslations(t){const e=t.rules.map(t=>{var e,i,o,n;const s=t.arguments.join(", "),r=(null===(e=wp(t.type))||void 0===e?void 0:e.name)||t.type,a=null===(n=null===(o=null===(i=this.definition)||void 0===i?void 0:i.localization)||void 0===o?void 0:o[this.languageCode])||void 0===n?void 0:n[t.uuid];return{original:s,translated:Array.isArray(null==a?void 0:a.arguments)?a.arguments.join(", "):null,isRule:!0,operatorName:r}});return[...e,...t.categories.map(t=>({original:t.name,translated:this.getTranslatedCategoryName(t.uuid),isRule:!1}))]}getEntryRailColor(t){var e,i,o,n,s,r,a;if("message"===t.kind){const i=vm[t.action.type],o=null==i?void 0:i.group;return o&&(null===(e=ju[o])||void 0===e?void 0:e.color)||"#cbd5e1"}const l=null===(s=null===(n=null===(o=null===(i=this.definition)||void 0===i?void 0:i._ui)||void 0===o?void 0:o.nodes)||void 0===n?void 0:n[t.node.uuid])||void 0===s?void 0:s.type;if(!l)return"#cbd5e1";const d=ym[l],c=null==d?void 0:d.group;return c&&((null===(r=ju[c])||void 0===r?void 0:r.color)||(null===(a=Wu[c])||void 0===a?void 0:a.color))||"#cbd5e1"}render(){const t=this.getEntries();if(0===t.length)return H`<div class="empty-state">
15697
+ `}getEntries(){var t,e,i,o,n,s,r,a,l,d,c,h,u;if(!(null===(t=this.definition)||void 0===t?void 0:t.nodes))return[];const p=[];let m=0;for(const t of this.definition.nodes){m++;for(const e of t.actions||[]){const i=vm[e.type];("send_msg"===e.type||(null==i?void 0:i.localizable)&&i.localizable.length>0)&&p.push({kind:"message",node:t,action:e,nodeIndex:m})}if(!this.isTranslating)continue;const g=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.nodes)||void 0===o?void 0:o[t.uuid],f=null==g?void 0:g.type,v=(null===(s=null===(n=this.definition)||void 0===n?void 0:n.localization)||void 0===s?void 0:s[this.languageCode])||{};let b=[];if(null===(a=null===(r=t.router)||void 0===r?void 0:r.cases)||void 0===a?void 0:a.length){const e=null===(l=null==g?void 0:g.config)||void 0===l?void 0:l.localizeRules;b=t.router.cases.filter(t=>{var e;return(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&t.arguments.some(t=>t)}).filter(t=>{var i,o;return e||(null===(o=null===(i=v[t.uuid])||void 0===i?void 0:i.arguments)||void 0===o?void 0:o.some(t=>t))}).map(t=>({uuid:t.uuid,type:t.type,arguments:[...t.arguments]}))}let y=[];if(f&&"categories"===(null===(d=ym[f])||void 0===d?void 0:d.localizable)&&(null===(h=null===(c=t.router)||void 0===c?void 0:c.categories)||void 0===h?void 0:h.length)){const e=null===(u=null==g?void 0:g.config)||void 0===u?void 0:u.localizeCategories,i=$m(f,t.router.categories);y=e?i:i.filter(t=>{var e,i;return null===(i=null===(e=v[t.uuid])||void 0===e?void 0:e.name)||void 0===i?void 0:i.some(t=>t)})}(b.length>0||y.length>0)&&p.push({kind:"localization-group",node:t,rules:b,categories:y,nodeIndex:m})}return p}focusSearchResult(t,e){const i=Array.from(this.renderRoot.querySelectorAll("tr[data-node-uuid]"));if(!i.length)return;let o=e?i.find(i=>i.dataset.nodeUuid===t&&i.dataset.actionUuid===e):i.find(e=>e.dataset.nodeUuid===t&&"category-group"===e.dataset.entryKind);o||(o=i.find(e=>e.dataset.nodeUuid===t)),null==o||o.scrollIntoView({behavior:"smooth",block:"center"})}getTranslatedText(t){var e,i,o;if(!this.isTranslating||!this.languageCode)return null;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[t];return(null==n?void 0:n.text)&&Array.isArray(n.text)&&n.text[0]||null}getTranslatedQuickReplies(t){var e,i,o;if(!this.isTranslating||!this.languageCode)return[];const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[t];return Array.isArray(null==n?void 0:n.quick_replies)?n.quick_replies.map(t=>"string"==typeof t?t.trim():"").filter(t=>t.length>0):[]}stripLeadingLineBreaks(t){return t.replace(/^(?:\r?\n)+/,"")}getTranslatedCategoryName(t){var e,i,o;if(!this.isTranslating||!this.languageCode)return null;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[t];return(null==n?void 0:n.name)?Array.isArray(n.name)?n.name[0]||null:"string"==typeof n.name?n.name:null:null}getTranslatedField(t,e){var i,o,n;if(!this.isTranslating||!this.languageCode)return null;const s=null===(n=null===(o=null===(i=this.definition)||void 0===i?void 0:i.localization)||void 0===o?void 0:o[this.languageCode])||void 0===n?void 0:n[t];return(null==s?void 0:s[e])&&Array.isArray(s[e])&&s[e][0]||null}getTranslatedArrayField(t,e){var i,o,n;if(!this.isTranslating||!this.languageCode)return[];const s=null===(n=null===(o=null===(i=this.definition)||void 0===i?void 0:i.localization)||void 0===o?void 0:o[this.languageCode])||void 0===n?void 0:n[t];return Array.isArray(null==s?void 0:s[e])?s[e]:[]}hasAnyTranslation(t){var e,i,o;const n=vm[t.action.type];if(!(null==n?void 0:n.localizable))return!1;const s=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[t.action.uuid];return!!s&&n.localizable.some(t=>{const e=s[t];return!!Array.isArray(e)&&e.some(t=>"string"==typeof t&&t.trim())})}usesPairedRows(t){const e=vm[t.type];if(!(null==e?void 0:e.localizable))return!1;return e.localizable.filter(t=>{var i;const o=null===(i=e.form)||void 0===i?void 0:i[t];return o&&("text"===o.type||"textarea"===o.type)}).length>1}getPairedFields(t){const e=vm[t.type];return(null==e?void 0:e.localizable)&&e.form?e.localizable.filter(t=>{var i;const o=null===(i=e.form)||void 0===i?void 0:i[t];return o&&("text"===o.type||"textarea"===o.type)}).map(i=>{const o=e.form[i];return{key:i,label:"string"==typeof o.label?o.label:i,original:t[i]||"",translated:this.getTranslatedField(t.uuid,i)}}):[]}renderAttachments(t){return t&&0!==t.length?H`<div class="attachments">
15698
+ ${t.map(t=>{const e=t.indexOf(":");if(e<0)return H``;const i=t.substring(0,e).split("/")[0],o=Uk.ATTACHMENT_ICONS[i]||ko.attachment;return H`<div class="attachment-icon">
15699
+ <temba-icon name="${o}"></temba-icon>
15700
+ </div>`})}
15701
+ </div>`:H``}renderOriginalContent(t){const e=t.action,i=vm[e.type],o=(null==i?void 0:i.localizable)||[],n=[];if(null==i?void 0:i.form)for(const t of o){const o=i.form[t];if(o&&("text"===o.type||"textarea"===o.type||"message-editor"===o.type)){const i=e[t]||"";i&&n.push(xu(this.stripLeadingLineBreaks(i),!0))}}const s=e.quick_replies||[];s.length>0&&n.push(H`<div class="quick-replies ${0===n.length?"standalone":""}">${s.map(t=>H`<div class="quick-reply">${t}</div>`)}</div>`);const r=e.attachments||[];return r.length>0&&n.push(this.renderAttachments(r)),0===n.length?H`<span style="color: #bbb; font-style: italic;">Empty</span>`:H`${n}`}renderTranslatedContent(t){const e=t.action,i=vm[e.type],o=(null==i?void 0:i.localizable)||[],n=[];if(null==i?void 0:i.form)for(const t of o){const o=i.form[t];if(o&&("text"===o.type||"textarea"===o.type||"message-editor"===o.type)){const i=this.getTranslatedField(e.uuid,t);"string"==typeof i&&n.push(xu(this.stripLeadingLineBreaks(i),!0))}}const s=this.getTranslatedQuickReplies(e.uuid);s.length>0&&n.push(H`<div class="quick-replies ${0===n.length?"standalone":""}">${s.map(t=>H`<div class="quick-reply">${t}</div>`)}</div>`);const r=this.getTranslatedArrayField(e.uuid,"attachments");return r.length>0&&n.push(this.renderAttachments(r)),0===n.length?H`No translation`:H`${n}`}handleBaseTextClick(t){this.fireCustomEvent(Io.ActionEditRequested,{action:t.action,nodeUuid:t.node.uuid,forceBase:!0})}handleTranslationClick(t){this.fireCustomEvent(Io.ActionEditRequested,{action:t.action,nodeUuid:t.node.uuid})}handleBaseGroupClick(t){var e,i,o;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.nodes)||void 0===o?void 0:o[t.node.uuid];n&&this.fireCustomEvent(Io.NodeEditRequested,{node:t.node,nodeUI:n,forceBase:!0})}handleGroupTranslationClick(t){var e,i,o;const n=null===(o=null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.nodes)||void 0===o?void 0:o[t.node.uuid];n&&this.fireCustomEvent(Io.NodeEditRequested,{node:t.node,nodeUI:n})}getGroupTranslations(t){const e=t.rules.map(t=>{var e,i,o,n;const s=t.arguments.join(", "),r=(null===(e=wp(t.type))||void 0===e?void 0:e.name)||t.type,a=null===(n=null===(o=null===(i=this.definition)||void 0===i?void 0:i.localization)||void 0===o?void 0:o[this.languageCode])||void 0===n?void 0:n[t.uuid];return{original:s,translated:Array.isArray(null==a?void 0:a.arguments)?a.arguments.join(", "):null,isRule:!0,operatorName:r}});return[...e,...t.categories.map(t=>({original:t.name,translated:this.getTranslatedCategoryName(t.uuid),isRule:!1}))]}getEntryRailColor(t){var e,i,o,n,s,r,a;if("message"===t.kind){const i=vm[t.action.type],o=null==i?void 0:i.group;return o&&(null===(e=ju[o])||void 0===e?void 0:e.color)||"#cbd5e1"}const l=null===(s=null===(n=null===(o=null===(i=this.definition)||void 0===i?void 0:i._ui)||void 0===o?void 0:o.nodes)||void 0===n?void 0:n[t.node.uuid])||void 0===s?void 0:s.type;if(!l)return"#cbd5e1";const d=ym[l],c=null==d?void 0:d.group;return c&&((null===(r=ju[c])||void 0===r?void 0:r.color)||(null===(a=Wu[c])||void 0===a?void 0:a.color))||"#cbd5e1"}renderPairedRows(t,e,i,o,n){return H`
15702
+ ${t.map((s,r)=>H`
15703
+ <tr
15704
+ class="category-row localization-paired-row ${0===r?"localization-paired-first":""} ${r===t.length-1?"localization-paired-last":""}"
15705
+ style=${`--node-rail-color: ${this.getEntryRailColor(e)};`}
15706
+ data-node-uuid=${e.node.uuid}
15707
+ data-entry-kind=${e.kind}
15708
+ data-action-uuid=${"message"===e.kind?e.action.uuid:""}
15709
+ >
15710
+ <td>
15711
+ <div
15712
+ class="message-cell category-message-cell"
15713
+ @click=${i}
15714
+ title="Click to edit"
15715
+ >
15716
+ <div class="category-item category-original-item">
15717
+ <span>${s.original}</span>
15718
+ </div>
15719
+ </div>
15720
+ </td>
15721
+ ${n?H`<td class="translation-td">
15722
+ <div
15723
+ class="translation-cell category-translation-cell"
15724
+ @click=${o}
15725
+ title="Click to edit translation"
15726
+ >
15727
+ <div
15728
+ class="category-item category-translation-item ${null!==s.translated?"":"missing"}"
15729
+ >
15730
+ <span>${null!==s.translated?s.translated:"No translation"}</span>
15731
+ </div>
15732
+ </div>
15733
+ </td>`:""}
15734
+ </tr>
15735
+ `)}
15736
+ `}render(){const t=this.getEntries();if(0===t.length)return H`<div class="empty-state">
15639
15737
  No messages or localizable content in this flow.
15640
15738
  </div>`;const e=this.isTranslating;return H`
15641
15739
  <table class="message-table">
@@ -15646,54 +15744,20 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15646
15744
  </tr>
15647
15745
  </thead>
15648
15746
  <tbody>
15649
- ${t.map(t=>{const i="localization-group"===t.kind,o=e&&"message"===t.kind?this.getTranslatedText(t.action.uuid):null,n=e&&"message"===t.kind?this.getTranslatedQuickReplies(t.action.uuid):[],s=e&&i?this.getGroupTranslations(t):null,r=Array.isArray(s)&&s.some(t=>!!t.translated),a="message"===t.kind&&(!!o||n.length>0),l="message"===t.kind?a:r,d=i?"translation-cell category-translation-cell":"translation-cell "+(l?"has-translation":"missing-translation"),c=()=>{"message"===t.kind?this.handleBaseTextClick(t):i&&this.handleBaseGroupClick(t)},h=()=>{"message"===t.kind?this.handleTranslationClick(t):i&&this.handleGroupTranslationClick(t)};return i&&e?H`
15650
- ${s.map((e,i)=>H`
15651
- <tr
15652
- class="category-row localization-paired-row ${0===i?"localization-paired-first":""} ${i===s.length-1?"localization-paired-last":""}"
15653
- style=${`--node-rail-color: ${this.getEntryRailColor(t)};`}
15654
- data-node-uuid=${t.node.uuid}
15655
- data-entry-kind=${t.kind}
15656
- >
15657
- <td>
15658
- <div
15659
- class="message-cell category-message-cell"
15660
- @click=${c}
15661
- title="Click to edit"
15662
- >
15663
- <div class="category-item category-original-item">
15664
- <span>${e.isRule&&e.operatorName?H`<span class="rule-operator">${e.operatorName}</span> `:""}${xu(e.original,!0)}</span>
15665
- </div>
15666
- </div>
15667
- </td>
15668
- <td class="translation-td">
15669
- <div
15670
- class="translation-cell category-translation-cell"
15671
- @click=${h}
15672
- title="Click to edit translation"
15673
- >
15674
- <div
15675
- class="category-item category-translation-item ${e.translated?"":"missing"}"
15676
- >
15677
- <span>${e.isRule&&e.operatorName?H`<span class="rule-operator">${e.operatorName}</span> `:""}${e.translated?xu(e.translated,!0):"No translation"}</span>
15678
- </div>
15679
- </div>
15680
- </td>
15681
- </tr>
15682
- `)}
15683
- `:H`
15747
+ ${t.map(t=>{const i="localization-group"===t.kind,o=()=>{"message"===t.kind?this.handleBaseTextClick(t):i&&this.handleBaseGroupClick(t)},n=()=>{"message"===t.kind?this.handleTranslationClick(t):i&&this.handleGroupTranslationClick(t)};if(i&&e){const i=this.getGroupTranslations(t).map(t=>({original:H`${t.isRule&&t.operatorName?H`<span class="rule-operator">${t.operatorName}</span> `:""}${xu(t.original,!0)}`,translated:null!==t.translated?H`${t.isRule&&t.operatorName?H`<span class="rule-operator">${t.operatorName}</span> `:""}${xu(t.translated,!0)}`:null}));return this.renderPairedRows(i,t,o,n,e)}if("message"===t.kind&&this.usesPairedRows(t.action)){const i=this.getPairedFields(t.action).map(t=>({original:H`${t.original?xu(this.stripLeadingLineBreaks(t.original),!0):H`<span style="color: #bbb; font-style: italic;">Empty</span>`}`,translated:null!==t.translated?H`${xu(this.stripLeadingLineBreaks(t.translated),!0)}`:null}));return this.renderPairedRows(i,t,o,n,e)}const s="translation-cell "+("message"===t.kind&&e&&this.hasAnyTranslation(t)?"has-translation":"missing-translation");return H`
15684
15748
  <tr
15685
15749
  style=${`--node-rail-color: ${this.getEntryRailColor(t)};`}
15686
15750
  data-node-uuid=${t.node.uuid}
15687
15751
  data-entry-kind=${t.kind}
15688
15752
  data-action-uuid=${"message"===t.kind?t.action.uuid:""}
15689
15753
  >
15690
- <td>
15754
+ <td class="rail-td">
15691
15755
  <div
15692
15756
  class="message-cell"
15693
- @click=${c}
15694
- title="Click to edit message"
15757
+ @click=${o}
15758
+ title="Click to edit"
15695
15759
  >
15696
- ${"message"===t.kind?H`${xu(this.stripLeadingLineBreaks(t.action.text||""),!0)}${(t.action.quick_replies||[]).length>0?H`<div class="quick-replies">${(t.action.quick_replies||[]).map(t=>H`<div class="quick-reply">${t}</div>`)}</div>`:""}`:i?H`
15760
+ ${"message"===t.kind?this.renderOriginalContent(t):i?H`
15697
15761
  <div class="category-stack category-stack-original">
15698
15762
  ${t.rules.map(t=>{var e;return H`
15699
15763
  <div class="category-item category-original-item">
@@ -15711,22 +15775,18 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15711
15775
  </td>
15712
15776
  ${e?H`<td class="translation-td">
15713
15777
  <div
15714
- class=${d}
15715
- @click=${h}
15778
+ class=${s}
15779
+ @click=${n}
15716
15780
  title="Click to edit translation"
15717
15781
  >
15718
- ${"message"===t.kind?H`${"string"==typeof o?xu(this.stripLeadingLineBreaks(o),!0):0===n.length?"No translation":""}${n.length>0?H`<div
15719
- class="quick-replies ${o?"":"standalone"}"
15720
- >
15721
- ${n.map(t=>H`<div class="quick-reply">${t}</div>`)}
15722
- </div>`:""}`:"No translation"}
15782
+ ${"message"===t.kind?this.renderTranslatedContent(t):"No translation"}
15723
15783
  </div>
15724
15784
  </td>`:""}
15725
15785
  </tr>
15726
15786
  `})}
15727
15787
  </tbody>
15728
15788
  </table>
15729
- `}}function jk(t,e){window.customElements.get(t)||window.customElements.define(t,e)}t([Ad(Sd,t=>t.flowDefinition)],Uk.prototype,"definition",void 0),t([Ad(Sd,t=>t.languageCode)],Uk.prototype,"languageCode",void 0),t([Ad(Sd,t=>t.isTranslating)],Uk.prototype,"isTranslating",void 0),jk("temba-anchor",yh),jk("temba-alert",ch),jk("temba-store",Td),jk("temba-textinput",Lo),jk("temba-datepicker",Nh),jk("temba-range-picker",rk),jk("temba-date",Vh),jk("temba-completion",fc),jk("temba-checkbox",Co),jk("temba-select",gc),jk("temba-options",Dd),jk("temba-loading",_c),jk("temba-lightbox",Yh),jk("temba-button",wc),jk("temba-omnibox",gh),jk("temba-tip",fh),jk("temba-contact-name",Ch),jk("temba-contact-name-fetch",Rh),jk("temba-contact-field",Eh),jk("temba-contact-fields",Ah),jk("temba-field-manager",qh),jk("temba-urn",Sh),jk("temba-content-menu",Wh),jk("temba-dialog",yc),jk("temba-modax",xc),jk("temba-charcount",Ic),jk("temba-contact-chat",oh),jk("temba-contact-details",class extends Pc{static get styles(){return a`
15789
+ `}}function jk(t,e){window.customElements.get(t)||window.customElements.define(t,e)}Uk.ATTACHMENT_ICONS={image:ko.attachment_image,audio:ko.attachment_audio,video:ko.attachment_video,application:ko.attachment_document},t([Ad(Sd,t=>t.flowDefinition)],Uk.prototype,"definition",void 0),t([Ad(Sd,t=>t.languageCode)],Uk.prototype,"languageCode",void 0),t([Ad(Sd,t=>t.isTranslating)],Uk.prototype,"isTranslating",void 0),jk("temba-anchor",yh),jk("temba-alert",ch),jk("temba-store",Td),jk("temba-textinput",Lo),jk("temba-datepicker",Nh),jk("temba-range-picker",rk),jk("temba-date",Vh),jk("temba-completion",fc),jk("temba-checkbox",Co),jk("temba-select",gc),jk("temba-options",Dd),jk("temba-loading",_c),jk("temba-lightbox",Yh),jk("temba-button",wc),jk("temba-omnibox",gh),jk("temba-tip",fh),jk("temba-contact-name",Ch),jk("temba-contact-name-fetch",Rh),jk("temba-contact-field",Eh),jk("temba-contact-fields",Ah),jk("temba-field-manager",qh),jk("temba-urn",Sh),jk("temba-content-menu",Wh),jk("temba-dialog",yc),jk("temba-modax",xc),jk("temba-charcount",Ic),jk("temba-contact-chat",oh),jk("temba-contact-details",class extends Pc{static get styles(){return a`
15730
15790
  .urn {
15731
15791
  display: flex;
15732
15792
  padding: 0.4em 1em 0.8em 1em;