@nyaruka/temba-components 0.156.14 → 0.156.15

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.
@@ -613,7 +613,7 @@ class ul{constructor(){this.settled=!1,this.promise=new Promise((t,e)=>{this._re
613
613
  -webkit-box-orient: vertical;
614
614
  overflow: hidden;
615
615
  }
616
- `,t([mt({type:Number})],zl.prototype,"scale",void 0),t([mt({type:Boolean})],zl.prototype,"showName",void 0),t([mt({type:Boolean})],zl.prototype,"system",void 0),t([mt({type:String,attribute:!1})],zl.prototype,"bgimage",void 0),t([mt({type:String,attribute:!1})],zl.prototype,"bgcolor",void 0),t([mt({type:String,attribute:!1})],zl.prototype,"initials",void 0),t([mt({type:String})],zl.prototype,"name",void 0),t([mt({type:String})],zl.prototype,"email",void 0),t([mt({type:String})],zl.prototype,"uuid",void 0),t([mt({type:String})],zl.prototype,"avatar",void 0);const Il=t=>{let e;const i=new Set,o=(t,o)=>{const n="function"==typeof t?t(e):t;if(!Object.is(n,e)){const t=e;e=(null!=o?o:"object"!=typeof n||null===n)?n:Object.assign({},e,n),i.forEach(i=>i(e,t))}},n=()=>e,s={setState:o,getState:n,getInitialState:()=>r,subscribe:t=>(i.add(t),()=>i.delete(t))},r=e=t(o,n,s);return s};var Ol=Symbol.for("immer-nothing"),Ll=Symbol.for("immer-draftable"),Pl=Symbol.for("immer-state"),Rl=[function(t){return`The plugin for '${t}' has not been loaded into Immer. To enable the plugin, import and call \`enable${t}()\` when initializing your application.`},function(t){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${t}'`},"This object has been frozen and should not be mutated",function(t){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+t},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(t){return`'current' expects a draft, got: ${t}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(t){return`'original' expects a draft, got: ${t}`}];function Nl(t,...e){{const i=Rl[t],o="function"==typeof i?i.apply(null,e):i;throw new Error(`[Immer] ${o}`)}}var Bl=Object.getPrototypeOf;function Fl(t){return!!t&&!!t[Pl]}function ql(t){return!!t&&(Hl(t)||Array.isArray(t)||!!t[Ll]||!!t.constructor?.[Ll]||Kl(t)||Gl(t))}var Ul=Object.prototype.constructor.toString(),jl=new WeakMap;function Hl(t){if(!t||"object"!=typeof t)return!1;const e=Object.getPrototypeOf(t);if(null===e||e===Object.prototype)return!0;const i=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(i===Object)return!0;if("function"!=typeof i)return!1;let o=jl.get(i);return void 0===o&&(o=Function.toString.call(i),jl.set(i,o)),o===Ul}function Wl(t,e,i=!0){if(0===Vl(t)){(i?Reflect.ownKeys(t):Object.keys(t)).forEach(i=>{e(i,t[i],t)})}else t.forEach((i,o)=>e(o,i,t))}function Vl(t){const e=t[Pl];return e?e.type_:Array.isArray(t)?1:Kl(t)?2:Gl(t)?3:0}function Zl(t,e){return 2===Vl(t)?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function Yl(t,e,i){const o=Vl(t);2===o?t.set(e,i):3===o?t.add(i):t[e]=i}function Kl(t){return t instanceof Map}function Gl(t){return t instanceof Set}function Xl(t){return t.copy_||t.base_}function Ql(t,e){if(Kl(t))return new Map(t);if(Gl(t))return new Set(t);if(Array.isArray(t))return Array.prototype.slice.call(t);const i=Hl(t);if(!0===e||"class_only"===e&&!i){const e=Object.getOwnPropertyDescriptors(t);delete e[Pl];let i=Reflect.ownKeys(e);for(let o=0;o<i.length;o++){const n=i[o],s=e[n];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(e[n]={configurable:!0,writable:!0,enumerable:s.enumerable,value:t[n]})}return Object.create(Bl(t),e)}{const e=Bl(t);if(null!==e&&i)return{...t};const o=Object.create(e);return Object.assign(o,t)}}function Jl(t,e=!1){return ed(t)||Fl(t)||!ql(t)||(Vl(t)>1&&Object.defineProperties(t,{set:td,add:td,clear:td,delete:td}),Object.freeze(t),e&&Object.values(t).forEach(t=>Jl(t,!0))),t}var td={value:function(){Nl(2)}};function ed(t){return null===t||"object"!=typeof t||Object.isFrozen(t)}var id,od={};function nd(t){const e=od[t];return e||Nl(0,t),e}function sd(){return id}function rd(t,e){e&&(nd("Patches"),t.patches_=[],t.inversePatches_=[],t.patchListener_=e)}function ad(t){ld(t),t.drafts_.forEach(cd),t.drafts_=null}function ld(t){t===id&&(id=t.parent_)}function dd(t){return id={drafts_:[],parent_:id,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function cd(t){const e=t[Pl];0===e.type_||1===e.type_?e.revoke_():e.revoked_=!0}function hd(t,e){e.unfinalizedDrafts_=e.drafts_.length;const i=e.drafts_[0];return void 0!==t&&t!==i?(i[Pl].modified_&&(ad(e),Nl(4)),ql(t)&&(t=ud(e,t),e.parent_||md(e,t)),e.patches_&&nd("Patches").generateReplacementPatches_(i[Pl].base_,t,e.patches_,e.inversePatches_)):t=ud(e,i,[]),ad(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),t!==Ol?t:void 0}function ud(t,e,i){if(ed(e))return e;const o=t.immer_.shouldUseStrictIteration(),n=e[Pl];if(!n)return Wl(e,(o,s)=>pd(t,n,e,o,s,i),o),e;if(n.scope_!==t)return e;if(!n.modified_)return md(t,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;const e=n.copy_;let s=e,r=!1;3===n.type_&&(s=new Set(e),e.clear(),r=!0),Wl(s,(o,s)=>pd(t,n,e,o,s,i,r),o),md(t,e,!1),i&&t.patches_&&nd("Patches").generatePatches_(n,i,t.patches_,t.inversePatches_)}return n.copy_}function pd(t,e,i,o,n,s,r){if(null==n)return;if("object"!=typeof n&&!r)return;const a=ed(n);if(!a||r){if(n===i&&Nl(5),Fl(n)){const r=ud(t,n,s&&e&&3!==e.type_&&!Zl(e.assigned_,o)?s.concat(o):void 0);if(Yl(i,o,r),!Fl(r))return;t.canAutoFreeze_=!1}else r&&i.add(n);if(ql(n)&&!a){if(!t.immer_.autoFreeze_&&t.unfinalizedDrafts_<1)return;if(e&&e.base_&&e.base_[o]===n&&a)return;ud(t,n),e&&e.scope_.parent_||"symbol"==typeof o||!(Kl(i)?i.has(o):Object.prototype.propertyIsEnumerable.call(i,o))||md(t,n)}}}function md(t,e,i=!1){!t.parent_&&t.immer_.autoFreeze_&&t.canAutoFreeze_&&Jl(e,i)}var gd={get(t,e){if(e===Pl)return t;const i=Xl(t);if(!Zl(i,e))return function(t,e,i){const o=bd(e,i);return o?"value"in o?o.value:o.get?.call(t.draft_):void 0}(t,i,e);const o=i[e];return t.finalized_||!ql(o)?o:o===vd(t.base_,e)?(xd(t),t.copy_[e]=wd(o,t)):o},has:(t,e)=>e in Xl(t),ownKeys:t=>Reflect.ownKeys(Xl(t)),set(t,e,i){const o=bd(Xl(t),e);if(o?.set)return o.set.call(t.draft_,i),!0;if(!t.modified_){const o=vd(Xl(t),e),n=o?.[Pl];if(n&&n.base_===i)return t.copy_[e]=i,t.assigned_[e]=!1,!0;if(function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}(i,o)&&(void 0!==i||Zl(t.base_,e)))return!0;xd(t),yd(t)}return t.copy_[e]===i&&(void 0!==i||e in t.copy_)||Number.isNaN(i)&&Number.isNaN(t.copy_[e])||(t.copy_[e]=i,t.assigned_[e]=!0),!0},deleteProperty:(t,e)=>(void 0!==vd(t.base_,e)||e in t.base_?(t.assigned_[e]=!1,xd(t),yd(t)):delete t.assigned_[e],t.copy_&&delete t.copy_[e],!0),getOwnPropertyDescriptor(t,e){const i=Xl(t),o=Reflect.getOwnPropertyDescriptor(i,e);return o?{writable:!0,configurable:1!==t.type_||"length"!==e,enumerable:o.enumerable,value:i[e]}:o},defineProperty(){Nl(11)},getPrototypeOf:t=>Bl(t.base_),setPrototypeOf(){Nl(12)}},fd={};function vd(t,e){const i=t[Pl];return(i?Xl(i):t)[e]}function bd(t,e){if(!(e in t))return;let i=Bl(t);for(;i;){const t=Object.getOwnPropertyDescriptor(i,e);if(t)return t;i=Bl(i)}}function yd(t){t.modified_||(t.modified_=!0,t.parent_&&yd(t.parent_))}function xd(t){t.copy_||(t.copy_=Ql(t.base_,t.scope_.immer_.useStrictShallowCopy_))}Wl(gd,(t,e)=>{fd[t]=function(){return arguments[0]=arguments[0][0],e.apply(this,arguments)}}),fd.deleteProperty=function(t,e){return isNaN(parseInt(e))&&Nl(13),fd.set.call(this,t,e,void 0)},fd.set=function(t,e,i){return"length"!==e&&isNaN(parseInt(e))&&Nl(14),gd.set.call(this,t[0],e,i,t[0])};function wd(t,e){const i=Kl(t)?nd("MapSet").proxyMap_(t,e):Gl(t)?nd("MapSet").proxySet_(t,e):function(t,e){const i=Array.isArray(t),o={type_:i?1:0,scope_:e?e.scope_:sd(),modified_:!1,finalized_:!1,assigned_:{},parent_:e,base_:t,draft_:null,copy_:null,revoke_:null,isManual_:!1};let n=o,s=gd;i&&(n=[o],s=fd);const{revoke:r,proxy:a}=Proxy.revocable(n,s);return o.draft_=a,o.revoke_=r,a}(t,e);return(e?e.scope_:sd()).drafts_.push(i),i}function _d(t){if(!ql(t)||ed(t))return t;const e=t[Pl];let i,o=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,i=Ql(t,e.scope_.immer_.useStrictShallowCopy_),o=e.scope_.immer_.shouldUseStrictIteration()}else i=Ql(t,!0);return Wl(i,(t,e)=>{Yl(i,t,_d(e))},o),e&&(e.finalized_=!1),i}var kd=new class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,e,i)=>{if("function"==typeof t&&"function"!=typeof e){const i=e;e=t;const o=this;return function(t=i,...n){return o.produce(t,t=>e.call(this,t,...n))}}let o;if("function"!=typeof e&&Nl(6),void 0!==i&&"function"!=typeof i&&Nl(7),ql(t)){const n=dd(this),s=wd(t,void 0);let r=!0;try{o=e(s),r=!1}finally{r?ad(n):ld(n)}return rd(n,i),hd(o,n)}if(!t||"object"!=typeof t){if(o=e(t),void 0===o&&(o=t),o===Ol&&(o=void 0),this.autoFreeze_&&Jl(o,!0),i){const e=[],n=[];nd("Patches").generateReplacementPatches_(t,o,e,n),i(e,n)}return o}Nl(1,t)},this.produceWithPatches=(t,e)=>{if("function"==typeof t)return(e,...i)=>this.produceWithPatches(e,e=>t(e,...i));let i,o;const n=this.produce(t,e,(t,e)=>{i=t,o=e});return[n,i,o]},"boolean"==typeof t?.autoFreeze&&this.setAutoFreeze(t.autoFreeze),"boolean"==typeof t?.useStrictShallowCopy&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),"boolean"==typeof t?.useStrictIteration&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(t){ql(t)||Nl(8),Fl(t)&&(t=function(t){Fl(t)||Nl(10,t);return _d(t)}(t));const e=dd(this),i=wd(t,void 0);return i[Pl].isManual_=!0,ld(e),i}finishDraft(t,e){const i=t&&t[Pl];i&&i.isManual_||Nl(9);const{scope_:o}=i;return rd(o,e),hd(void 0,o)}setAutoFreeze(t){this.autoFreeze_=t}setUseStrictShallowCopy(t){this.useStrictShallowCopy_=t}setUseStrictIteration(t){this.useStrictIteration_=t}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(t,e){let i;for(i=e.length-1;i>=0;i--){const o=e[i];if(0===o.path.length&&"replace"===o.op){t=o.value;break}}i>-1&&(e=e.slice(i+1));const o=nd("Patches").applyPatches_;return Fl(t)?o(t,e):this.produce(t,t=>o(t,e))}},Cd=kd.produce;const Sd=t=>(e,i,o)=>(o.setState=(t,i,...o)=>{const n="function"==typeof t?Cd(t):t;return e(n,i,...o)},t(o.setState,i,o)),Ad=t=>(e,i,o)=>{const n=o.subscribe;o.subscribe=(t,e,i)=>{let s=t;if(e){const n=(null==i?void 0:i.equalityFn)||Object.is;let r=t(o.getState());s=i=>{const o=t(i);if(!n(r,o)){const t=r;e(r=o,t)}},(null==i?void 0:i.fireImmediately)&&e(r,r)}return n(s)};return t(e,i,o)},$d="14.3";function Ed(t){var e,i;if((null==t?void 0:t.nodes)&&(null===(e=null==t?void 0:t._ui)||void 0===e?void 0:e.nodes))for(const e of t.nodes){const o=t._ui.nodes[e.uuid];if(!o)continue;const n=null===(i=e.actions)||void 0===i?void 0:i.some(t=>!0===t.terminal);"execute_actions"===o.type&&n?o.type="terminal":"terminal"!==o.type||n||(o.type="execute_actions")}}function Td(t){var e,i,o;if((null==t?void 0:t.nodes)&&(null===(e=null==t?void 0:t._ui)||void 0===e?void 0:e.nodes))for(const e of t.nodes){const n=t._ui.nodes[e.uuid];if(!n||"wait_for_response"!==n.type)continue;const s=null===(o=null===(i=e.router)||void 0===i?void 0:i.wait)||void 0===o?void 0:o.hint;s&&("digits"===s.type&&1===s.count?n.type="wait_for_menu":"digits"===s.type?n.type="wait_for_digits":"audio"===s.type&&(n.type="wait_for_audio"))}}function Dd(t,e){t.sort((t,i)=>{var o,n;const s=null===(o=e[t.uuid])||void 0===o?void 0:o.position,r=null===(n=e[i.uuid])||void 0===n?void 0:n.position;return s&&r?s.top!==r.top?s.top-r.top:s.left-r.left:0})}function Md(t=[]){const e=new Map,i=new Map;for(const o of t)if(o.action_uuid){const t=i.get(o.action_uuid)||[];t.push(o),i.set(o.action_uuid,t)}else{const t=e.get(o.node_uuid)||[];t.push(o),e.set(o.node_uuid,t)}return{byNode:e,byAction:i}}const zd=Il(Ad(Sd((t,e)=>({features:[],languageNames:{},canvasSize:{width:0,height:0},languageCode:"",workspace:null,flowDefinition:null,flowInfo:null,issuesByNode:new Map,issuesByAction:new Map,isTranslating:!1,viewingRevision:!1,dirtyDate:null,activity:null,simulatorActivity:null,activityEndpoint:null,simulatorActive:!1,flushSave:null,setFlushSave:e=>{t({flushSave:e})},setDirtyDate:e=>{t(t=>{t.dirtyDate=e})},fetchRevision:async(e,i=null)=>{var o;const n=!!i&&"latest"!==i;i||(i="latest");const s=await fetch(`${e}/${i}/?version=${$d}`);if(!s.ok)throw new Error("Network response was not ok");const r=await s.json();Ed(r.definition),Td(r.definition);const a=Md(null===(o=r.info)||void 0===o?void 0:o.issues),l=r.definition.language;t({flowInfo:r.info,flowDefinition:r.definition,viewingRevision:n,issuesByNode:a.byNode,issuesByAction:a.byAction,languageCode:l,isTranslating:!1})},fetchWorkspace:async e=>{const i=await fetch(e);if(!i.ok)throw new Error("Network response was not ok");const o=await i.json();t({workspace:o})},fetchAllLanguages:async e=>{const i=(await fe(e)).reduce(function(t,e){return t[e.value]=e.name,t},{});t({languageNames:i})},setActivityEndpoint:e=>{t({activityEndpoint:e})},fetchActivity:async e=>{try{const i=await fetch(e);if(!i.ok)return;const o=await i.json();t({activity:o})}catch(t){console.error("Failed to fetch activity:",t)}},updateActivity:e=>{t({activity:e})},updateSimulatorActivity:e=>{t({simulatorActivity:e})},setSimulatorActive:e=>{t({simulatorActive:e})},getCurrentActivity:()=>{const t=e();return t.simulatorActive?t.simulatorActivity:t.activity},getFlowResults:()=>e().flowInfo.results,getResultByKey:t=>e().flowInfo.results.find(e=>e.key===t),getLanguage:()=>{const t=e(),i=t.languageCode;return{name:t.languageNames[i],code:i}},setFeatures:e=>{t({features:e})},clearFlowData:()=>{t({flowDefinition:null,flowInfo:null,issuesByNode:new Map,issuesByAction:new Map,activity:null,simulatorActivity:null,simulatorActive:!1,dirtyDate:null,viewingRevision:!1})},setFlowContents:e=>{t(t=>{var i,o,n,s;const r=e.definition.language;t.flowDefinition={...e.definition,nodes:[...e.definition.nodes||[]]},t.flowInfo=e.info;const a=Md(null===(i=e.info)||void 0===i?void 0:i.issues);t.issuesByNode=a.byNode,t.issuesByAction=a.byAction,t.languageCode=r,t.isTranslating=!1,t.viewingRevision=!1,Ed(t.flowDefinition),Td(t.flowDefinition),(null===(o=t.flowDefinition)||void 0===o?void 0:o.nodes)&&(null===(s=null===(n=t.flowDefinition)||void 0===n?void 0:n._ui)||void 0===s?void 0:s.nodes)&&Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes)})},setFlowInfo:e=>{t(t=>{t.flowInfo=e;const i=Md(null==e?void 0:e.issues);t.issuesByNode=i.byNode,t.issuesByAction=i.byAction})},setRevision:e=>{t(t=>{t.flowDefinition.revision=e})},setLanguageCode:e=>{t(t=>{t.languageCode=e,t.isTranslating=t.flowDefinition.language!==e})},expandCanvas:(e,i)=>{t(t=>{const o=Math.max(t.canvasSize.width,e+800),n=Math.max(t.canvasSize.height,i+800);t.canvasSize.width=o,t.canvasSize.height=n})},updateCanvasPositions:e=>{t(t=>{for(const i in e)t.flowDefinition._ui.nodes[i]?t.flowDefinition._ui.nodes[i].position=e[i]:t.flowDefinition._ui.stickies[i]&&(t.flowDefinition._ui.stickies[i].position=e[i]);Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes),t.dirtyDate=new Date})},removeNodes:e=>{t(t=>{for(const i of e)delete t.flowDefinition._ui.nodes[i];t.flowDefinition=Cd(t.flowDefinition,t=>{e.forEach(i=>{const o=t.nodes.find(t=>t.uuid===i);if(!o||!o.exits.length)return;const n=o.exits.map(t=>t.destination_uuid).filter(t=>t);if(n.length===o.exits.length&&n.every(t=>t===n[0])){const o=n[0];if(e.includes(o))return;t.nodes.forEach(t=>{t.exits.forEach(t=>{t.destination_uuid===i&&(t.destination_uuid=o)})})}}),t.nodes=t.nodes.filter(t=>!e.includes(t.uuid)),t.nodes.forEach(t=>{t.exits.forEach(t=>{e.includes(t.destination_uuid)&&(t.destination_uuid=null)})}),Dd(t.nodes,t._ui.nodes)}),t.dirtyDate=new Date})},removeStickyNotes:e=>{t(t=>{var i;if(null===(i=t.flowDefinition._ui)||void 0===i?void 0:i.stickies)for(const i of e)delete t.flowDefinition._ui.stickies[i];t.dirtyDate=new Date})},updateNode:(e,i)=>{t(t=>{var o;const n=null===(o=t.flowDefinition)||void 0===o?void 0:o.nodes.find(t=>t.uuid===e);n&&(n.actions=i.actions,n.uuid=i.uuid,n.exits=i.exits,n.router=i.router),t.dirtyDate=new Date})},updateNodeUIConfig:(e,i)=>{t(t=>{if(t.flowDefinition._ui.nodes[e]){void 0!==i.type&&(t.flowDefinition._ui.nodes[e].type=i.type),t.flowDefinition._ui.nodes[e].config||(t.flowDefinition._ui.nodes[e].config={});const{type:o,...n}=i;Object.assign(t.flowDefinition._ui.nodes[e].config,n)}t.dirtyDate=new Date})},updateConnection:(e,i,o)=>{t(t=>{const n=t.flowDefinition.nodes.find(t=>t.uuid===e),s=null==n?void 0:n.exits.find(t=>t.uuid===i);s&&(s.destination_uuid=o,t.dirtyDate=new Date)})},updateStickyNote:(e,i)=>{t(t=>{t.flowDefinition._ui.stickies||(t.flowDefinition._ui.stickies={}),t.flowDefinition._ui.stickies[e]=i,t.dirtyDate=new Date})},createStickyNote:e=>{const i=Kt();return t(t=>{t.flowDefinition._ui.stickies||(t.flowDefinition._ui.stickies={});const o={position:e,title:"",body:"",color:"yellow"};t.flowDefinition._ui.stickies[i]=o,t.dirtyDate=new Date}),i},createNode:(e,i)=>{const o=Kt(),n=Kt();return t(t=>{const s={uuid:o,actions:[],exits:[{uuid:n,destination_uuid:null}]};t.flowDefinition.nodes.push(s),t.flowDefinition._ui.nodes||(t.flowDefinition._ui.nodes={}),t.flowDefinition._ui.nodes[o]={position:i,type:e,config:{}},Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes),t.dirtyDate=new Date}),o},addNode:(e,i)=>{t(t=>{t.flowDefinition.nodes.push(e),t.flowDefinition._ui.nodes||(t.flowDefinition._ui.nodes={}),t.flowDefinition._ui.nodes[e.uuid]=i,Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes),t.dirtyDate=new Date})},duplicateNodes:i=>{var o,n;const s=e(),r=new Set(i),a={},l=s.flowDefinition._ui.stickies||{};for(const t of i){if(l[t]){a[t]=Kt();continue}const e=s.flowDefinition.nodes.find(e=>e.uuid===t);if(e){a[t]=Kt();for(const t of e.actions)a[t.uuid]=Kt();for(const t of e.exits)a[t.uuid]=Kt();if(e.router){for(const t of e.router.categories)a[t.uuid]=Kt();for(const t of e.router.cases||[])a[t.uuid]=Kt()}}}const d=[],c=[];for(const t of i){if(l[t]){const e=JSON.parse(JSON.stringify(l[t]));c.push({uuid:a[t],sticky:e});continue}const e=s.flowDefinition.nodes.find(e=>e.uuid===t),i=s.flowDefinition._ui.nodes[t];if(!e||!i)continue;const h=JSON.parse(JSON.stringify(e));h.uuid=a[t];for(const t of h.actions)t.uuid=a[t.uuid];for(const t of h.exits)t.uuid=a[t.uuid],t.destination_uuid&&r.has(t.destination_uuid)?t.destination_uuid=a[t.destination_uuid]:t.destination_uuid=null;if(h.router){for(const t of h.router.categories)t.uuid=a[t.uuid],t.exit_uuid=a[t.exit_uuid];if(h.router.cases)for(const t of h.router.cases)t.uuid=a[t.uuid],t.category_uuid=a[t.category_uuid];h.router.default_category_uuid&&(h.router.default_category_uuid=a[h.router.default_category_uuid]),(null===(n=null===(o=h.router.wait)||void 0===o?void 0:o.timeout)||void 0===n?void 0:n.category_uuid)&&(h.router.wait.timeout.category_uuid=a[h.router.wait.timeout.category_uuid])}const u=JSON.parse(JSON.stringify(i));d.push({node:h,ui:u})}const h={},u=s.flowDefinition.localization;if(u)for(const t of Object.keys(u)){const e=u[t];for(const i of Object.keys(a))e[i]&&(h[t]||(h[t]={}),h[t][a[i]]=JSON.parse(JSON.stringify(e[i])))}return t(t=>{for(const{node:e,ui:i}of d)t.flowDefinition.nodes.push(e),t.flowDefinition._ui.nodes[e.uuid]=i;t.flowDefinition._ui.stickies||(t.flowDefinition._ui.stickies={});for(const{uuid:e,sticky:i}of c)t.flowDefinition._ui.stickies[e]=i;for(const e of Object.keys(h)){t.flowDefinition.localization[e]||(t.flowDefinition.localization[e]={});for(const[i,o]of Object.entries(h[e]))t.flowDefinition.localization[e][i]=o}Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes)}),a},updateLocalization:(e,i,o)=>{t(t=>{t.flowDefinition.localization||(t.flowDefinition.localization={}),t.flowDefinition.localization[e]||(t.flowDefinition.localization[e]={}),Object.keys(o).length>0?t.flowDefinition.localization[e][i]=o:delete t.flowDefinition.localization[e][i],0===Object.keys(t.flowDefinition.localization[e]).length&&delete t.flowDefinition.localization[e],0===Object.keys(t.flowDefinition.localization).length&&delete t.flowDefinition.localization,t.dirtyDate=new Date})},setTranslationFilters:e=>{t(t=>{var i;if(!(null===(i=t.flowDefinition)||void 0===i?void 0:i._ui))return;const o=t.flowDefinition._ui.translation_filters||{categories:!1},n=!!e.categories;o.categories!==n&&(t.flowDefinition._ui.translation_filters={...o,categories:n},t.dirtyDate=new Date)})},markAutoTranslated:(e,i,o)=>{t(t=>{var n;if(!(null===(n=t.flowDefinition)||void 0===n?void 0:n._ui))return;t.flowDefinition._ui.auto_translations||(t.flowDefinition._ui.auto_translations={}),t.flowDefinition._ui.auto_translations[e]||(t.flowDefinition._ui.auto_translations[e]={});const s=t.flowDefinition._ui.auto_translations[e][i]||[],r=Array.from(new Set([...s,...o||[]]));t.flowDefinition._ui.auto_translations[e][i]=r,t.dirtyDate=new Date})}}))));function Id(t,e){return(i,o)=>{mt()(i,o);const n="connectedCallback",s="disconnectedCallback",r=i[n],a=i[s];i[n]=function(){var i;null!==(i=this._zustandUnsubscribe)&&void 0!==i||(this._zustandUnsubscribe={}),this[o]=e(t.getState()),this._zustandUnsubscribe[o]=t.subscribe(e,t=>{this[o]=t}),r&&r.call(this)},i[s]=function(){var t,e;null===(e=null===(t=this._zustandUnsubscribe)||void 0===t?void 0:t[o])||void 0===e||e.call(t),a&&a.call(this)}}}var Od;!function(t){t.Text="text",t.ExpressionPrefix="prefix",t.Identifier="identifier",t.Paren="paren",t.Operator="operator",t.FunctionName="fn",t.StringLiteral="string",t.NumberLiteral="number",t.Keyword="keyword",t.ContextRef="context-ref",t.Separator="separator",t.Whitespace="ws",t.Arrow="arrow",t.Bracket="bracket",t.EscapedAt="escaped-at"}(Od||(Od={}));const Ld=new Set(["true","false","null"]),Pd=new Set(["+","-","*","/","^","&","=","<",">"]),Rd=t=>t>="0"&&t<="9",Nd=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t>="0"&&t<="9"||"_"===t;function Bd(t,e,i){const o=[];let n=0,s=i;const r=(e=0)=>t[n+e],a=(i,n)=>{const s=t.substring(i,n),r=e+i;if(Ld.has(s.toLowerCase()))return void o.push({type:Od.Keyword,text:s,start:r});let a=n;for(;a<t.length&&" "===t[a];)a++;a<t.length&&"("===t[a]?o.push({type:Od.FunctionName,text:s,start:r}):o.push({type:Od.ContextRef,text:s,start:r})};for(;n<t.length;){const i=t[n];if('"'===i){const i=n;for(n++;n<t.length;)if("\\"===t[n]&&n+1<t.length&&'"'===t[n+1])n+=2;else{if('"'===t[n]){n++;break}n++}o.push({type:Od.StringLiteral,text:t.substring(i,n),start:e+i});continue}if(Rd(i)||"."===i&&r(1)&&Rd(r(1))){const i=n;for(;n<t.length&&Rd(t[n]);)n++;if(n<t.length&&"."===t[n]&&n+1<t.length&&Rd(t[n+1]))for(n++;n<t.length&&Rd(t[n]);)n++;o.push({type:Od.NumberLiteral,text:t.substring(i,n),start:e+i});continue}if(Nd(i)&&!Rd(i)){const e=n;for(;n<t.length&&(Nd(t[n])||"."===t[n])&&("."!==t[n]||!(n+1>=t.length)&&Nd(t[n+1]));)n++;a(e,n);continue}if("("!==i)if(")"!==i)if("["!==i&&"]"!==i)if("="!==i||">"!==r(1))if("!"===i&&"="===r(1)||"<"===i&&"="===r(1)||">"===i&&"="===r(1))o.push({type:Od.Operator,text:i+r(1),start:e+n}),n+=2;else if(Pd.has(i))o.push({type:Od.Operator,text:i,start:e+n}),n++;else if(","!==i){if(" "===i||"\t"===i||"\n"===i||"\r"===i){const i=n;for(;n<t.length&&(" "===t[n]||"\t"===t[n]||"\n"===t[n]||"\r"===t[n]);)n++;o.push({type:Od.Whitespace,text:t.substring(i,n),start:e+i});continue}o.push({type:Od.Text,text:i,start:e+n}),n++}else o.push({type:Od.Separator,text:",",start:e+n}),n++;else o.push({type:Od.Arrow,text:"=>",start:e+n}),n+=2;else o.push({type:Od.Bracket,text:i,start:e+n}),n++;else s--,o.push({type:Od.Paren,text:")",start:e+n,depth:Math.max(0,s),balanced:!0}),n++;else o.push({type:Od.Paren,text:"(",start:e+n,depth:s,balanced:!0}),s++,n++}return o}function Fd(t,e){if(!t)return[];const i=e.findExpressions(t),o=[];let n=0;for(const e of i){if(e.start>n){const i=t.substring(n,e.start);let s=0;for(;s<i.length;){const t=i.indexOf("@@",s);if(-1===t){s<i.length&&o.push({type:Od.Text,text:i.substring(s),start:n+s});break}t>s&&o.push({type:Od.Text,text:i.substring(s,t),start:n+s}),o.push({type:Od.EscapedAt,text:"@@",start:n+t}),s=t+2}}const i=e.text;if(o.push({type:Od.ExpressionPrefix,text:"@",start:e.start}),i.length>1&&"("===i[1]){o.push({type:Od.Paren,text:"(",start:e.start+1,depth:0,balanced:e.closed});const t=e.closed&&")"===i[i.length-1],n=t?i.length-1:i.length,s=i.substring(2,n);if(s.length>0){const t=Bd(s,e.start+2,1);o.push(...t)}t&&o.push({type:Od.Paren,text:")",start:e.start+i.length-1,depth:0,balanced:!0}),e.closed||qd(o,e.start)}else o.push({type:Od.Identifier,text:i.substring(1),start:e.start+1});n=e.end}if(n<t.length){const e=t.substring(n);let i=0;for(;i<e.length;){const t=e.indexOf("@@",i);if(-1===t){i<e.length&&o.push({type:Od.Text,text:e.substring(i),start:n+i});break}t>i&&o.push({type:Od.Text,text:e.substring(i,t),start:n+i}),o.push({type:Od.EscapedAt,text:"@@",start:n+t}),i=t+2}}return o}function qd(t,e){for(const i of t)i.type===Od.Paren&&i.start>=e&&"("===i.text&&0===i.depth&&(i.balanced=!1)}const Ud={expression:"#0086e0",fn:"#0086e0",string:"#06a810",number:"#c25ceb",keyword:"#1750eb",operator:"#666",paren:"#999",parenUnmatched:"#ff0011"},jd={[Od.Text]:"tok-text",[Od.ExpressionPrefix]:"tok-prefix",[Od.Identifier]:"tok-id",[Od.FunctionName]:"tok-fn",[Od.StringLiteral]:"tok-str",[Od.NumberLiteral]:"tok-num",[Od.Keyword]:"tok-kw",[Od.Operator]:"tok-op",[Od.ContextRef]:"tok-ctx",[Od.Separator]:"tok-sep",[Od.Whitespace]:"tok-ws",[Od.Arrow]:"tok-arrow",[Od.Bracket]:"tok-bracket",[Od.EscapedAt]:"tok-text",[Od.Paren]:"tok-paren"},Hd=new Set([Od.ExpressionPrefix,Od.Identifier,Od.FunctionName,Od.StringLiteral,Od.NumberLiteral,Od.Keyword,Od.Operator,Od.ContextRef,Od.Separator,Od.Whitespace,Od.Arrow,Od.Bracket,Od.Paren]);function Wd(t){return t.type===Od.Paren&&!1===t.balanced?"tok-paren-unmatched":jd[t.type]||"tok-text"}const Vd=t=>r(Ud[t]),Zd=a`
616
+ `,t([mt({type:Number})],zl.prototype,"scale",void 0),t([mt({type:Boolean})],zl.prototype,"showName",void 0),t([mt({type:Boolean})],zl.prototype,"system",void 0),t([mt({type:String,attribute:!1})],zl.prototype,"bgimage",void 0),t([mt({type:String,attribute:!1})],zl.prototype,"bgcolor",void 0),t([mt({type:String,attribute:!1})],zl.prototype,"initials",void 0),t([mt({type:String})],zl.prototype,"name",void 0),t([mt({type:String})],zl.prototype,"email",void 0),t([mt({type:String})],zl.prototype,"uuid",void 0),t([mt({type:String})],zl.prototype,"avatar",void 0);const Il=t=>{let e;const i=new Set,o=(t,o)=>{const n="function"==typeof t?t(e):t;if(!Object.is(n,e)){const t=e;e=(null!=o?o:"object"!=typeof n||null===n)?n:Object.assign({},e,n),i.forEach(i=>i(e,t))}},n=()=>e,s={setState:o,getState:n,getInitialState:()=>r,subscribe:t=>(i.add(t),()=>i.delete(t))},r=e=t(o,n,s);return s};var Ol=Symbol.for("immer-nothing"),Ll=Symbol.for("immer-draftable"),Pl=Symbol.for("immer-state"),Rl=[function(t){return`The plugin for '${t}' has not been loaded into Immer. To enable the plugin, import and call \`enable${t}()\` when initializing your application.`},function(t){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${t}'`},"This object has been frozen and should not be mutated",function(t){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+t},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(t){return`'current' expects a draft, got: ${t}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(t){return`'original' expects a draft, got: ${t}`}];function Nl(t,...e){{const i=Rl[t],o="function"==typeof i?i.apply(null,e):i;throw new Error(`[Immer] ${o}`)}}var Bl=Object.getPrototypeOf;function Fl(t){return!!t&&!!t[Pl]}function ql(t){return!!t&&(Hl(t)||Array.isArray(t)||!!t[Ll]||!!t.constructor?.[Ll]||Kl(t)||Gl(t))}var Ul=Object.prototype.constructor.toString(),jl=new WeakMap;function Hl(t){if(!t||"object"!=typeof t)return!1;const e=Object.getPrototypeOf(t);if(null===e||e===Object.prototype)return!0;const i=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(i===Object)return!0;if("function"!=typeof i)return!1;let o=jl.get(i);return void 0===o&&(o=Function.toString.call(i),jl.set(i,o)),o===Ul}function Wl(t,e,i=!0){if(0===Vl(t)){(i?Reflect.ownKeys(t):Object.keys(t)).forEach(i=>{e(i,t[i],t)})}else t.forEach((i,o)=>e(o,i,t))}function Vl(t){const e=t[Pl];return e?e.type_:Array.isArray(t)?1:Kl(t)?2:Gl(t)?3:0}function Zl(t,e){return 2===Vl(t)?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function Yl(t,e,i){const o=Vl(t);2===o?t.set(e,i):3===o?t.add(i):t[e]=i}function Kl(t){return t instanceof Map}function Gl(t){return t instanceof Set}function Xl(t){return t.copy_||t.base_}function Ql(t,e){if(Kl(t))return new Map(t);if(Gl(t))return new Set(t);if(Array.isArray(t))return Array.prototype.slice.call(t);const i=Hl(t);if(!0===e||"class_only"===e&&!i){const e=Object.getOwnPropertyDescriptors(t);delete e[Pl];let i=Reflect.ownKeys(e);for(let o=0;o<i.length;o++){const n=i[o],s=e[n];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(e[n]={configurable:!0,writable:!0,enumerable:s.enumerable,value:t[n]})}return Object.create(Bl(t),e)}{const e=Bl(t);if(null!==e&&i)return{...t};const o=Object.create(e);return Object.assign(o,t)}}function Jl(t,e=!1){return ed(t)||Fl(t)||!ql(t)||(Vl(t)>1&&Object.defineProperties(t,{set:td,add:td,clear:td,delete:td}),Object.freeze(t),e&&Object.values(t).forEach(t=>Jl(t,!0))),t}var td={value:function(){Nl(2)}};function ed(t){return null===t||"object"!=typeof t||Object.isFrozen(t)}var id,od={};function nd(t){const e=od[t];return e||Nl(0,t),e}function sd(){return id}function rd(t,e){e&&(nd("Patches"),t.patches_=[],t.inversePatches_=[],t.patchListener_=e)}function ad(t){ld(t),t.drafts_.forEach(cd),t.drafts_=null}function ld(t){t===id&&(id=t.parent_)}function dd(t){return id={drafts_:[],parent_:id,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function cd(t){const e=t[Pl];0===e.type_||1===e.type_?e.revoke_():e.revoked_=!0}function hd(t,e){e.unfinalizedDrafts_=e.drafts_.length;const i=e.drafts_[0];return void 0!==t&&t!==i?(i[Pl].modified_&&(ad(e),Nl(4)),ql(t)&&(t=ud(e,t),e.parent_||md(e,t)),e.patches_&&nd("Patches").generateReplacementPatches_(i[Pl].base_,t,e.patches_,e.inversePatches_)):t=ud(e,i,[]),ad(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),t!==Ol?t:void 0}function ud(t,e,i){if(ed(e))return e;const o=t.immer_.shouldUseStrictIteration(),n=e[Pl];if(!n)return Wl(e,(o,s)=>pd(t,n,e,o,s,i),o),e;if(n.scope_!==t)return e;if(!n.modified_)return md(t,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;const e=n.copy_;let s=e,r=!1;3===n.type_&&(s=new Set(e),e.clear(),r=!0),Wl(s,(o,s)=>pd(t,n,e,o,s,i,r),o),md(t,e,!1),i&&t.patches_&&nd("Patches").generatePatches_(n,i,t.patches_,t.inversePatches_)}return n.copy_}function pd(t,e,i,o,n,s,r){if(null==n)return;if("object"!=typeof n&&!r)return;const a=ed(n);if(!a||r){if(n===i&&Nl(5),Fl(n)){const r=ud(t,n,s&&e&&3!==e.type_&&!Zl(e.assigned_,o)?s.concat(o):void 0);if(Yl(i,o,r),!Fl(r))return;t.canAutoFreeze_=!1}else r&&i.add(n);if(ql(n)&&!a){if(!t.immer_.autoFreeze_&&t.unfinalizedDrafts_<1)return;if(e&&e.base_&&e.base_[o]===n&&a)return;ud(t,n),e&&e.scope_.parent_||"symbol"==typeof o||!(Kl(i)?i.has(o):Object.prototype.propertyIsEnumerable.call(i,o))||md(t,n)}}}function md(t,e,i=!1){!t.parent_&&t.immer_.autoFreeze_&&t.canAutoFreeze_&&Jl(e,i)}var gd={get(t,e){if(e===Pl)return t;const i=Xl(t);if(!Zl(i,e))return function(t,e,i){const o=bd(e,i);return o?"value"in o?o.value:o.get?.call(t.draft_):void 0}(t,i,e);const o=i[e];return t.finalized_||!ql(o)?o:o===vd(t.base_,e)?(xd(t),t.copy_[e]=wd(o,t)):o},has:(t,e)=>e in Xl(t),ownKeys:t=>Reflect.ownKeys(Xl(t)),set(t,e,i){const o=bd(Xl(t),e);if(o?.set)return o.set.call(t.draft_,i),!0;if(!t.modified_){const o=vd(Xl(t),e),n=o?.[Pl];if(n&&n.base_===i)return t.copy_[e]=i,t.assigned_[e]=!1,!0;if(function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}(i,o)&&(void 0!==i||Zl(t.base_,e)))return!0;xd(t),yd(t)}return t.copy_[e]===i&&(void 0!==i||e in t.copy_)||Number.isNaN(i)&&Number.isNaN(t.copy_[e])||(t.copy_[e]=i,t.assigned_[e]=!0),!0},deleteProperty:(t,e)=>(void 0!==vd(t.base_,e)||e in t.base_?(t.assigned_[e]=!1,xd(t),yd(t)):delete t.assigned_[e],t.copy_&&delete t.copy_[e],!0),getOwnPropertyDescriptor(t,e){const i=Xl(t),o=Reflect.getOwnPropertyDescriptor(i,e);return o?{writable:!0,configurable:1!==t.type_||"length"!==e,enumerable:o.enumerable,value:i[e]}:o},defineProperty(){Nl(11)},getPrototypeOf:t=>Bl(t.base_),setPrototypeOf(){Nl(12)}},fd={};function vd(t,e){const i=t[Pl];return(i?Xl(i):t)[e]}function bd(t,e){if(!(e in t))return;let i=Bl(t);for(;i;){const t=Object.getOwnPropertyDescriptor(i,e);if(t)return t;i=Bl(i)}}function yd(t){t.modified_||(t.modified_=!0,t.parent_&&yd(t.parent_))}function xd(t){t.copy_||(t.copy_=Ql(t.base_,t.scope_.immer_.useStrictShallowCopy_))}Wl(gd,(t,e)=>{fd[t]=function(){return arguments[0]=arguments[0][0],e.apply(this,arguments)}}),fd.deleteProperty=function(t,e){return isNaN(parseInt(e))&&Nl(13),fd.set.call(this,t,e,void 0)},fd.set=function(t,e,i){return"length"!==e&&isNaN(parseInt(e))&&Nl(14),gd.set.call(this,t[0],e,i,t[0])};function wd(t,e){const i=Kl(t)?nd("MapSet").proxyMap_(t,e):Gl(t)?nd("MapSet").proxySet_(t,e):function(t,e){const i=Array.isArray(t),o={type_:i?1:0,scope_:e?e.scope_:sd(),modified_:!1,finalized_:!1,assigned_:{},parent_:e,base_:t,draft_:null,copy_:null,revoke_:null,isManual_:!1};let n=o,s=gd;i&&(n=[o],s=fd);const{revoke:r,proxy:a}=Proxy.revocable(n,s);return o.draft_=a,o.revoke_=r,a}(t,e);return(e?e.scope_:sd()).drafts_.push(i),i}function _d(t){if(!ql(t)||ed(t))return t;const e=t[Pl];let i,o=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,i=Ql(t,e.scope_.immer_.useStrictShallowCopy_),o=e.scope_.immer_.shouldUseStrictIteration()}else i=Ql(t,!0);return Wl(i,(t,e)=>{Yl(i,t,_d(e))},o),e&&(e.finalized_=!1),i}var kd=new class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,e,i)=>{if("function"==typeof t&&"function"!=typeof e){const i=e;e=t;const o=this;return function(t=i,...n){return o.produce(t,t=>e.call(this,t,...n))}}let o;if("function"!=typeof e&&Nl(6),void 0!==i&&"function"!=typeof i&&Nl(7),ql(t)){const n=dd(this),s=wd(t,void 0);let r=!0;try{o=e(s),r=!1}finally{r?ad(n):ld(n)}return rd(n,i),hd(o,n)}if(!t||"object"!=typeof t){if(o=e(t),void 0===o&&(o=t),o===Ol&&(o=void 0),this.autoFreeze_&&Jl(o,!0),i){const e=[],n=[];nd("Patches").generateReplacementPatches_(t,o,e,n),i(e,n)}return o}Nl(1,t)},this.produceWithPatches=(t,e)=>{if("function"==typeof t)return(e,...i)=>this.produceWithPatches(e,e=>t(e,...i));let i,o;const n=this.produce(t,e,(t,e)=>{i=t,o=e});return[n,i,o]},"boolean"==typeof t?.autoFreeze&&this.setAutoFreeze(t.autoFreeze),"boolean"==typeof t?.useStrictShallowCopy&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),"boolean"==typeof t?.useStrictIteration&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(t){ql(t)||Nl(8),Fl(t)&&(t=function(t){Fl(t)||Nl(10,t);return _d(t)}(t));const e=dd(this),i=wd(t,void 0);return i[Pl].isManual_=!0,ld(e),i}finishDraft(t,e){const i=t&&t[Pl];i&&i.isManual_||Nl(9);const{scope_:o}=i;return rd(o,e),hd(void 0,o)}setAutoFreeze(t){this.autoFreeze_=t}setUseStrictShallowCopy(t){this.useStrictShallowCopy_=t}setUseStrictIteration(t){this.useStrictIteration_=t}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(t,e){let i;for(i=e.length-1;i>=0;i--){const o=e[i];if(0===o.path.length&&"replace"===o.op){t=o.value;break}}i>-1&&(e=e.slice(i+1));const o=nd("Patches").applyPatches_;return Fl(t)?o(t,e):this.produce(t,t=>o(t,e))}},Cd=kd.produce;const Sd=t=>(e,i,o)=>(o.setState=(t,i,...o)=>{const n="function"==typeof t?Cd(t):t;return e(n,i,...o)},t(o.setState,i,o)),Ad=t=>(e,i,o)=>{const n=o.subscribe;o.subscribe=(t,e,i)=>{let s=t;if(e){const n=(null==i?void 0:i.equalityFn)||Object.is;let r=t(o.getState());s=i=>{const o=t(i);if(!n(r,o)){const t=r;e(r=o,t)}},(null==i?void 0:i.fireImmediately)&&e(r,r)}return n(s)};return t(e,i,o)},$d="14.3";function Ed(t){var e,i;if((null==t?void 0:t.nodes)&&(null===(e=null==t?void 0:t._ui)||void 0===e?void 0:e.nodes))for(const e of t.nodes){const o=t._ui.nodes[e.uuid];if(!o)continue;const n=null===(i=e.actions)||void 0===i?void 0:i.some(t=>!0===t.terminal);"execute_actions"===o.type&&n?o.type="terminal":"terminal"!==o.type||n||(o.type="execute_actions")}}function Td(t){var e,i,o;if((null==t?void 0:t.nodes)&&(null===(e=null==t?void 0:t._ui)||void 0===e?void 0:e.nodes))for(const e of t.nodes){const n=t._ui.nodes[e.uuid];if(!n||"wait_for_response"!==n.type)continue;const s=null===(o=null===(i=e.router)||void 0===i?void 0:i.wait)||void 0===o?void 0:o.hint;s&&("digits"===s.type&&1===s.count?n.type="wait_for_menu":"digits"===s.type?n.type="wait_for_digits":"audio"===s.type&&(n.type="wait_for_audio"))}}function Dd(t,e){t.sort((t,i)=>{var o,n;const s=null===(o=e[t.uuid])||void 0===o?void 0:o.position,r=null===(n=e[i.uuid])||void 0===n?void 0:n.position;return s&&r?s.top!==r.top?s.top-r.top:s.left-r.left:0})}function Md(t=[]){const e=new Map,i=new Map;for(const o of t)if(o.action_uuid){const t=i.get(o.action_uuid)||[];t.push(o),i.set(o.action_uuid,t)}else{const t=e.get(o.node_uuid)||[];t.push(o),e.set(o.node_uuid,t)}return{byNode:e,byAction:i}}const zd=Il(Ad(Sd((t,e)=>({features:[],brand:"",languageNames:{},canvasSize:{width:0,height:0},languageCode:"",workspace:null,flowDefinition:null,flowInfo:null,issuesByNode:new Map,issuesByAction:new Map,isTranslating:!1,viewingRevision:!1,dirtyDate:null,activity:null,simulatorActivity:null,activityEndpoint:null,simulatorActive:!1,flushSave:null,setFlushSave:e=>{t({flushSave:e})},setDirtyDate:e=>{t(t=>{t.dirtyDate=e})},fetchRevision:async(e,i=null)=>{var o;const n=!!i&&"latest"!==i;i||(i="latest");const s=await fetch(`${e}/${i}/?version=${$d}`);if(!s.ok)throw new Error("Network response was not ok");const r=await s.json();Ed(r.definition),Td(r.definition);const a=Md(null===(o=r.info)||void 0===o?void 0:o.issues),l=r.definition.language;t({flowInfo:r.info,flowDefinition:r.definition,viewingRevision:n,issuesByNode:a.byNode,issuesByAction:a.byAction,languageCode:l,isTranslating:!1})},fetchWorkspace:async e=>{const i=await fetch(e);if(!i.ok)throw new Error("Network response was not ok");const o=await i.json();t({workspace:o})},fetchAllLanguages:async e=>{const i=(await fe(e)).reduce(function(t,e){return t[e.value]=e.name,t},{});t({languageNames:i})},setActivityEndpoint:e=>{t({activityEndpoint:e})},fetchActivity:async e=>{try{const i=await fetch(e);if(!i.ok)return;const o=await i.json();t({activity:o})}catch(t){console.error("Failed to fetch activity:",t)}},updateActivity:e=>{t({activity:e})},updateSimulatorActivity:e=>{t({simulatorActivity:e})},setSimulatorActive:e=>{t({simulatorActive:e})},getCurrentActivity:()=>{const t=e();return t.simulatorActive?t.simulatorActivity:t.activity},getFlowResults:()=>e().flowInfo.results,getResultByKey:t=>e().flowInfo.results.find(e=>e.key===t),getLanguage:()=>{const t=e(),i=t.languageCode;return{name:t.languageNames[i],code:i}},setFeatures:e=>{t({features:e})},clearFlowData:()=>{t({flowDefinition:null,flowInfo:null,issuesByNode:new Map,issuesByAction:new Map,activity:null,simulatorActivity:null,simulatorActive:!1,dirtyDate:null,viewingRevision:!1})},setFlowContents:e=>{t(t=>{var i,o,n,s;const r=e.definition.language;t.flowDefinition={...e.definition,nodes:[...e.definition.nodes||[]]},t.flowInfo=e.info;const a=Md(null===(i=e.info)||void 0===i?void 0:i.issues);t.issuesByNode=a.byNode,t.issuesByAction=a.byAction,t.languageCode=r,t.isTranslating=!1,t.viewingRevision=!1,Ed(t.flowDefinition),Td(t.flowDefinition),(null===(o=t.flowDefinition)||void 0===o?void 0:o.nodes)&&(null===(s=null===(n=t.flowDefinition)||void 0===n?void 0:n._ui)||void 0===s?void 0:s.nodes)&&Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes)})},setFlowInfo:e=>{t(t=>{t.flowInfo=e;const i=Md(null==e?void 0:e.issues);t.issuesByNode=i.byNode,t.issuesByAction=i.byAction})},setRevision:e=>{t(t=>{t.flowDefinition.revision=e})},setLanguageCode:e=>{t(t=>{t.languageCode=e,t.isTranslating=t.flowDefinition.language!==e})},expandCanvas:(e,i)=>{t(t=>{const o=Math.max(t.canvasSize.width,e+800),n=Math.max(t.canvasSize.height,i+800);t.canvasSize.width=o,t.canvasSize.height=n})},updateCanvasPositions:e=>{t(t=>{for(const i in e)t.flowDefinition._ui.nodes[i]?t.flowDefinition._ui.nodes[i].position=e[i]:t.flowDefinition._ui.stickies[i]&&(t.flowDefinition._ui.stickies[i].position=e[i]);Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes),t.dirtyDate=new Date})},removeNodes:e=>{t(t=>{for(const i of e)delete t.flowDefinition._ui.nodes[i];t.flowDefinition=Cd(t.flowDefinition,t=>{e.forEach(i=>{const o=t.nodes.find(t=>t.uuid===i);if(!o||!o.exits.length)return;const n=o.exits.map(t=>t.destination_uuid).filter(t=>t);if(n.length===o.exits.length&&n.every(t=>t===n[0])){const o=n[0];if(e.includes(o))return;t.nodes.forEach(t=>{t.exits.forEach(t=>{t.destination_uuid===i&&(t.destination_uuid=o)})})}}),t.nodes=t.nodes.filter(t=>!e.includes(t.uuid)),t.nodes.forEach(t=>{t.exits.forEach(t=>{e.includes(t.destination_uuid)&&(t.destination_uuid=null)})}),Dd(t.nodes,t._ui.nodes)}),t.dirtyDate=new Date})},removeStickyNotes:e=>{t(t=>{var i;if(null===(i=t.flowDefinition._ui)||void 0===i?void 0:i.stickies)for(const i of e)delete t.flowDefinition._ui.stickies[i];t.dirtyDate=new Date})},updateNode:(e,i)=>{t(t=>{var o;const n=null===(o=t.flowDefinition)||void 0===o?void 0:o.nodes.find(t=>t.uuid===e);n&&(n.actions=i.actions,n.uuid=i.uuid,n.exits=i.exits,n.router=i.router),t.dirtyDate=new Date})},updateNodeUIConfig:(e,i)=>{t(t=>{if(t.flowDefinition._ui.nodes[e]){void 0!==i.type&&(t.flowDefinition._ui.nodes[e].type=i.type),t.flowDefinition._ui.nodes[e].config||(t.flowDefinition._ui.nodes[e].config={});const{type:o,...n}=i;Object.assign(t.flowDefinition._ui.nodes[e].config,n)}t.dirtyDate=new Date})},updateConnection:(e,i,o)=>{t(t=>{const n=t.flowDefinition.nodes.find(t=>t.uuid===e),s=null==n?void 0:n.exits.find(t=>t.uuid===i);s&&(s.destination_uuid=o,t.dirtyDate=new Date)})},updateStickyNote:(e,i)=>{t(t=>{t.flowDefinition._ui.stickies||(t.flowDefinition._ui.stickies={}),t.flowDefinition._ui.stickies[e]=i,t.dirtyDate=new Date})},createStickyNote:e=>{const i=Kt();return t(t=>{t.flowDefinition._ui.stickies||(t.flowDefinition._ui.stickies={});const o={position:e,title:"",body:"",color:"yellow"};t.flowDefinition._ui.stickies[i]=o,t.dirtyDate=new Date}),i},createNode:(e,i)=>{const o=Kt(),n=Kt();return t(t=>{const s={uuid:o,actions:[],exits:[{uuid:n,destination_uuid:null}]};t.flowDefinition.nodes.push(s),t.flowDefinition._ui.nodes||(t.flowDefinition._ui.nodes={}),t.flowDefinition._ui.nodes[o]={position:i,type:e,config:{}},Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes),t.dirtyDate=new Date}),o},addNode:(e,i)=>{t(t=>{t.flowDefinition.nodes.push(e),t.flowDefinition._ui.nodes||(t.flowDefinition._ui.nodes={}),t.flowDefinition._ui.nodes[e.uuid]=i,Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes),t.dirtyDate=new Date})},duplicateNodes:i=>{var o,n;const s=e(),r=new Set(i),a={},l=s.flowDefinition._ui.stickies||{};for(const t of i){if(l[t]){a[t]=Kt();continue}const e=s.flowDefinition.nodes.find(e=>e.uuid===t);if(e){a[t]=Kt();for(const t of e.actions)a[t.uuid]=Kt();for(const t of e.exits)a[t.uuid]=Kt();if(e.router){for(const t of e.router.categories)a[t.uuid]=Kt();for(const t of e.router.cases||[])a[t.uuid]=Kt()}}}const d=[],c=[];for(const t of i){if(l[t]){const e=JSON.parse(JSON.stringify(l[t]));c.push({uuid:a[t],sticky:e});continue}const e=s.flowDefinition.nodes.find(e=>e.uuid===t),i=s.flowDefinition._ui.nodes[t];if(!e||!i)continue;const h=JSON.parse(JSON.stringify(e));h.uuid=a[t];for(const t of h.actions)t.uuid=a[t.uuid];for(const t of h.exits)t.uuid=a[t.uuid],t.destination_uuid&&r.has(t.destination_uuid)?t.destination_uuid=a[t.destination_uuid]:t.destination_uuid=null;if(h.router){for(const t of h.router.categories)t.uuid=a[t.uuid],t.exit_uuid=a[t.exit_uuid];if(h.router.cases)for(const t of h.router.cases)t.uuid=a[t.uuid],t.category_uuid=a[t.category_uuid];h.router.default_category_uuid&&(h.router.default_category_uuid=a[h.router.default_category_uuid]),(null===(n=null===(o=h.router.wait)||void 0===o?void 0:o.timeout)||void 0===n?void 0:n.category_uuid)&&(h.router.wait.timeout.category_uuid=a[h.router.wait.timeout.category_uuid])}const u=JSON.parse(JSON.stringify(i));d.push({node:h,ui:u})}const h={},u=s.flowDefinition.localization;if(u)for(const t of Object.keys(u)){const e=u[t];for(const i of Object.keys(a))e[i]&&(h[t]||(h[t]={}),h[t][a[i]]=JSON.parse(JSON.stringify(e[i])))}return t(t=>{for(const{node:e,ui:i}of d)t.flowDefinition.nodes.push(e),t.flowDefinition._ui.nodes[e.uuid]=i;t.flowDefinition._ui.stickies||(t.flowDefinition._ui.stickies={});for(const{uuid:e,sticky:i}of c)t.flowDefinition._ui.stickies[e]=i;for(const e of Object.keys(h)){t.flowDefinition.localization[e]||(t.flowDefinition.localization[e]={});for(const[i,o]of Object.entries(h[e]))t.flowDefinition.localization[e][i]=o}Dd(t.flowDefinition.nodes,t.flowDefinition._ui.nodes)}),a},updateLocalization:(e,i,o)=>{t(t=>{t.flowDefinition.localization||(t.flowDefinition.localization={}),t.flowDefinition.localization[e]||(t.flowDefinition.localization[e]={}),Object.keys(o).length>0?t.flowDefinition.localization[e][i]=o:delete t.flowDefinition.localization[e][i],0===Object.keys(t.flowDefinition.localization[e]).length&&delete t.flowDefinition.localization[e],0===Object.keys(t.flowDefinition.localization).length&&delete t.flowDefinition.localization,t.dirtyDate=new Date})},setTranslationFilters:e=>{t(t=>{var i;if(!(null===(i=t.flowDefinition)||void 0===i?void 0:i._ui))return;const o=t.flowDefinition._ui.translation_filters||{categories:!1},n=!!e.categories;o.categories!==n&&(t.flowDefinition._ui.translation_filters={...o,categories:n},t.dirtyDate=new Date)})},markAutoTranslated:(e,i,o)=>{t(t=>{var n;if(!(null===(n=t.flowDefinition)||void 0===n?void 0:n._ui))return;t.flowDefinition._ui.auto_translations||(t.flowDefinition._ui.auto_translations={}),t.flowDefinition._ui.auto_translations[e]||(t.flowDefinition._ui.auto_translations[e]={});const s=t.flowDefinition._ui.auto_translations[e][i]||[],r=Array.from(new Set([...s,...o||[]]));t.flowDefinition._ui.auto_translations[e][i]=r,t.dirtyDate=new Date})}}))));function Id(t,e){return(i,o)=>{mt()(i,o);const n="connectedCallback",s="disconnectedCallback",r=i[n],a=i[s];i[n]=function(){var i;null!==(i=this._zustandUnsubscribe)&&void 0!==i||(this._zustandUnsubscribe={}),this[o]=e(t.getState()),this._zustandUnsubscribe[o]=t.subscribe(e,t=>{this[o]=t}),r&&r.call(this)},i[s]=function(){var t,e;null===(e=null===(t=this._zustandUnsubscribe)||void 0===t?void 0:t[o])||void 0===e||e.call(t),a&&a.call(this)}}}var Od;!function(t){t.Text="text",t.ExpressionPrefix="prefix",t.Identifier="identifier",t.Paren="paren",t.Operator="operator",t.FunctionName="fn",t.StringLiteral="string",t.NumberLiteral="number",t.Keyword="keyword",t.ContextRef="context-ref",t.Separator="separator",t.Whitespace="ws",t.Arrow="arrow",t.Bracket="bracket",t.EscapedAt="escaped-at"}(Od||(Od={}));const Ld=new Set(["true","false","null"]),Pd=new Set(["+","-","*","/","^","&","=","<",">"]),Rd=t=>t>="0"&&t<="9",Nd=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t>="0"&&t<="9"||"_"===t;function Bd(t,e,i){const o=[];let n=0,s=i;const r=(e=0)=>t[n+e],a=(i,n)=>{const s=t.substring(i,n),r=e+i;if(Ld.has(s.toLowerCase()))return void o.push({type:Od.Keyword,text:s,start:r});let a=n;for(;a<t.length&&" "===t[a];)a++;a<t.length&&"("===t[a]?o.push({type:Od.FunctionName,text:s,start:r}):o.push({type:Od.ContextRef,text:s,start:r})};for(;n<t.length;){const i=t[n];if('"'===i){const i=n;for(n++;n<t.length;)if("\\"===t[n]&&n+1<t.length&&'"'===t[n+1])n+=2;else{if('"'===t[n]){n++;break}n++}o.push({type:Od.StringLiteral,text:t.substring(i,n),start:e+i});continue}if(Rd(i)||"."===i&&r(1)&&Rd(r(1))){const i=n;for(;n<t.length&&Rd(t[n]);)n++;if(n<t.length&&"."===t[n]&&n+1<t.length&&Rd(t[n+1]))for(n++;n<t.length&&Rd(t[n]);)n++;o.push({type:Od.NumberLiteral,text:t.substring(i,n),start:e+i});continue}if(Nd(i)&&!Rd(i)){const e=n;for(;n<t.length&&(Nd(t[n])||"."===t[n])&&("."!==t[n]||!(n+1>=t.length)&&Nd(t[n+1]));)n++;a(e,n);continue}if("("!==i)if(")"!==i)if("["!==i&&"]"!==i)if("="!==i||">"!==r(1))if("!"===i&&"="===r(1)||"<"===i&&"="===r(1)||">"===i&&"="===r(1))o.push({type:Od.Operator,text:i+r(1),start:e+n}),n+=2;else if(Pd.has(i))o.push({type:Od.Operator,text:i,start:e+n}),n++;else if(","!==i){if(" "===i||"\t"===i||"\n"===i||"\r"===i){const i=n;for(;n<t.length&&(" "===t[n]||"\t"===t[n]||"\n"===t[n]||"\r"===t[n]);)n++;o.push({type:Od.Whitespace,text:t.substring(i,n),start:e+i});continue}o.push({type:Od.Text,text:i,start:e+n}),n++}else o.push({type:Od.Separator,text:",",start:e+n}),n++;else o.push({type:Od.Arrow,text:"=>",start:e+n}),n+=2;else o.push({type:Od.Bracket,text:i,start:e+n}),n++;else s--,o.push({type:Od.Paren,text:")",start:e+n,depth:Math.max(0,s),balanced:!0}),n++;else o.push({type:Od.Paren,text:"(",start:e+n,depth:s,balanced:!0}),s++,n++}return o}function Fd(t,e){if(!t)return[];const i=e.findExpressions(t),o=[];let n=0;for(const e of i){if(e.start>n){const i=t.substring(n,e.start);let s=0;for(;s<i.length;){const t=i.indexOf("@@",s);if(-1===t){s<i.length&&o.push({type:Od.Text,text:i.substring(s),start:n+s});break}t>s&&o.push({type:Od.Text,text:i.substring(s,t),start:n+s}),o.push({type:Od.EscapedAt,text:"@@",start:n+t}),s=t+2}}const i=e.text;if(o.push({type:Od.ExpressionPrefix,text:"@",start:e.start}),i.length>1&&"("===i[1]){o.push({type:Od.Paren,text:"(",start:e.start+1,depth:0,balanced:e.closed});const t=e.closed&&")"===i[i.length-1],n=t?i.length-1:i.length,s=i.substring(2,n);if(s.length>0){const t=Bd(s,e.start+2,1);o.push(...t)}t&&o.push({type:Od.Paren,text:")",start:e.start+i.length-1,depth:0,balanced:!0}),e.closed||qd(o,e.start)}else o.push({type:Od.Identifier,text:i.substring(1),start:e.start+1});n=e.end}if(n<t.length){const e=t.substring(n);let i=0;for(;i<e.length;){const t=e.indexOf("@@",i);if(-1===t){i<e.length&&o.push({type:Od.Text,text:e.substring(i),start:n+i});break}t>i&&o.push({type:Od.Text,text:e.substring(i,t),start:n+i}),o.push({type:Od.EscapedAt,text:"@@",start:n+t}),i=t+2}}return o}function qd(t,e){for(const i of t)i.type===Od.Paren&&i.start>=e&&"("===i.text&&0===i.depth&&(i.balanced=!1)}const Ud={expression:"#0086e0",fn:"#0086e0",string:"#06a810",number:"#c25ceb",keyword:"#1750eb",operator:"#666",paren:"#999",parenUnmatched:"#ff0011"},jd={[Od.Text]:"tok-text",[Od.ExpressionPrefix]:"tok-prefix",[Od.Identifier]:"tok-id",[Od.FunctionName]:"tok-fn",[Od.StringLiteral]:"tok-str",[Od.NumberLiteral]:"tok-num",[Od.Keyword]:"tok-kw",[Od.Operator]:"tok-op",[Od.ContextRef]:"tok-ctx",[Od.Separator]:"tok-sep",[Od.Whitespace]:"tok-ws",[Od.Arrow]:"tok-arrow",[Od.Bracket]:"tok-bracket",[Od.EscapedAt]:"tok-text",[Od.Paren]:"tok-paren"},Hd=new Set([Od.ExpressionPrefix,Od.Identifier,Od.FunctionName,Od.StringLiteral,Od.NumberLiteral,Od.Keyword,Od.Operator,Od.ContextRef,Od.Separator,Od.Whitespace,Od.Arrow,Od.Bracket,Od.Paren]);function Wd(t){return t.type===Od.Paren&&!1===t.balanced?"tok-paren-unmatched":jd[t.type]||"tok-text"}const Vd=t=>r(Ud[t]),Zd=a`
617
617
  .tok-text {
618
618
  color: inherit;
619
619
  }
@@ -746,7 +746,7 @@ class ul{constructor(){this.settled=!1,this.promise=new Promise((t,e)=>{this._re
746
746
  </div>`,qc=(t,e,i)=>{const o=[],n=4===t.length?4:Math.min(3,t.length);for(let s=0;s<n;s++)o.push(Fc(t[s],e,i));if(t.length>3&&4!==t.length){const e=t.length-3;o.push(W`<div style="display:flex;align-items:center;margin-top:0.2em;">
747
747
  ${i?W`<div style="margin-right:0.4em; width: 1em;"></div>`:null}
748
748
  <div style="font-size:0.8em">+${e} more</div>
749
- </div>`)}return o},Uc=(t,e)=>qc(t,Fo.FlowClicked,e),jc=(t,e)=>qc(t,Fo.GroupClicked,e),Hc=[{scheme:"tel",name:"SMS",path:"Phone Number"},{scheme:"whatsapp",name:"WhatsApp",path:"WhatsApp Number"},{scheme:"facebook",name:"Facebook",path:"Facebook ID"},{scheme:"instagram",name:"Instagram",path:"Instagram ID"},{scheme:"twitterid",name:"Twitter",path:"Twitter ID",excludeFromSplit:!0},{scheme:"telegram",name:"Telegram",path:"Telegram ID"},{scheme:"viber",name:"Viber",path:"Viber ID"},{scheme:"line",name:"Line",path:"Line ID"},{scheme:"wechat",name:"WeChat",path:"WeChat ID"},{scheme:"fcm",name:"Firebase",path:"Firebase ID"},{scheme:"jiochat",name:"JioChat",path:"JioChat ID"},{scheme:"freshchat",name:"Freshchat",path:"Freshchat ID"},{scheme:"mailto",name:"Email",path:"Email Address",excludeFromSplit:!0},{scheme:"twitter",name:"Twitter",path:"Twitter Handle",excludeFromSplit:!0},{scheme:"vk",name:"VK",path:"VK ID"},{scheme:"discord",name:"Discord",path:"Discord ID"},{scheme:"webchat",name:"Webchat",path:"Webchat ID",excludeFromSplit:!0},{scheme:"rocketchat",name:"RocketChat",path:"RocketChat ID"},{scheme:"ext",name:"External",path:"External ID"}],Wc=(t,e,i)=>{const o=i||document.querySelector(`[id="${t}"]`);if(!o)return null;const n=o.offsetWidth,s=o.offsetHeight;return{uuid:t,left:e.left,top:e.top,right:e.left+n,bottom:e.top+s,width:n,height:s}},Vc=(t,e)=>!(t.right<=e.left-10||t.left>=e.right+10||t.bottom<=e.top-10||t.top>=e.bottom+10),Zc=["down","up","right","left"],Yc=(t,e,i)=>({...t,left:e,top:i,right:e+t.width,bottom:i+t.height}),Kc=(t,e,i)=>{switch(i){case"down":{const i=Math.max(...e.map(t=>t.bottom)),o=Mc(i+30);return{left:t.left,top:o}}case"up":{const i=Math.min(...e.map(t=>t.top)),o=Mc(i-t.height-30);return o<0?{left:t.left,top:0}:{left:t.left,top:o}}case"right":{const i=Math.max(...e.map(t=>t.right));return{left:Mc(i+30),top:t.top}}case"left":{const i=Math.min(...e.map(t=>t.left)),o=Mc(i-t.width-30);return o<0?{left:0,top:t.top}:{left:o,top:t.top}}}};function Gc(t,e){if(!e)return t;const i={...t};for(const o of Object.keys(e)){const n=e[o];Array.isArray(n)&&n.length>0&&(Array.isArray(t[o])?i[o]=n:i[o]=n[0])}return i}const{setLocale:Xc}=(t=>(function(t){if(hl)throw new Error("lit-localize can only be configured once");cl=t,hl=!0}((t,e)=>vl(kl,t,e)),Cl=xl=t.sourceLocale,wl=new Set(t.targetLocales),wl.add(t.sourceLocale),_l=t.loadLocale,{getLocale:$l,setLocale:El}))({sourceLocale:"en",targetLocales:Tl,loadLocale:t=>import(`./locales/${t}.js`)}),Qc=()=>document.querySelector("temba-store");class Jc extends Ve{constructor(){super(...arguments),this.settings={},this.ttl=6e4,this.max=20,this.ready=!1,this.loader=!1,this.keyedAssets={},this.locale=[...navigator.languages],this.fields={},this.groups={},this.shortcuts=[],this.languages={},this.featuredFields=[],this.dirtyElements=[],this.pendingResolves={},this.fetching={}}static get styles(){return a`
749
+ </div>`)}return o},Uc=(t,e)=>qc(t,Fo.FlowClicked,e),jc=(t,e)=>qc(t,Fo.GroupClicked,e),Hc=[{scheme:"tel",name:"SMS",path:"Phone Number"},{scheme:"whatsapp",name:"WhatsApp",path:"WhatsApp Number"},{scheme:"facebook",name:"Facebook",path:"Facebook ID"},{scheme:"instagram",name:"Instagram",path:"Instagram ID"},{scheme:"twitterid",name:"Twitter",path:"Twitter ID",excludeFromSplit:!0},{scheme:"telegram",name:"Telegram",path:"Telegram ID"},{scheme:"viber",name:"Viber",path:"Viber ID"},{scheme:"line",name:"Line",path:"Line ID"},{scheme:"wechat",name:"WeChat",path:"WeChat ID"},{scheme:"fcm",name:"Firebase",path:"Firebase ID"},{scheme:"jiochat",name:"JioChat",path:"JioChat ID"},{scheme:"freshchat",name:"Freshchat",path:"Freshchat ID"},{scheme:"mailto",name:"Email",path:"Email Address",excludeFromSplit:!0},{scheme:"twitter",name:"Twitter",path:"Twitter Handle",excludeFromSplit:!0},{scheme:"vk",name:"VK",path:"VK ID"},{scheme:"discord",name:"Discord",path:"Discord ID"},{scheme:"webchat",name:"Webchat",path:"Webchat ID",excludeFromSplit:!0},{scheme:"rocketchat",name:"RocketChat",path:"RocketChat ID"},{scheme:"ext",name:"External",path:"External ID"}],Wc=(t,e,i)=>{const o=i||document.querySelector(`[id="${t}"]`);if(!o)return null;const n=o.offsetWidth,s=o.offsetHeight;return{uuid:t,left:e.left,top:e.top,right:e.left+n,bottom:e.top+s,width:n,height:s}},Vc=(t,e)=>!(t.right<=e.left-10||t.left>=e.right+10||t.bottom<=e.top-10||t.top>=e.bottom+10),Zc=["down","up","right","left"],Yc=(t,e,i)=>({...t,left:e,top:i,right:e+t.width,bottom:i+t.height}),Kc=(t,e,i)=>{switch(i){case"down":{const i=Math.max(...e.map(t=>t.bottom)),o=Mc(i+30);return{left:t.left,top:o}}case"up":{const i=Math.min(...e.map(t=>t.top)),o=Mc(i-t.height-30);return o<0?{left:t.left,top:0}:{left:t.left,top:o}}case"right":{const i=Math.max(...e.map(t=>t.right));return{left:Mc(i+30),top:t.top}}case"left":{const i=Math.min(...e.map(t=>t.left)),o=Mc(i-t.width-30);return o<0?{left:0,top:t.top}:{left:o,top:t.top}}}};function Gc(t,e){if(!e)return t;const i={...t};for(const o of Object.keys(e)){const n=e[o];Array.isArray(n)&&n.length>0&&(Array.isArray(t[o])?i[o]=n:i[o]=n[0])}return i}const{setLocale:Xc}=(t=>(function(t){if(hl)throw new Error("lit-localize can only be configured once");cl=t,hl=!0}((t,e)=>vl(kl,t,e)),Cl=xl=t.sourceLocale,wl=new Set(t.targetLocales),wl.add(t.sourceLocale),_l=t.loadLocale,{getLocale:$l,setLocale:El}))({sourceLocale:"en",targetLocales:Tl,loadLocale:t=>import(`./locales/${t}.js`)}),Qc=()=>document.querySelector("temba-store");class Jc extends Ve{constructor(){super(...arguments),this.settings={},this.ttl=6e4,this.max=20,this.ready=!1,this.loader=!1,this.brand="",this.keyedAssets={},this.locale=[...navigator.languages],this.fields={},this.groups={},this.shortcuts=[],this.languages={},this.featuredFields=[],this.dirtyElements=[],this.pendingResolves={},this.fetching={}}static get styles(){return a`
750
750
  :host {
751
751
  position: fixed;
752
752
  z-index: 1000;
@@ -757,7 +757,7 @@ class ul{constructor(){this.settled=!1,this.promise=new Promise((t,e)=>{this._re
757
757
  width: 100%;
758
758
  top: 0.5em;
759
759
  }
760
- `}markDirty(t){this.dirtyElements.includes(t)||this.dirtyElements.push(t)}cleanAll(){this.dirtyElements.forEach(t=>t.markClean()),this.dirtyElements=[]}markClean(t){this.dirtyElements=this.dirtyElements.filter(e=>e!==t)}getDirtyMessage(){if(this.dirtyElements.length>0)return this.dirtyElements[0].dirtyMessage||"You have unsaved changes, are you sure you want to continue?"}getLocale(){return this.locale[0]}clearCache(){this.cache=jo(this.max,this.ttl)}reset(){const t=this.getState();this.ready=!1,this.clearCache(),this.settings=JSON.parse($e("settings")||"{}");const e=[];this.completionEndpoint&&e.push(pe(this.completionEndpoint).then(t=>{this.schema=t.json.context,this.fnOptions=t.json.functions})),this.fieldsEndpoint&&e.push(this.refreshFields()),this.globalsEndpoint&&e.push(be(this.globalsEndpoint).then(t=>{this.keyedAssets.globals=t.map(t=>t.key)})),this.languagesEndpoint&&(t.fetchAllLanguages(this.languagesEndpoint),e.push(be(this.languagesEndpoint).then(t=>{this.languages=t.reduce(function(t,e){return t[e.value]=e.name,t},{})}))),this.groupsEndpoint&&e.push(be(this.groupsEndpoint).then(t=>{t.forEach(t=>{this.groups[t.uuid]=t})})),this.workspaceEndpoint&&(t.fetchWorkspace(this.workspaceEndpoint),e.push(pe(this.workspaceEndpoint).then(t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.shortcutsEndpoint&&e.push(this.refreshShortcuts()),this.initialHttpComplete=Promise.all(e),this.initialHttpComplete.then(()=>{this.ready=!0})}getShortcuts(){return this.shortcuts||[]}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}async refreshGlobals(){return be(this.globalsEndpoint).then(t=>{this.keyedAssets.globals=t.map(t=>t.key)})}async refreshShortcuts(){return be(this.shortcutsEndpoint).then(t=>{this.shortcuts=t})}async refreshFields(){return be(this.fieldsEndpoint).then(t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach(t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)}),this.featuredFields.sort((t,e)=>e.priority-t.priority),this.keyedAssets.fields.sort(),this.fireCustomEvent(Fo.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})})}shiftAndRound(t,e,i){const o=Math.round(t.shiftTo(e).get(e));return 1==o?`1 ${i}`:`${o} ${e}`}getCountdown(t){const e=t.diff(rl.now()).rescale();return e.months>0?"> 1 month":e.days>1?`~ ${this.shiftAndRound(e,"days","day")}`:e.hours>0?`~ ${this.shiftAndRound(e,"hours","hour")}`:`~ ${this.shiftAndRound(e,"minutes","minute")}`}getShortDuration(t,e=null){const i=e||rl.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=rl.fromISO(t),o=e?rl.fromISO(e):rl.now();return this.getShortDuration(i,o)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){if(super.updated(t),t.has("ready")&&this.ready){const t=this.getLanguageCode(),e=Tl.find(e=>e===t);e&&Xc(e)}}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){const e=this.languages[t];return e&&"und"!==e&&"und"!==t?e:$c(t)}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return rl.fromISO(t).setLocale(this.getLocale()).toLocaleString(rl.DATETIME_SHORT)}postJSON(t,e=""){return xe(t,e)}postForm(t,e,i={}){return((t,e,i={})=>{const o=new FormData;return Object.keys(e).forEach(t=>{o.append(t,e[t])}),we(t,o,i)})(t,e,i)}postUrl(t,e="",i={},o=null){return ye(t,e,i,o)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise(e=>{e(this.cache.get(t))}):pe(t,e.controller,e.headers||{}).then(i=>new Promise((o,n)=>{i.status>=200&&i.status<=300?(e.skipCache||this.cache.set(t,i),o(i)):n("Status: "+i.status)}))}getResults(t,e){e=e||{};const i="results_"+t,o=this.cache.get(i);return!e.force&&o?new Promise(t=>{t(o)}):new Promise(e=>{const o=this.pendingResolves[t]||[];o.push(e),this.pendingResolves[t]=o,o.length<=1&&fe(t).then(e=>{this.cache.set(i,e);const o=this.pendingResolves[t]||[];for(;o.length>0;){o.pop()(e)}})})}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent(Fo.StoreUpdated,{url:t,data:e})}removeFromCache(t){this.cache.delete(t)}resolveUsers(t,e){return new Promise(i=>{const o=new Set;t.forEach(t=>{e.forEach(e=>{const i=e.split(".");let n=t;for(let t=0;t<i.length&&(n=n[i[t]],n);t++);n&&n.uuid&&o.add(n.uuid)})});const n=[];o.forEach(t=>{n.push(this.getUrl(`/api/v2/users.json?uuid=${encodeURIComponent(t)}`,{force:!0}))}),Promise.all(n).then(o=>{o.forEach(i=>{if(i&&i.json){const o=i.json.results;if(o&&1===o.length){const i=o[0];t.forEach(t=>{e.forEach(e=>{const o=e.split(".");let n=t,s=n;for(let t=0;t<o.length&&(s=n,n=n[o[t]],n);t++);if(n&&n.email===i.email){const t=s[o[o.length-1]];t.avatar=i.avatar,t.name=Ml(i),t.uuid=i.uuid,s[o[o.length-1]].avatar=i.avatar}})})}}}),i()})})}makeRequest(t,e){const i=this.fetching[t],o=(new Date).getTime();if(i)return void setTimeout(()=>{this.makeRequest(t,e)},500);let n=this.cache.get(t);n&&!e.force?(n=e.prepareData?e.prepareData(n):n,this.fireCustomEvent(Fo.StoreUpdated,{url:t,data:n})):(e=e||{},this.fetching[t]=o,fe(t).then(i=>{i?(this.cache.set(t,i),delete this.fetching[t],i=e.prepareData?e.prepareData(i):i,this.fireCustomEvent(Fo.StoreUpdated,{url:t,data:i})):delete this.fetching[t]}))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return W`<temba-loading size="10" units="8"></temba-loading>`}getCompletions(t){const e=this.getState().flowInfo;return"results"===t?e.results.map(t=>t.key):"locals"===t?e.locals:this.keyedAssets[t]||[]}getApp(){return zd}getState(){return zd.getState()}}t([mt({type:Number})],Jc.prototype,"ttl",void 0),t([mt({type:Number})],Jc.prototype,"max",void 0),t([mt({type:Boolean})],Jc.prototype,"ready",void 0),t([mt({type:Boolean})],Jc.prototype,"loader",void 0),t([mt({type:String,attribute:"completion"})],Jc.prototype,"completionEndpoint",void 0),t([mt({type:String,attribute:"fields"})],Jc.prototype,"fieldsEndpoint",void 0),t([mt({type:String,attribute:"groups"})],Jc.prototype,"groupsEndpoint",void 0),t([mt({type:String,attribute:"globals"})],Jc.prototype,"globalsEndpoint",void 0),t([mt({type:String,attribute:"languages"})],Jc.prototype,"languagesEndpoint",void 0),t([mt({type:String,attribute:"workspace"})],Jc.prototype,"workspaceEndpoint",void 0),t([mt({type:String,attribute:"shortcuts"})],Jc.prototype,"shortcutsEndpoint",void 0),t([mt({type:Object,attribute:!1})],Jc.prototype,"schema",void 0),t([mt({type:Object,attribute:!1})],Jc.prototype,"fnOptions",void 0),t([mt({type:Object,attribute:!1})],Jc.prototype,"keyedAssets",void 0);class th extends Ve{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.internalFocusDisabled=!1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.showEmptyMessage=!1,this.scrollParent=null,this.setCursor=Ce(function(t){this.internalFocusDisabled||t!==this.cursorIndex&&(this.cursorIndex=t)},50)}static get styles(){return a`
760
+ `}markDirty(t){this.dirtyElements.includes(t)||this.dirtyElements.push(t)}cleanAll(){this.dirtyElements.forEach(t=>t.markClean()),this.dirtyElements=[]}markClean(t){this.dirtyElements=this.dirtyElements.filter(e=>e!==t)}getDirtyMessage(){if(this.dirtyElements.length>0)return this.dirtyElements[0].dirtyMessage||"You have unsaved changes, are you sure you want to continue?"}getLocale(){return this.locale[0]}clearCache(){this.cache=jo(this.max,this.ttl)}reset(){const t=this.getState();this.ready=!1,this.clearCache(),this.settings=JSON.parse($e("settings")||"{}"),zd.setState({brand:this.brand});const e=[];this.completionEndpoint&&e.push(pe(this.completionEndpoint).then(t=>{this.schema=t.json.context,this.fnOptions=t.json.functions})),this.fieldsEndpoint&&e.push(this.refreshFields()),this.globalsEndpoint&&e.push(be(this.globalsEndpoint).then(t=>{this.keyedAssets.globals=t.map(t=>t.key)})),this.languagesEndpoint&&(t.fetchAllLanguages(this.languagesEndpoint),e.push(be(this.languagesEndpoint).then(t=>{this.languages=t.reduce(function(t,e){return t[e.value]=e.name,t},{})}))),this.groupsEndpoint&&e.push(be(this.groupsEndpoint).then(t=>{t.forEach(t=>{this.groups[t.uuid]=t})})),this.workspaceEndpoint&&(t.fetchWorkspace(this.workspaceEndpoint),e.push(pe(this.workspaceEndpoint).then(t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.shortcutsEndpoint&&e.push(this.refreshShortcuts()),this.initialHttpComplete=Promise.all(e),this.initialHttpComplete.then(()=>{this.ready=!0})}getShortcuts(){return this.shortcuts||[]}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}async refreshGlobals(){return be(this.globalsEndpoint).then(t=>{this.keyedAssets.globals=t.map(t=>t.key)})}async refreshShortcuts(){return be(this.shortcutsEndpoint).then(t=>{this.shortcuts=t})}async refreshFields(){return be(this.fieldsEndpoint).then(t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach(t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)}),this.featuredFields.sort((t,e)=>e.priority-t.priority),this.keyedAssets.fields.sort(),this.fireCustomEvent(Fo.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})})}shiftAndRound(t,e,i){const o=Math.round(t.shiftTo(e).get(e));return 1==o?`1 ${i}`:`${o} ${e}`}getCountdown(t){const e=t.diff(rl.now()).rescale();return e.months>0?"> 1 month":e.days>1?`~ ${this.shiftAndRound(e,"days","day")}`:e.hours>0?`~ ${this.shiftAndRound(e,"hours","hour")}`:`~ ${this.shiftAndRound(e,"minutes","minute")}`}getShortDuration(t,e=null){const i=e||rl.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=rl.fromISO(t),o=e?rl.fromISO(e):rl.now();return this.getShortDuration(i,o)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){if(super.updated(t),t.has("ready")&&this.ready){const t=this.getLanguageCode(),e=Tl.find(e=>e===t);e&&Xc(e)}}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){const e=this.languages[t];return e&&"und"!==e&&"und"!==t?e:$c(t)}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return rl.fromISO(t).setLocale(this.getLocale()).toLocaleString(rl.DATETIME_SHORT)}postJSON(t,e=""){return xe(t,e)}postForm(t,e,i={}){return((t,e,i={})=>{const o=new FormData;return Object.keys(e).forEach(t=>{o.append(t,e[t])}),we(t,o,i)})(t,e,i)}postUrl(t,e="",i={},o=null){return ye(t,e,i,o)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise(e=>{e(this.cache.get(t))}):pe(t,e.controller,e.headers||{}).then(i=>new Promise((o,n)=>{i.status>=200&&i.status<=300?(e.skipCache||this.cache.set(t,i),o(i)):n("Status: "+i.status)}))}getResults(t,e){e=e||{};const i="results_"+t,o=this.cache.get(i);return!e.force&&o?new Promise(t=>{t(o)}):new Promise(e=>{const o=this.pendingResolves[t]||[];o.push(e),this.pendingResolves[t]=o,o.length<=1&&fe(t).then(e=>{this.cache.set(i,e);const o=this.pendingResolves[t]||[];for(;o.length>0;){o.pop()(e)}})})}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent(Fo.StoreUpdated,{url:t,data:e})}removeFromCache(t){this.cache.delete(t)}resolveUsers(t,e){return new Promise(i=>{const o=new Set;t.forEach(t=>{e.forEach(e=>{const i=e.split(".");let n=t;for(let t=0;t<i.length&&(n=n[i[t]],n);t++);n&&n.uuid&&o.add(n.uuid)})});const n=[];o.forEach(t=>{n.push(this.getUrl(`/api/v2/users.json?uuid=${encodeURIComponent(t)}`,{force:!0}))}),Promise.all(n).then(o=>{o.forEach(i=>{if(i&&i.json){const o=i.json.results;if(o&&1===o.length){const i=o[0];t.forEach(t=>{e.forEach(e=>{const o=e.split(".");let n=t,s=n;for(let t=0;t<o.length&&(s=n,n=n[o[t]],n);t++);if(n&&n.email===i.email){const t=s[o[o.length-1]];t.avatar=i.avatar,t.name=Ml(i),t.uuid=i.uuid,s[o[o.length-1]].avatar=i.avatar}})})}}}),i()})})}makeRequest(t,e){const i=this.fetching[t],o=(new Date).getTime();if(i)return void setTimeout(()=>{this.makeRequest(t,e)},500);let n=this.cache.get(t);n&&!e.force?(n=e.prepareData?e.prepareData(n):n,this.fireCustomEvent(Fo.StoreUpdated,{url:t,data:n})):(e=e||{},this.fetching[t]=o,fe(t).then(i=>{i?(this.cache.set(t,i),delete this.fetching[t],i=e.prepareData?e.prepareData(i):i,this.fireCustomEvent(Fo.StoreUpdated,{url:t,data:i})):delete this.fetching[t]}))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return W`<temba-loading size="10" units="8"></temba-loading>`}getCompletions(t){const e=this.getState().flowInfo;return"results"===t?e.results.map(t=>t.key):"locals"===t?e.locals:this.keyedAssets[t]||[]}getApp(){return zd}getState(){return zd.getState()}}t([mt({type:Number})],Jc.prototype,"ttl",void 0),t([mt({type:Number})],Jc.prototype,"max",void 0),t([mt({type:Boolean})],Jc.prototype,"ready",void 0),t([mt({type:Boolean})],Jc.prototype,"loader",void 0),t([mt({type:String,attribute:"completion"})],Jc.prototype,"completionEndpoint",void 0),t([mt({type:String,attribute:"fields"})],Jc.prototype,"fieldsEndpoint",void 0),t([mt({type:String,attribute:"groups"})],Jc.prototype,"groupsEndpoint",void 0),t([mt({type:String,attribute:"globals"})],Jc.prototype,"globalsEndpoint",void 0),t([mt({type:String,attribute:"languages"})],Jc.prototype,"languagesEndpoint",void 0),t([mt({type:String,attribute:"workspace"})],Jc.prototype,"workspaceEndpoint",void 0),t([mt({type:String,attribute:"shortcuts"})],Jc.prototype,"shortcutsEndpoint",void 0),t([mt({type:String})],Jc.prototype,"brand",void 0),t([mt({type:Object,attribute:!1})],Jc.prototype,"schema",void 0),t([mt({type:Object,attribute:!1})],Jc.prototype,"fnOptions",void 0),t([mt({type:Object,attribute:!1})],Jc.prototype,"keyedAssets",void 0);class th extends Ve{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.internalFocusDisabled=!1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.showEmptyMessage=!1,this.scrollParent=null,this.setCursor=Ce(function(t){this.internalFocusDisabled||t!==this.cursorIndex&&(this.cursorIndex=t)},50)}static get styles(){return a`
761
761
  :host {
762
762
  --transition-speed: 0;
763
763
  }
@@ -1846,10 +1846,7 @@ class ul{constructor(){this.settled=!1,this.promise=new Promise((t,e)=>{this._re
1846
1846
  }
1847
1847
 
1848
1848
  .dialog-footer {
1849
- background: var(
1850
- --dialog-footer-background,
1851
- var(--color-primary-light)
1852
- );
1849
+ background: var(--dialog-footer-background, var(--color-primary-light));
1853
1850
  padding: var(--dialog-footer-padding-top, 10px) 10px 10px;
1854
1851
  display: flex;
1855
1852
  flex-flow: row;
@@ -8879,7 +8876,7 @@ background: #ccc;
8879
8876
  ${this.renderUploader()}
8880
8877
  </div>
8881
8878
  </div>
8882
- </div>`}}t([mt({type:String,attribute:!1})],rp.prototype,"endpoint",void 0),t([mt({type:Boolean})],rp.prototype,"pendingDrop",void 0),t([mt({type:Boolean})],rp.prototype,"ignoreDrops",void 0),t([mt({type:String})],rp.prototype,"icon",void 0),t([mt({type:String})],rp.prototype,"accept",void 0),t([mt({type:Number})],rp.prototype,"max",void 0),t([mt({type:Array})],rp.prototype,"attachments",void 0),t([mt({type:Boolean,attribute:!1})],rp.prototype,"uploading",void 0);let ap="dev";try{ap="0.156.14"}catch(t){}const lp=ap,dp="message",cp="voice",hp="background",up={[dp]:[{type:"send_msg",name:"Send Message",icon:"send"},{type:"wait_for_response",name:"Wait for Response",icon:"message"}],[cp]:[{type:"say_msg",name:"Say Message",icon:"recording"},{type:"wait_for_menu",name:"Wait for Menu",icon:"dots-grid"}],[hp]:[{type:"set_contact_field",name:"Update Contact",icon:"contact"}]},pp="ai",mp="airtime",gp="auto_translate",fp={send:"send",contacts:"contacts",save:"save",services:"services",broadcast:"broadcast",trigger:"trigger"},vp={wait:"wait",split:"split"},bp={[fp.send]:{color:"#3498db",title:"Send",description:"Actions that send messages or content to contacts"},[fp.contacts]:{color:"#01c1af",title:"Contact",description:"Actions that update contact information"},[fp.save]:{color:"#1a777c",title:"Save",description:"Actions that save or store data"},[fp.services]:{color:"#f79035ff",title:"Services",description:"Call external services and APIs"},[fp.broadcast]:{color:"#8e5ea7",title:"Other People",description:"Actions that apply to others instead of the contact"},[fp.trigger]:{color:"#df419f",title:"Trigger",description:"Actions that trigger other behavior"}},yp={[vp.wait]:{color:"#4d7dad",title:"Wait",description:"Wait for user and split on their response"},[vp.split]:{color:"#aaaaaa",title:"Split",description:"Split the flow based on conditions"}},xp={name:"Add Input Labels",group:fp.save,flowTypes:[cp,dp,hp],render:(t,e)=>{return W`<div>${i=e.labels,o="label",Nc(i.map(t=>t.name),o)}</div>`;var i,o},toFormData:t=>({labels:t.labels||null,uuid:t.uuid}),form:{labels:{type:"select",label:"Labels",helpText:"Select labels to add to the input. Type a new label name to create it.",required:!0,options:[],multi:!0,searchable:!0,endpoint:"/api/v2/labels.json",valueKey:"uuid",nameKey:"name",placeholder:"Search for labels or type to create new ones...",allowCreate:!0,createArbitraryOption:(t,e)=>!e.find(e=>e.name.toLowerCase().trim()===t.toLowerCase().trim())&&t.trim()?{name:t.trim(),arbitrary:!0}:null}},fromFormData:t=>({uuid:t.uuid,type:"add_input_labels",labels:(t.labels||[]).map(t=>({uuid:t.uuid,name:t.name}))})},wp={name:"Add URN",group:fp.contacts,flowTypes:[cp,dp,hp],render:(t,e)=>{const i=Hc.find(t=>t.scheme===e.scheme),o=(null==i?void 0:i.path)||e.scheme;return Pc(W`Add ${o} ${Lc(e.path,!0)}`,`Add ${o} ${e.path}`)},toFormData:t=>{const e=Hc.find(e=>e.scheme===t.scheme);return{uuid:t.uuid,scheme:e?[{name:e.path,value:t.scheme}]:null,path:t.path||""}},fromFormData:t=>{const e=Array.isArray(t.scheme)&&t.scheme.length>0?t.scheme[0].value:"tel";return{uuid:t.uuid,type:"add_contact_urn",scheme:e,path:t.path||""}},form:{scheme:{type:"select",label:"URN Type",helpText:"Select the type of URN to add to the contact",required:!0,searchable:!1,multi:!1,options:Hc.map(t=>({name:t.path,value:t.scheme}))},path:{type:"text",label:"URN Value",helpText:"Enter the URN value (e.g., phone number, Facebook ID, etc.)",required:!0,placeholder:"Enter the URN value...",evaluated:!0}},validate:t=>{const e={};return t.scheme&&0!==t.scheme.length||(e.scheme="URN type is required"),t.path&&""!==t.path.trim()||(e.path="URN value is required"),{valid:0===Object.keys(e).length,errors:e}}},_p={name:"Update Field",group:fp.contacts,flowTypes:[cp,dp,hp],render:(t,e)=>e.value?Pc(W`Set <strong>${e.field.name}</strong> to
8879
+ </div>`}}t([mt({type:String,attribute:!1})],rp.prototype,"endpoint",void 0),t([mt({type:Boolean})],rp.prototype,"pendingDrop",void 0),t([mt({type:Boolean})],rp.prototype,"ignoreDrops",void 0),t([mt({type:String})],rp.prototype,"icon",void 0),t([mt({type:String})],rp.prototype,"accept",void 0),t([mt({type:Number})],rp.prototype,"max",void 0),t([mt({type:Array})],rp.prototype,"attachments",void 0),t([mt({type:Boolean,attribute:!1})],rp.prototype,"uploading",void 0);let ap="dev";try{ap="0.156.15"}catch(t){}const lp=ap,dp="message",cp="voice",hp="background",up={[dp]:[{type:"send_msg",name:"Send Message",icon:"send"},{type:"wait_for_response",name:"Wait for Response",icon:"message"}],[cp]:[{type:"say_msg",name:"Say Message",icon:"recording"},{type:"wait_for_menu",name:"Wait for Menu",icon:"dots-grid"}],[hp]:[{type:"set_contact_field",name:"Update Contact",icon:"contact"}]},pp="ai",mp="airtime",gp="auto_translate",fp={send:"send",contacts:"contacts",save:"save",services:"services",broadcast:"broadcast",trigger:"trigger"},vp={wait:"wait",split:"split"},bp={[fp.send]:{color:"#3498db",title:"Send",description:"Actions that send messages or content to contacts"},[fp.contacts]:{color:"#01c1af",title:"Contact",description:"Actions that update contact information"},[fp.save]:{color:"#1a777c",title:"Save",description:"Actions that save or store data"},[fp.services]:{color:"#f79035ff",title:"Services",description:"Call external services and APIs"},[fp.broadcast]:{color:"#8e5ea7",title:"Other People",description:"Actions that apply to others instead of the contact"},[fp.trigger]:{color:"#df419f",title:"Trigger",description:"Actions that trigger other behavior"}},yp={[vp.wait]:{color:"#4d7dad",title:"Wait",description:"Wait for user and split on their response"},[vp.split]:{color:"#aaaaaa",title:"Split",description:"Split the flow based on conditions"}},xp={name:"Add Input Labels",group:fp.save,flowTypes:[cp,dp,hp],render:(t,e)=>{return W`<div>${i=e.labels,o="label",Nc(i.map(t=>t.name),o)}</div>`;var i,o},toFormData:t=>({labels:t.labels||null,uuid:t.uuid}),form:{labels:{type:"select",label:"Labels",helpText:"Select labels to add to the input. Type a new label name to create it.",required:!0,options:[],multi:!0,searchable:!0,endpoint:"/api/v2/labels.json",valueKey:"uuid",nameKey:"name",placeholder:"Search for labels or type to create new ones...",allowCreate:!0,createArbitraryOption:(t,e)=>!e.find(e=>e.name.toLowerCase().trim()===t.toLowerCase().trim())&&t.trim()?{name:t.trim(),arbitrary:!0}:null}},fromFormData:t=>({uuid:t.uuid,type:"add_input_labels",labels:(t.labels||[]).map(t=>({uuid:t.uuid,name:t.name}))})},wp={name:"Add URN",group:fp.contacts,flowTypes:[cp,dp,hp],render:(t,e)=>{const i=Hc.find(t=>t.scheme===e.scheme),o=(null==i?void 0:i.path)||e.scheme;return Pc(W`Add ${o} ${Lc(e.path,!0)}`,`Add ${o} ${e.path}`)},toFormData:t=>{const e=Hc.find(e=>e.scheme===t.scheme);return{uuid:t.uuid,scheme:e?[{name:e.path,value:t.scheme}]:null,path:t.path||""}},fromFormData:t=>{const e=Array.isArray(t.scheme)&&t.scheme.length>0?t.scheme[0].value:"tel";return{uuid:t.uuid,type:"add_contact_urn",scheme:e,path:t.path||""}},form:{scheme:{type:"select",label:"URN Type",helpText:"Select the type of URN to add to the contact",required:!0,searchable:!1,multi:!1,options:Hc.map(t=>({name:t.path,value:t.scheme}))},path:{type:"text",label:"URN Value",helpText:"Enter the URN value (e.g., phone number, Facebook ID, etc.)",required:!0,placeholder:"Enter the URN value...",evaluated:!0}},validate:t=>{const e={};return t.scheme&&0!==t.scheme.length||(e.scheme="URN type is required"),t.path&&""!==t.path.trim()||(e.path="URN value is required"),{valid:0===Object.keys(e).length,errors:e}}},_p={name:"Update Field",group:fp.contacts,flowTypes:[cp,dp,hp],render:(t,e)=>e.value?Pc(W`Set <strong>${e.field.name}</strong> to
8883
8880
  ${Lc(e.value,!0)}`,`Set ${e.field.name} to ${e.value}`):Pc(W`Clear <strong>${e.field.name}</strong>`,`Clear ${e.field.name}`),form:{field:{type:"select",label:"Field",required:!0,searchable:!0,clearable:!1,placeholder:"Search for contact fields...",nameKey:"name",valueKey:"key",endpoint:"/api/v2/fields.json",helpText:"Select the contact field to update",allowCreate:!0,createArbitraryOption:t=>({key:t,name:t,type:"text"})},value:{type:"textarea",label:"Value",placeholder:"Enter field value...",evaluated:!0,helpText:"The new value for the contact field. You can use expressions like @contact.name"}},toFormData:t=>({uuid:t.uuid,field:t.field?[t.field]:null,value:t.value}),fromFormData:t=>{const e=t.field[0];return{uuid:t.uuid,type:"set_contact_field",field:{name:e.name,key:e.key},value:t.value}},sanitize:t=>{t.value&&"string"==typeof t.value&&(t.value=t.value.trim())}},kp={name:"Update Channel",group:fp.contacts,flowTypes:[cp,dp,hp],render:(t,e)=>Pc(W`Set to <strong>${e.channel.name}</strong>`,`Set to ${e.channel.name}`),form:{channel:{type:"select",label:"Channel",required:!0,searchable:!0,clearable:!1,endpoint:"/api/v2/channels.json",valueKey:"uuid",nameKey:"name",placeholder:"Select channel",helpText:"Select the channel to set for the contact"}},toFormData:t=>({uuid:t.uuid,channel:t.channel?[t.channel]:null}),fromFormData:t=>{var e;const i=null===(e=t.channel)||void 0===e?void 0:e[0];return{uuid:t.uuid,type:"set_contact_channel",channel:{uuid:i.uuid||i.value,name:i.name}}}},Cp={name:"Update Language",group:fp.contacts,flowTypes:[cp,dp,hp],render:(t,e)=>{const i=$c(e.language);return Pc(W`Set to <strong>${i}</strong>`,`Set to ${i}`)},form:{language:{type:"select",label:"Language",required:!0,searchable:!0,clearable:!1,valueKey:"value",nameKey:"name",helpText:"Select the language to set for the contact",getDynamicOptions:()=>{const t=Qc(),e=null==t?void 0:t.getState().workspace;return(null==e?void 0:e.languages)&&Array.isArray(e.languages)?e.languages.map(t=>({value:t,name:$c(t)})):[]}}},toFormData:t=>t.language?{language:[{value:t.language,name:$c(t.language)}],uuid:t.uuid}:{language:null,uuid:t.uuid},fromFormData:t=>({uuid:t.uuid,type:"set_contact_language",language:t.language[0].value}),validate:t=>{const e={};return t.language||(e.language="Language is required"),{valid:0===Object.keys(e).length,errors:e}}},Sp={name:"Update Status",group:fp.contacts,flowTypes:[cp,dp,hp],render:(t,e)=>Pc(W`Set to <strong>${je(e.status)}</strong>`,`Set to ${je(e.status)}`),toFormData:t=>({uuid:t.uuid,status:[{name:je(t.status||"active"),value:t.status||"active"}]}),fromFormData:t=>({status:t.status[0].value,type:"set_contact_status",uuid:t.uuid}),form:{status:{type:"select",label:"Status",required:!0,searchable:!1,clearable:!1,options:[{value:"active",name:"Active"},{value:"archived",name:"Archived"},{value:"stopped",name:"Stopped"},{value:"blocked",name:"Blocked"}],helpText:"Select the status to set for the contact"}}},Ap={name:"Send Broadcast",group:fp.broadcast,flowTypes:[cp,dp,hp],render:(t,e)=>{const i=[...(e.groups||[]).map(t=>({name:t.name,icon:Do.group,uuid:t.uuid,eventType:Fo.GroupClicked})),...(e.contacts||[]).map(t=>({name:t.name,icon:Do.contacts,uuid:t.uuid,eventType:Fo.ContactClicked})),...(e.legacy_vars||[]).map(t=>({name:t,icon:Do.contacts,content:Lc(t,!0)}))];return W`<div>
8884
8881
  <div>${Bc(i)}</div>
8885
8882
  <div style="margin-top: 0.5em">
@@ -9377,7 +9374,7 @@ background: #ccc;
9377
9374
  </button>
9378
9375
  `)}
9379
9376
  </div>
9380
- `}}function Fm(t,e){if(!t||!(null==e?void 0:e.length))return[];const i=Rm[t],o=null==i?void 0:i.nonTranslatableCategories;if(!o)return[...e];if("all"===o)return e.filter(t=>Qt.has(t.name));const n=new Set(o);return e.filter(t=>!n.has(t.name)||Qt.has(t.name))}function qm(t){if(null==t)return null;if(Array.isArray(t)){const e=t.map(t=>qm(t)).filter(t=>!!t);return e.length>0?e.join(", "):null}if("object"==typeof t)return"name"in t&&t.name?String(t.name):"arguments"in t&&Array.isArray(t.arguments)?t.arguments.join(" "):null;if("number"==typeof t)return t.toString();if("string"==typeof t){const e=t.trim();return e.length>0?e:null}return null}function Um(t,e,i,o,n){const s=[];return i.forEach(i=>{if("quick_replies"===i)return;const r=i.split(".");let a=o,l=[];for(;r.length>0&&a;){a.uuid&&(l=n[a.uuid]);const t=r.shift();if(!t)break;l&&(l=l[t]),a=a[t]}if(!a)return;const d=qm(a);if(!d)return;const c=l?qm(l):null;s.push({uuid:e,type:t,attribute:i,from:d,to:c})}),s}function jm(t,e){var i;if(!t||!e||e===t.language)return[];const o=(null===(i=t.localization)||void 0===i?void 0:i[e])||{},n=[];return t.nodes.forEach(e=>{var i,s,r,a,l,d,c,h,u;null===(i=e.actions)||void 0===i||i.forEach(t=>{const i=Lm[t.type];if(!(null==i?void 0:i.localizable)||0===i.localizable.length)return;const s="send_msg"===t.type?i.localizable.filter(t=>"text"===t):i.localizable,r=Um("property",t.uuid,s,t,o);r.length>0&&n.push({nodeUuid:e.uuid,actionUuid:t.uuid,translations:r})});const p=null===(r=null===(s=t._ui)||void 0===s?void 0:s.nodes)||void 0===r?void 0:r[e.uuid],m=null==p?void 0:p.type;if(!m)return;if((null===(a=null==p?void 0:p.config)||void 0===a?void 0:a.localizeRules)&&(null===(d=null===(l=e.router)||void 0===l?void 0:l.cases)||void 0===d?void 0:d.length)){const t=e.router.cases.filter(t=>{var e;return(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&t.arguments.some(t=>t)}).flatMap(t=>Um("property",t.uuid,["arguments"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}const g=Rm[m];if((null===(c=null==p?void 0:p.config)||void 0===c?void 0:c.localizeCategories)&&"categories"===(null==g?void 0:g.localizable)&&(null===(u=null===(h=e.router)||void 0===h?void 0:h.categories)||void 0===u?void 0:u.length)){const t=Fm(m,e.router.categories).flatMap(t=>Um("category",t.uuid,["name"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}}),n}t([mt({type:Boolean,attribute:"message-view"})],Bm.prototype,"messageView",void 0),t([mt({type:Number})],Bm.prototype,"zoom",void 0),t([mt({type:Boolean,attribute:"zoom-initialized"})],Bm.prototype,"zoomInitialized",void 0),t([mt({type:Boolean,attribute:"zoom-fitted"})],Bm.prototype,"zoomFitted",void 0),t([mt({type:Boolean,attribute:"revisions-active"})],Bm.prototype,"revisionsActive",void 0),t([mt({type:Boolean,attribute:"is-saving"})],Bm.prototype,"isSaving",void 0),t([mt({type:Boolean,attribute:"search-disabled"})],Bm.prototype,"searchDisabled",void 0),t([mt({type:Array})],Bm.prototype,"languageOptions",void 0),t([mt({type:String,attribute:"current-language-name"})],Bm.prototype,"currentLanguageName",void 0),t([mt({type:Boolean,attribute:"is-base-language"})],Bm.prototype,"isBaseLanguage",void 0),t([mt({type:Number,attribute:"language-percent"})],Bm.prototype,"languagePercent",void 0),t([mt({type:Boolean,attribute:"show-localization-tools"})],Bm.prototype,"showLocalizationTools",void 0),t([mt({type:Boolean,attribute:"has-pending-translations"})],Bm.prototype,"hasPendingTranslations",void 0),t([mt({type:Boolean,attribute:"auto-translate-disabled"})],Bm.prototype,"autoTranslateDisabled",void 0),t([mt({type:Boolean,attribute:"auto-translating"})],Bm.prototype,"autoTranslating",void 0),t([gt()],Bm.prototype,"showLanguageOptions",void 0);const Hm=60,Wm=20;function Vm(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=Zm(e.get(u),i);for(const e of p){const p=Mc(h);if(u===t[0]){let t=0;for(const o of e){const e=o===s?p:p+40;c[o]={left:Mc(t),top:e},t+=((null===(r=i.get(o))||void 0===r?void 0:r.width)||200)+Hm}}else{let t=0;for(const o of e)t+=(null===(a=i.get(o))||void 0===a?void 0:a.width)||200;t+=Hm*(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:Mc(h),top:p},h=Mc(h)+e+Hm}}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:Mc(Math.max(0,c[i].left-t)),top:Mc(Math.max(0,c[i].top-e))}}return c}(c,d,h,r,l,i)}function Zm(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?Hm+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 Ym(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}function Km(t){if("touches"in t){const e=t.touches[0]||t.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}}return{clientX:t.clientX,clientY:t.clientY}}function Gm(t,e,i,o,n=20,s=10,r=5,a="top",l=0){const d=r;if("top"===a){const r=e+n,a=o-s;let c=`M ${t} ${e}`;if(t===i)c+=` L ${i} ${a}`;else{const o=i>t?1:-1,n=Math.max(e+d,Math.min(r,a-d)),s=Math.max(e+d,Math.min(n+l,a-d-3)),h=Math.min(d,s-e);h>=1?(c+=` L ${t} ${s-h}`,c+=` Q ${t} ${s}, ${t+o*h} ${s}`):c+=` L ${t} ${s}`;const u=3,p=Math.min(d,Math.max(0,a-s-u));p>=1?(c+=` L ${i-o*p} ${s}`,c+=` Q ${i} ${s}, ${i} ${s+p}`):c+=` L ${i} ${s}`,c+=` L ${i} ${a}`}return c+=` L ${i} ${o}`,c}if("left"===a||"right"===a){const r=e+(o<e?0:n),l="left"===a?-1:1,c=i+l*s,h=c>t?1:-1,u=3,p=h===l?r+2*d:Math.max(r+2*d,o);let m=`M ${t} ${e} L ${t} ${r}`;p-r>d&&(m+=` L ${t} ${p-d}`,m+=` Q ${t} ${p}, ${t+h*d} ${p}`);const g=Math.abs(p-o);if(g<1)m+=` L ${c} ${o}`,m+=` L ${i} ${o}`;else{const t=o<p?-1:1,e=Math.min(d,Math.max(0,Math.floor((g-u)/2)),Math.max(0,s-u));e>=1?(m+=` L ${c-h*e} ${p}`,m+=` Q ${c} ${p}, ${c} ${p+t*e}`,m+=` L ${c} ${o-t*e}`,m+=` Q ${c} ${o}, ${c-l*e} ${o}`):(m+=` L ${c} ${p}`,m+=` L ${c} ${o}`),m+=` L ${i} ${o}`}return m}return`M ${t} ${e} L ${i} ${o}`}class Xm{constructor(t,e){this.connections=new Map,this.sources=new Map,this.pendingConnections=[],this.connectionWait=null,this.connectionListeners=new Map,this.dragState=null,this.retryCount=0,this.maxRetries=3,this.activityData=null,this.overlays=new Map,this.hoveredActivityKey=null,this.recentContactsPopup=null,this.recentContactsCache={},this.pendingFetches={},this.hideContactsTimeout=null,this.showContactsTimeout=null,this.connectionDragging=!1,this.zoom=1,this.canvas=t,this.editor=e}setContainer(t){this.canvas=t}notifyListeners(t,e){(this.connectionListeners.get(t)||[]).forEach(t=>t(e))}on(t,e){this.connectionListeners.has(t)||this.connectionListeners.set(t,[]),this.connectionListeners.get(t).push(e)}off(t,e){if(!this.connectionListeners.has(t))return;const i=this.connectionListeners.get(t),o=i.indexOf(e);-1!==o&&i.splice(o,1)}makeSource(t){const e=document.getElementById(t);if(!e)return;this.sources.has(t)&&this.sources.get(t)();let i=null;const o=o=>{if("button"in o&&Tc(o))return;if(this.connections.has(t))return;const n="touches"in o;n&&o.preventDefault();const{clientX:s,clientY:r}=Km(o),a=e.closest("temba-flow-node"),l=(null==a?void 0:a.getAttribute("uuid"))||"",d=e=>{const{clientX:i,clientY:o}=Km(e),n=i-s,a=o-r;Math.sqrt(n*n+a*a)>5&&(h(),this.startDrag(t,l,null,e))},c=()=>{h()},h=()=>{document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",c),document.removeEventListener("touchmove",d),document.removeEventListener("touchend",c),document.removeEventListener("touchcancel",c),i=null};document.addEventListener("mousemove",d),document.addEventListener("mouseup",c),document.addEventListener("touchmove",d,{passive:!1}),document.addEventListener("touchend",c),document.addEventListener("touchcancel",c),i={startX:s,startY:r,onMove:d,onUp:c,isTouch:n}};e.addEventListener("mousedown",o),e.addEventListener("touchstart",o,{passive:!1}),this.sources.set(t,()=>{e.removeEventListener("mousedown",o),e.removeEventListener("touchstart",o),i&&(document.removeEventListener("mousemove",i.onMove),document.removeEventListener("mouseup",i.onUp),document.removeEventListener("touchmove",i.onMove),document.removeEventListener("touchend",i.onUp),document.removeEventListener("touchcancel",i.onUp),i=null)})}makeTarget(t){}connectIds(t,e,i){this.pendingConnections.push({scope:t,fromId:e,toId:i}),this.processPendingConnections()}processPendingConnections(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.connectionWait=requestAnimationFrame(()=>{const t=[],e=new Set;if(this.pendingConnections.forEach(i=>{const{scope:o,fromId:n,toId:s}=i;this.removeConnectionSVG(n),this.createConnectionSVG(n,o,s)?e.add(s):t.push(i)}),this.pendingConnections=[],e.size>0){const t=new Set;this.connections.forEach(i=>{e.has(i.toId)&&t.add(i.scope)}),this.connections.forEach((i,o)=>{(e.has(i.toId)||t.has(i.scope))&&this.updateConnectionSVG(o)})}t.length>0&&this.retryCount<this.maxRetries?(this.retryCount++,this.pendingConnections=t,this.processPendingConnections()):this.retryCount=0})}toCanvas(t){return t/this.zoom}determineTargetFace(t,e,i,o){return o-e>30?"top":t<i?"left":"right"}getConnectionEndpoints(t,e,i){const o=document.getElementById(t),n=document.getElementById(e);if(!o||!n)return null;const s=this.canvas.getBoundingClientRect(),r=o.getBoundingClientRect(),a=n.getBoundingClientRect();if(0===r.width||0===a.width)return null;const l=this.toCanvas(r.left+r.width/2-s.left),d=this.toCanvas(r.bottom-s.top),c=this.toCanvas(a.left+a.width/2-s.left),h=this.toCanvas(a.top-s.top),u=this.determineTargetFace(l,d,c,h),p=new Map;this.connections.forEach(t=>{if(t.toId===e){const e=document.getElementById(t.fromId);if(e){const i=e.getBoundingClientRect(),o=this.toCanvas(i.left+i.width/2-s.left),n=this.toCanvas(i.bottom-s.top),r=this.determineTargetFace(o,n,c,h);p.has(r)||p.set(r,[]);const a="top"===r?o:n;p.get(r).push({fromId:t.fromId,sortPos:a})}}}),p.has(u)||p.set(u,[]);const m=p.get(u);if(!m.find(e=>e.fromId===t)){const e="top"===u?l:d;m.push({fromId:t,sortPos:e})}m.sort((t,e)=>t.sortPos-e.sortPos);const g=m.findIndex(e=>e.fromId===t),f=m.length,v=this.toCanvas(a.left-s.left),b=h,y=this.toCanvas(a.width),x=this.toCanvas(a.height);let w,_;if("top"===u){w=1===f?v+y/2:v+.2*y+.6*y*(g+.5)/f,_=b}else if("left"===u){w=v;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}else{w=v+y;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}let k=0;if("top"===u&&i){const o=8,n=50,r=[];if(this.connections.forEach(t=>{if(t.scope===i&&t.toId!==e){const e=document.getElementById(t.fromId),i=document.getElementById(t.toId);if(e&&i){const o=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=this.toCanvas(o.left+o.width/2-s.left),l=this.toCanvas(o.bottom-s.top),d=this.toCanvas(n.left+n.width/2-s.left),c=this.toCanvas(n.top-s.top);if("top"===this.determineTargetFace(a,l,d,c)){const e=this.toCanvas(n.left-s.left),i=this.toCanvas(n.width);r.push({fromId:t.fromId,targetX:e+i/2})}}}}),r.length>0){r.push({fromId:t,targetX:w}),r.sort((t,e)=>t.targetX-e.targetX);const e=r.findIndex(e=>e.fromId===t),i=r.length;k=(e-(i-1)/2)*((i-1)*o>n?n/(i-1):o)}}return{sourceX:l,sourceY:d,targetX:w,targetY:_,targetFace:u,jogYOffset:k}}createSVGElement(){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.classList.add("plumb-connector"),t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",t.style.overflow="visible";const e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("fill","none"),e.setAttribute("stroke","var(--color-connectors)"),e.setAttribute("stroke-width","3"),e.style.pointerEvents="stroke";const i=document.createElementNS("http://www.w3.org/2000/svg","polygon");i.setAttribute("fill","var(--color-connectors)"),i.classList.add("plumb-arrow"),i.style.pointerEvents="fill",i.style.cursor="pointer";const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("r","18"),o.setAttribute("fill","transparent"),o.style.pointerEvents="fill",o.style.cursor="pointer",t.appendChild(e),t.appendChild(o),t.appendChild(i);const n=()=>t.classList.add("hover"),s=()=>t.classList.remove("hover");return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",s),i.addEventListener("mouseenter",n),i.addEventListener("mouseleave",s),o.addEventListener("mouseenter",n),o.addEventListener("mouseleave",s),{svgEl:t,pathEl:e,arrowEl:i,hitAreaEl:o}}updateSVGPath(t,e,i,o,n,s,r="top",a=0,l){const d=6.5,c=13;let h=n,u=s;"top"===r?u=s-c:"left"===r?h=n-c:"right"===r&&(h=n+c);const p=Gm(i,o,h,u,30,8,5,r,a);if(t.setAttribute("d",p),"top"===r?e.setAttribute("points",`${n},${s} ${n-d},${s-c} ${n+d},${s-c}`):"left"===r?e.setAttribute("points",`${n},${s} ${n-c},${s-d} ${n-c},${s+d}`):e.setAttribute("points",`${n},${s} ${n+c},${s-d} ${n+c},${s+d}`),l){const t=6.5;let e=n,i=s;"top"===r?i=s-t:e="left"===r?n-t:n+t,l.setAttribute("cx",String(e)),l.setAttribute("cy",String(i))}}createConnectionSVG(t,e,i){const o=this.getConnectionEndpoints(t,i,e);if(!o)return!1;const{svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a}=this.createSVGElement();this.updateSVGPath(s,r,o.sourceX,o.sourceY,o.targetX,o.targetY,o.targetFace,o.jogYOffset,a),this.canvas.appendChild(n),this.connections.set(t,{scope:e,fromId:t,toId:i,svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a});const l=o=>{if("button"in o&&Tc(o))return;o.stopPropagation(),"touches"in o&&o.preventDefault();const{clientX:n,clientY:s}=Km(o),r=o=>{const{clientX:l,clientY:d}=Km(o),c=l-n,h=d-s;Math.sqrt(c*c+h*h)>5&&(document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a),this.startDrag(t,e,i,o))},a=()=>{document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a)};document.addEventListener("mousemove",r),document.addEventListener("mouseup",a),document.addEventListener("touchmove",r,{passive:!1}),document.addEventListener("touchend",a),document.addEventListener("touchcancel",a)};r.addEventListener("mousedown",l),r.addEventListener("touchstart",l,{passive:!1}),a.addEventListener("mousedown",l),a.addEventListener("touchstart",l,{passive:!1}),s.addEventListener("mousedown",l),s.addEventListener("touchstart",l,{passive:!1});const d=document.getElementById(t);if(d&&d.classList.add("connected"),this.activityData){const e=`${t}:${i}`,o=this.activityData.segments[e];if(o&&o>0){const i=this.createOverlayElement(o,e);this.canvas.appendChild(i),this.overlays.set(t,i),this.updateOverlayPosition(t)}}return!0}updateConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.getConnectionEndpoints(e.fromId,e.toId,e.scope);i&&(this.updateSVGPath(e.pathEl,e.arrowEl,i.sourceX,i.sourceY,i.targetX,i.targetY,i.targetFace,i.jogYOffset,e.hitAreaEl),this.updateOverlayPosition(t))}removeConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.overlays.get(t);i&&(i.remove(),this.overlays.delete(t)),e.svgEl.remove(),this.connections.delete(t)}repaintEverything(){this.connections.forEach((t,e)=>{this.updateConnectionSVG(e)})}revalidate(t){const e=[],i=new Set;this.connections.forEach((o,n)=>{(t.includes(o.fromId)||t.includes(o.toId)||t.includes(o.scope))&&(e.push(n),i.add(o.toId))});const o=new Set(e);this.connections.forEach((t,e)=>{i.has(t.toId)&&o.add(e)}),o.forEach(t=>{this.updateConnectionSVG(t)})}forgetNode(t){var e;const i=[];this.connections.forEach((e,o)=>{e.scope!==t&&e.toId!==t||i.push(o)}),i.forEach(t=>this.removeConnectionSVG(t));const o=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");o&&o.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}removeNodeConnections(t,e){var i;(e||Array.from((null===(i=document.getElementById(t))||void 0===i?void 0:i.querySelectorAll(".exit"))||[]).map(t=>t.id)).forEach(t=>this.removeConnectionSVG(t))}removeExitConnection(t){return!!this.connections.has(t)&&(this.removeConnectionSVG(t),!0)}removeAllEndpoints(t){var e;const i=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");i&&i.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}setConnectionRemovingState(t,e){const i=this.connections.get(t);return!!i&&(e?i.svgEl.classList.add("removing"):i.svgEl.classList.remove("removing"),!0)}setActivityData(t){this.activityData=t,this.clearRecentContactsCache(),this.updateActivityOverlays()}updateActivityOverlays(){if(!this.activityData)return this.overlays.forEach(t=>t.remove()),void this.overlays.clear();const t=new Set;this.connections.forEach((e,i)=>{const o=`${e.fromId}:${e.toId}`,n=this.activityData.segments[o];if(n&&n>0){t.add(i);let e=this.overlays.get(i);e?(e.textContent=n.toLocaleString(),e.setAttribute("data-activity-key",o)):(e=this.createOverlayElement(n,o),this.canvas.appendChild(e),this.overlays.set(i,e)),this.updateOverlayPosition(i)}}),this.overlays.forEach((e,i)=>{t.has(i)||(e.remove(),this.overlays.delete(i))})}createOverlayElement(t,e){const i=document.createElement("div");return i.className="activity-overlay",i.textContent=t.toLocaleString(),i.setAttribute("data-activity-key",e),i.addEventListener("mouseenter",()=>{const t=this.getFlowUuid();t&&(this.fetchRecentContacts(e,t),this.showContactsTimeout=window.setTimeout(()=>{this.showRecentContacts(e,t)},500))}),i.addEventListener("mouseleave",()=>{this.showContactsTimeout&&(clearTimeout(this.showContactsTimeout),this.showContactsTimeout=null),this.hoveredActivityKey=null,this.hideRecentContacts()}),i}updateOverlayPosition(t){const e=this.overlays.get(t),i=this.connections.get(t);if(!e||!i)return;const o=this.getConnectionEndpoints(i.fromId,i.toId,i.scope);o&&(e.style.position="absolute",e.style.left=`${o.sourceX}px`,e.style.top=`${o.sourceY+15}px`,e.style.transform="translate(-50%, -50%)")}getFlowUuid(){var t,e;return(null===(e=null===(t=this.editor)||void 0===t?void 0:t.definition)||void 0===e?void 0:e.uuid)||null}async fetchRecentContacts(t,e){if(this.recentContactsCache[t]||this.pendingFetches[t])return;const i=new AbortController;this.pendingFetches[t]=i;try{const[o,n]=t.split(":"),s=`/flow/recent_contacts/${e}/${o}/${n}/`,r=await fetch(s,{signal:i.signal});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const a=await r.json();this.recentContactsCache[t]=Array.isArray(a)?a:a.results||[]}catch(t){"AbortError"!==t.name&&console.error("Failed to fetch recent contacts:",t)}finally{delete this.pendingFetches[t]}}async showRecentContacts(t,e){const i=this.findOverlayForActivityKey(t);i&&(this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null),this.hoveredActivityKey=t,this.recentContactsPopup||(this.recentContactsPopup=document.createElement("div"),this.recentContactsPopup.className="recent-contacts-popup",this.recentContactsPopup.style.position="absolute",this.recentContactsPopup.style.zIndex="1015",this.recentContactsPopup.style.display="none",document.body.appendChild(this.recentContactsPopup),this.recentContactsPopup.onmouseenter=()=>{this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null)},this.recentContactsPopup.onmouseleave=()=>{this.hoveredActivityKey=null,this.hideRecentContacts()},this.recentContactsPopup.onclick=t=>{const e=t.target;if(e.classList.contains("contact-name")){this.hideRecentContacts(!1);const i=e.getAttribute("data-uuid");i&&this.editor.fireCustomEvent("temba-contact-clicked",{uuid:i,metaKey:t.metaKey,ctrlKey:t.ctrlKey})}}),this.recentContactsCache[t]?(this.renderRecentContactsPopup(this.recentContactsCache[t]),this.positionPopup(i)):(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">Loading...</div>',this.positionPopup(i),await this.fetchRecentContacts(t,e),this.hoveredActivityKey===t&&(this.renderRecentContactsPopup(this.recentContactsCache[t]||[]),this.positionPopup(i))))}findOverlayForActivityKey(t){for(const[,e]of this.overlays)if(e.getAttribute("data-activity-key")===t)return e;return null}positionPopup(t){if(!this.recentContactsPopup)return;const e=t.getBoundingClientRect();this.recentContactsPopup.style.left=`${e.left+window.scrollX}px`,this.recentContactsPopup.style.top=`${e.bottom+window.scrollY+5}px`,this.recentContactsPopup.style.display="",this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.offsetWidth,this.recentContactsPopup.classList.add("show")}renderRecentContactsPopup(t){if(!this.recentContactsPopup)return;if(0===t.length)return void(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">No Recent Contacts</div>');let e='<div class="popup-title">Recent Contacts</div>';t.forEach(t=>{if(e+='<div class="contact-row">',e+=`<div class="contact-name" data-uuid="${t.contact.uuid}">${t.contact.name}</div>`,t.operand&&(e+=`<div class="contact-operand">${t.operand}</div>`),t.time){const i=new Date(t.time),o=Date.now()-i.getTime(),n=Math.floor(o/6e4),s=Math.floor(o/36e5),r=Math.floor(o/864e5);let a="";a=n<1?"just now":n<60?`${n}m ago`:s<24?`${s}h ago`:`${r}d ago`,e+=`<div class="contact-time">${a}</div>`}e+="</div>"}),this.recentContactsPopup.innerHTML=e}hideRecentContacts(t=!0){t?this.hideContactsTimeout=window.setTimeout(()=>{!this.hoveredActivityKey&&this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)},200):this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)}clearRecentContactsCache(){this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={}}startDrag(t,e,i,o){const n=this.connections.get(t);if(n){n.svgEl.style.display="none";const e=this.overlays.get(t);e&&(e.style.display="none")}const{svgEl:s,pathEl:r,arrowEl:a,hitAreaEl:l}=this.createSVGElement();s.classList.add("dragging"),r.style.pointerEvents="none",a.style.pointerEvents="none",l.style.pointerEvents="none",this.canvas.appendChild(s);const d=document.getElementById(t);if(!d)return void s.remove();const c=this.canvas.getBoundingClientRect(),h=d.getBoundingClientRect(),u=this.toCanvas(h.left+h.width/2-c.left),p=this.toCanvas(h.bottom-c.top),m=6.5,g=(t,e)=>{const i=e<p;let o,n="top";i&&(n=t<u?"left":"right"),o=i?e+1+13:e-1;const s=Gm(u,p,t,o,30,i?0:8,5,n);if(r.setAttribute("d",s),i){const i=e+1;a.setAttribute("points",`${t},${i} ${t-m},${o} ${t+m},${o}`)}else{const e=o+13;a.setAttribute("points",`${t},${e} ${t-m},${o} ${t+m},${o}`)}},{clientX:f,clientY:v}=Km(o),b=this.toCanvas(f-c.left),y=this.toCanvas(v-c.top);g(b,y),this.connectionDragging=!0;const x=t=>{"touches"in t&&t.preventDefault();const e=this.canvas.getBoundingClientRect(),{clientX:i,clientY:o}=Km(t),n=this.toCanvas(i-e.left),s=this.toCanvas(o-e.top);g(n,s)},w=o=>{document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",w),document.removeEventListener("touchmove",x),document.removeEventListener("touchend",w),document.removeEventListener("touchcancel",w),s.remove(),this.removeConnectionSVG(t),this.connectionDragging=!1,this.dragState=null,this.notifyListeners("connection:abort",{source:d,sourceId:t,target:{id:i},data:{nodeId:e}})};document.addEventListener("mousemove",x),document.addEventListener("mouseup",w),document.addEventListener("touchmove",x,{passive:!1}),document.addEventListener("touchend",w),document.addEventListener("touchcancel",w),this.dragState={sourceId:t,scope:e,originalTargetId:i,svgEl:s,pathEl:r,arrowEl:a,onMove:x,onUp:w},this.notifyListeners("connection:drag",{sourceId:t,sourceX:u,sourceY:p,data:{nodeId:e},target:{id:i}})}reset(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.pendingConnections=[],this.connections.forEach(t=>t.svgEl.remove()),this.connections.clear(),this.overlays.forEach(t=>t.remove()),this.overlays.clear(),this.hideRecentContacts(!1),this.recentContactsPopup&&(this.recentContactsPopup.remove(),this.recentContactsPopup=null),this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={},this.sources.forEach(t=>t()),this.sources.clear(),this.dragState&&(document.removeEventListener("mousemove",this.dragState.onMove),document.removeEventListener("mouseup",this.dragState.onUp),this.dragState.svgEl.remove(),this.dragState=null,this.connectionDragging=!1)}}class Qm extends Ve{createRenderRoot(){return this}static get styles(){return a`
9377
+ `}}function Fm(t,e){if(!t||!(null==e?void 0:e.length))return[];const i=Rm[t],o=null==i?void 0:i.nonTranslatableCategories;if(!o)return[...e];if("all"===o)return e.filter(t=>Qt.has(t.name));const n=new Set(o);return e.filter(t=>!n.has(t.name)||Qt.has(t.name))}function qm(t){if(null==t)return null;if(Array.isArray(t)){const e=t.map(t=>qm(t)).filter(t=>!!t);return e.length>0?e.join(", "):null}if("object"==typeof t)return"name"in t&&t.name?String(t.name):"arguments"in t&&Array.isArray(t.arguments)?t.arguments.join(" "):null;if("number"==typeof t)return t.toString();if("string"==typeof t){const e=t.trim();return e.length>0?e:null}return null}function Um(t,e,i,o,n){const s=[];return i.forEach(i=>{if("quick_replies"===i)return;const r=i.split(".");let a=o,l=[];for(;r.length>0&&a;){a.uuid&&(l=n[a.uuid]);const t=r.shift();if(!t)break;l&&(l=l[t]),a=a[t]}if(!a)return;const d=qm(a);if(!d)return;const c=l?qm(l):null,h=t=>Array.isArray(t)?t.map(t=>null==t?"":String(t)):null==t?[]:[String(t)],u=h(a),p=null!=l?h(l):null;s.push({uuid:e,type:t,attribute:i,from:d,to:c,fromValues:u,toValues:p})}),s}function jm(t,e){var i;if(!t||!e||e===t.language)return[];const o=(null===(i=t.localization)||void 0===i?void 0:i[e])||{},n=[];return t.nodes.forEach(e=>{var i,s,r,a,l,d,c,h,u;null===(i=e.actions)||void 0===i||i.forEach(t=>{const i=Lm[t.type];if(!(null==i?void 0:i.localizable)||0===i.localizable.length)return;const s="send_msg"===t.type?i.localizable.filter(t=>"text"===t):i.localizable,r=Um("property",t.uuid,s,t,o);r.length>0&&n.push({nodeUuid:e.uuid,actionUuid:t.uuid,translations:r})});const p=null===(r=null===(s=t._ui)||void 0===s?void 0:s.nodes)||void 0===r?void 0:r[e.uuid],m=null==p?void 0:p.type;if(!m)return;if((null===(a=null==p?void 0:p.config)||void 0===a?void 0:a.localizeRules)&&(null===(d=null===(l=e.router)||void 0===l?void 0:l.cases)||void 0===d?void 0:d.length)){const t=e.router.cases.filter(t=>{var e;return(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&t.arguments.some(t=>t)}).flatMap(t=>Um("property",t.uuid,["arguments"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}const g=Rm[m];if((null===(c=null==p?void 0:p.config)||void 0===c?void 0:c.localizeCategories)&&"categories"===(null==g?void 0:g.localizable)&&(null===(u=null===(h=e.router)||void 0===h?void 0:h.categories)||void 0===u?void 0:u.length)){const t=Fm(m,e.router.categories).flatMap(t=>Um("category",t.uuid,["name"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}}),n}t([mt({type:Boolean,attribute:"message-view"})],Bm.prototype,"messageView",void 0),t([mt({type:Number})],Bm.prototype,"zoom",void 0),t([mt({type:Boolean,attribute:"zoom-initialized"})],Bm.prototype,"zoomInitialized",void 0),t([mt({type:Boolean,attribute:"zoom-fitted"})],Bm.prototype,"zoomFitted",void 0),t([mt({type:Boolean,attribute:"revisions-active"})],Bm.prototype,"revisionsActive",void 0),t([mt({type:Boolean,attribute:"is-saving"})],Bm.prototype,"isSaving",void 0),t([mt({type:Boolean,attribute:"search-disabled"})],Bm.prototype,"searchDisabled",void 0),t([mt({type:Array})],Bm.prototype,"languageOptions",void 0),t([mt({type:String,attribute:"current-language-name"})],Bm.prototype,"currentLanguageName",void 0),t([mt({type:Boolean,attribute:"is-base-language"})],Bm.prototype,"isBaseLanguage",void 0),t([mt({type:Number,attribute:"language-percent"})],Bm.prototype,"languagePercent",void 0),t([mt({type:Boolean,attribute:"show-localization-tools"})],Bm.prototype,"showLocalizationTools",void 0),t([mt({type:Boolean,attribute:"has-pending-translations"})],Bm.prototype,"hasPendingTranslations",void 0),t([mt({type:Boolean,attribute:"auto-translate-disabled"})],Bm.prototype,"autoTranslateDisabled",void 0),t([mt({type:Boolean,attribute:"auto-translating"})],Bm.prototype,"autoTranslating",void 0),t([gt()],Bm.prototype,"showLanguageOptions",void 0);const Hm=60,Wm=20;function Vm(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=Zm(e.get(u),i);for(const e of p){const p=Mc(h);if(u===t[0]){let t=0;for(const o of e){const e=o===s?p:p+40;c[o]={left:Mc(t),top:e},t+=((null===(r=i.get(o))||void 0===r?void 0:r.width)||200)+Hm}}else{let t=0;for(const o of e)t+=(null===(a=i.get(o))||void 0===a?void 0:a.width)||200;t+=Hm*(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:Mc(h),top:p},h=Mc(h)+e+Hm}}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:Mc(Math.max(0,c[i].left-t)),top:Mc(Math.max(0,c[i].top-e))}}return c}(c,d,h,r,l,i)}function Zm(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?Hm+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 Ym(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}function Km(t){if("touches"in t){const e=t.touches[0]||t.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}}return{clientX:t.clientX,clientY:t.clientY}}function Gm(t,e,i,o,n=20,s=10,r=5,a="top",l=0){const d=r;if("top"===a){const r=e+n,a=o-s;let c=`M ${t} ${e}`;if(t===i)c+=` L ${i} ${a}`;else{const o=i>t?1:-1,n=Math.max(e+d,Math.min(r,a-d)),s=Math.max(e+d,Math.min(n+l,a-d-3)),h=Math.min(d,s-e);h>=1?(c+=` L ${t} ${s-h}`,c+=` Q ${t} ${s}, ${t+o*h} ${s}`):c+=` L ${t} ${s}`;const u=3,p=Math.min(d,Math.max(0,a-s-u));p>=1?(c+=` L ${i-o*p} ${s}`,c+=` Q ${i} ${s}, ${i} ${s+p}`):c+=` L ${i} ${s}`,c+=` L ${i} ${a}`}return c+=` L ${i} ${o}`,c}if("left"===a||"right"===a){const r=e+(o<e?0:n),l="left"===a?-1:1,c=i+l*s,h=c>t?1:-1,u=3,p=h===l?r+2*d:Math.max(r+2*d,o);let m=`M ${t} ${e} L ${t} ${r}`;p-r>d&&(m+=` L ${t} ${p-d}`,m+=` Q ${t} ${p}, ${t+h*d} ${p}`);const g=Math.abs(p-o);if(g<1)m+=` L ${c} ${o}`,m+=` L ${i} ${o}`;else{const t=o<p?-1:1,e=Math.min(d,Math.max(0,Math.floor((g-u)/2)),Math.max(0,s-u));e>=1?(m+=` L ${c-h*e} ${p}`,m+=` Q ${c} ${p}, ${c} ${p+t*e}`,m+=` L ${c} ${o-t*e}`,m+=` Q ${c} ${o}, ${c-l*e} ${o}`):(m+=` L ${c} ${p}`,m+=` L ${c} ${o}`),m+=` L ${i} ${o}`}return m}return`M ${t} ${e} L ${i} ${o}`}class Xm{constructor(t,e){this.connections=new Map,this.sources=new Map,this.pendingConnections=[],this.connectionWait=null,this.connectionListeners=new Map,this.dragState=null,this.retryCount=0,this.maxRetries=3,this.activityData=null,this.overlays=new Map,this.hoveredActivityKey=null,this.recentContactsPopup=null,this.recentContactsCache={},this.pendingFetches={},this.hideContactsTimeout=null,this.showContactsTimeout=null,this.connectionDragging=!1,this.zoom=1,this.canvas=t,this.editor=e}setContainer(t){this.canvas=t}notifyListeners(t,e){(this.connectionListeners.get(t)||[]).forEach(t=>t(e))}on(t,e){this.connectionListeners.has(t)||this.connectionListeners.set(t,[]),this.connectionListeners.get(t).push(e)}off(t,e){if(!this.connectionListeners.has(t))return;const i=this.connectionListeners.get(t),o=i.indexOf(e);-1!==o&&i.splice(o,1)}makeSource(t){const e=document.getElementById(t);if(!e)return;this.sources.has(t)&&this.sources.get(t)();let i=null;const o=o=>{if("button"in o&&Tc(o))return;if(this.connections.has(t))return;const n="touches"in o;n&&o.preventDefault();const{clientX:s,clientY:r}=Km(o),a=e.closest("temba-flow-node"),l=(null==a?void 0:a.getAttribute("uuid"))||"",d=e=>{const{clientX:i,clientY:o}=Km(e),n=i-s,a=o-r;Math.sqrt(n*n+a*a)>5&&(h(),this.startDrag(t,l,null,e))},c=()=>{h()},h=()=>{document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",c),document.removeEventListener("touchmove",d),document.removeEventListener("touchend",c),document.removeEventListener("touchcancel",c),i=null};document.addEventListener("mousemove",d),document.addEventListener("mouseup",c),document.addEventListener("touchmove",d,{passive:!1}),document.addEventListener("touchend",c),document.addEventListener("touchcancel",c),i={startX:s,startY:r,onMove:d,onUp:c,isTouch:n}};e.addEventListener("mousedown",o),e.addEventListener("touchstart",o,{passive:!1}),this.sources.set(t,()=>{e.removeEventListener("mousedown",o),e.removeEventListener("touchstart",o),i&&(document.removeEventListener("mousemove",i.onMove),document.removeEventListener("mouseup",i.onUp),document.removeEventListener("touchmove",i.onMove),document.removeEventListener("touchend",i.onUp),document.removeEventListener("touchcancel",i.onUp),i=null)})}makeTarget(t){}connectIds(t,e,i){this.pendingConnections.push({scope:t,fromId:e,toId:i}),this.processPendingConnections()}processPendingConnections(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.connectionWait=requestAnimationFrame(()=>{const t=[],e=new Set;if(this.pendingConnections.forEach(i=>{const{scope:o,fromId:n,toId:s}=i;this.removeConnectionSVG(n),this.createConnectionSVG(n,o,s)?e.add(s):t.push(i)}),this.pendingConnections=[],e.size>0){const t=new Set;this.connections.forEach(i=>{e.has(i.toId)&&t.add(i.scope)}),this.connections.forEach((i,o)=>{(e.has(i.toId)||t.has(i.scope))&&this.updateConnectionSVG(o)})}t.length>0&&this.retryCount<this.maxRetries?(this.retryCount++,this.pendingConnections=t,this.processPendingConnections()):this.retryCount=0})}toCanvas(t){return t/this.zoom}determineTargetFace(t,e,i,o){return o-e>30?"top":t<i?"left":"right"}getConnectionEndpoints(t,e,i){const o=document.getElementById(t),n=document.getElementById(e);if(!o||!n)return null;const s=this.canvas.getBoundingClientRect(),r=o.getBoundingClientRect(),a=n.getBoundingClientRect();if(0===r.width||0===a.width)return null;const l=this.toCanvas(r.left+r.width/2-s.left),d=this.toCanvas(r.bottom-s.top),c=this.toCanvas(a.left+a.width/2-s.left),h=this.toCanvas(a.top-s.top),u=this.determineTargetFace(l,d,c,h),p=new Map;this.connections.forEach(t=>{if(t.toId===e){const e=document.getElementById(t.fromId);if(e){const i=e.getBoundingClientRect(),o=this.toCanvas(i.left+i.width/2-s.left),n=this.toCanvas(i.bottom-s.top),r=this.determineTargetFace(o,n,c,h);p.has(r)||p.set(r,[]);const a="top"===r?o:n;p.get(r).push({fromId:t.fromId,sortPos:a})}}}),p.has(u)||p.set(u,[]);const m=p.get(u);if(!m.find(e=>e.fromId===t)){const e="top"===u?l:d;m.push({fromId:t,sortPos:e})}m.sort((t,e)=>t.sortPos-e.sortPos);const g=m.findIndex(e=>e.fromId===t),f=m.length,v=this.toCanvas(a.left-s.left),b=h,y=this.toCanvas(a.width),x=this.toCanvas(a.height);let w,_;if("top"===u){w=1===f?v+y/2:v+.2*y+.6*y*(g+.5)/f,_=b}else if("left"===u){w=v;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}else{w=v+y;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}let k=0;if("top"===u&&i){const o=8,n=50,r=[];if(this.connections.forEach(t=>{if(t.scope===i&&t.toId!==e){const e=document.getElementById(t.fromId),i=document.getElementById(t.toId);if(e&&i){const o=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=this.toCanvas(o.left+o.width/2-s.left),l=this.toCanvas(o.bottom-s.top),d=this.toCanvas(n.left+n.width/2-s.left),c=this.toCanvas(n.top-s.top);if("top"===this.determineTargetFace(a,l,d,c)){const e=this.toCanvas(n.left-s.left),i=this.toCanvas(n.width);r.push({fromId:t.fromId,targetX:e+i/2})}}}}),r.length>0){r.push({fromId:t,targetX:w}),r.sort((t,e)=>t.targetX-e.targetX);const e=r.findIndex(e=>e.fromId===t),i=r.length;k=(e-(i-1)/2)*((i-1)*o>n?n/(i-1):o)}}return{sourceX:l,sourceY:d,targetX:w,targetY:_,targetFace:u,jogYOffset:k}}createSVGElement(){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.classList.add("plumb-connector"),t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",t.style.overflow="visible";const e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("fill","none"),e.setAttribute("stroke","var(--color-connectors)"),e.setAttribute("stroke-width","3"),e.style.pointerEvents="stroke";const i=document.createElementNS("http://www.w3.org/2000/svg","polygon");i.setAttribute("fill","var(--color-connectors)"),i.classList.add("plumb-arrow"),i.style.pointerEvents="fill",i.style.cursor="pointer";const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("r","18"),o.setAttribute("fill","transparent"),o.style.pointerEvents="fill",o.style.cursor="pointer",t.appendChild(e),t.appendChild(o),t.appendChild(i);const n=()=>t.classList.add("hover"),s=()=>t.classList.remove("hover");return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",s),i.addEventListener("mouseenter",n),i.addEventListener("mouseleave",s),o.addEventListener("mouseenter",n),o.addEventListener("mouseleave",s),{svgEl:t,pathEl:e,arrowEl:i,hitAreaEl:o}}updateSVGPath(t,e,i,o,n,s,r="top",a=0,l){const d=6.5,c=13;let h=n,u=s;"top"===r?u=s-c:"left"===r?h=n-c:"right"===r&&(h=n+c);const p=Gm(i,o,h,u,30,8,5,r,a);if(t.setAttribute("d",p),"top"===r?e.setAttribute("points",`${n},${s} ${n-d},${s-c} ${n+d},${s-c}`):"left"===r?e.setAttribute("points",`${n},${s} ${n-c},${s-d} ${n-c},${s+d}`):e.setAttribute("points",`${n},${s} ${n+c},${s-d} ${n+c},${s+d}`),l){const t=6.5;let e=n,i=s;"top"===r?i=s-t:e="left"===r?n-t:n+t,l.setAttribute("cx",String(e)),l.setAttribute("cy",String(i))}}createConnectionSVG(t,e,i){const o=this.getConnectionEndpoints(t,i,e);if(!o)return!1;const{svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a}=this.createSVGElement();this.updateSVGPath(s,r,o.sourceX,o.sourceY,o.targetX,o.targetY,o.targetFace,o.jogYOffset,a),this.canvas.appendChild(n),this.connections.set(t,{scope:e,fromId:t,toId:i,svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a});const l=o=>{if("button"in o&&Tc(o))return;o.stopPropagation(),"touches"in o&&o.preventDefault();const{clientX:n,clientY:s}=Km(o),r=o=>{const{clientX:l,clientY:d}=Km(o),c=l-n,h=d-s;Math.sqrt(c*c+h*h)>5&&(document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a),this.startDrag(t,e,i,o))},a=()=>{document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a)};document.addEventListener("mousemove",r),document.addEventListener("mouseup",a),document.addEventListener("touchmove",r,{passive:!1}),document.addEventListener("touchend",a),document.addEventListener("touchcancel",a)};r.addEventListener("mousedown",l),r.addEventListener("touchstart",l,{passive:!1}),a.addEventListener("mousedown",l),a.addEventListener("touchstart",l,{passive:!1}),s.addEventListener("mousedown",l),s.addEventListener("touchstart",l,{passive:!1});const d=document.getElementById(t);if(d&&d.classList.add("connected"),this.activityData){const e=`${t}:${i}`,o=this.activityData.segments[e];if(o&&o>0){const i=this.createOverlayElement(o,e);this.canvas.appendChild(i),this.overlays.set(t,i),this.updateOverlayPosition(t)}}return!0}updateConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.getConnectionEndpoints(e.fromId,e.toId,e.scope);i&&(this.updateSVGPath(e.pathEl,e.arrowEl,i.sourceX,i.sourceY,i.targetX,i.targetY,i.targetFace,i.jogYOffset,e.hitAreaEl),this.updateOverlayPosition(t))}removeConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.overlays.get(t);i&&(i.remove(),this.overlays.delete(t)),e.svgEl.remove(),this.connections.delete(t)}repaintEverything(){this.connections.forEach((t,e)=>{this.updateConnectionSVG(e)})}revalidate(t){const e=[],i=new Set;this.connections.forEach((o,n)=>{(t.includes(o.fromId)||t.includes(o.toId)||t.includes(o.scope))&&(e.push(n),i.add(o.toId))});const o=new Set(e);this.connections.forEach((t,e)=>{i.has(t.toId)&&o.add(e)}),o.forEach(t=>{this.updateConnectionSVG(t)})}forgetNode(t){var e;const i=[];this.connections.forEach((e,o)=>{e.scope!==t&&e.toId!==t||i.push(o)}),i.forEach(t=>this.removeConnectionSVG(t));const o=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");o&&o.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}removeNodeConnections(t,e){var i;(e||Array.from((null===(i=document.getElementById(t))||void 0===i?void 0:i.querySelectorAll(".exit"))||[]).map(t=>t.id)).forEach(t=>this.removeConnectionSVG(t))}removeExitConnection(t){return!!this.connections.has(t)&&(this.removeConnectionSVG(t),!0)}removeAllEndpoints(t){var e;const i=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");i&&i.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}setConnectionRemovingState(t,e){const i=this.connections.get(t);return!!i&&(e?i.svgEl.classList.add("removing"):i.svgEl.classList.remove("removing"),!0)}setActivityData(t){this.activityData=t,this.clearRecentContactsCache(),this.updateActivityOverlays()}updateActivityOverlays(){if(!this.activityData)return this.overlays.forEach(t=>t.remove()),void this.overlays.clear();const t=new Set;this.connections.forEach((e,i)=>{const o=`${e.fromId}:${e.toId}`,n=this.activityData.segments[o];if(n&&n>0){t.add(i);let e=this.overlays.get(i);e?(e.textContent=n.toLocaleString(),e.setAttribute("data-activity-key",o)):(e=this.createOverlayElement(n,o),this.canvas.appendChild(e),this.overlays.set(i,e)),this.updateOverlayPosition(i)}}),this.overlays.forEach((e,i)=>{t.has(i)||(e.remove(),this.overlays.delete(i))})}createOverlayElement(t,e){const i=document.createElement("div");return i.className="activity-overlay",i.textContent=t.toLocaleString(),i.setAttribute("data-activity-key",e),i.addEventListener("mouseenter",()=>{const t=this.getFlowUuid();t&&(this.fetchRecentContacts(e,t),this.showContactsTimeout=window.setTimeout(()=>{this.showRecentContacts(e,t)},500))}),i.addEventListener("mouseleave",()=>{this.showContactsTimeout&&(clearTimeout(this.showContactsTimeout),this.showContactsTimeout=null),this.hoveredActivityKey=null,this.hideRecentContacts()}),i}updateOverlayPosition(t){const e=this.overlays.get(t),i=this.connections.get(t);if(!e||!i)return;const o=this.getConnectionEndpoints(i.fromId,i.toId,i.scope);o&&(e.style.position="absolute",e.style.left=`${o.sourceX}px`,e.style.top=`${o.sourceY+15}px`,e.style.transform="translate(-50%, -50%)")}getFlowUuid(){var t,e;return(null===(e=null===(t=this.editor)||void 0===t?void 0:t.definition)||void 0===e?void 0:e.uuid)||null}async fetchRecentContacts(t,e){if(this.recentContactsCache[t]||this.pendingFetches[t])return;const i=new AbortController;this.pendingFetches[t]=i;try{const[o,n]=t.split(":"),s=`/flow/recent_contacts/${e}/${o}/${n}/`,r=await fetch(s,{signal:i.signal});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const a=await r.json();this.recentContactsCache[t]=Array.isArray(a)?a:a.results||[]}catch(t){"AbortError"!==t.name&&console.error("Failed to fetch recent contacts:",t)}finally{delete this.pendingFetches[t]}}async showRecentContacts(t,e){const i=this.findOverlayForActivityKey(t);i&&(this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null),this.hoveredActivityKey=t,this.recentContactsPopup||(this.recentContactsPopup=document.createElement("div"),this.recentContactsPopup.className="recent-contacts-popup",this.recentContactsPopup.style.position="absolute",this.recentContactsPopup.style.zIndex="1015",this.recentContactsPopup.style.display="none",document.body.appendChild(this.recentContactsPopup),this.recentContactsPopup.onmouseenter=()=>{this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null)},this.recentContactsPopup.onmouseleave=()=>{this.hoveredActivityKey=null,this.hideRecentContacts()},this.recentContactsPopup.onclick=t=>{const e=t.target;if(e.classList.contains("contact-name")){this.hideRecentContacts(!1);const i=e.getAttribute("data-uuid");i&&this.editor.fireCustomEvent("temba-contact-clicked",{uuid:i,metaKey:t.metaKey,ctrlKey:t.ctrlKey})}}),this.recentContactsCache[t]?(this.renderRecentContactsPopup(this.recentContactsCache[t]),this.positionPopup(i)):(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">Loading...</div>',this.positionPopup(i),await this.fetchRecentContacts(t,e),this.hoveredActivityKey===t&&(this.renderRecentContactsPopup(this.recentContactsCache[t]||[]),this.positionPopup(i))))}findOverlayForActivityKey(t){for(const[,e]of this.overlays)if(e.getAttribute("data-activity-key")===t)return e;return null}positionPopup(t){if(!this.recentContactsPopup)return;const e=t.getBoundingClientRect();this.recentContactsPopup.style.left=`${e.left+window.scrollX}px`,this.recentContactsPopup.style.top=`${e.bottom+window.scrollY+5}px`,this.recentContactsPopup.style.display="",this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.offsetWidth,this.recentContactsPopup.classList.add("show")}renderRecentContactsPopup(t){if(!this.recentContactsPopup)return;if(0===t.length)return void(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">No Recent Contacts</div>');let e='<div class="popup-title">Recent Contacts</div>';t.forEach(t=>{if(e+='<div class="contact-row">',e+=`<div class="contact-name" data-uuid="${t.contact.uuid}">${t.contact.name}</div>`,t.operand&&(e+=`<div class="contact-operand">${t.operand}</div>`),t.time){const i=new Date(t.time),o=Date.now()-i.getTime(),n=Math.floor(o/6e4),s=Math.floor(o/36e5),r=Math.floor(o/864e5);let a="";a=n<1?"just now":n<60?`${n}m ago`:s<24?`${s}h ago`:`${r}d ago`,e+=`<div class="contact-time">${a}</div>`}e+="</div>"}),this.recentContactsPopup.innerHTML=e}hideRecentContacts(t=!0){t?this.hideContactsTimeout=window.setTimeout(()=>{!this.hoveredActivityKey&&this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)},200):this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)}clearRecentContactsCache(){this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={}}startDrag(t,e,i,o){const n=this.connections.get(t);if(n){n.svgEl.style.display="none";const e=this.overlays.get(t);e&&(e.style.display="none")}const{svgEl:s,pathEl:r,arrowEl:a,hitAreaEl:l}=this.createSVGElement();s.classList.add("dragging"),r.style.pointerEvents="none",a.style.pointerEvents="none",l.style.pointerEvents="none",this.canvas.appendChild(s);const d=document.getElementById(t);if(!d)return void s.remove();const c=this.canvas.getBoundingClientRect(),h=d.getBoundingClientRect(),u=this.toCanvas(h.left+h.width/2-c.left),p=this.toCanvas(h.bottom-c.top),m=6.5,g=(t,e)=>{const i=e<p;let o,n="top";i&&(n=t<u?"left":"right"),o=i?e+1+13:e-1;const s=Gm(u,p,t,o,30,i?0:8,5,n);if(r.setAttribute("d",s),i){const i=e+1;a.setAttribute("points",`${t},${i} ${t-m},${o} ${t+m},${o}`)}else{const e=o+13;a.setAttribute("points",`${t},${e} ${t-m},${o} ${t+m},${o}`)}},{clientX:f,clientY:v}=Km(o),b=this.toCanvas(f-c.left),y=this.toCanvas(v-c.top);g(b,y),this.connectionDragging=!0;const x=t=>{"touches"in t&&t.preventDefault();const e=this.canvas.getBoundingClientRect(),{clientX:i,clientY:o}=Km(t),n=this.toCanvas(i-e.left),s=this.toCanvas(o-e.top);g(n,s)},w=o=>{document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",w),document.removeEventListener("touchmove",x),document.removeEventListener("touchend",w),document.removeEventListener("touchcancel",w),s.remove(),this.removeConnectionSVG(t),this.connectionDragging=!1,this.dragState=null,this.notifyListeners("connection:abort",{source:d,sourceId:t,target:{id:i},data:{nodeId:e}})};document.addEventListener("mousemove",x),document.addEventListener("mouseup",w),document.addEventListener("touchmove",x,{passive:!1}),document.addEventListener("touchend",w),document.addEventListener("touchcancel",w),this.dragState={sourceId:t,scope:e,originalTargetId:i,svgEl:s,pathEl:r,arrowEl:a,onMove:x,onUp:w},this.notifyListeners("connection:drag",{sourceId:t,sourceX:u,sourceY:p,data:{nodeId:e},target:{id:i}})}reset(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.pendingConnections=[],this.connections.forEach(t=>t.svgEl.remove()),this.connections.clear(),this.overlays.forEach(t=>t.remove()),this.overlays.clear(),this.hideRecentContacts(!1),this.recentContactsPopup&&(this.recentContactsPopup.remove(),this.recentContactsPopup=null),this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={},this.sources.forEach(t=>t()),this.sources.clear(),this.dragState&&(document.removeEventListener("mousemove",this.dragState.onMove),document.removeEventListener("mouseup",this.dragState.onUp),this.dragState.svgEl.remove(),this.dragState=null,this.connectionDragging=!1)}}class Qm extends Ve{createRenderRoot(){return this}static get styles(){return a`
9381
9378
 
9382
9379
  .node {
9383
9380
  background-color: #fff;
@@ -10934,7 +10931,7 @@ background: #ccc;
10934
10931
  </div>
10935
10932
  </div>
10936
10933
  </div>
10937
- </div>`}checkCollisionsAndReflow(t=[]){var e,i;if(!this.definition)return;const o=[];for(const t of this.definition.nodes){const i=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid];if(!(null==i?void 0:i.position))continue;const n=Wc(t.uuid,i.position);n&&o.push(n)}const n=(null===(i=this.definition._ui)||void 0===i?void 0:i.stickies)||{};for(const[t,e]of Object.entries(n)){if(!e.position)continue;const i=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(!i)continue;const n=Wc(t,e.position,i);n&&o.push(n)}const s=((t,e)=>{const i=new Map,o=new Set(t),n=new Map;for(const t of e)n.set(t.uuid,{...t});for(const t of[...o]){const e=n.get(t);if(e)for(const[i,s]of n)if(i!==t&&!o.has(i)&&Vc(e,s)&&e.top>s.top&&s.top<30){o.delete(t),o.add(i);break}}const s=[],r=new Set;for(const t of o){const e=n.get(t);if(e)for(const[t,i]of n)o.has(t)||r.has(t)||Vc(e,i)&&(s.push(t),r.add(t))}const a=new Set;let l=0;for(;s.length>0&&l<200;){l++;const t=s.shift();if(a.has(t))continue;const e=n.get(t),d=[];for(const[i,s]of n)i!==t&&(o.has(i)||a.has(i))&&Vc(e,s)&&d.push(s);if(0===d.length)continue;const c=d.filter(t=>o.has(t.uuid)),h=[...Zc];let u=null;if(c.length>0){for(const t of c){if(e.top>t.top){const t=h.indexOf("up");-1!==t&&h.splice(t,1)}if(e.left>t.left){const t=h.indexOf("left");-1!==t&&h.splice(t,1)}}let t=0,i=0;for(const o of c)t+=Math.min(e.right,o.right)-Math.max(e.left,o.left),i+=Math.min(e.bottom,o.bottom)-Math.max(e.top,o.top);t>i?u="vertical":i>t&&(u="horizontal")}let p=null,m=1/0;for(const i of h){const s=Kc(e,d,i);if(!s)continue;const r=Yc(e,s.left,s.top);let l=!1,h=0;for(const[e,i]of n)if(e!==t&&Vc(r,i)){if(o.has(e)||a.has(e)){l=!0;break}h++}if(l)continue;const g=Math.abs(s.left-e.left)+Math.abs(s.top-e.top);let f;if(c.length>0){const t="up"===i||"down"===i;f=2e3*h+(null===u||"vertical"===u&&t||"horizontal"===u&&!t?0:5e3)+g}else f=1e4*h+g;f<m&&(m=f,p=s)}if(p){i.set(t,{left:p.left,top:p.top});const l=Yc(e,p.left,p.top);n.set(t,l),a.add(t);for(const[e,i]of n)e!==t&&(o.has(e)||a.has(e)||r.has(e)||Vc(l,i)&&(s.push(e),r.add(e)))}}return i})(t,o);if(s.size>0){const t={};for(const[e,i]of s.entries())t[e]=i;Qc().getState().updateCanvasPositions(t)}}findTargetNodeAt(t,e){var i;const o=document.elementFromPoint(t,e);return null!==(i=null==o?void 0:o.closest("temba-flow-node"))&&void 0!==i?i:null}updateCanvasSize(){var t;if(!this.definition)return;const e=Qc();if(!e)return;let i=0,o=0;this.definition.nodes.forEach(t=>{const e=this.definition._ui.nodes[t.uuid];if(e&&e.position){const n=this.querySelector(`[id="${t.uuid}"]`);n&&(i=Math.max(i,e.position.left+n.offsetWidth),o=Math.max(o,e.position.top+n.offsetHeight))}});const n=(null===(t=this.definition._ui)||void 0===t?void 0:t.stickies)||{};Object.entries(n).forEach(([t,e])=>{if(e.position){const n=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(n){const t=n.clientWidth,s=n.clientHeight;i=Math.max(i,e.position.left+t),o=Math.max(o,e.position.top+s)}else i=Math.max(i,e.position.left+(e.width||200)),o=Math.max(o,e.position.top+(e.height||100))}}),e.getState().expandCanvas(i,o)}handleCanvasContextMenu(t){if(this.isReadOnly())return void t.preventDefault();"canvas"===t.target.id&&(t.preventDefault(),t.stopPropagation(),this.dragManager.blurActiveContentEditable(),this.showContextMenuAt(t.clientX,t.clientY))}showContextMenuAt(t,e){if(this.isReadOnly())return;const i=this.querySelector("#canvas");if(!i)return;const o=i.getBoundingClientRect(),n=(t-o.left)/this.zoom-10,s=(e-o.top)/this.zoom-10,r=Mc(n),a=Mc(s),l=this.querySelector("temba-canvas-menu");if(l){const i=this.definition&&this.definition.nodes.length>0;l.show(t,e,{x:r,y:a},!0,i,up[this.flowType])}}handleEmptyFlowClick(t){const e=this.querySelector("#editor");if(!e)return;e.scrollTo({left:0,top:0,behavior:"smooth"});const i=this.querySelector("temba-canvas-menu");if(i){const e=t.currentTarget.getBoundingClientRect(),o=265,n=e.left+e.width/2-o/2,s=e.bottom+8;i.show(n,s,{x:0,y:0},!1,!1,up[this.flowType])}}handleCanvasMenuSelection(t){const e=t.detail,i=Qc();if("reflow"!==e.action)if("sticky"===e.action){const t=i.getState().createStickyNote({left:e.position.x,top:e.position.y});requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])}),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null}else if("other"===e.action){const t=this.querySelector("temba-node-type-selector");t&&t.show("all",e.position)}else this.handleNodeTypeSelection(new CustomEvent(Fo.Selection,{detail:{nodeType:e.action,position:e.position}}));else this.performReflow()}cleanUpConnection(){this.isCreatingNewNode&&(this.isCreatingNewNode=!1,this.pendingNodePosition=null),this.originalConnectionTargetId&&(this.plumber.connectIds(this.dragFromNodeId,this.sourceId,this.originalConnectionTargetId),this.originalConnectionTargetId=null),this.pendingCanvasConnection&&(this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null,this.originalConnectionTargetId=null)}handleCanvasMenuClosed(){this.cleanUpConnection()}handleNodeTypeSelectorClosed(){this.addActionToNodeUuid=null,this.cleanUpConnection()}handleNodeTypeSelection(t){const e=t.detail;if(this.pendingCanvasConnection,this.addActionToNodeUuid){const t=this.definition.nodes.find(t=>t.uuid===this.addActionToNodeUuid),i=this.definition._ui.nodes[this.addActionToNodeUuid];if(t&&i){const o=Kt();return this.editingAction={uuid:o,type:e.nodeType},this.editingNode=t,this.editingNodeUI=i,this.isCreatingNewNode=!1,void(this.addActionToNodeUuid=null)}this.addActionToNodeUuid=null}const i=Kt(),o=e.nodeType in Lm,n=o?"execute_actions":e.nodeType,s=Rm[n],r=(null==s?void 0:s.form)&&Object.keys(s.form).some(t=>{var e;return["rules","categories","cases"].includes(t)||"array"===(null===(e=s.form[t])||void 0===e?void 0:e.type)}),a={uuid:i,actions:[],exits:r?[]:[{uuid:Kt(),destination_uuid:null}]};r&&(a.router={type:"switch",categories:[],cases:[],operand:"@input.text",default_category_uuid:void 0});const l={position:this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},type:n,config:{}};if(this.isCreatingNewNode=!0,this.pendingNodePosition=this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},this.editingNode=a,this.editingNodeUI=l,o){const t=Kt();this.editingAction={uuid:t,type:e.nodeType}}}handleActionEditRequested(t){this.editingAction=t.detail.action,this.editForceBase=!!t.detail.forceBase,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null;const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);i&&(this.editingNode=i,this.editingNodeUI=this.definition._ui.nodes[e])}handleAddActionRequested(t){const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);if(!i)return;const o=this.definition._ui.nodes[e];if(!o)return;const n=this.querySelector("temba-node-type-selector");n&&(n.show("action-no-branching",{x:o.position.left,y:o.position.top}),this.addActionToNodeUuid=e)}handleNodeEditRequested(t){this.editForceBase=!!t.detail.forceBase,this.editingAction=null,this.editingNode=t.detail.node,this.editingNodeUI=t.detail.nodeUI,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null}handleNodeDeleted(t){const e=t.detail.uuid;e&&this.deleteNodes([e])}handleActionSaved(t){var e,i;if(this.editingNode&&this.editingAction){let o;o=this.editingNode.actions.findIndex(t=>t.uuid===this.editingAction.uuid)>=0?this.editingNode.actions.map(e=>e.uuid===this.editingAction.uuid?t:e):[...this.editingNode.actions,t];const n={...this.editingNode,actions:o};if(this.isCreatingNewNode){const t=Qc(),i={position:this.pendingNodePosition||{left:0,top:0},type:null===(e=this.editingNodeUI)||void 0===e?void 0:e.type,config:{}};t.getState().addNode(n,i),this.pendingCanvasConnection&&(t.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,n.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([n.uuid])})}else{const t=this.editingNode.uuid;null===(i=Qc())||void 0===i||i.getState().updateNode(t,n),requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])})}}this.closeNodeEditor()}closeNodeEditor(){this.editingNode=null,this.editingNodeUI=null,this.editingAction=null,this.dialogOrigin=null,this.editForceBase=!1}handleActionEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}handleNodeSaved(t,e){var i,o,n;if(this.editingNode)if(this.isCreatingNewNode){const o=Qc(),n={position:this.pendingNodePosition||{left:0,top:0},type:null===(i=this.editingNodeUI)||void 0===i?void 0:i.type,config:e||{}};o.getState().addNode(t,n),this.pendingCanvasConnection&&(o.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,t.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t.uuid])})}else{if(this.plumber){const e=this.editingNode.exits||[],i=t.exits||[];e.filter(t=>!i.find(e=>e.uuid===t.uuid)).forEach(t=>{this.plumber.removeExitConnection(t.uuid)})}this.plumber.revalidate([t.uuid]),null===(o=Qc())||void 0===o||o.getState().updateNode(this.editingNode.uuid,t),e&&(null===(n=Qc())||void 0===n||n.getState().updateNodeUIConfig(t.uuid,e));const i=t.uuid;requestAnimationFrame(()=>{this.checkCollisionsAndReflow([i])})}this.closeNodeEditor()}handleNodeEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}getNodeAtPosition(t,e){const i=this.querySelectorAll("temba-flow-node");for(const o of Array.from(i)){const i=o.getBoundingClientRect();if(t>=i.left&&t<=i.right&&e>=i.top&&e<=i.bottom)return o.getAttribute("data-node-uuid")}return null}calculateCanvasDropPosition(t,e,i=!0){const o=this.querySelector("#canvas");if(!o)return{left:0,top:0};const n=o.getBoundingClientRect(),s=(t-n.left)/this.zoom-20,r=(e-n.top)/this.zoom-20;return i?{left:Mc(s),top:Mc(r)}:{left:s,top:r}}handleActionDragExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d=60,isLastAction:c=!1}=t.detail,h=!this.isActionExternalDrag;if(this.isActionExternalDrag=!0,this.actionDragLastDetail={action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d,isLastAction:c},h){null!==(i=null===(e=this.querySelector("#canvas"))||void 0===e?void 0:e.classList.contains("shift-held"))&&void 0!==i&&i?(this.actionDragIsCopy=!0,this.showActionOriginal(!0)):null===(o=this.querySelector("#drag-hint"))||void 0===o||o.classList.add("visible")}const u=this.getNodeAtPosition(a,l);if(u&&u!==s){const t=this.definition._ui.nodes[u],e=this.definition.nodes.find(t=>t.uuid===u);if("execute_actions"===(null==t?void 0:t.type)&&e){if(this.previousActionDragTargetNodeUuid&&this.previousActionDragTargetNodeUuid!==u){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1}))}this.actionDragTargetNodeUuid=u,this.previousActionDragTargetNodeUuid=u,this.canvasDropPreview=null;const t=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);t&&t.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1}));const e=this.querySelector(`temba-flow-node[data-node-uuid="${u}"]`);return e&&e.dispatchEvent(new CustomEvent("action-drag-over",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d},bubbles:!1})),void this.requestUpdate()}}if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.actionDragTargetNodeUuid=null;const p=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);if(!c||this.actionDragIsCopy){p&&p.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const t=this.calculateCanvasDropPosition(a,l,!1);this.canvasDropPreview={action:n,nodeUuid:s,actionIndex:r,position:t,actionHeight:d}}else p&&p.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null;this.requestUpdate()}handleActionDragInternal(t){var e;if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible"),this.actionDragLastDetail=null}showActionOriginal(t){if(!this.actionDragLastDetail)return;const e=this.querySelector(`temba-flow-node[data-node-uuid="${this.actionDragLastDetail.nodeUuid}"]`);e&&e.dispatchEvent(new CustomEvent(t?"action-show-original":"action-hide-original",{detail:{},bubbles:!1}))}reprocessActionDrag(){if(!this.actionDragLastDetail)return;const{action:t,nodeUuid:e,actionIndex:i,mouseX:o,mouseY:n,actionHeight:s}=this.actionDragLastDetail,r=this.querySelector(`temba-flow-node[data-node-uuid="${e}"]`);if(!this.actionDragTargetNodeUuid)if(this.actionDragIsCopy){r&&r.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const a=this.calculateCanvasDropPosition(o,n,!1);this.canvasDropPreview={action:t,nodeUuid:e,actionIndex:i,position:a,actionHeight:s}}else r&&r.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null}handleActionDropExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isLastAction:d=!1}=t.detail,c=this.actionDragIsCopy;this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,this.actionDragLastDetail=null,this.previousActionDragTargetNodeUuid=null,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible");const h=this.actionDragTargetNodeUuid;if(h&&h!==s){const t=this.querySelector(`temba-flow-node[data-node-uuid="${h}"]`);return t&&t.dispatchEvent(new CustomEvent("action-drop",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isCopy:c},bubbles:!1})),this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null)}if(d&&!c)return this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null);const u=this.calculateCanvasDropPosition(a,l,!0);if(!c){const t=this.definition.nodes.find(t=>t.uuid===s);if(!t)return;const e=t.actions.filter((t,e)=>e!==r);if(0===e.length)this.deleteNodes([s]);else{const o={...t,actions:e};null===(i=Qc())||void 0===i||i.getState().updateNode(s,o)}}const p=c?{...n,uuid:Kt()}:n,m={uuid:Kt(),actions:[p],exits:[{uuid:Kt(),destination_uuid:null}]},g={position:u,type:"execute_actions",config:{}};null===(o=Qc())||void 0===o||o.getState().addNode(m,g),c&&this.copyActionLocalizations(n.uuid,p.uuid),this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([m.uuid])})}copyActionLocalizations(t,e){var i,o,n;const s=null===(i=this.definition)||void 0===i?void 0:i.localization;if(!s)return;const r=null===(o=Qc())||void 0===o?void 0:o.getState();if(r)for(const i of Object.keys(s)){const o=null===(n=s[i])||void 0===n?void 0:n[t];o&&r.updateLocalization(i,e,JSON.parse(JSON.stringify(o)))}}closeOpenWindows(){var t;if(this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0),this.simulatorActive){const t=document.querySelector("temba-simulator");null==t||t.handleClose()}}closeFloatingWindows(){var t;this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0)}getRevisionsWindow(){return this.querySelector("temba-revisions-window")}handleIssuesTabClick(){this.issuesWindowHidden?(this.closeOpenWindows(),this.issuesWindowHidden=!1):this.issuesWindowHidden=!0}handleIssueSelected(t){var e;const{issue:i}=t.detail;this.issuesWindowHidden=!0,this.focusNode(i.node_uuid);const o=this.definition.nodes.find(t=>t.uuid===i.node_uuid);if(o)if(i.action_uuid){const t=null===(e=o.actions)||void 0===e?void 0:e.find(t=>t.uuid===i.action_uuid);t&&(this.editingAction=t,this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid])}else this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid]}handleRevisionViewed(){var t;this.viewingRevision=!0,this.closeFlowSearch(),null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionCancelled(){var t;this.viewingRevision=!1,null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionsClosed(){this.viewingRevision=!1,this.revisionsWindowHidden=!0}async handleRevisionReverted(t){var e;const{definition:i,languageCode:o}=t.detail;this.viewingRevision=!1,this.revisionsWindowHidden=!0,null===(e=this.plumber)||void 0===e||e.reset(),await this.saveChanges(i),Qc().getState().fetchRevision(`/flow/revisions/${this.flow}`).finally(()=>{o&&this.handleLanguageChange(o)})}renderToolbarElement(){var t,e,i,o;const n=this.getLocalizationLanguages(),s=this.getAvailableLanguages(),r=null===(t=this.definition)||void 0===t?void 0:t.language,a=(null===(e=s.find(t=>t.code===r))||void 0===e?void 0:e.name)||(r?$c(r):"")||"Primary language",l=!this.languageCode||this.languageCode===r||!n.some(t=>t.code===this.languageCode),d=l?null:n.find(t=>t.code===this.languageCode),c=d||{name:a},h=this.getLocalizationProgress(l?"":this.languageCode),u=Math.round(h.localized/Math.max(h.total,1)*100),p=!this.definition||0===this.definition.nodes.length?[]:[{name:a,value:Nm},...n.map(t=>{const e=this.getLocalizationProgress(t.code),i=Math.round(e.localized/Math.max(e.total,1)*100);return{name:t.name,value:t.code,percent:i}})],m=this.autoTranslateEnabled&&Boolean(d)&&h.total>0&&h.localized<h.total;return W`
10934
+ </div>`}checkCollisionsAndReflow(t=[]){var e,i;if(!this.definition)return;const o=[];for(const t of this.definition.nodes){const i=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid];if(!(null==i?void 0:i.position))continue;const n=Wc(t.uuid,i.position);n&&o.push(n)}const n=(null===(i=this.definition._ui)||void 0===i?void 0:i.stickies)||{};for(const[t,e]of Object.entries(n)){if(!e.position)continue;const i=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(!i)continue;const n=Wc(t,e.position,i);n&&o.push(n)}const s=((t,e)=>{const i=new Map,o=new Set(t),n=new Map;for(const t of e)n.set(t.uuid,{...t});for(const t of[...o]){const e=n.get(t);if(e)for(const[i,s]of n)if(i!==t&&!o.has(i)&&Vc(e,s)&&e.top>s.top&&s.top<30){o.delete(t),o.add(i);break}}const s=[],r=new Set;for(const t of o){const e=n.get(t);if(e)for(const[t,i]of n)o.has(t)||r.has(t)||Vc(e,i)&&(s.push(t),r.add(t))}const a=new Set;let l=0;for(;s.length>0&&l<200;){l++;const t=s.shift();if(a.has(t))continue;const e=n.get(t),d=[];for(const[i,s]of n)i!==t&&(o.has(i)||a.has(i))&&Vc(e,s)&&d.push(s);if(0===d.length)continue;const c=d.filter(t=>o.has(t.uuid)),h=[...Zc];let u=null;if(c.length>0){for(const t of c){if(e.top>t.top){const t=h.indexOf("up");-1!==t&&h.splice(t,1)}if(e.left>t.left){const t=h.indexOf("left");-1!==t&&h.splice(t,1)}}let t=0,i=0;for(const o of c)t+=Math.min(e.right,o.right)-Math.max(e.left,o.left),i+=Math.min(e.bottom,o.bottom)-Math.max(e.top,o.top);t>i?u="vertical":i>t&&(u="horizontal")}let p=null,m=1/0;for(const i of h){const s=Kc(e,d,i);if(!s)continue;const r=Yc(e,s.left,s.top);let l=!1,h=0;for(const[e,i]of n)if(e!==t&&Vc(r,i)){if(o.has(e)||a.has(e)){l=!0;break}h++}if(l)continue;const g=Math.abs(s.left-e.left)+Math.abs(s.top-e.top);let f;if(c.length>0){const t="up"===i||"down"===i;f=2e3*h+(null===u||"vertical"===u&&t||"horizontal"===u&&!t?0:5e3)+g}else f=1e4*h+g;f<m&&(m=f,p=s)}if(p){i.set(t,{left:p.left,top:p.top});const l=Yc(e,p.left,p.top);n.set(t,l),a.add(t);for(const[e,i]of n)e!==t&&(o.has(e)||a.has(e)||r.has(e)||Vc(l,i)&&(s.push(e),r.add(e)))}}return i})(t,o);if(s.size>0){const t={};for(const[e,i]of s.entries())t[e]=i;Qc().getState().updateCanvasPositions(t)}}findTargetNodeAt(t,e){var i;const o=document.elementFromPoint(t,e);return null!==(i=null==o?void 0:o.closest("temba-flow-node"))&&void 0!==i?i:null}updateCanvasSize(){var t;if(!this.definition)return;const e=Qc();if(!e)return;let i=0,o=0;this.definition.nodes.forEach(t=>{const e=this.definition._ui.nodes[t.uuid];if(e&&e.position){const n=this.querySelector(`[id="${t.uuid}"]`);n&&(i=Math.max(i,e.position.left+n.offsetWidth),o=Math.max(o,e.position.top+n.offsetHeight))}});const n=(null===(t=this.definition._ui)||void 0===t?void 0:t.stickies)||{};Object.entries(n).forEach(([t,e])=>{if(e.position){const n=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(n){const t=n.clientWidth,s=n.clientHeight;i=Math.max(i,e.position.left+t),o=Math.max(o,e.position.top+s)}else i=Math.max(i,e.position.left+(e.width||200)),o=Math.max(o,e.position.top+(e.height||100))}}),e.getState().expandCanvas(i,o)}handleCanvasContextMenu(t){if(this.isReadOnly())return void t.preventDefault();"canvas"===t.target.id&&(t.preventDefault(),t.stopPropagation(),this.dragManager.blurActiveContentEditable(),this.showContextMenuAt(t.clientX,t.clientY))}showContextMenuAt(t,e){if(this.isReadOnly())return;const i=this.querySelector("#canvas");if(!i)return;const o=i.getBoundingClientRect(),n=(t-o.left)/this.zoom-10,s=(e-o.top)/this.zoom-10,r=Mc(n),a=Mc(s),l=this.querySelector("temba-canvas-menu");if(l){const i=this.definition&&this.definition.nodes.length>0;l.show(t,e,{x:r,y:a},!0,i,up[this.flowType])}}handleEmptyFlowClick(t){const e=this.querySelector("#editor");if(!e)return;e.scrollTo({left:0,top:0,behavior:"smooth"});const i=this.querySelector("temba-canvas-menu");if(i){const e=t.currentTarget.getBoundingClientRect(),o=265,n=e.left+e.width/2-o/2,s=e.bottom+8;i.show(n,s,{x:0,y:0},!1,!1,up[this.flowType])}}handleCanvasMenuSelection(t){const e=t.detail,i=Qc();if("reflow"!==e.action)if("sticky"===e.action){const t=i.getState().createStickyNote({left:e.position.x,top:e.position.y});requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])}),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null}else if("other"===e.action){const t=this.querySelector("temba-node-type-selector");t&&t.show("all",e.position)}else this.handleNodeTypeSelection(new CustomEvent(Fo.Selection,{detail:{nodeType:e.action,position:e.position}}));else this.performReflow()}cleanUpConnection(){this.isCreatingNewNode&&(this.isCreatingNewNode=!1,this.pendingNodePosition=null),this.originalConnectionTargetId&&(this.plumber.connectIds(this.dragFromNodeId,this.sourceId,this.originalConnectionTargetId),this.originalConnectionTargetId=null),this.pendingCanvasConnection&&(this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null,this.originalConnectionTargetId=null)}handleCanvasMenuClosed(){this.cleanUpConnection()}handleNodeTypeSelectorClosed(){this.addActionToNodeUuid=null,this.cleanUpConnection()}handleNodeTypeSelection(t){const e=t.detail;if(this.pendingCanvasConnection,this.addActionToNodeUuid){const t=this.definition.nodes.find(t=>t.uuid===this.addActionToNodeUuid),i=this.definition._ui.nodes[this.addActionToNodeUuid];if(t&&i){const o=Kt();return this.editingAction={uuid:o,type:e.nodeType},this.editingNode=t,this.editingNodeUI=i,this.isCreatingNewNode=!1,void(this.addActionToNodeUuid=null)}this.addActionToNodeUuid=null}const i=Kt(),o=e.nodeType in Lm,n=o?"execute_actions":e.nodeType,s=Rm[n],r=(null==s?void 0:s.form)&&Object.keys(s.form).some(t=>{var e;return["rules","categories","cases"].includes(t)||"array"===(null===(e=s.form[t])||void 0===e?void 0:e.type)}),a={uuid:i,actions:[],exits:r?[]:[{uuid:Kt(),destination_uuid:null}]};r&&(a.router={type:"switch",categories:[],cases:[],operand:"@input.text",default_category_uuid:void 0});const l={position:this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},type:n,config:{}};if(this.isCreatingNewNode=!0,this.pendingNodePosition=this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},this.editingNode=a,this.editingNodeUI=l,o){const t=Kt();this.editingAction={uuid:t,type:e.nodeType}}}handleActionEditRequested(t){this.editingAction=t.detail.action,this.editForceBase=!!t.detail.forceBase,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null;const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);i&&(this.editingNode=i,this.editingNodeUI=this.definition._ui.nodes[e])}handleAddActionRequested(t){const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);if(!i)return;const o=this.definition._ui.nodes[e];if(!o)return;const n=this.querySelector("temba-node-type-selector");n&&(n.show("action-no-branching",{x:o.position.left,y:o.position.top}),this.addActionToNodeUuid=e)}handleNodeEditRequested(t){this.editForceBase=!!t.detail.forceBase,this.editingAction=null,this.editingNode=t.detail.node,this.editingNodeUI=t.detail.nodeUI,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null}handleNodeDeleted(t){const e=t.detail.uuid;e&&this.deleteNodes([e])}handleActionSaved(t){var e,i;if(this.editingNode&&this.editingAction){let o;o=this.editingNode.actions.findIndex(t=>t.uuid===this.editingAction.uuid)>=0?this.editingNode.actions.map(e=>e.uuid===this.editingAction.uuid?t:e):[...this.editingNode.actions,t];const n={...this.editingNode,actions:o};if(this.isCreatingNewNode){const t=Qc(),i={position:this.pendingNodePosition||{left:0,top:0},type:null===(e=this.editingNodeUI)||void 0===e?void 0:e.type,config:{}};t.getState().addNode(n,i),this.pendingCanvasConnection&&(t.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,n.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([n.uuid])})}else{const t=this.editingNode.uuid;null===(i=Qc())||void 0===i||i.getState().updateNode(t,n),requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])})}}this.closeNodeEditor()}closeNodeEditor(){this.editingNode=null,this.editingNodeUI=null,this.editingAction=null,this.dialogOrigin=null,this.editForceBase=!1}handleActionEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}handleNodeSaved(t,e){var i,o,n;if(this.editingNode)if(this.isCreatingNewNode){const o=Qc(),n={position:this.pendingNodePosition||{left:0,top:0},type:null===(i=this.editingNodeUI)||void 0===i?void 0:i.type,config:e||{}};o.getState().addNode(t,n),this.pendingCanvasConnection&&(o.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,t.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t.uuid])})}else{if(this.plumber){const e=this.editingNode.exits||[],i=t.exits||[];e.filter(t=>!i.find(e=>e.uuid===t.uuid)).forEach(t=>{this.plumber.removeExitConnection(t.uuid)})}this.plumber.revalidate([t.uuid]),null===(o=Qc())||void 0===o||o.getState().updateNode(this.editingNode.uuid,t),e&&(null===(n=Qc())||void 0===n||n.getState().updateNodeUIConfig(t.uuid,e));const i=t.uuid;requestAnimationFrame(()=>{this.checkCollisionsAndReflow([i])})}this.closeNodeEditor()}handleNodeEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}getNodeAtPosition(t,e){const i=this.querySelectorAll("temba-flow-node");for(const o of Array.from(i)){const i=o.getBoundingClientRect();if(t>=i.left&&t<=i.right&&e>=i.top&&e<=i.bottom)return o.getAttribute("data-node-uuid")}return null}calculateCanvasDropPosition(t,e,i=!0){const o=this.querySelector("#canvas");if(!o)return{left:0,top:0};const n=o.getBoundingClientRect(),s=(t-n.left)/this.zoom-20,r=(e-n.top)/this.zoom-20;return i?{left:Mc(s),top:Mc(r)}:{left:s,top:r}}handleActionDragExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d=60,isLastAction:c=!1}=t.detail,h=!this.isActionExternalDrag;if(this.isActionExternalDrag=!0,this.actionDragLastDetail={action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d,isLastAction:c},h){null!==(i=null===(e=this.querySelector("#canvas"))||void 0===e?void 0:e.classList.contains("shift-held"))&&void 0!==i&&i?(this.actionDragIsCopy=!0,this.showActionOriginal(!0)):null===(o=this.querySelector("#drag-hint"))||void 0===o||o.classList.add("visible")}const u=this.getNodeAtPosition(a,l);if(u&&u!==s){const t=this.definition._ui.nodes[u],e=this.definition.nodes.find(t=>t.uuid===u);if("execute_actions"===(null==t?void 0:t.type)&&e){if(this.previousActionDragTargetNodeUuid&&this.previousActionDragTargetNodeUuid!==u){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1}))}this.actionDragTargetNodeUuid=u,this.previousActionDragTargetNodeUuid=u,this.canvasDropPreview=null;const t=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);t&&t.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1}));const e=this.querySelector(`temba-flow-node[data-node-uuid="${u}"]`);return e&&e.dispatchEvent(new CustomEvent("action-drag-over",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d},bubbles:!1})),void this.requestUpdate()}}if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.actionDragTargetNodeUuid=null;const p=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);if(!c||this.actionDragIsCopy){p&&p.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const t=this.calculateCanvasDropPosition(a,l,!1);this.canvasDropPreview={action:n,nodeUuid:s,actionIndex:r,position:t,actionHeight:d}}else p&&p.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null;this.requestUpdate()}handleActionDragInternal(t){var e;if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible"),this.actionDragLastDetail=null}showActionOriginal(t){if(!this.actionDragLastDetail)return;const e=this.querySelector(`temba-flow-node[data-node-uuid="${this.actionDragLastDetail.nodeUuid}"]`);e&&e.dispatchEvent(new CustomEvent(t?"action-show-original":"action-hide-original",{detail:{},bubbles:!1}))}reprocessActionDrag(){if(!this.actionDragLastDetail)return;const{action:t,nodeUuid:e,actionIndex:i,mouseX:o,mouseY:n,actionHeight:s}=this.actionDragLastDetail,r=this.querySelector(`temba-flow-node[data-node-uuid="${e}"]`);if(!this.actionDragTargetNodeUuid)if(this.actionDragIsCopy){r&&r.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const a=this.calculateCanvasDropPosition(o,n,!1);this.canvasDropPreview={action:t,nodeUuid:e,actionIndex:i,position:a,actionHeight:s}}else r&&r.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null}handleActionDropExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isLastAction:d=!1}=t.detail,c=this.actionDragIsCopy;this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,this.actionDragLastDetail=null,this.previousActionDragTargetNodeUuid=null,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible");const h=this.actionDragTargetNodeUuid;if(h&&h!==s){const t=this.querySelector(`temba-flow-node[data-node-uuid="${h}"]`);return t&&t.dispatchEvent(new CustomEvent("action-drop",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isCopy:c},bubbles:!1})),this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null)}if(d&&!c)return this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null);const u=this.calculateCanvasDropPosition(a,l,!0);if(!c){const t=this.definition.nodes.find(t=>t.uuid===s);if(!t)return;const e=t.actions.filter((t,e)=>e!==r);if(0===e.length)this.deleteNodes([s]);else{const o={...t,actions:e};null===(i=Qc())||void 0===i||i.getState().updateNode(s,o)}}const p=c?{...n,uuid:Kt()}:n,m={uuid:Kt(),actions:[p],exits:[{uuid:Kt(),destination_uuid:null}]},g={position:u,type:"execute_actions",config:{}};null===(o=Qc())||void 0===o||o.getState().addNode(m,g),c&&this.copyActionLocalizations(n.uuid,p.uuid),this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([m.uuid])})}copyActionLocalizations(t,e){var i,o,n;const s=null===(i=this.definition)||void 0===i?void 0:i.localization;if(!s)return;const r=null===(o=Qc())||void 0===o?void 0:o.getState();if(r)for(const i of Object.keys(s)){const o=null===(n=s[i])||void 0===n?void 0:n[t];o&&r.updateLocalization(i,e,JSON.parse(JSON.stringify(o)))}}closeOpenWindows(){var t;if(this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0),this.simulatorActive){const t=document.querySelector("temba-simulator");null==t||t.handleClose()}}closeFloatingWindows(){var t;this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0)}getRevisionsWindow(){return this.querySelector("temba-revisions-window")}handleIssuesTabClick(){this.issuesWindowHidden?(this.closeOpenWindows(),this.issuesWindowHidden=!1):this.issuesWindowHidden=!0}handleIssueSelected(t){var e;const{issue:i}=t.detail;this.issuesWindowHidden=!0,this.focusNode(i.node_uuid);const o=this.definition.nodes.find(t=>t.uuid===i.node_uuid);if(o)if(i.action_uuid){const t=null===(e=o.actions)||void 0===e?void 0:e.find(t=>t.uuid===i.action_uuid);t&&(this.editingAction=t,this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid])}else this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid]}handleRevisionViewed(){var t;this.viewingRevision=!0,this.closeFlowSearch(),null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionCancelled(){var t;this.viewingRevision=!1,null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionsClosed(){this.viewingRevision=!1,this.revisionsWindowHidden=!0}async handleRevisionReverted(t){var e;const{definition:i,languageCode:o}=t.detail;this.viewingRevision=!1,this.revisionsWindowHidden=!0,null===(e=this.plumber)||void 0===e||e.reset(),await this.saveChanges(i),Qc().getState().fetchRevision(`/flow/revisions/${this.flow}`).finally(()=>{o&&this.handleLanguageChange(o)})}renderToolbarElement(){var t,e,i,o;const n=this.getLocalizationLanguages(),s=this.getAvailableLanguages(),r=null===(t=this.definition)||void 0===t?void 0:t.language,a=(null===(e=s.find(t=>t.code===r))||void 0===e?void 0:e.name)||(r?$c(r):"")||"Primary language",l=!this.languageCode||this.languageCode===r||!n.some(t=>t.code===this.languageCode),d=l?null:n.find(t=>t.code===this.languageCode),c=d||{name:a},h=this.getLocalizationProgress(l?"":this.languageCode),u=Math.round(h.localized/Math.max(h.total,1)*100),p=!this.definition||0===this.definition.nodes.length?[]:[{name:a,value:Nm},...n.map(t=>{const e=this.getLocalizationProgress(t.code),i=Math.round(e.localized/Math.max(e.total,1)*100);return{name:t.name,value:t.code,percent:i}})],m=this.autoTranslateEnabled&&Boolean(d)&&h.total>0;return W`
10938
10935
  <temba-editor-toolbar
10939
10936
  ?message-view=${this.showMessageTable}
10940
10937
  .zoom=${this.zoom}
@@ -15446,7 +15443,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15446
15443
  </div>
15447
15444
  </div>
15448
15445
  </temba-floating-window>
15449
- `}async fetchRevisions(){this.isLoading=!0;try{const t=await fe(`/flow/revisions/${this.flow}/?version=${$d}`);this.revisions=t.slice(1)}catch(t){console.error("Error fetching revisions",t)}finally{this.isLoading=!1}}async handleRevisionClick(t){var e;if((null===(e=this.viewingRevision)||void 0===e?void 0:e.id)===t.id)return;const i=Qc().getState();this.viewingRevision||(this.preRevertState={definition:i.flowDefinition,dirtyDate:i.dirtyDate},this.browseLanguageCode=i.languageCode),this.viewingRevision=t,this.isLoading=!0,this.fireCustomEvent(Fo.RevisionViewed,{revision:t});try{await i.fetchRevision(`/flow/revisions/${this.flow}`,t.id.toString()),this.browseLanguageCode&&i.setLanguageCode(this.browseLanguageCode)}catch(t){console.error("Error fetching revision details",t),this.cancelRevisionView()}finally{this.isLoading=!1}}cancelRevisionView(){const t=Qc().getState(),e=this.browseLanguageCode||t.languageCode;if(this.preRevertState){const i=t.flowInfo;t.setFlowContents({definition:this.preRevertState.definition,info:i}),this.preRevertState.dirtyDate&&t.setDirtyDate(this.preRevertState.dirtyDate),e&&t.setLanguageCode(e)}else t.fetchRevision(`/flow/revisions/${this.flow}`).finally(()=>{e&&t.setLanguageCode(e)});this.viewingRevision=null,this.preRevertState=null,this.browseLanguageCode=null,this.fireCustomEvent(Fo.RevisionCancelled)}async handleRevertClick(){if(!this.viewingRevision||!this.preRevertState)return;const t=Qc().getState(),e=this.browseLanguageCode||t.languageCode,i={...t.flowDefinition,revision:this.preRevertState.definition.revision};this.viewingRevision=null,this.preRevertState=null,this.browseLanguageCode=null,this.fireCustomEvent(Fo.RevisionReverted,{definition:i,languageCode:e})}resetScroll(){var t,e;const i=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("temba-floating-window"),o=null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelector(".body");o&&(o.scrollTop=0)}}t([mt({type:String})],hC.prototype,"flow",void 0),t([mt({type:Boolean})],hC.prototype,"hidden",void 0),t([mt({type:Boolean})],hC.prototype,"saving",void 0),t([gt()],hC.prototype,"revisions",void 0),t([gt()],hC.prototype,"viewingRevision",void 0),t([gt()],hC.prototype,"isLoading",void 0);const uC="/api/internal/llms.json";class pC extends Ve{constructor(){super(...arguments),this.definition=null,this.languageCode="",this.disabled=!1,this.running=!1,this.dialogOpen=!1,this.models=[],this.modelsLoading=!1,this.selectedModel=null,this.progress={done:0,total:0},this.error=null,this.errorExpanded=!1,this.interrupt=!1,this.everOpened=!1}static get styles(){return a`
15446
+ `}async fetchRevisions(){this.isLoading=!0;try{const t=await fe(`/flow/revisions/${this.flow}/?version=${$d}`);this.revisions=t.slice(1)}catch(t){console.error("Error fetching revisions",t)}finally{this.isLoading=!1}}async handleRevisionClick(t){var e;if((null===(e=this.viewingRevision)||void 0===e?void 0:e.id)===t.id)return;const i=Qc().getState();this.viewingRevision||(this.preRevertState={definition:i.flowDefinition,dirtyDate:i.dirtyDate},this.browseLanguageCode=i.languageCode),this.viewingRevision=t,this.isLoading=!0,this.fireCustomEvent(Fo.RevisionViewed,{revision:t});try{await i.fetchRevision(`/flow/revisions/${this.flow}`,t.id.toString()),this.browseLanguageCode&&i.setLanguageCode(this.browseLanguageCode)}catch(t){console.error("Error fetching revision details",t),this.cancelRevisionView()}finally{this.isLoading=!1}}cancelRevisionView(){const t=Qc().getState(),e=this.browseLanguageCode||t.languageCode;if(this.preRevertState){const i=t.flowInfo;t.setFlowContents({definition:this.preRevertState.definition,info:i}),this.preRevertState.dirtyDate&&t.setDirtyDate(this.preRevertState.dirtyDate),e&&t.setLanguageCode(e)}else t.fetchRevision(`/flow/revisions/${this.flow}`).finally(()=>{e&&t.setLanguageCode(e)});this.viewingRevision=null,this.preRevertState=null,this.browseLanguageCode=null,this.fireCustomEvent(Fo.RevisionCancelled)}async handleRevertClick(){if(!this.viewingRevision||!this.preRevertState)return;const t=Qc().getState(),e=this.browseLanguageCode||t.languageCode,i={...t.flowDefinition,revision:this.preRevertState.definition.revision};this.viewingRevision=null,this.preRevertState=null,this.browseLanguageCode=null,this.fireCustomEvent(Fo.RevisionReverted,{definition:i,languageCode:e})}resetScroll(){var t,e;const i=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("temba-floating-window"),o=null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelector(".body");o&&(o.scrollTop=0)}}t([mt({type:String})],hC.prototype,"flow",void 0),t([mt({type:Boolean})],hC.prototype,"hidden",void 0),t([mt({type:Boolean})],hC.prototype,"saving",void 0),t([gt()],hC.prototype,"revisions",void 0),t([gt()],hC.prototype,"viewingRevision",void 0),t([gt()],hC.prototype,"isLoading",void 0);const uC="/api/internal/llms.json";class pC extends Ve{constructor(){super(...arguments),this.definition=null,this.languageCode="",this.disabled=!1,this.running=!1,this.dialogOpen=!1,this.models=[],this.modelsLoading=!1,this.selectedModel=null,this.progress={done:0,total:0},this.error=null,this.errorExpanded=!1,this.interrupt=!1,this.updateExisting=!1,this.everOpened=!1}static get styles(){return a`
15450
15447
  :host {
15451
15448
  display: contents;
15452
15449
  }
@@ -15488,10 +15485,6 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15488
15485
  text-decoration: underline;
15489
15486
  }
15490
15487
 
15491
- .auto-translate-single-model {
15492
- font-size: 13px;
15493
- }
15494
-
15495
15488
  .auto-translate-status {
15496
15489
  display: flex;
15497
15490
  align-items: center;
@@ -15551,7 +15544,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15551
15544
  white-space: pre-wrap;
15552
15545
  word-break: break-word;
15553
15546
  }
15554
- `}async start(){this.disabled||(this.running?this.interrupt=!0:(this.error=null,this.errorExpanded=!1,this.selectedModel=null,this.dialogOpen=!0,await this.loadModels(),1===this.models.length&&(this.selectedModel=this.models[0])))}async loadModels(){var t;this.modelsLoading=!0;try{const e=Qc(),i=e&&null!==(t=await e.getResults(uC,{force:!0}))&&void 0!==t?t:[];this.models=i.filter(t=>Hp(t,"editing")).map(t=>({uuid:t.uuid,name:t.name}))}catch(t){console.error("Failed to load AI models",t),this.models=[],this.error="Unable to load AI models."}finally{this.modelsLoading=!1}}handleModelChange(t){var e;const i=t.target,o=null===(e=null==i?void 0:i.values)||void 0===e?void 0:e[0];this.selectedModel=o?{uuid:o.uuid,name:o.name}:null}confirmTranslate(){this.selectedModel&&(this.dialogOpen=!1,this.runAutoTranslation().catch(t=>{console.error("Auto translation failed",t),this.error="Auto translation failed. Please try again.",this.running=!1}))}cancelDialog(){this.dialogOpen=!1}dismissError(){this.error=null,this.errorExpanded=!1,this.progress={done:0,total:0}}buildTranslationBatches(){var t,e;const i=new Map,o=[],n=new Map,s=new Map;if(!this.definition)return{keyToEntries:i,batches:o,preTranslated:n,duplicateKeyToCanonical:s};const r=jm(this.definition,this.languageCode),a=new Map,l=(null===(t=this.definition.localization)||void 0===t?void 0:t[this.languageCode])||{};for(const t of r)for(const i of t.translations){if(!i.to||0===i.to.trim().length)continue;if(!i.from||0===i.from.trim().length)continue;const t=null===(e=l[i.uuid])||void 0===e?void 0:e[i.attribute];if(!Array.isArray(t)||0===t.length)continue;const o=JSON.stringify([i.from]);a.has(o)||a.set(o,t)}const d=new Map;for(const t of r)for(const e of t.translations){if(e.to&&e.to.trim().length>0)continue;if(!e.from||0===e.from.trim().length)continue;const t=`${e.uuid}:${e.attribute}`,o=i.get(t)||[];o.push(e),i.set(t,o);const n=d.get(t)||[];n.push(e.from),d.set(t,n)}const c=new Map,h=[];for(const[t,e]of d){const i=JSON.stringify(e),o=a.get(i);if(o&&o.length===e.length){n.set(t,o);continue}const r=c.get(i);r?s.set(t,r):(c.set(i,t),h.push({key:t,values:e}))}const u=this.definition.language,p=this.languageCode,m=t=>JSON.stringify({source:u,target:p,items:t}).length;let g={};for(const{key:t,values:e}of h){const i={...g,[t]:e},n=m(i),s=Object.keys(g).length>0;n>1e4&&s?(o.push({items:g}),g={[t]:e}):g=i}return Object.keys(g).length>0&&o.push({items:g}),{keyToEntries:i,batches:o,preTranslated:n,duplicateKeyToCanonical:s}}async runAutoTranslation(){var t,e;if(!this.definition||!this.selectedModel||this.languageCode===this.definition.language)return;const{keyToEntries:i,batches:o,preTranslated:n,duplicateKeyToCanonical:s}=this.buildTranslationBatches();if(n.size>0&&this.applyBatchTranslations(Object.fromEntries(n),i),0===o.length)return;const r=new Map;for(const[t,e]of s){const i=r.get(e)||[];i.push(t),r.set(e,i)}this.running=!0,this.interrupt=!1,this.progress={done:0,total:o.length};const a=this.definition.language,l=this.languageCode,d=`/llm/translate/${this.selectedModel.uuid}/`,c=Qc();if(c){for(let n=0;n<o.length&&!this.interrupt;n++){try{const s=await c.postJSON(d,{source:a,target:l,items:o[n].items});if(!(s.status>=200&&s.status<300)){this.error=(null===(e=s.json)||void 0===e?void 0:e.error)||`Translate request failed (${s.status}).`;break}{const e=(null===(t=s.json)||void 0===t?void 0:t.items)||{},o={...e};for(const t of Object.keys(e)){const i=r.get(t);if(i)for(const n of i)o[n]=e[t]}this.applyBatchTranslations(o,i)}}catch(t){console.error("Translate request failed",t),this.error="Translate request failed.";break}this.progress={done:n+1,total:o.length}}this.running=!1,this.interrupt=!1}else this.running=!1}applyBatchTranslations(t,e){var i,o;const n=Qc();if(!n||!this.definition)return;const s=new Map;for(const[n,r]of Object.entries(t)){const t=e.get(n);if(!t||0===t.length)continue;const[a]=t,l=a.uuid,d=a.attribute;if(e.delete(n),!r||0===r.length)continue;const c=zd.getState().flowDefinition,h=(null===(o=null===(i=null==c?void 0:c.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[l])||{},u=s.get(l)||{...h};u[d]=r,s.set(l,u)}for(const[t,e]of s.entries())n.getState().updateLocalization(this.languageCode,t,e),zd.getState().markAutoTranslated(this.languageCode,t,Object.keys(e).filter(t=>e[t]&&e[t].length>0))}updated(t){t.has("running")&&this.dispatchEvent(new CustomEvent("temba-auto-translate-changed",{detail:{running:this.running},bubbles:!0,composed:!0}))}handleDialogButton(t){var e,i;const o=null===(i=null===(e=t.detail)||void 0===e?void 0:e.button)||void 0===i?void 0:i.name;this.error?this.dismissError():this.running?this.interrupt||(this.interrupt=!0):"Translate"===o?this.confirmTranslate():this.cancelDialog()}render(){const t=this.dialogOpen,e=this.running||!!this.error,i=t||e;if(!i&&!this.everOpened)return"";i&&(this.everOpened=!0);let o="Auto Translation",n=W``,s="",r="",a="",l=!1;if(this.error)o="Problem with AI Model",n=this.renderErrorBody(),a="Dismiss";else if(this.running)n=this.renderRunningBody(),s=this.renderRunningGutter(),r="Stop",l=this.interrupt;else if(t){const t=!this.modelsLoading&&0===this.models.length;n=this.renderPickerBody(),a=t?"Close":"Cancel",r=t?"":"Translate",l=this.modelsLoading||t||!this.selectedModel}return W`
15547
+ `}async start(){this.disabled||(this.running?this.interrupt=!0:(this.error=null,this.errorExpanded=!1,this.selectedModel=null,this.updateExisting=!1,this.dialogOpen=!0,await this.loadModels(),1===this.models.length&&(this.selectedModel=this.models[0])))}async loadModels(){var t;this.modelsLoading=!0;try{const e=Qc(),i=e&&null!==(t=await e.getResults(uC,{force:!0}))&&void 0!==t?t:[];this.models=i.filter(t=>Hp(t,"editing")).map(t=>({uuid:t.uuid,name:t.name}))}catch(t){console.error("Failed to load AI models",t),this.models=[],this.error="Unable to load AI models."}finally{this.modelsLoading=!1}}handleModelChange(t){var e;const i=t.target,o=null===(e=null==i?void 0:i.values)||void 0===e?void 0:e[0];this.selectedModel=o?{uuid:o.uuid,name:o.name}:null}handleUpdateExistingChange(t){const e=t.target;this.updateExisting=!!(null==e?void 0:e.checked)}confirmTranslate(){this.selectedModel&&(this.dialogOpen=!1,this.runAutoTranslation().catch(t=>{console.error("Auto translation failed",t),this.error="Auto translation failed. Please try again.",this.running=!1}))}cancelDialog(){this.dialogOpen=!1}dismissError(){this.error=null,this.errorExpanded=!1,this.progress={done:0,total:0}}buildTranslationBatches(){var t,e;const i=new Map,o=[],n=new Map,s=new Map;if(!this.definition)return{keyToEntries:i,batches:o,preTranslated:n,duplicateKeyToCanonical:s};const r=jm(this.definition,this.languageCode),a=this.updateExisting,l=new Map,d=(null===(t=this.definition.localization)||void 0===t?void 0:t[this.languageCode])||{};if(!a)for(const t of r)for(const i of t.translations){if(!i.toValues||!i.toValues.some(t=>t&&t.trim().length>0))continue;if(!i.fromValues||0===i.fromValues.length)continue;const t=null===(e=d[i.uuid])||void 0===e?void 0:e[i.attribute];if(!Array.isArray(t)||0===t.length)continue;const o=JSON.stringify(i.fromValues);l.has(o)||l.set(o,t)}const c=new Map;for(const t of r)for(const e of t.translations){if(!a&&e.toValues&&e.toValues.some(t=>t&&t.trim().length>0))continue;if(!e.fromValues||0===e.fromValues.length)continue;const t=`${e.uuid}:${e.attribute}`,o=i.get(t)||[];o.push(e),i.set(t,o),c.has(t)||c.set(t,e.fromValues)}const h=new Map,u=[];for(const[t,e]of c){const i=JSON.stringify(e),o=l.get(i);if(o&&o.length===e.length){n.set(t,o);continue}const r=h.get(i);r?s.set(t,r):(h.set(i,t),u.push({key:t,values:e}))}const p=this.definition.language,m=this.languageCode,g=t=>JSON.stringify({source:p,target:m,items:t}).length;let f={};for(const{key:t,values:e}of u){const i={...f,[t]:e},n=g(i),s=Object.keys(f).length>0;n>1e4&&s?(o.push({items:f}),f={[t]:e}):f=i}return Object.keys(f).length>0&&o.push({items:f}),{keyToEntries:i,batches:o,preTranslated:n,duplicateKeyToCanonical:s}}async runAutoTranslation(){var t,e;if(!this.definition||!this.selectedModel||this.languageCode===this.definition.language)return;const{keyToEntries:i,batches:o,preTranslated:n,duplicateKeyToCanonical:s}=this.buildTranslationBatches();if(n.size>0&&this.applyBatchTranslations(Object.fromEntries(n),i),0===o.length)return;const r=new Map;for(const[t,e]of s){const i=r.get(e)||[];i.push(t),r.set(e,i)}this.running=!0,this.interrupt=!1,this.progress={done:0,total:o.length};const a=this.definition.language,l=this.languageCode,d=`/llm/translate/${this.selectedModel.uuid}/`,c=Qc();if(c){for(let n=0;n<o.length&&!this.interrupt;n++){try{const s=await c.postJSON(d,{source:a,target:l,items:o[n].items});if(!(s.status>=200&&s.status<300)){this.error=(null===(e=s.json)||void 0===e?void 0:e.error)||`Translate request failed (${s.status}).`;break}{const e=(null===(t=s.json)||void 0===t?void 0:t.items)||{},o={...e};for(const t of Object.keys(e)){const i=r.get(t);if(i)for(const n of i)o[n]=e[t]}this.applyBatchTranslations(o,i)}}catch(t){console.error("Translate request failed",t),this.error="Translate request failed.";break}this.progress={done:n+1,total:o.length}}this.running=!1,this.interrupt=!1}else this.running=!1}applyBatchTranslations(t,e){var i,o;const n=Qc();if(!n||!this.definition)return;const s=new Map;for(const[n,r]of Object.entries(t)){const t=e.get(n);if(!t||0===t.length)continue;const[a]=t,l=a.uuid,d=a.attribute;if(e.delete(n),!r||0===r.length)continue;const c=zd.getState().flowDefinition,h=(null===(o=null===(i=null==c?void 0:c.localization)||void 0===i?void 0:i[this.languageCode])||void 0===o?void 0:o[l])||{},u=Array.isArray(h[d])?h[d]:null,p=!!u&&u.length===r.length,m=r.map((t,e)=>(null==t||"string"==typeof t&&0===t.trim().length)&&p&&u[e]?u[e]:t),g=m.some(t=>t&&("string"!=typeof t||t.trim().length>0));if(!g)continue;const f=s.get(l)||{...h};f[d]=m,s.set(l,f)}for(const[t,e]of s.entries())n.getState().updateLocalization(this.languageCode,t,e),zd.getState().markAutoTranslated(this.languageCode,t,Object.keys(e).filter(t=>e[t]&&e[t].length>0))}updated(t){t.has("running")&&this.dispatchEvent(new CustomEvent("temba-auto-translate-changed",{detail:{running:this.running},bubbles:!0,composed:!0}))}handleDialogButton(t){var e,i;const o=null===(i=null===(e=t.detail)||void 0===e?void 0:e.button)||void 0===i?void 0:i.name;this.error?this.dismissError():this.running?this.interrupt||(this.interrupt=!0):"Translate"===o?this.confirmTranslate():this.cancelDialog()}render(){const t=this.dialogOpen,e=this.running||!!this.error,i=t||e;if(!i&&!this.everOpened)return"";i&&(this.everOpened=!0);let o="Auto Translation",n=W``,s="",r="",a="",l=!1;if(this.error)o="Problem with AI Model",n=this.renderErrorBody(),a="Dismiss";else if(this.running)n=this.renderRunningBody(),s=this.renderRunningGutter(),r="Stop",l=this.interrupt;else if(t){const t=!this.modelsLoading&&0===this.models.length;n=this.renderPickerBody(),a=t?"Close":"Cancel",r=t?"":"Translate",l=this.modelsLoading||t||!this.selectedModel}return W`
15555
15548
  <temba-dialog
15556
15549
  header=${o}
15557
15550
  .open=${i}
@@ -15565,7 +15558,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15565
15558
  <div class="auto-translate-body">${n}</div>
15566
15559
  ${s?W`<div slot="gutter">${s}</div>`:""}
15567
15560
  </temba-dialog>
15568
- `}renderPickerBody(){var t;if(this.modelsLoading)return W`<div class="auto-translate-loading">
15561
+ `}renderPickerBody(){if(this.modelsLoading)return W`<div class="auto-translate-loading">
15569
15562
  <temba-loading units="3" size="8"></temba-loading>
15570
15563
  </div>`;if(0===this.models.length)return W`
15571
15564
  <div class="auto-translate-empty">
@@ -15576,24 +15569,29 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15576
15569
  >
15577
15570
  </p>
15578
15571
  </div>
15579
- `;const e=this.selectedModel?[this.selectedModel]:[],i=$c(this.languageCode);return W`
15572
+ `;const t=this.selectedModel?[this.selectedModel]:[],e=$c(this.languageCode),i=this.brand?W`${this.brand} uses AI for automatic translation, which can make
15573
+ mistakes,`:W`Automatic translation uses AI, which can make mistakes,`;return W`
15580
15574
  <p>
15581
- All remaining text for <strong>${i}</strong> will be
15582
- translated automatically. Remember, AI models can make mistakes so it is
15583
- important to review all of your translations to verify they are correct.
15575
+ All remaining text for <strong>${e}</strong> will be
15576
+ translated automatically. ${i} so it is important to review all
15577
+ of your translations to verify they are correct.
15584
15578
  </p>
15585
15579
  ${this.models.length>1?W`<temba-select
15586
15580
  class="auto-translate-model-select"
15587
15581
  endpoint="${uC}"
15588
15582
  valueKey="uuid"
15589
- .values=${e}
15583
+ .values=${t}
15590
15584
  .shouldExclude=${t=>!Hp(t,"editing")}
15591
15585
  ?searchable=${!0}
15592
15586
  placeholder="Select an AI model"
15593
15587
  @change=${this.handleModelChange}
15594
- ></temba-select>`:W`<div class="auto-translate-single-model">
15595
- Using <strong>${null===(t=this.models[0])||void 0===t?void 0:t.name}</strong>
15596
- </div>`}
15588
+ ></temba-select>`:""}
15589
+ <temba-checkbox
15590
+ class="auto-translate-update-existing"
15591
+ label="Update existing translations"
15592
+ ?checked=${this.updateExisting}
15593
+ @change=${this.handleUpdateExistingChange}
15594
+ ></temba-checkbox>
15597
15595
  `}renderRunningBody(){const{done:t,total:e}=this.progress,i=e>0?Math.round(t/e*100):0;return W`
15598
15596
  <temba-progress
15599
15597
  .total=${e}
@@ -15625,7 +15623,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
15625
15623
  Show details
15626
15624
  </button>`}
15627
15625
  </div>
15628
- `}}t([mt({attribute:!1})],pC.prototype,"definition",void 0),t([mt({type:String,attribute:"language-code"})],pC.prototype,"languageCode",void 0),t([mt({type:Boolean})],pC.prototype,"disabled",void 0),t([mt({type:Boolean,reflect:!0})],pC.prototype,"running",void 0),t([gt()],pC.prototype,"dialogOpen",void 0),t([gt()],pC.prototype,"models",void 0),t([gt()],pC.prototype,"modelsLoading",void 0),t([gt()],pC.prototype,"selectedModel",void 0),t([gt()],pC.prototype,"progress",void 0),t([gt()],pC.prototype,"error",void 0),t([gt()],pC.prototype,"errorExpanded",void 0),t([gt()],pC.prototype,"interrupt",void 0);class mC extends Ve{static get styles(){return a`
15626
+ `}}t([mt({attribute:!1})],pC.prototype,"definition",void 0),t([mt({type:String,attribute:"language-code"})],pC.prototype,"languageCode",void 0),t([mt({type:Boolean})],pC.prototype,"disabled",void 0),t([Id(zd,t=>t.brand)],pC.prototype,"brand",void 0),t([mt({type:Boolean,reflect:!0})],pC.prototype,"running",void 0),t([gt()],pC.prototype,"dialogOpen",void 0),t([gt()],pC.prototype,"models",void 0),t([gt()],pC.prototype,"modelsLoading",void 0),t([gt()],pC.prototype,"selectedModel",void 0),t([gt()],pC.prototype,"progress",void 0),t([gt()],pC.prototype,"error",void 0),t([gt()],pC.prototype,"errorExpanded",void 0),t([gt()],pC.prototype,"interrupt",void 0),t([gt()],pC.prototype,"updateExisting",void 0);class mC extends Ve{static get styles(){return a`
15629
15627
  :host {
15630
15628
  display: block;
15631
15629
  overflow: auto;