@telia-ace/widget-conversational-hub 1.1.2

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.
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import ConversationalHubProviderPlugin from './plugin';
2
+ export { ConversationalHubProviderPlugin };
package/index.js ADDED
@@ -0,0 +1,160 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Pt=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},bs=n=>{const t=n.container||n;return{info:(e,...s)=>Pt(t,"info",e,...s),warn:(e,...s)=>Pt(t,"warning",e,...s),error:(e,...s)=>Pt(t,"error",e,...s)}};var X=(n=>(n.Implementation="implementation",n.Widget="widget",n))(X||{}),T=(n=>(n.Pre="pre",n.Post="post",n))(T||{});const $s=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let a;return i[r]&&(a=i[r].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function fe(n,t){return typeof n>"u"?t:n}let ws=class{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:X.Widget,stage:T.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:fe(e.scope,X.Widget),stage:fe(e.stage,T.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((a,c)=>{c===o.length-1?r[a]||(r[a]=()=>i):r=this.part[a]=this.part[a]||{}}),this}get(){return this.part}};const Qe=n=>{const t=new ws({});return n(t),t.get()};Qe(n=>{n.createCommand("types.register",{scope:X.Implementation,stage:T.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:T.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:T.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:T.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,a=e,c=s;typeof e=="string"&&(o=e,a=s,c=i);const h=l=>{const{transformPluginSettings:d}=t.container.get("$environmentOptions"),u=d?d(c||{},o,t.container,a):s;try{const p=$s(o,a,r,u);r.get("$plugins").push(p),l&&p.invoke("initialize",null)}catch(p){bs(t).warn("Error when initializing plugin",p)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})});const _s=Qe(n=>{n.createCommand("ready",{scope:X.Implementation,stage:T.Pre},t=>e=>{const{container:s}=t,i=s.owner;s.get("bootstrapping").ready?e(i):i.events.subscribeOnce("bootstrap:ready",()=>{e(i)})})}),kt=new WeakMap;function J(){return n=>(kt.has(n)||kt.set(n,{}),kt.get(n))}const St=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},$=n=>{const t=n.container||n;return{info:(e,...s)=>St(t,"info",e,...s),warn:(e,...s)=>St(t,"warning",e,...s),error:(e,...s)=>St(t,"error",e,...s)}},g=J(),Gt=(()=>{let n=0;return()=>++n})(),Xt=(n,t,e)=>{const s=g(n).touchQueue.get(t);s&&s.forEach(i=>{i(e,n)})};let As=class{constructor(t,e,s,i){this.key=t,this.factory=e,this.parent=s,this.container=i,this.id=Gt(),this.resolved=!1,this.constructed=!1,this.async=!0}resolve(){if(!this.constructed){const t=this.factory(this.parent,this.container);return this.constructed=!0,this.value=Promise.resolve(t).then(e=>(this.resolved=!0,Xt(this.container,this.key,e),e))}return this.value}},Es=class{constructor(t,e,s,i){this.key=t,this.value=e,this.parent=s,this.container=i,this.id=Gt(),this.async=!1,this.resolved=!1,this.constructed=!0,this.resolve=()=>(this.resolved=!0,Xt(this.container,this.key,this.value),this.value)}},xs=class{constructor(t,e,s,i){this.key=t,this.value=e,this.parent=s,this.container=i,this.id=Gt(),this.async=!1,this.resolved=!1,this.constructed=!1,this.resolve=()=>{this.resolved=!0,this.constructed=!0;const r=this.value(this.parent,this.container);return Xt(this.container,this.key,this.value),r}}},Cs=class Ye{constructor(t,e,s){this.owner=t,this.name=e,this.parent=s,g(this).resolvers=new Map,g(this).touchQueue=new Map,g(this).children=[]}delete(t){const e=g(this).resolvers,s=Array.from(e.values()).find(i=>i.id===t);return s?(g(this).touchQueue.delete(s.key),Promise.resolve(e.delete(s.key))):this.parent?this.parent.delete(t):Promise.resolve(!1)}clear(){const t=g(this).resolvers,e=Array.from(t.values());return Promise.all(e.map(s=>{if(s.constructed)return Promise.resolve(s.resolve()).then(i=>{if(i!==null&&typeof i=="object"&&typeof i.dispose=="function")return i.dispose.call(i,this,s)})})).then(()=>{e.forEach(s=>this.delete(s.id)),g(this).children.forEach(s=>s.clear())})}detach(){if(this.parent){const t=g(this.parent).children,e=t.indexOf(this);e>-1&&(t.splice(e,1),delete this.parent)}}touch(t,e){const s=g(this).resolvers.get(t);if(s&&s.constructed)Promise.resolve(s.resolve()).then(i=>{e(i,this)});else{const i=g(this).touchQueue;let r=i.get(t);r||(r=[],i.set(t,r)),r.push(e)}return this.parent&&!s?this.parent.touch(t,e):Promise.resolve()}registerAsync(t,e){const s=g(this).resolvers.get(t);s&&!s.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${t}') previously used by a non-async resolver.`);const i=new As(t,e,s,this);return g(this).resolvers.set(t,i),i.id}registerFactory(t,e){const s=g(this).resolvers.get(t);s&&s.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);const i=new xs(t,e,s,this);return g(this).resolvers.set(t,i),i.id}register(t,e){const s=g(this).resolvers.get(t);s&&s.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);const i=new Es(t,e,s,this);return g(this).resolvers.set(t,i),i.id}get(t){const e=g(this).resolvers.get(t);if(e)return e.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`You are retrieving an async value (with key '${t}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`),e.resolve();if(this.parent)return this.parent.get(t)}getAsync(t){const e=g(this).resolvers.get(t);if(e){if(!e.async)throw process.env.NODE_ENV!=="production"&&$(this).warn(`You are retrieving a non-async value (with key '${t}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`),"Mismatching resolver type";return e.resolve()}return this.parent?this.parent.getAsync(t):Promise.resolve(void 0)}getMany(...t){const e={};return t.forEach(s=>e[s]=this.get(s)),e}getManyAsync(...t){const e={};return Promise.all(t.map(s=>this.getAsync(s).then(i=>e[s]=i))).then(()=>e)}createChild(t,e){const s=new Ye(t,e,this);return g(this).children.push(s),s}},ye=class{constructor(t,e,s=!1,i=!1){this.type=t,this.target=e,this.cancelable=!!s,this.bubbles=!!i,this.defaultPrevented=!1}preventDefault(){this.cancelable&&(this.defaultPrevented=!0)}};const x=J(),be=(n,t)=>[].concat(x(n).listenerLookup.get(t.toLowerCase())||[],x(n).listenerLookup.get("*")||[]),$e=(n,t,e,s)=>{let i,r;return t instanceof ye?(i=t,r=t.type):(i=new ye(t,n.target,!!e.cancelable,!!e.bubbles),r=t),{event:i,type:r,async:s}};let Ps=class Ze{constructor(t,e){this.target=t,this.parent=e,x(this).listenerLookup=new Map,x(this).children=[]}clear(){x(this).listenerLookup.clear(),x(this).children.forEach(t=>t.clear())}detach(){if(this.parent){const t=x(this.parent).children,e=t.indexOf(this);e>-1&&t.splice(e,1)}}subscribe(t,e,s){const i=x(this).listenerLookup,r=t.toLowerCase();return i.has(r)||i.set(r,[]),i.get(r).push(e),()=>this.unsubscribe(t,e)}subscribeOnce(t,e){const s=this.subscribe(t,(i,r)=>(s(),e(i,r)))}unsubscribe(t,e){const s=x(this).listenerLookup.get(t.toLowerCase());if(s){const i=s.indexOf(e);i>-1&&s.splice(i,1)}}dispatchAsync(t,e,s={}){const{event:i,type:r}=$e(this,t,s,!0),o=be(this,r);let a=0;const c=o.length;let h=Promise.resolve();for(a=0;a<c;a++)(l=>{h=h.then(d=>d?Promise.resolve(!0):Promise.resolve(l(i,e)).then(()=>i.defaultPrevented))})(o[a]);return h.then(l=>!l&&i.bubbles&&this.parent?this.parent.dispatchAsync(i,e):l)}dispatch(t,e,s={}){const{event:i,type:r}=$e(this,t,s,!1),o=be(this,r);let a=0;const c=o.length;let h=!1;for(a=0;a<c;a++)if(o[a](i,e),i.defaultPrevented){h=!0;break}return!h&&i.bubbles&&this.parent&&(h=this.parent.dispatch(i,e)),h}createChild(t){const e=new Ze(t,this);return x(this).children.push(e),e}};const ot=(n,t,e)=>{const s=n.get("$plugins").map(i=>{try{return i.invoke(t,e)}catch(r){$(n).error("An error occured when invoking a plugin.",i,r)}});return Promise.all(s)};let ks=class{constructor(t){this.widget=t.get("$widget"),this.events=this.widget.events,this.container=this.widget.container,this.initialized=null,this.activated=null,this.initialize=this.initialize.bind(this),this.activate=this.activate.bind(this),this.deactivate=this.deactivate.bind(this),this.invoke=this.invoke.bind(this),this.createInstance()}createInstance(){if(!this.widget.container.get("$instance")){const t=this.widget.container.get("$types"),e=this.widget.container.get("$type");!e&&$(this).error("Unable to create widget. No type is specified.");const s=t[e];!s&&$(this).error(`Unable to create widget. Type '${e}' is not registered.`),this.widget.events.dispatch("widget:create-instance",{},{bubbles:!0});try{this.widget.container.register("$instance",new s(this.container))}catch(i){$(this).error("Unable to create widget type.",i)}this.widget.events.dispatch("widget:instance-created",{},{bubbles:!0})}}initialize(t){return this.initialized=this.initialized||(()=>{const e=this.container.get("$instance"),s=e.initialize||(()=>{});return this.initialized=Promise.resolve(s.call(e,t)).then(()=>ot(this.container,"initialize",t)).then(()=>{})})()}activate(t){return(this.initialized||this.initialize()).then(()=>{this.activated=this.activated||(()=>ot(this.container,"activate").then(()=>{const e=this.container.get("$instance");return this.activated=e.activate(t)}))()})}deactivate(){const t=this.container.get("$instance"),e=t.deactivate||(()=>{});return ot(this.container,"deactivate").then(()=>Promise.resolve(e.call(t))).then(()=>{this.initialized=null,this.activated=null}).then(()=>{})}invoke(t,...e){return ot(this.container,"invoke",{command:t,args:e}).then(()=>{const s=this.container.get("$instance");if(s[t])return s[t].apply(s,e);const i=s.invoke;if(i)return i.call(s,t,...e)})}};const z=(n,t)=>{if(!t)return!0;if(typeof t=="string"){const e=t.split(",");for(let s=0,i=e.length;s<i;s++){const r=e[s].trim();if(r===n||r==="*")return!0}}return t instanceof Array?t.indexOf(n)>-1:!1},Ss=(n,t)=>{if(typeof t=="function")return t(n);const e=typeof t=="string"?Ts(t):t;return!(!z(n.implementation.tenant||"",e.tenant||"")||!z(n.implementation.name,e.implementation||"")||!z(n.name,e.widget||"")||!z(n.container.get("$type"),e.type||""))},Os=(n,t)=>{if(typeof t=="function")return t(n);const e=typeof t=="string"?Ms(t):t;return!(!z(n.tenant||"",e.tenant||"")||!z(n.name,e.implementation||""))},Ge=n=>t=>Ss(t,n),Ns=n=>t=>Os(t,n),k=n=>n instanceof Array&&n.length===1?n[0]:n,Ts=n=>{const t={},e=n.split(":");return e.length===1?t.widget=k(e[0].split(",")):e.length===2?(t.implementation=k(e[0].split(",")),t.widget=k(e[1].split(","))):(t.tenant=k(e[0].split(",")),t.implementation=k(e[1].split(",")),t.widget=k(e[2].split(","))),t},Ms=n=>{const t={},e=n.split(":");return e.length===1?t.implementation=k(e[0].split(",")):(t.tenant=k(e[0].split(",")),t.implementation=k(e[1].split(","))),t},ut=J(),we=(n,t,e)=>n.filter(s=>s.stage===t&&Ge(s.selector)(e));function Is(n){const t=n.container.get("$environment");let e=ut(t).configurationCache;e&&(e=e.filter(s=>s[0]!==n),ut(t).configurationCache=e)}var pt=(n=>(n.Implementation="implementation",n.Widget="widget",n))(pt||{}),S=(n=>(n.Pre="pre",n.Post="post",n))(S||{});const Xe=(n,t,e)=>(Object.keys(t).forEach(s=>{const i=t[s];if(typeof i=="function"){const r=i();typeof r.defaultArgs<"u"&&e(r,...r.defaultArgs),n[s]=(...o)=>{const a=Object.assign({},r,{handlerResolver:r.handlerResolver.bind({})});return e(a,...o),n}}else n[s]=Xe({},i,e)}),n),Ds=(n,t)=>{switch(t){case"implementation":return n.implementation;case"widget":return n}},_e=(n,t,e,s)=>(s.forEach(i=>{Xe(n,i,(r,...o)=>{const a={selector:t,stage:r.stage,handler:c=>{const h=Ds(c,r.scope),l={container:h.container,events:h.events},d=r.handlerResolver,u=d(l);let p=ut(e.environment).configurationCache;return p||(p=ut(e.environment).configurationCache=[]),p.find(b=>b.indexOf(h)>-1&&b.indexOf(d)>-1)?Promise.resolve():(p.push([h,d]),Promise.resolve(u(...o)))}};e.instructions.push(a)})}),n);function Us(n,t){function e(s){return _e({},s,n,t)}return _e(e,"*",n,t)}const Hs=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let a;return i[r]&&(a=i[r].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function Ae(n,t){return typeof n>"u"?t:n}let js=class{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:pt.Widget,stage:S.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:Ae(e.scope,pt.Widget),stage:Ae(e.stage,S.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((a,c)=>{c===o.length-1?r[a]||(r[a]=()=>i):r=this.part[a]=this.part[a]||{}}),this}get(){return this.part}};const ts=n=>{const t=new js({});return n(t),t.get()},Ls=ts(n=>{n.createCommand("types.register",{scope:pt.Implementation,stage:S.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:S.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:S.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:S.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,a=e,c=s;typeof e=="string"&&(o=e,a=s,c=i);const h=l=>{const{transformPluginSettings:d}=t.container.get("$environmentOptions"),u=d?d(c||{},o,t.container,a):s;try{const p=Hs(o,a,r,u);r.get("$plugins").push(p),l&&p.invoke("initialize",null)}catch(p){$(t).warn("Error when initializing plugin",p)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})}),Rs=Ls;function zs(n,t,e=[]){const s=[Rs].concat(e),i=Us(t,s);n(i,t)}let Ws=class{constructor(){this.tasks=[],this.current=Promise.resolve(),this.next=this.next.bind(this)}add(t,e,s,i){this.tasks.push({task:t,resolve:e,reject:s,done:i}),this.next()}next(){this.current=this.current.then(()=>{const t=this.tasks.shift();if(t){const e=Promise.resolve(t.task());return Promise.resolve(e).then(this.next).then(()=>e.then(s=>{t.done(),t.resolve(s)})).catch(s=>(t.done(),t.reject(s),this.next()))}return Promise.resolve()})}};const at=new WeakMap;function Bs(n){return at.has(n)||at.set(n,new Ws),t=>new Promise((e,s)=>{const i=at.get(n);i.add(t,e,s,()=>{i.tasks.length||at.delete(n)})})}const Ee=n=>typeof n<"u",K=(n,t)=>{n.events.dispatch("widget:state-change",{state:t},{bubbles:!0}),n.state=t,n.events.dispatch("widget:state-changed",{},{bubbles:!0})},E=J(),qs=n=>{const{container:t,events:e}=n;t.get("$controller")||(t.register("$controller",new ks(t)),e.dispatch("widget:controller-created",{},{bubbles:!0}))};class Vs{constructor(t,e,s){this.state="deactivated",this.name=t,this.implementation=e,this.container=e.container.createChild(this,t),this.events=e.events.createChild(this),E(this).subscriptions=[],s&&e.configure(i=>{const r=i(t);Ee(s.type)&&r.type(s.type),Ee(s.settings)&&r.settings(s.settings),s.plugins&&Object.keys(s.plugins).forEach(o=>{var a;const c=(a=s.plugins)==null?void 0:a[o];r.plugin(o,c)})}),this.load=this.load.bind(this),this.activate=this.activate.bind(this),this.invoke=this.invoke.bind(this),this.deactivate=this.deactivate.bind(this)}load(){return Bs(this)(()=>{E(this).deactivatedPromise=null;const t=this.state==="deactivated";t&&(K(this,"activating"),this.container.register("$widget",this),this.container.register("$controller",null),this.container.register("$plugins",[]),this.container.register("$type",null),this.container.register("$instance",null)),K(this,"loading");const e=this.implementation.instructions,s=we(e,S.Pre,this);return Promise.all(s.map(i=>i.handler(this))).then(()=>{qs(this);const i=we(e,S.Post,this);return Promise.all(i.map(r=>r.handler(this))).then(()=>{t&&this.container.get("$controller").initialize()})}).then(()=>(K(this,"activated"),this))})}activate(t){E(this).subscriptions.push(this.implementation.events.subscribe("implementation:configured",()=>{["activated","activating","loading"].indexOf(this.state)>-1&&this.load()}));const e=E(this).activatedPromise;return e?(process.env.NODE_ENV!=="production"&&$(this).warn(`Widget '${this.name}' has already been activated. The passed arguments for this activation will be discarded.`,t),e):E(this).activatedPromise=this.load().then(()=>this.container.get("$controller").activate(t))}invoke(t,...e){const s=E(this).activatedPromise,i=(r,...o)=>s.then(this.load).then(()=>this.container.get("$controller").invoke(r,...o));return s?i(t,...e):(process.env.NODE_ENV!=="production"&&$(this).warn("You are invoking a command on a deactivated widget. The invocation will be queued until the widget is activated.",this),new Promise(r=>{const o=this.events.subscribe("widget:state-changed",()=>{this.state==="activated"&&(o(),r(i(t,...e)))})}))}deactivate(){return E(this).deactivatedPromise||(this.state==="deactivated"?Promise.resolve():(K(this,"deactivating"),E(this).deactivatedPromise=this.container.get("$controller").deactivate().then(()=>(E(this).activatedPromise=null,E(this).subscriptions.forEach(e=>e()),E(this).subscriptions=[],this.container.clear().then(()=>{this.events.clear(),Is(this),K(this,"deactivated")})))))}}const xe=J();class Js{constructor(t,e,s=[]){this.instructions=[],this.widgets=new Map,this.name=t.name,this.tenant=t.tenant,this.environment=e,this.container=e.container.createChild(this,this.name),this.events=e.events.createChild(this),this.container.register("$types",{}),xe(this).configurationApiExtensions=s}load(){const t=Array.from(this.widgets.values());return Promise.all(t.map(e=>e.load())).then(()=>t)}configure(t){return zs(t,this,xe(this).configurationApiExtensions),this.events.dispatch("implementation:configured",{implementation:this},{bubbles:!0}),this}createWidget(t,e){const s=new Vs(t,this,e);return this.widgets.set(s.name,s),s}}function Fs(n,t,e){const s=new Js(n,t,e);return n.widgets&&Object.keys(n.widgets).forEach(i=>{var r;const o=(r=n.widgets)==null?void 0:r[i];s.createWidget(i,o)}),s}let Ce=class es{constructor(t,e){this.selectorFactory=e,typeof t=="function"?this.resolver=t:this.resolver=()=>t}append(t){const e=typeof t=="function"?t:()=>t;return new es(()=>this.all().concat(e()),this.selectorFactory)}all(){return this.resolver().concat([])}query(t){return this.all().filter(this.selectorFactory(t))}find(t){const e=this.query(t);if(e.length)return e[0]}};const te="#____version____#",Ot=J(),Ks=n=>n.tenant?`${n.name}:${n.tenant}`:n.name,ss=class{constructor(t,e=[],s={}){this.widgets=new Ce(()=>{let i=[];return this.implementations.all().forEach(r=>{i=i.concat(Array.from(r.widgets.values()))}),i},Ge),this.implementations=new Ce([],Ns),this.name=t,this.container=new Cs(this,t),this.events=new Ps(this),this.container.register("$version",te),this.container.register("$environment",this),this.container.register("$environmentOptions",s),Ot(this).configurationApiExtensions=e}createImplementation(t){const e=Ks(t);let s=this.implementations.find(e);if(s)return process.env.NODE_ENV!=="production"&&$(s).warn(`Implementation "${e}" already exist on current environment.`),s;const i=Ot(this).configurationApiExtensions;return s=Fs(t,this,i),this.implementations=this.implementations.append([s]),this.events.dispatch("implementation:created",{implementation:s}),s}patch(t={}){const{name:e,configurationApiExtensions:s}=t;typeof e<"u"&&e!==null&&(this.name=e),s&&s.forEach(i=>{Ot(this).configurationApiExtensions.push(i)})}static create(t={}){return new ss(t.name||"",t.configurationApiExtensions,t.options)}};let ns=ss;ns.version=te;const yt=(n,t,...e)=>typeof t=="string"?n(`[humany] ${t}`,...e):n(t,...e),Y=class{constructor(){this.keys=[],this.log=(t,...e)=>this.lookup(t,()=>Y.log(...e)),this.warn=(t,...e)=>this.lookup(t,()=>Y.warn(...e)),this.error=(t,...e)=>this.lookup(t,()=>Y.error(...e)),this.info=(t,...e)=>this.lookup(t,()=>Y.info(...e))}lookup(t,e){this.keys.indexOf(t)===-1&&(this.keys.push(t),e())}};let _=Y;_.log=(...n)=>yt(console.log,...n);_.warn=(...n)=>yt(console.warn,...n);_.error=(...n)=>yt(console.error,...n);_.info=(...n)=>yt(console.info,...n);const is=n=>{let t={},e,s;if(typeof n!="object"||n===null)return n;t=Array.isArray(n)?[]:{};for(s in n)e=n[s],t[s]=typeof e=="object"&&e!==null?is(e):e;return t},Qs=is;function Pe(n){let t=0;if(n.length===0)return t.toString();for(let e=0;e<n.length;e++){const s=n.charCodeAt(e);t=(t<<5)-t+s,t=t&t}return t.toString()}let Ys=class{constructor(t,e){this.lockWarningTime=t,this.lockErrorTime=e,this.tasks=[],this.current=Promise.resolve(),this.next=this.next.bind(this)}add(t,e,s,i){this.tasks.push({task:t,resolve:e,reject:s,done:i}),this.next()}next(){this.current=this.current.then(()=>{const t=this.tasks.shift();if(t){let e;const s=setTimeout(()=>{process.env.NODE_ENV!=="production"&&_.warn(`A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,t),e=setTimeout(()=>{t.reject("lock timeout exceeded")},this.lockErrorTime)},this.lockWarningTime),i=Promise.resolve(t.task()).then(r=>(clearTimeout(s),clearTimeout(e),r));return Promise.resolve(i).then(this.next).then(()=>i.then(r=>{t.done(),t.resolve(r)})).catch(r=>(t.done(),t.reject(r),this.next()))}return Promise.resolve()})}};const ct=new WeakMap;function nt(n,t=5e3,e=1e3){return ct.has(n)||ct.set(n,new Ys(t,e)),s=>new Promise((i,r)=>{const o=ct.get(n);o.add(s,i,r,()=>{o.tasks.length||ct.delete(n)})})}const O=()=>Math.floor((1+Math.random())*65536).toString(16).substring(1);function M(){return O()+O()+"-"+O()+"-"+O()+"-"+O()+"-"+O()+O()+O()}var Zs=Object.defineProperty,Gs=Object.defineProperties,Xs=Object.getOwnPropertyDescriptors,ke=Object.getOwnPropertySymbols,tn=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable,Se=(n,t,e)=>t in n?Zs(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,qt=(n,t)=>{for(var e in t||(t={}))tn.call(t,e)&&Se(n,e,t[e]);if(ke)for(var e of ke(t))en.call(t,e)&&Se(n,e,t[e]);return n},sn=(n,t)=>Gs(n,Xs(t));const nn=n=>{const t=[];return[(e,s)=>{t.push(n.subscribe(e,s))},()=>{t.forEach(e=>{e()})}]};let rs=class{constructor(t,e=[]){this.platform=t,this.rules=e}match(t){return this.rules.every(e=>!(e.id&&e.id!==t.id||e.type&&e.type!==t.type))}ofType(t){return this.rules.push({type:t}),this}withId(t){return this.rules.push({id:t}),this}select(){return new on(this.platform,this)}},rn=class{constructor(t,e,s){this.platform=t,this.node=e,this.actions=new ee(t,new rs(t).withId(e.id),s);const[i,r]=nn(this.platform.events);this.subscribe=i,this.unsubscribe=r}properties(t){return t&&this.node.touchProperties(e=>t(e)),this.node.attributes.properties}context(t){return t&&this.subscribe("components:context-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.context)}),this.node.attributes.context}layout(t){return t&&this.subscribe("components:layout-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.layout)}),this.node.attributes.layout}writeProperties(t,e){this.node.writeProperties(t,e)}writeContext(t,e){this.node.writeProperties(t,e)}writeLayout(t,e){this.node.writeLayout(t,e)}dispose(){this.unsubscribe(),this.actions.dispose()}};class on{constructor(t,e,s=!0){this.platform=t,this.target=e,this.clearOnDispose=s,this.removes=[],this.actions=new ee(this.platform,this.target)}writeProperties(t,e){this.removes.push(this.platform.write({options:e,attributes:{properties:t},target:this.target,removable:this.clearOnDispose}))}writeContext(t,e){this.removes.push(this.platform.write({options:e,attributes:{context:t},target:this.target,removable:this.clearOnDispose}))}writeLayout(t,e){this.removes.push(this.platform.write({options:e,attributes:{layout:t},target:this.target,removable:this.clearOnDispose}))}dispose(){this.removes.forEach(t=>{t()}),this.actions.dispose()}}const an=(n,t,e)=>{const s=n.concat(),i=(r,o,a)=>{let c=!0;if(s.length){const h=s.shift(),l=(d,u)=>(c=!1,i(d,Object.assign({},o,u),a));return Promise.resolve(h(r,l,a)).then(d=>sn(qt({},d),{cancelled:c}))}return Promise.resolve({data:r,cancelled:!1,options:o})};return i(t,{},e)};let ee=class{constructor(t,e,s){this.platform=t,this.target=e,this.ns=s,this.subscriptions=[],this.create=this.create.bind(this)}create(t,e=()=>{}){const s={key:t,fn:e,target:this.target,ns:this.ns};this.platform.actionsState.handlers.push(s);const i=()=>{const r=this.platform.actionsState.handlers.indexOf(s);r>-1&&this.platform.actionsState.handlers.splice(r,1)};return this.subscriptions.push(i),i}dispatch(t,e){const s=this.platform.nodes.all.concat(this.platform.nodes.detached),i={},r=this.platform.actionsState.handlers.filter(o=>o.key===t&&(!o.ns||!this.ns||o.ns===this.ns));return Promise.all(r.map(o=>{const a=s.filter(h=>o.target.match(h)&&this.target.match(h)),c=this.platform.actionsState.watchers.filter(h=>h.key===t&&(!h.ns||!this.ns||h.ns===this.ns)&&a.some(l=>h.target.match(l))).map(h=>h.fn);return Promise.all(a.map(h=>{const l=new rn(this.platform,h,this.ns);return an(c,e,l).then(d=>{const{data:u={},options:p,cancelled:b}=d;return Promise.resolve(b?{}:o.fn(u,p,l)).then(w=>{i[h.id]=w})})}))})).then(()=>i)}watch(t,e){let s=t,i=this.ns;const r=t.split(".");r.length>1&&(i=r[0],s=r.splice(1).join("."));const o={fn:e,target:this.target,key:s,ns:i};this.platform.actionsState.watchers.push(o);const a=()=>{const c=this.platform.actionsState.watchers.indexOf(o);c>-1&&this.platform.actionsState.watchers.splice(c,1)};return this.subscriptions.push(a),a}dispose(){this.subscriptions.forEach(t=>t())}};ts(n=>{n.createCommand("components",t=>e=>{t.events.subscribeOnce("components:platform-created",(s,{platform:i})=>{e.handlers&&e.handlers.forEach(([r,o])=>{i.addComponentHandler(r,o)})})})});let Oe=class{constructor(t,e){this.events=t,this.tags=[],this.children={},this.changesets=[],this.mountCount=0,this.id=M(),this.type=e,this.attributes={context:{},properties:{},layout:{},tags:[]},this.writeLayout({size:"full",indent:0})}mount(t,e){let s=t.get("mounted-nodes");return s||(s=new Map,t.register("mounted-nodes",s)),s.has(this)?(process.env.NODE_ENV!=="production"&&_.error("Trying to mount an already mounted component node.",this),()=>{}):(this.events.dispatch("components:node-mounted",{node:this}),this.mountCount===0&&(this.mountCount=this.mountCount+1,this.events.dispatch("components:node-enter",{node:this})),()=>{s.delete(this),this.events.dispatch("components:node-unmounted",{node:this}),this.mountCount=this.mountCount-1,this.mountCount===0&&this.events.dispatch("components:node-exit",{node:this})})}appendChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].push(t),this.events.dispatch("components:node-appended",{node:t})}prependChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].unshift(t),this.events.dispatch("components:node-appended",{node:t})}touchProperties(t,e={},s){const i=[{properties:t},e];return this.changesets.push(i),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeProperties(t,e={},s){const i=[{properties:t},e];return this.changesets.push(i),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeLayout(t,e={},s){const i=[{layout:t},e];return this.changesets.push(i),this.events.dispatch("components:set-layout",{node:this}),()=>{if(!s)return;const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-layout",{node:this}))}}writeContext(t,e={},s){const i=[{context:t},e];return this.changesets.push(i),this.events.dispatch("components:set-context",{node:this}),()=>{if(!s)return;const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-context",{node:this}))}}getChildren(t="default"){const e=this.children[t]||[];return e.reduce((s,i,r)=>{const{order:o=r}=i.attributes.layout;return s[o]?s.splice(o,0,i):s[o]=i,s},Array(e.length))}remove(){this.parent&&this.parent.removeChild(this)}removeChild(t){Object.keys(this.children).forEach(e=>{const s=this.children[e],i=s.indexOf(t);i>-1&&(s.splice(i,1),this.events.dispatch("components:node-removed",{node:t,parentNode:this}))}),delete t.parent}};const os=(n,t,e)=>{for(let s=0,i=n.length;s<i&&e(n[s])!==!0;s++){const r=t[n[s].id]||"default",o=n[s].getChildren(r);os(o,t,e)}},se=(n,t,e)=>{if(e(n)!==!0){const s=t[n.id]||"default",i=n.children[s];os(i,t,e)}},Nt=(n,t)=>{const e=[];return se(n,t,s=>{e.push(s)}),e},cn=(n,t,e)=>{let s;return se(n,t,i=>{if(e(i))return s=i,!0}),s};class hn{constructor(t,e,s){this.root=t,this.switches=e,this.all=[],this.visible=[],this.detached=[],s.subscribe("components:node-appended",(i,r)=>{this.all.push(r.node),this.visible=Nt(t,e)}),s.subscribe("components:node-removed",(i,r)=>{let o=this.all.indexOf(r.node);o>-1&&this.all.splice(o,1),o=this.visible.indexOf(r.node),o>-1&&this.visible.splice(o,1),this.visible=Nt(t,e)}),s.subscribe("components:node-switched",(i,r)=>{this.visible=Nt(t,e)})}query(t={}){const e=[];return se(this.root,this.switches,s=>{Object.keys(t).every(i=>t[i]===s[i])&&e.push(s)}),e}get(t){return cn(this.root,this.switches,e=>e.id===t)||this.detached.find(e=>e.id===t)}}class ln{constructor(){this.handlers=new Map}add(t,e){this.handlers.set(t,e)}get(t){return this.handlers.get(t)}}const dn=n=>{let t=n,e=0;for(;t.parent;)e=e+1,t=t.parent;return e},un=n=>n.map(([t,e])=>[dn(t),t,e]).sort(([t],[e])=>t-e).map(([,t,e])=>[t,e]),Tt=n=>n instanceof Date?!1:n&&typeof n=="object"&&!Array.isArray(n),P=(n,...t)=>{if(!t.length)return n;const e=t.shift();if(Tt(n)&&Tt(e))for(const s in e)Tt(e[s])?(n[s]||Object.assign(n,{[s]:{}}),P(n[s],e[s])):Object.assign(n,{[s]:e[s]});return P(n,...t)},pn=(n,t)=>!n||n==="all"?!0:n.some(e=>t.indexOf(e)>-1),gn=(n,t)=>{let e=[],s=[],i;const r=()=>{process.env.NODE_ENV!=="production"&&console.time("state-processor.flush");const a=new Map,c=un(e.map((l,d)=>[l,s[d]])),h=(l,d)=>{var u;const p=a.get(l)||{},b=d.context&&!p.context,w=d.properties&&!p.properties,xt=d.layout&&!p.layout;a.set(l,{context:p.context||b,properties:p.properties||w,layout:p.layout||xt}),w&&(l.attributes.properties={}),xt&&(l.attributes.layout={}),b&&(l.attributes.context=P({},(u=l.parent)==null?void 0:u.attributes.context));const ge=[],me=[],ve=[];if(l.changesets.forEach(C=>{const[A,Ct]=C;pn(Ct.breakpoints,n.breakpoints)&&(w&&(typeof A.properties=="function"?ge.push(A.properties):P(l.attributes.properties,A.properties)),xt&&(typeof A.layout=="function"?me.push(A.layout):P(l.attributes.layout,A.layout)),b&&(typeof A.context=="function"?ve.push(A.context):P(l.attributes.context,A.context)))}),ge.forEach(C=>{P(l.attributes.properties,C(l.attributes.properties))}),me.forEach(C=>{P(l.attributes.layout,C(l.attributes.layout))}),ve.forEach(C=>{P(l.attributes.context,C(l.attributes.context))}),b||d.recursive){const C=n.getBranch(l),A=d.recursive?d:{context:!!b};l.getChildren(C).forEach(Ct=>{h(Ct,A)})}};process.env.NODE_ENV!=="production"&&console.timeEnd("state-processor.flush"),c.forEach(([l,d])=>{h(l,d)}),e=[],s=[],t(a)},o=()=>{clearTimeout(i),i=setTimeout(r,0)};return(a,c)=>{const h=e.indexOf(a);if(h>-1){const l=s[h];return c.context&&(l.context=!0),c.properties&&(l.properties=!0),c.layout&&(l.layout=!0),c.recursive&&(l.recursive=!0),o()}return e.push(a),s.push(c),o()}};class mn{constructor(t,e={}){this.providers=e,this.breakpoints=[],this.actionsState={handlers:[],watchers:[]},this.switches={},this.changesets=[],this.subscriptions=[],this.customComponentHandler=new ln,this.events=t.events.createChild(this);const s=new Oe(this.events,"root");s.name=`root-${t.name}`,this.nodes=new hn(s,this.switches,this.events);const i=this.processNode=gn(this,r=>{const o=Array.from(r.keys());process.env.NODE_ENV!=="production"&&console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
2
+ ${o.map(a=>`${a.name||"<no name>"} (${a.id})
3
+ `)}`),o.forEach(a=>{const c=r.get(a);a.parent&&a.parent.type==="root"&&this.events.dispatch("components:root-children-changed",{node:a}),c!=null&&c.context&&this.events.dispatch("components:context-changed",{node:a}),c!=null&&c.properties&&this.events.dispatch("components:properties-changed",{node:a}),c!=null&&c.layout&&this.events.dispatch("components:layout-changed",{node:a})}),this.events.dispatch("components:component-model-initialized",{},{bubbles:!0})});Promise.all(Object.keys(e).map(r=>e[r].load(this))),this.subscriptions.push(this.events.subscribe("components:node-appended",(r,o)=>{const{node:a}=o;this.changesets.forEach(c=>{const{changeset:h,target:l,removes:d}=c,[u,p]=h;l.match(o.node)&&(u.properties&&d.push(a.writeProperties(u.properties,p)),u.context&&d.push(a.writeContext(u.context,p)),u.layout&&d.push(a.writeLayout(u.layout,p)))})})),this.subscriptions.push(this.events.subscribe("components:node-appended",(r,o)=>{i(o.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-properties",(r,o)=>{i(o.node,{properties:!0})})),this.subscriptions.push(this.events.subscribe("components:set-context",(r,o)=>{i(o.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-indent",(r,o)=>{i(o.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:set-layout",(r,o)=>{i(o.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:node-switched",(r,{node:o,branch:a})=>{i(o,{layout:!0,recursive:!0,properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:node-removed",(r,{parentNode:o})=>{i(o,{properties:!0})})),this.events.parent&&this.events.parent.dispatch("components:platform-created",{platform:this})}static getInstance(t){return t.getAsync("components")}addBreakpoint(t){this.breakpoints.indexOf(t)===-1&&(this.breakpoints.push(t),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}removeBreakpoint(t){const e=this.breakpoints.indexOf(t);e>-1&&(this.breakpoints.splice(e,1),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}setSwitch(t,e){this.switches[t.id]=e,this.events.dispatch("components:node-switched",{node:t,branch:e})}getBranch(t){return this.switches[t.id]}createNode(t,e={}){const s=new Oe(this.events,t);return e.detached&&this.nodes.detached.push(s),s}components(){return new rs(this)}actions(t,e){return new ee(this,t,e)}write(t){const{provider:e,target:s,attributes:i,options:r={},removable:o}=t,a=t.key||M(),c={changeset:[i,r],target:s,removes:[]};if(e){const h=this.providers[e];h.write(a,s,i,r),c.removes.push(()=>{h.remove(a)})}return this.changesets.push(c),this.nodes.all.forEach(h=>{if(s.match(h)){let l=()=>{};i.properties&&(l=h.writeProperties(i.properties,r,o)),i.context&&(l=h.writeContext(i.context,r,o)),i.layout&&(l=h.writeContext(i.layout,r,o)),c.removes.push(l)}}),()=>{if(o){c.removes.forEach(l=>l());const h=this.changesets.indexOf(c);h>-1&&this.changesets.splice(h,1)}}}addComponentHandler(t,e){this.customComponentHandler.add(t,e)}getComponentHandler(t){return this.customComponentHandler.get(t)}dispose(){this.subscriptions.forEach(t=>t())}}const vn="#____version____#",as=class extends ns{constructor(t,e=[]){super(t,e,{transformPluginSettings:(s,i,r)=>{const o=r.get("$settings"),a=o.plugins&&i?o.plugins[i]||{}:{};return qt(qt({},a),s)}})}createImplementation(t){const e=super.createImplementation(t);return e.bindings=t.bindings,e}navigate(t,e,s){this.widgets.query(t).forEach(i=>i.invoke("navigate",{route:e,params:s}))}static create(t={}){const e=[_s].concat(t.configurationApiExtensions||[]);return new as("humany",e)}static createFromGlobal(t,e={}){if(this.isRuntime(t))return t.patch(e),t;const s=[],i=t&&t._c;i&&i.forEach(o=>s.push(o));const r=this.create(e);return r.container.register("$runtimecfg",s),r}static isRuntime(t){return!!(t&&typeof t=="object"&&t.container&&typeof t.container.get=="function"&&t.container.get("$environment")===t&&t.container.owner===t)}};let fn=as;fn.version=`${vn} (${te})`;var yn=Object.defineProperty,Ne=Object.getOwnPropertySymbols,bn=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,Te=(n,t,e)=>t in n?yn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,L=(n,t)=>{for(var e in t||(t={}))bn.call(t,e)&&Te(n,e,t[e]);if(Ne)for(var e of Ne(t))$n.call(t,e)&&Te(n,e,t[e]);return n},y=(n=>(n.Cookie="cookie",n.Local="local",n.Session="session",n))(y||{}),bt=(n=>(n.Tenant="tenant",n.Implementation="implementation",n.Widget="widget",n))(bt||{}),f=(n=>(n.Necessary="necessary",n.Functional="functional",n.Analytical="analytical",n.Marketing="marketing",n))(f||{});const $t=(n,t,e,s={})=>Me(n,e).then(i=>(process.env.NODE_ENV!=="production"&&i&&_.warn(`createStorageWriter: Attempted to create storage writer using unallowed category.
4
+ Key: ${t}
5
+ Category: ${JSON.stringify(e)}
6
+ Options: ${JSON.stringify(s)}`),r=>(ie(n),Me(n,e).then(o=>{if(o){process.env.NODE_ENV!=="production"&&_.warn(`storageWriter: Attempted to write to storage using unallowed category.
7
+ Key: ${t}
8
+ Category: ${JSON.stringify(e)}
9
+ Value: ${JSON.stringify(r)}
10
+ Options: ${JSON.stringify(s)}`);return}const{scope:a=bt.Widget,medium:c=y.Session,duration:h}=s,l=_n();return l[a][t]=ls(r,e,h),c===y.Cookie?Pn(n,l):Sn(n,c,l)})))),W=(n,t,e=y.Session)=>(ie(n),typeof t>"u"?(process.env.NODE_ENV!=="production"&&_.warn("readStorage: Undefined key passed when reading storage. ",t,e),Promise.resolve(void 0)):e===y.Cookie?Cn(n).then(s=>Jt(s,t)):kn(n,e).then(s=>Jt(s,t))),B=n=>!!Object.entries(n).filter(([t,e])=>typeof e<"u").length,Mt=n=>Object.entries(n).filter(([t,e])=>typeof e<"u").forEach(([t,{value:e}])=>{typeof e>"u"&&delete n[t]}),cs=(n,t)=>{const e={tenant:L(L({},n.tenant),t.tenant),implementation:L(L({},n.implementation),t.implementation),widget:L(L({},n.widget),t.widget)};return Mt(e.tenant),Mt(e.implementation),Mt(e.widget),e},wn=n=>Object.entries(n).reduce((t,e)=>{const[s,i]=e;return Object.entries(i).forEach(r=>{const[o,{expiration:a}]=r;a&&t.push(a)}),t},[]).slice().sort((t,e)=>new Date(e).valueOf()-new Date(t).valueOf()).shift()||re(),wt=n=>{const{name:t,implementation:{name:e,tenant:s}}=n.get("$widget");return[`humany_${s}`,`humany_${Pe(s+e)}`,`humany_${Pe(s+e+t)}`]},It=n=>{const t=new RegExp(`(?:^|;)\\s?${n}=(.*?)(?:;|$)`,"i"),e=document.cookie.match(t);return e&&e[1]&&JSON.parse(e[1])||void 0},Dt=(n,t,e)=>{const s=`${n}=${JSON.stringify(t).trim()}`,i=`expires=${new Date(e).toUTCString()}`,r="path=/",o="SameSite=None;Secure";return document.cookie=`${s}; ${i}; ${r}; ${o}`},ne=n=>{const[t,e,s]=wt(n),i=It(t)||{},r=It(e)||{},o=It(s)||{};return{tenant:i,implementation:r,widget:o}},hs=(n,t)=>{const e=ne(n),s=cs(e,t),[i,r,o]=wt(n),{tenant:a,implementation:c,widget:h}=s,l=wn(t),d=re({days:-1});Dt(i,a,B(a)?l:d),Dt(r,c,B(c)?l:d),Dt(o,h,B(h)?l:d)},gt=(n,t)=>{const[e,s,i]=wt(n),r=t.getItem(e)||"{}",o=t.getItem(s)||"{}",a=t.getItem(i)||"{}";return{tenant:JSON.parse(r),implementation:JSON.parse(o),widget:JSON.parse(a)}},Vt=(n,t,e)=>{const s=gt(n,t),i=cs(s,e),[r,o,a]=wt(n),{tenant:c,implementation:h,widget:l}=i;B(c)?t.setItem(r,JSON.stringify(c)):t.removeItem(r),B(h)?t.setItem(o,JSON.stringify(h)):t.removeItem(o),B(l)?t.setItem(a,JSON.stringify(l)):t.removeItem(a)},_n=()=>({tenant:{},implementation:{},widget:{}}),An=n=>n?!!n&&new Date>new Date(n):!1,Jt=(n,t)=>{const e=n.widget[t]||n.implementation[t]||n.tenant[t];return e==null?void 0:e.value},ls=(n,t,e)=>e?{value:n,category:t,expiration:typeof e=="object"?re(e):e}:{value:n,category:t},En=(n,t)=>{const e=Qs(n);return Object.entries(e).forEach(([s,i])=>{Object.entries(i).forEach(([r,o])=>{const{expiration:a,category:c}=o;(An(a)||xn(t,c))&&(i[r]=ls(void 0,c,a))})}),e},Me=(n,t)=>W(n,"storagePolicy",y.Cookie).then((e=[f.Necessary])=>!!t&&e.indexOf(t)===-1),xn=(n=[f.Necessary],t)=>!!t&&n.indexOf(t)===-1,ie=n=>{const t=ne(n),e=gt(n,window.localStorage),s=gt(n,sessionStorage),i=Jt(t,"storagePolicy"),[r,o,a]=[t,e,s].map(c=>En(c,i));hs(n,r),Vt(n,window.localStorage,o),Vt(n,window.sessionStorage,a)},re=(n={days:30})=>{const{days:t=0,hours:e=0,minutes:s=0,seconds:i=0}=n,r=new Date;return r.setTime(r.getTime()+e*60*60*1e3),r.setTime(r.getTime()+t*24*60*60*1e3),r.setTime(r.getTime()+s*60*1e3),r.setTime(r.getTime()+i*1e3),r.toISOString()},Cn=n=>nt(document)(()=>ne(n)),Pn=(n,t)=>nt(document)(()=>hs(n,t)),kn=(n,t)=>{const e=t===y.Local?window.localStorage:window.sessionStorage;return nt(e)(()=>gt(n,e))},Sn=(n,t,e)=>{const s=t===y.Local?window.localStorage:window.sessionStorage;return nt(s)(()=>Vt(n,s,e))},Ut=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},On=n=>{const t=n.container||n;return{info:(e,...s)=>Ut(t,"info",e,...s),warn:(e,...s)=>Ut(t,"warning",e,...s),error:(e,...s)=>Ut(t,"error",e,...s)}};var mt=(n=>(n.Implementation="implementation",n.Widget="widget",n))(mt||{}),D=(n=>(n.Pre="pre",n.Post="post",n))(D||{});const Nn=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let a;return i[r]&&(a=i[r].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function Ie(n,t){return typeof n>"u"?t:n}class Tn{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:mt.Widget,stage:D.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:Ie(e.scope,mt.Widget),stage:Ie(e.stage,D.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((a,c)=>{c===o.length-1?r[a]||(r[a]=()=>i):r=this.part[a]=this.part[a]||{}}),this}get(){return this.part}}const ds=n=>{const t=new Tn({});return n(t),t.get()};ds(n=>{n.createCommand("types.register",{scope:mt.Implementation,stage:D.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:D.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:D.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:D.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,a=e,c=s;typeof e=="string"&&(o=e,a=s,c=i);const h=l=>{const{transformPluginSettings:d}=t.container.get("$environmentOptions"),u=d?d(c||{},o,t.container,a):s;try{const p=Nn(o,a,r,u);r.get("$plugins").push(p),l&&p.invoke("initialize",null)}catch(p){On(t).warn("Error when initializing plugin",p)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})});ds(n=>{n.createCommand("storage",t=>(e={})=>{const{consent:s}=e;if(typeof s<"u"){if(typeof s!="number"&&typeof s!="string"&&!Array.isArray(s)){process.env.NODE_ENV!=="production"&&_.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
11
+ Passed consent: ${JSON.stringify(s)}`);return}if(Array.isArray(s)&&!s.every(r=>typeof r=="number"||typeof r=="string")){process.env.NODE_ENV!=="production"&&_.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
12
+ Passed consent: ${JSON.stringify(s)}`);return}const i=[f.Necessary,f.Functional,f.Analytical,f.Marketing].filter((r,o,a)=>typeof s=="number"?s>o:typeof s=="string"?a.indexOf(s)+1>o:Array.isArray(s)?s.findIndex(c=>c===o+1||c===r)>-1:!0);return i.indexOf(f.Necessary)===-1&&(process.env.NODE_ENV!=="production"&&_.warn(`storagePolicyConfigurationApi: passed consent does not include category: '${f.Necessary}'. Consent has to atleast include the '${f.Necessary}' category.
13
+ Passed consent: ${JSON.stringify(s)}`),i.unshift(f.Necessary)),$t(t.container,"storagePolicy",f.Necessary,{medium:y.Cookie,scope:bt.Tenant,duration:{days:365}}).then(r=>r(i)).then(()=>{ie(t.container),t.events.dispatch("storage:policy-changed",i)})}})});class Mn{constructor(t){this.controller=t,this.cache=new Map,this.subscriptions=[];const{events:e}=t.container.get("$widget"),s=e.subscribe("data-client:fetched",(i,r)=>{r.type==="contact-method"&&this.cache.set(r.response.id,r.response)});this.subscriptions.push(s)}getConversationLogs(){return this.controller.messages.reduce((e,s)=>{const i=At(s),{content:r,type:o,sender:a,timestamp:c}=i.content,h=this.parseEntry(r,o,a,c);return h&&e.push(h),e},[])}parseEntry(t,e,s,i){const r=h=>{let l=[],d=[],u;if(Array.isArray(h)){const[b,w]=h;u=w}else u=h;return this.createMessageContent(u).length&&(d=[...d,this.createMessageContent(u)]),l=[...l,...this.createMessageOptions(u)],{messagesAsList:d,options:l}};let o=[],a=[];if(Array.isArray(t.items)){const{items:h}=t;h.forEach(l=>{const d=r(l);o=[...o,...d.options],a=[...a,...d.messagesAsList]})}else{const h=r(t);o=[...o,...h.options],a=[...a,...h.messagesAsList]}return{options:o,message:a.length?a.join(`
14
+ `):void 0,source:this.createMessageSource(e),alias:this.createAlias(e,s),timestamp:i}}createMessageSource(t){return t}createAlias(t,e){return t===_t.System?"system":(e==null?void 0:e.name)||"Me"}handleContactMethod(t){if(!this.cache.has(t))return;const e=this.cache.get(t);let s="";return s=this.appendText(s,`${e.clientName}:`),s=this.appendText(s,e.title),e.description&&(s=this.appendText(s,e.title)),s}getDetails(t,e=!0){if(!t)return"";const{header:s,title:i,label:r,description:o,text:a,html:c,body:h,contactMethodId:l}=t;let d="";if(l){const u=this.handleContactMethod(l.toString());u&&(d=this.appendText(d,u,e))}return s&&(d=this.appendText(d,s,e)),i&&(d=this.appendText(d,i,e)),o&&(d=this.appendText(d,o,e)),a&&(d=this.appendText(d,a,e)),r&&(d=this.appendText(d,r,e)),c&&(d=this.appendText(d,c,e)),h&&typeof h=="string"&&(d=this.appendText(d,h,e)),d}createMessageContent(t){let e="";return e=this.getDetails(t),e}createMessageOptions(t){let e=[],s=[];return Array.isArray(t==null?void 0:t.actions)?s=t.actions:typeof(t==null?void 0:t.actions)=="object"&&(s=Object.entries(t.actions).map(([i,r])=>({actionKey:i,label:r}))),s.length&&(e=s.map(i=>this.getDetails(i,!1))),e}appendText(t,e,s=!0){return s&&t.length?`${t}
15
+ ${e}`:t.length?`${t} ${e}`:e}dispose(){this.subscriptions.forEach(t=>{t()})}}class Ft{constructor(t,e){this.provider=t,this.print=(s,i)=>{const r={name:this.name,avatar:this.avatar,id:this.id},o=At(s,i);return this.provider.createEntry(o.key,o.content,_t.Agent,r,o.timestamp)},this.typing=()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}),this.id=e.id||M(),this.name=e.name,this.avatar=e.avatar}update(t){var i;const{name:e,avatar:s}=t;s===null?this.avatar=void 0:s&&(this.avatar=s),e===null?this.name=void 0:e&&(this.name=e),(i=this.provider.controller)==null||i.events.dispatch("conversation:agent-updated",{agent:this})}}class oe{constructor(t,e,s){this.name=t,this.controller=s,this.subscriptions=[],this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(t,e,s){return new oe(t,e,s)}createAgent(t={}){var e;if(this.controller){const s=this.controller.getAgentById(t.id),i=s?new Ft(this,{...s,...t}):new Ft(this,t);return s||(e=this.controller)==null||e.events.dispatch("conversation:agent-created",{agent:i}),i}}print(t){var e;return(e=this.controller)==null?void 0:e.print(t)}setTypingState(t,e){var s;return(s=this.controller)==null?void 0:s.setTypingState(t,e)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(t,e,s,i,r){var o;return(o=this.controller)==null?void 0:o.createEntry(t,e,s,i,r)}dispose(){var t;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(t=this.controller)==null||t.disposeProvider(this),this.controller=null,this.subscriptions.forEach(e=>e())}isRehydrated(){var t;return((t=this.controller)==null?void 0:t.isRehydrated())||Promise.resolve(!1)}getHistory(){var t;return((t=this.controller)==null?void 0:t.getHistory())||[]}complete(){var t;(t=this.controller)==null||t.onCompleteProvider()}setOptions(t={silent:!1}){this.options=t}onUnreadMessage(t){var e;if(this.controller){const s=(e=this.controller)==null?void 0:e.onUnreadMessage(t);return this.subscriptions.push(s),()=>{s()}}}onMounted(t){var e;if(this.controller){const s=(e=this.controller)==null?void 0:e.events.subscribe("conversation:component-mount-changed",t);return this.subscriptions.push(s),t({},this.controller.getComponentMountedState()),()=>{s()}}}}const us=n=>`conversation-${n}`;class In{constructor(){this._locking=Promise.resolve(),this._locks=0}isLocked(){return this._locks>0}lock(){this._locks+=1;let t;const e=new Promise(i=>t=()=>{this._locks-=1,i()}),s=this._locking.then(()=>t);return this._locking=this._locking.then(()=>e),s}}class Dn{constructor(t,e,s){this.container=t,this.enabled=s,this.locker=new In,this.initialStoredAgents=[],this.sessionStorageKey=us(e.id),e.onStarted(async()=>{if(e.messages.length>0)return;const{agents:i}=await this.read(),r=[];i&&i.forEach(a=>{const c=e.providerIndex(a.providerName),h=c>-1?e.registeredProviders[c]:e.createProvider(a.providerName),l=new Ft(h,{name:a.name,avatar:a.avatar,id:a.id});r.push(l)});const{messages:o}=await this.read();o.forEach(a=>{switch(a.type){case"agent":{const c=r.find(h=>{var l;return h.id===((l=a.sender)==null?void 0:l.id)});c&&c.print(a.content.items||a.content,{key:a.key});return}case"user":{e.user.print(a.content.items||a.content,{key:a.key});return}case"system":default:e.print(a.content.items||a.content)}})}),e.onMessageCreated(async(i,r)=>{this.write(r.message,"messages")}),e.events.subscribe("conversation:agent-created",async(i,r)=>{const o={id:r.agent.id,name:r.agent.name,avatar:r.agent.avatar,providerName:r.agent.provider.name};await this.write(o,"agents")}),e.events.subscribe("conversation:agent-updated",async(i,r)=>{const{agents:o}=await this.read();await this.write([...o.map(a=>a.id===r.agent.id?{...a,name:r.agent.name,avatar:r.agent.avatar}:a)],"agents","update")})}setInitialData(t){this.initialStoredAgents=t.agents}async isRehydrated(){const{messages:t}=await this.read();return t.length>0}getStoredAgent(t){if(this.enabled)return this.initialStoredAgents.find(e=>e.id===t)}async write(t,e,s="add"){if(!this.enabled)return;const i=await this.locker.lock();return $t(this.container,this.sessionStorageKey,f.Necessary).then(async r=>{if(s==="add"){const o=await this.read();if(e==="messages"&&o.messages.findIndex(c=>c.key===t.key)>-1){i();return}const a={...o};return e==="messages"?a.messages=[...a.messages,t]:e==="agents"&&(a.agents=[...a.agents,t]),r({...o,...a}).then(()=>{i()})}if(s==="update"&&e==="agents"){const o=await this.read();return r({...o,agents:t}).then(()=>{i()})}return r(t).then(()=>{i()})})}async read(){return W(this.container,this.sessionStorageKey).then(t=>t||{messages:[],agents:[]})}}class Un{constructor(t){this.controller=t,this.print=(e,s)=>{const i=At(e,s);return this.controller.createEntry(i.key,i.content,_t.User,void 0,i.timestamp)}}}const Kt=async(n,t,e)=>{const s=await n.getAsync("conversation"),i=await n.getAsync("components"),r=s.controllers.find(o=>o.conversation.id===t);if(r){const o=[...r.conversation.providers];o.forEach(c=>{r.conversation.setProviderOptions(c,{silent:!0})}),r.conversation.queueProviders(o),r.conversation.setProviders([e]);const a=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e]}},target:a,provider:"localStorage"})}};class Hn{constructor(t){this.writer=t,this.entryId=M()}update(t){const e=this.getNormalizedSettings(t);this.writer(e)}remove(){this.writer(null)}getNormalizedSettings(t){return typeof t=="string"?{body:t}:t.length>-1&&typeof t=="object"?{items:t}:t}}var _t=(n=>(n.User="user",n.Agent="agent",n.System="system",n))(_t||{});const At=(n,t)=>{let e,s=(t==null?void 0:t.key)||M(),i=Date.now();return Array.isArray(n)&&n.length>-1?typeof n[0]=="string"?e={items:[n]}:e={items:n}:typeof n=="string"?e={body:n}:(n=n||{},n.type?e={...n}:(e={body:n.body,actions:n.actions,title:n.title},n.key&&(s=n.key),n.timestamp&&(i=n.timestamp),n.form,n.timestamp===null&&(i=null))),{content:e,key:s,timestamp:i}},De=(n,t)=>{if(!t)return;const e=JSON.stringify(t),s=n.findIndex(i=>e===JSON.stringify(i));if(s>-1)return n.splice(s,1)};class jn{constructor(t,e,s){this.container=t,this.id=e,this.formHandlers={},this.user=new Un(this),this.providers=[],this.active=!1,this.queuedProviders=[],this.registeredProviders=[],this.loaders=0,this.componentMounted=!1,this.messages=[],this.typingActors=[],this.print=r=>{const o=At(r);return this.createEntry(o.key,o.content,"system",void 0,o.timestamp)};const i=t.get("$widget");this.events=i.events.createChild(this),this.store=new Dn(t,this,s.rehydrate),this.conversationHistory=new Mn(this)}setInitialStorage(t){this.store.setInitialData(t)}setProviders(t){const e=[],s=[];this.providers.reduce((i,r)=>(t.indexOf(r)===-1&&i.push(r),i),[]).forEach(i=>{const r=this.providers.indexOf(i);r>-1&&(e.push(i),this.providers.splice(r,1))}),t.forEach(i=>{this.providers.indexOf(i)===-1&&(s.push(i),this.providers.push(i))}),(s.length||e.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:e})}createProvider(t){const e=this.providerIndex(t);if(e>-1)return this.registeredProviders[e];const s=oe.create(t,this.container,this);return this.registeredProviders.push(s),s}providerIndex(t){return this.registeredProviders.findIndex(e=>e.name===t)}getAgentById(t){if(t)return this.store.getStoredAgent(t)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(t=>t.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(t){return this.events.subscribe("conversation:controller-disposed",t)}onStarted(t){return this.events.subscribe("conversation:started",t)}onMessageCreated(t){return this.events.subscribe("conversation:message-created",t)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(t){const e=this.providerIndex(t.name);e>-1&&this.registeredProviders.splice(e,1),this.events.dispatch("conversation:providers-changed",{removed:[t.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(t){return this.events.subscribe("conversation:providers-changed",t)}setComponentMountedState(t){this.componentMounted!==t&&(this.componentMounted=t,t&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",t))}setProviderOptions(t,e){const s=this.providerIndex(t);s>-1&&this.registeredProviders[s].setOptions(e)}changeProvider(t){this.registeredProviders.find(s=>s.name===t)&&Kt(this.container,this.id,t)}queueProviders(t){this.queuedProviders=t}onCompleteProvider(){const t=this.queuedProviders.pop();t&&Kt(this.container,this.id,t)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(t){return this.events.subscribe("conversation:unread-message",t)}createEntry(t,e,s,i,r){const o={key:t,content:e,type:s,sender:i||null,timestamp:r||r===null?r:Date.now()};this.messages.push(o),o.type==="agent"&&De(this.typingActors,i);const a=new Hn(c=>{if(c!==null){const{timestamp:h=void 0,...l}=c;o.content=l,h&&(o.timestamp=h)}else{const h=this.messages.indexOf(o);o.content=null,h>-1&&this.messages.splice(h,1)}this.events.dispatch("conversation:message-updated",{message:o}),this.update()});return this.events.dispatch("conversation:message-created",{message:o}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),a}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(t,e){return this.typingActors.indexOf(t)===-1&&(this.typingActors.push(t),this.update()),()=>{De(this.typingActors,t),this.update()}}loader(){this.loaders=this.loaders+1;let t=!1;return this.loaders===1&&this.update(),()=>{t||(t=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(t,e){this.formHandlers[t]={...this.formHandlers[t],submit:e}}validateForm(t,e){this.formHandlers[t]={...this.formHandlers[t],validate:e}}getHistory(){return this.conversationHistory.getConversationLogs()}}const Ln=(n,t)=>{const e=n.split("_contact");return t.widgets.get(e[0])},ae=n=>{const t=n.get("$widget"),{name:e,implementation:s}=n.get("$widget"),i=e.indexOf("_contact")>-1?Ln(e,s):t,{data:r}=n.get("$settings"),{trigger:o}=i.container.get("$settings"),a=`${e.replace("_contact-method","").replace("_contact","")}_contact-method`,c=s.widgets.get(a);return c&&!o?{chatWidget:c,mainWidget:i,data:r}:{mainWidget:i,data:r}},Rn=n=>{const{chatWidget:t}=ae(n);return!!t},Ue=(n,t,e)=>{const{mainWidget:s,data:i,chatWidget:r}=ae(n);return r?r.state==="activated"?r.invoke("open").then(()=>{r.container.getAsync("conversation").then(o=>{o.navigateToConversationIfActive(t.id)})}):r.activate().then(()=>{const{trigger:o}=r.container.get("$settings");return o.action="hide",r.invoke("setSettings",()=>({data:i,trigger:o,activate:!0})).then(()=>r.container.getAsync("components").then(a=>{const c=a.components().ofType("contact-method");a.write({key:"setContactMethodId",attributes:{properties:{id:t.id,guideId:t.guideId}},target:c,provider:"localStorage"});const h=a.components().ofType("conversation");a.write({key:"setConversationProvider",attributes:{properties:{providers:[t.clientName]}},target:h,provider:"localStorage"})}))}).then(()=>r.invoke("attach",{key:"contact-method",triggerDOMElement:e,withRenderState:"open"})).then(()=>($t(r.container,"activeStickyWidget",f.Necessary,{medium:y.Local,scope:bt.Implementation}).then(o=>o(r.name)),r.container.getAsync("conversation").then(o=>{o.setConversationEndedBehavior(ce.Deactivate)}).then(()=>!1))):!r},zn=(n,t,e="conversation")=>{const{mainWidget:s,chatWidget:i}=ae(n);return s.container.getAsync("conversation").then(r=>{var o;(o=r.setConversationEndedBehavior(ce.Navigate))==null||o.then(()=>{s.container.getAsync("components").then(a=>{const c=a.components().ofType("conversation");a.write({key:"setConversationProvider",attributes:{properties:{providers:[t.clientName]}},target:c,provider:"localStorage"})})})})},ht="conversations";var ce=(n=>(n.Deactivate="deactivate",n.Navigate="navigate",n.None="none",n))(ce||{});class he{constructor(t,e){this.container=t,this.components=e,this.controllers=[],this.providers=[],this.disposeProviders={},this.subscriptions=[],this.storageWriter=null,this.buttonQuery=null,this.sessionInfo=null;const s=t.get("$widget");this.events=s.events.createChild(this)}initialize(){$t(this.container,ht,f.Necessary,{medium:y.Local}).then(t=>this.storageWriter=t),W(this.container,ht,y.Local).then(t=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),t&&(this.sessionInfo=t,t.id&&t.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.events.subscribe("conversation:ended",(t,e)=>{var s;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(t){this.subscriptions.push(t)}static getInstance(t,e="conversation"){return nt(t)(()=>t.getAsync(e).then(s=>{let i=s;return i||mn.getInstance(t).then(r=>(i=new he(t,r),i.initialize(),t.registerAsync(e,()=>i),i))}))}setConversationEndedBehavior(t){return W(this.container,ht,y.Local).then(e=>{let s=e;return s?s.conversationEndedBehavior=t:s={conversationEndedBehavior:t},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(t,e){const s=us(t),{agents:i}=await W(this.container,s)||{agents:[]},r=this.controllers.findIndex(a=>a.conversation.id===t);let o;return r>-1?o=this.controllers[r].conversation:o=new jn(this.container,t,e),o.setInitialStorage({agents:i||[]}),o}registerProvider(t,e){const s={name:t,handler:e};this.providers.push(s),this.controllers.filter(i=>i.conversation.providers.indexOf(t)>-1).forEach(i=>{this.invokeHandler(s,i)})}registerController(t,e){const s=this.controllers.findIndex(r=>r.conversation.id===t.id);let i;if(s<0){i={conversation:t,component:e},this.controllers.push(i);const r=o=>{o&&this.providers.filter(a=>o.indexOf(a.name)>-1).forEach(a=>{this.invokeHandler(a,i)})};return this.subscriptions.push(t.onDispose((o,a)=>{const c=this.controllers.findIndex(h=>h.conversation===a);c>-1&&this.controllers.splice(c,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(t.onProvidersChange((o,a)=>{const{added:c,removed:h=[]}=a;h.forEach(l=>{(this.disposeProviders[l]||[]).forEach(d=>{d()})}),r(c)})),this.subscriptions.push(t.onStarted((o,a)=>{var h;const c={id:t.id,conversationEndedBehavior:(h=this.sessionInfo)==null?void 0:h.conversationEndedBehavior};this.sessionInfo=c,this.storageWriter&&this.storageWriter(c),this.writeToComponents({active:a})})),this.subscriptions.push(t.onUnreadMessage((o,a)=>{this.events.dispatch("conversation:unread-message",a),this.writeToComponents({alert:{show:a}})})),r(t.providers),!0}return i=this.controllers[s],!1}writeToComponents(t,e="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:t},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(t,e){const s=t.handler(e.conversation.createProvider(t.name),e.component);s&&(this.disposeProviders[t.name]||(this.disposeProviders[t.name]=[]),this.disposeProviders[t.name].push(s))}getComponentRoute(){return W(this.container,ht,y.Local).then(t=>t==null?void 0:t.route)}dispose(){Object.keys(this.disposeProviders).forEach(t=>{this.disposeProviders[t].forEach(e=>{e()})}),this.subscriptions.forEach(t=>{t()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(t,e,s,i){if(Rn(e)){t.preventDefault();let r=document.getElementById("humany-dynamic-anchor");r||(r=document.createElement("a"),r.setAttribute("href","#"),r.id="humany-dynamic-anchor",document.body.appendChild(r)),Ue(e,s,r)}Ue(e,s)}static async handleContactMethodSubmit(t,e){var s,i;return(i=(s=e==null?void 0:e.body.form.meta)==null?void 0:s.conversation)!=null&&i.id?Kt(t,e.body.form.meta.conversation.id,e.clientName):zn(t,e)}}/**
16
+ * @license
17
+ * Copyright 2019 Google LLC
18
+ * SPDX-License-Identifier: BSD-3-Clause
19
+ */const dt=window,le=dt.ShadowRoot&&(dt.ShadyCSS===void 0||dt.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,de=Symbol(),He=new WeakMap;let ps=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==de)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(le&&t===void 0){const s=e!==void 0&&e.length===1;s&&(t=He.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&He.set(e,t))}return t}toString(){return this.cssText}};const Wn=n=>new ps(typeof n=="string"?n:n+"",void 0,de),Bn=(n,...t)=>{const e=n.length===1?n[0]:t.reduce((s,i,r)=>s+(o=>{if(o._$cssResult$===!0)return o.cssText;if(typeof o=="number")return o;throw Error("Value passed to 'css' function must be a 'css' function result: "+o+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+n[r+1],n[0]);return new ps(e,n,de)},qn=(n,t)=>{le?n.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet):t.forEach(e=>{const s=document.createElement("style"),i=dt.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,n.appendChild(s)})},je=le?n=>n:n=>n instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return Wn(e)})(n):n;/**
20
+ * @license
21
+ * Copyright 2017 Google LLC
22
+ * SPDX-License-Identifier: BSD-3-Clause
23
+ */var Ht;const vt=window,Le=vt.trustedTypes,Vn=Le?Le.emptyScript:"",Re=vt.reactiveElementPolyfillSupport,Qt={toAttribute(n,t){switch(t){case Boolean:n=n?Vn:null;break;case Object:case Array:n=n==null?n:JSON.stringify(n)}return n},fromAttribute(n,t){let e=n;switch(t){case Boolean:e=n!==null;break;case Number:e=n===null?null:Number(n);break;case Object:case Array:try{e=JSON.parse(n)}catch{e=null}}return e}},gs=(n,t)=>t!==n&&(t==t||n==n),jt={attribute:!0,type:String,converter:Qt,reflect:!1,hasChanged:gs},Yt="finalized";let R=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),((e=this.h)!==null&&e!==void 0?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach((e,s)=>{const i=this._$Ep(s,e);i!==void 0&&(this._$Ev.set(i,s),t.push(i))}),t}static createProperty(t,e=jt){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const s=typeof t=="symbol"?Symbol():"__"+t,i=this.getPropertyDescriptor(t,s,e);i!==void 0&&Object.defineProperty(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){return{get(){return this[e]},set(i){const r=this[t];this[e]=i,this.requestUpdate(t,r,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||jt}static finalize(){if(this.hasOwnProperty(Yt))return!1;this[Yt]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),t.h!==void 0&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const e=this.properties,s=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const i of s)this.createProperty(i,e[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const i of s)e.unshift(je(i))}else t!==void 0&&e.push(je(t));return e}static _$Ep(t,e){const s=e.attribute;return s===!1?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$Eg(),this.requestUpdate(),(t=this.constructor.h)===null||t===void 0||t.forEach(e=>e(this))}addController(t){var e,s;((e=this._$ES)!==null&&e!==void 0?e:this._$ES=[]).push(t),this.renderRoot!==void 0&&this.isConnected&&((s=t.hostConnected)===null||s===void 0||s.call(t))}removeController(t){var e;(e=this._$ES)===null||e===void 0||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])})}createRenderRoot(){var t;const e=(t=this.shadowRoot)!==null&&t!==void 0?t:this.attachShadow(this.constructor.shadowRootOptions);return qn(e,this.constructor.elementStyles),e}connectedCallback(){var t;this.renderRoot===void 0&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$ES)===null||t===void 0||t.forEach(e=>{var s;return(s=e.hostConnected)===null||s===void 0?void 0:s.call(e)})}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$ES)===null||t===void 0||t.forEach(e=>{var s;return(s=e.hostDisconnected)===null||s===void 0?void 0:s.call(e)})}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$EO(t,e,s=jt){var i;const r=this.constructor._$Ep(t,s);if(r!==void 0&&s.reflect===!0){const o=(((i=s.converter)===null||i===void 0?void 0:i.toAttribute)!==void 0?s.converter:Qt).toAttribute(e,s.type);this._$El=t,o==null?this.removeAttribute(r):this.setAttribute(r,o),this._$El=null}}_$AK(t,e){var s;const i=this.constructor,r=i._$Ev.get(t);if(r!==void 0&&this._$El!==r){const o=i.getPropertyOptions(r),a=typeof o.converter=="function"?{fromAttribute:o.converter}:((s=o.converter)===null||s===void 0?void 0:s.fromAttribute)!==void 0?o.converter:Qt;this._$El=r,this[r]=a.fromAttribute(e,o.type),this._$El=null}}requestUpdate(t,e,s){let i=!0;t!==void 0&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||gs)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),s.reflect===!0&&this._$El!==t&&(this._$EC===void 0&&(this._$EC=new Map),this._$EC.set(t,s))):i=!1),!this.isUpdatePending&&i&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach((i,r)=>this[r]=i),this._$Ei=void 0);let e=!1;const s=this._$AL;try{e=this.shouldUpdate(s),e?(this.willUpdate(s),(t=this._$ES)===null||t===void 0||t.forEach(i=>{var r;return(r=i.hostUpdate)===null||r===void 0?void 0:r.call(i)}),this.update(s)):this._$Ek()}catch(i){throw e=!1,this._$Ek(),i}e&&this._$AE(s)}willUpdate(t){}_$AE(t){var e;(e=this._$ES)===null||e===void 0||e.forEach(s=>{var i;return(i=s.hostUpdated)===null||i===void 0?void 0:i.call(s)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){this._$EC!==void 0&&(this._$EC.forEach((e,s)=>this._$EO(s,this[s],e)),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}};R[Yt]=!0,R.elementProperties=new Map,R.elementStyles=[],R.shadowRootOptions={mode:"open"},Re==null||Re({ReactiveElement:R}),((Ht=vt.reactiveElementVersions)!==null&&Ht!==void 0?Ht:vt.reactiveElementVersions=[]).push("1.6.3");/**
24
+ * @license
25
+ * Copyright 2017 Google LLC
26
+ * SPDX-License-Identifier: BSD-3-Clause
27
+ */var Lt;const ft=window,q=ft.trustedTypes,ze=q?q.createPolicy("lit-html",{createHTML:n=>n}):void 0,Zt="$lit$",N=`lit$${(Math.random()+"").slice(9)}$`,ms="?"+N,Jn=`<${ms}>`,H=document,tt=()=>H.createComment(""),et=n=>n===null||typeof n!="object"&&typeof n!="function",vs=Array.isArray,Fn=n=>vs(n)||typeof(n==null?void 0:n[Symbol.iterator])=="function",Rt=`[
28
+ \f\r]`,Q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,We=/-->/g,Be=/>/g,I=RegExp(`>|${Rt}(?:([^\\s"'>=/]+)(${Rt}*=${Rt}*(?:[^
29
+ \f\r"'\`<>=]|("|')|))|$)`,"g"),qe=/'/g,Ve=/"/g,fs=/^(?:script|style|textarea|title)$/i,Kn=n=>(t,...e)=>({_$litType$:n,strings:t,values:e}),lt=Kn(1),j=Symbol.for("lit-noChange"),m=Symbol.for("lit-nothing"),Je=new WeakMap,U=H.createTreeWalker(H,129,null,!1);function ys(n,t){if(!Array.isArray(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return ze!==void 0?ze.createHTML(t):t}const Qn=(n,t)=>{const e=n.length-1,s=[];let i,r=t===2?"<svg>":"",o=Q;for(let a=0;a<e;a++){const c=n[a];let h,l,d=-1,u=0;for(;u<c.length&&(o.lastIndex=u,l=o.exec(c),l!==null);)u=o.lastIndex,o===Q?l[1]==="!--"?o=We:l[1]!==void 0?o=Be:l[2]!==void 0?(fs.test(l[2])&&(i=RegExp("</"+l[2],"g")),o=I):l[3]!==void 0&&(o=I):o===I?l[0]===">"?(o=i??Q,d=-1):l[1]===void 0?d=-2:(d=o.lastIndex-l[2].length,h=l[1],o=l[3]===void 0?I:l[3]==='"'?Ve:qe):o===Ve||o===qe?o=I:o===We||o===Be?o=Q:(o=I,i=void 0);const p=o===I&&n[a+1].startsWith("/>")?" ":"";r+=o===Q?c+Jn:d>=0?(s.push(h),c.slice(0,d)+Zt+c.slice(d)+N+p):c+N+(d===-2?(s.push(void 0),a):p)}return[ys(n,r+(n[e]||"<?>")+(t===2?"</svg>":"")),s]};class st{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let r=0,o=0;const a=t.length-1,c=this.parts,[h,l]=Qn(t,e);if(this.el=st.createElement(h,s),U.currentNode=this.el.content,e===2){const d=this.el.content,u=d.firstChild;u.remove(),d.append(...u.childNodes)}for(;(i=U.nextNode())!==null&&c.length<a;){if(i.nodeType===1){if(i.hasAttributes()){const d=[];for(const u of i.getAttributeNames())if(u.endsWith(Zt)||u.startsWith(N)){const p=l[o++];if(d.push(u),p!==void 0){const b=i.getAttribute(p.toLowerCase()+Zt).split(N),w=/([.?@])?(.*)/.exec(p);c.push({type:1,index:r,name:w[2],strings:b,ctor:w[1]==="."?Zn:w[1]==="?"?Xn:w[1]==="@"?ti:Et})}else c.push({type:6,index:r})}for(const u of d)i.removeAttribute(u)}if(fs.test(i.tagName)){const d=i.textContent.split(N),u=d.length-1;if(u>0){i.textContent=q?q.emptyScript:"";for(let p=0;p<u;p++)i.append(d[p],tt()),U.nextNode(),c.push({type:2,index:++r});i.append(d[u],tt())}}}else if(i.nodeType===8)if(i.data===ms)c.push({type:2,index:r});else{let d=-1;for(;(d=i.data.indexOf(N,d+1))!==-1;)c.push({type:7,index:r}),d+=N.length-1}r++}}static createElement(t,e){const s=H.createElement("template");return s.innerHTML=t,s}}function V(n,t,e=n,s){var i,r,o,a;if(t===j)return t;let c=s!==void 0?(i=e._$Co)===null||i===void 0?void 0:i[s]:e._$Cl;const h=et(t)?void 0:t._$litDirective$;return(c==null?void 0:c.constructor)!==h&&((r=c==null?void 0:c._$AO)===null||r===void 0||r.call(c,!1),h===void 0?c=void 0:(c=new h(n),c._$AT(n,e,s)),s!==void 0?((o=(a=e)._$Co)!==null&&o!==void 0?o:a._$Co=[])[s]=c:e._$Cl=c),c!==void 0&&(t=V(n,c._$AS(n,t.values),c,s)),t}class Yn{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){var e;const{el:{content:s},parts:i}=this._$AD,r=((e=t==null?void 0:t.creationScope)!==null&&e!==void 0?e:H).importNode(s,!0);U.currentNode=r;let o=U.nextNode(),a=0,c=0,h=i[0];for(;h!==void 0;){if(a===h.index){let l;h.type===2?l=new it(o,o.nextSibling,this,t):h.type===1?l=new h.ctor(o,h.name,h.strings,this,t):h.type===6&&(l=new ei(o,this,t)),this._$AV.push(l),h=i[++c]}a!==(h==null?void 0:h.index)&&(o=U.nextNode(),a++)}return U.currentNode=H,r}v(t){let e=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}}class it{constructor(t,e,s,i){var r;this.type=2,this._$AH=m,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this._$Cp=(r=i==null?void 0:i.isConnected)===null||r===void 0||r}get _$AU(){var t,e;return(e=(t=this._$AM)===null||t===void 0?void 0:t._$AU)!==null&&e!==void 0?e:this._$Cp}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return e!==void 0&&(t==null?void 0:t.nodeType)===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=V(this,t,e),et(t)?t===m||t==null||t===""?(this._$AH!==m&&this._$AR(),this._$AH=m):t!==this._$AH&&t!==j&&this._(t):t._$litType$!==void 0?this.g(t):t.nodeType!==void 0?this.$(t):Fn(t)?this.T(t):this._(t)}k(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}$(t){this._$AH!==t&&(this._$AR(),this._$AH=this.k(t))}_(t){this._$AH!==m&&et(this._$AH)?this._$AA.nextSibling.data=t:this.$(H.createTextNode(t)),this._$AH=t}g(t){var e;const{values:s,_$litType$:i}=t,r=typeof i=="number"?this._$AC(t):(i.el===void 0&&(i.el=st.createElement(ys(i.h,i.h[0]),this.options)),i);if(((e=this._$AH)===null||e===void 0?void 0:e._$AD)===r)this._$AH.v(s);else{const o=new Yn(r,this),a=o.u(this.options);o.v(s),this.$(a),this._$AH=o}}_$AC(t){let e=Je.get(t.strings);return e===void 0&&Je.set(t.strings,e=new st(t)),e}T(t){vs(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let s,i=0;for(const r of t)i===e.length?e.push(s=new it(this.k(tt()),this.k(tt()),this,this.options)):s=e[i],s._$AI(r),i++;i<e.length&&(this._$AR(s&&s._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){var s;for((s=this._$AP)===null||s===void 0||s.call(this,!1,!0,e);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i}}setConnected(t){var e;this._$AM===void 0&&(this._$Cp=t,(e=this._$AP)===null||e===void 0||e.call(this,t))}}class Et{constructor(t,e,s,i,r){this.type=1,this._$AH=m,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=r,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=m}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,s,i){const r=this.strings;let o=!1;if(r===void 0)t=V(this,t,e,0),o=!et(t)||t!==this._$AH&&t!==j,o&&(this._$AH=t);else{const a=t;let c,h;for(t=r[0],c=0;c<r.length-1;c++)h=V(this,a[s+c],e,c),h===j&&(h=this._$AH[c]),o||(o=!et(h)||h!==this._$AH[c]),h===m?t=m:t!==m&&(t+=(h??"")+r[c+1]),this._$AH[c]=h}o&&!i&&this.j(t)}j(t){t===m?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Zn extends Et{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===m?void 0:t}}const Gn=q?q.emptyScript:"";class Xn extends Et{constructor(){super(...arguments),this.type=4}j(t){t&&t!==m?this.element.setAttribute(this.name,Gn):this.element.removeAttribute(this.name)}}class ti extends Et{constructor(t,e,s,i,r){super(t,e,s,i,r),this.type=5}_$AI(t,e=this){var s;if((t=(s=V(this,t,e,0))!==null&&s!==void 0?s:m)===j)return;const i=this._$AH,r=t===m&&i!==m||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,o=t!==m&&(i===m||r);r&&this.element.removeEventListener(this.name,this,i),o&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,s;typeof this._$AH=="function"?this._$AH.call((s=(e=this.options)===null||e===void 0?void 0:e.host)!==null&&s!==void 0?s:this.element,t):this._$AH.handleEvent(t)}}class ei{constructor(t,e,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){V(this,t)}}const Fe=ft.litHtmlPolyfillSupport;Fe==null||Fe(st,it),((Lt=ft.litHtmlVersions)!==null&&Lt!==void 0?Lt:ft.litHtmlVersions=[]).push("2.8.0");const si=(n,t,e)=>{var s,i;const r=(s=e==null?void 0:e.renderBefore)!==null&&s!==void 0?s:t;let o=r._$litPart$;if(o===void 0){const a=(i=e==null?void 0:e.renderBefore)!==null&&i!==void 0?i:null;r._$litPart$=o=new it(t.insertBefore(tt(),a),a,void 0,e??{})}return o._$AI(n),o};/**
30
+ * @license
31
+ * Copyright 2017 Google LLC
32
+ * SPDX-License-Identifier: BSD-3-Clause
33
+ */var zt,Wt;class Z extends R{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t,e;const s=super.createRenderRoot();return(t=(e=this.renderOptions).renderBefore)!==null&&t!==void 0||(e.renderBefore=s.firstChild),s}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=si(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),(t=this._$Do)===null||t===void 0||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),(t=this._$Do)===null||t===void 0||t.setConnected(!1)}render(){return j}}Z.finalized=!0,Z._$litElement$=!0,(zt=globalThis.litElementHydrateSupport)===null||zt===void 0||zt.call(globalThis,{LitElement:Z});const Ke=globalThis.litElementPolyfillSupport;Ke==null||Ke({LitElement:Z});((Wt=globalThis.litElementVersions)!==null&&Wt!==void 0?Wt:globalThis.litElementVersions=[]).push("3.3.3");/**
34
+ * @license
35
+ * Copyright 2017 Google LLC
36
+ * SPDX-License-Identifier: BSD-3-Clause
37
+ */const ni=(n,t)=>t.kind==="method"&&t.descriptor&&!("value"in t.descriptor)?{...t,finisher(e){e.createProperty(t.key,n)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:t.key,initializer(){typeof t.initializer=="function"&&(this[t.key]=t.initializer.call(this))},finisher(e){e.createProperty(t.key,n)}},ii=(n,t,e)=>{t.constructor.createProperty(e,n)};function ue(n){return(t,e)=>e!==void 0?ii(n,t,e):ni(n,t)}/**
38
+ * @license
39
+ * Copyright 2017 Google LLC
40
+ * SPDX-License-Identifier: BSD-3-Clause
41
+ */function pe(n){return ue({...n,state:!0})}/**
42
+ * @license
43
+ * Copyright 2021 Google LLC
44
+ * SPDX-License-Identifier: BSD-3-Clause
45
+ */var Bt;((Bt=window.HTMLSlotElement)===null||Bt===void 0?void 0:Bt.prototype.assignedElements)!=null;/**
46
+ * @license
47
+ * Copyright 2017 Google LLC
48
+ * SPDX-License-Identifier: BSD-3-Clause
49
+ */const ri={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},oi=n=>(...t)=>({_$litDirective$:n,values:t});class ai{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,s){this._$Ct=t,this._$AM=e,this._$Ci=s}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}/**
50
+ * @license
51
+ * Copyright 2018 Google LLC
52
+ * SPDX-License-Identifier: BSD-3-Clause
53
+ */const ci=oi(class extends ai{constructor(n){var t;if(super(n),n.type!==ri.ATTRIBUTE||n.name!=="class"||((t=n.strings)===null||t===void 0?void 0:t.length)>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(n){return" "+Object.keys(n).filter(t=>n[t]).join(" ")+" "}update(n,[t]){var e,s;if(this.it===void 0){this.it=new Set,n.strings!==void 0&&(this.nt=new Set(n.strings.join(" ").split(/\s/).filter(r=>r!=="")));for(const r in t)t[r]&&!(!((e=this.nt)===null||e===void 0)&&e.has(r))&&this.it.add(r);return this.render(t)}const i=n.element.classList;this.it.forEach(r=>{r in t||(i.remove(r),this.it.delete(r))});for(const r in t){const o=!!t[r];o===this.it.has(r)||!((s=this.nt)===null||s===void 0)&&s.has(r)||(o?(i.add(r),this.it.add(r)):(i.remove(r),this.it.delete(r)))}return j}}),v=(n,t,e)=>{n&&e.style.setProperty(t,n)},hi=(n,t)=>{var e,s,i,r,o,a,c,h,l,d,u;v((e=n.colors)==null?void 0:e.primary,"--primary-color",t),v((s=n.colors)==null?void 0:s.secondary,"--secondary-color",t),v((i=n.colors)==null?void 0:i.text,"--text-color",t),v((r=n.colors)==null?void 0:r.link,"--link-color",t),v((o=n.colors)==null?void 0:o.gray,"--gray-color",t),v((a=n.colors)==null?void 0:a.grayDark,"--gray-dark-color",t),v((c=n.spacing)==null?void 0:c.xs,"--spacing-xs",t),v((h=n.spacing)==null?void 0:h.sm,"--spacing-sm",t),v((l=n.spacing)==null?void 0:l.md,"--spacing-md",t),v((d=n.spacing)==null?void 0:d.lg,"--spacing-lg",t),v((u=n.spacing)==null?void 0:u.xl,"--spacing-xl",t),v(n.boxShadow,"--box-shadow",t),v(n.borderRadius,"--border-radius",t),v(n.borderRadiusSm,"--border-radius-sm",t),v(n.fontFamily,"--font-family",t)};var li=Object.defineProperty,di=Object.getOwnPropertyDescriptor,rt=(n,t,e,s)=>{for(var i=s>1?void 0:s?di(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=(s?o(t,e,i):o(i))||i);return s&&i&&li(t,e,i),i};class F extends Z{constructor(){super(...arguments),this.active=!1,this.loaded=!1}async connectedCallback(){super.connectedCallback(),this.icon=await this._renderSymbol(this.symbol),this.loaded=!0,this._applyBranding()}_toggleActive(){this.active=!this.active}_applyBranding(){var s;const t=((s=this.container)==null?void 0:s.get("$settings"))??{},e=t==null?void 0:t.components[t==null?void 0:t.entry];e&&hi(e.context,this)}async _renderSymbol(t){const e=async s=>await Promise.resolve().then(()=>require("./index-6dd00f59.js")).then(r=>r[s]);if(t){const{type:s,content:i}=t;switch(s){case"Telia":{const r=await e(i);return r?lt`<telia-icon
54
+ class="trigger-icon"
55
+ svg=${r.svg}
56
+ size="lg"
57
+ ></telia-icon>`:m}case"FontAwesome":return lt`<i class="trigger-fa-icon fa fa-${i}"></i>`;case"Uri":return lt`<i
58
+ class="trigger-custom-icon"
59
+ style="background: url(${i}) no-repeat center center;background-size: contain;"
60
+ ></i>`;default:return m}}}render(){return lt`<button
61
+ class=${ci({trigger:!0,active:this.active,rendered:this.loaded})}
62
+ @click=${this._toggleActive}
63
+ >
64
+ ${this.icon}
65
+ <span class="trigger-close">
66
+ <svg
67
+ width="18"
68
+ height="9"
69
+ viewBox="0 0 18 9"
70
+ fill="none"
71
+ xmlns="http://www.w3.org/2000/svg"
72
+ >
73
+ <path
74
+ d="M9 9C8.81794 9.00045 8.63759 8.96634 8.46939 8.89965C8.3012 8.83295 8.14851 8.735 8.02015 8.61145L0.194523 1.12367C0.068294 0.99862 -0.00155266 0.831133 2.61958e-05 0.657285C0.00160506 0.483436 0.0744832 0.317136 0.202964 0.194202C0.331445 0.0712675 0.505249 0.00153576 0.686941 2.50649e-05C0.868634 -0.00148563 1.04368 0.0653456 1.17437 0.186125L9 7.6739L16.8256 0.186125C16.9563 0.0653456 17.1314 -0.00148563 17.3131 2.50649e-05C17.4948 0.00153576 17.6686 0.0712675 17.797 0.194202C17.9255 0.317136 17.9984 0.483436 18 0.657285C18.0016 0.831133 17.9317 0.99862 17.8055 1.12367L9.97985 8.61145C9.85149 8.735 9.6988 8.83295 9.53061 8.89965C9.36241 8.96634 9.18206 9.00045 9 9Z"
75
+ fill="white"
76
+ />
77
+ </svg>
78
+ </span>
79
+ <span class="trigger-loader">
80
+ <svg viewBox="25 25 50 50">
81
+ <circle
82
+ cx="50"
83
+ cy="50"
84
+ r="20"
85
+ fill="none"
86
+ stroke="#000"
87
+ stroke-width="2"
88
+ stroke-miterlimit="10"
89
+ />
90
+ </svg>
91
+ </span>
92
+ </button>`}}F.styles=[Bn`
93
+ :host {
94
+ --voca-rem-multiplier: 0.625;
95
+ display: block;
96
+ box-sizing: border-box;
97
+ }
98
+
99
+ .trigger {
100
+ position: fixed;
101
+ transform: scale(0);
102
+ box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px;
103
+ bottom: 20px;
104
+ right: 20px;
105
+ z-index: 5;
106
+ display: flex;
107
+ align-items: center;
108
+ justify-content: center;
109
+ border: none;
110
+ line-height: 55px;
111
+ height: 55px;
112
+ width: 55px;
113
+ border-radius: 55px;
114
+ cursor: pointer;
115
+ background-color: var(--trigger-bg, var(--primary-color));
116
+ font-family: Lato;
117
+ text-decoration: none;
118
+ border: 3px dashed transparent;
119
+ box-sizing: border-box;
120
+ transition: transform 200ms ease-out;
121
+ }
122
+ .trigger:hover {
123
+ transform: scale(1.1) !important;
124
+ }
125
+ .trigger.rendered {
126
+ transform: scale(1);
127
+ }
128
+ .trigger.active .trigger-icon {
129
+ opacity: 0;
130
+ transform: rotate(-180deg) scale(0);
131
+ }
132
+ .trigger.active .trigger-close {
133
+ opacity: 1;
134
+ transform: rotate(0deg) scale(1);
135
+ }
136
+
137
+ .trigger-icon {
138
+ display: inline-block;
139
+ line-height: inherit;
140
+ text-align: center;
141
+ opacity: 1;
142
+ transform: rotate(0deg) scale(1);
143
+ transition: opacity 200ms ease-out, transform 200ms ease-out;
144
+ color: var(--trigger-text-color, #fff);
145
+ }
146
+ .trigger-close {
147
+ opacity: 0;
148
+ transition: transform 200ms ease-out;
149
+ transform: rotate(180deg) scale(0);
150
+ position: absolute;
151
+ top: 0;
152
+ bottom: 0;
153
+ left: 0;
154
+ right: 0;
155
+ display: flex;
156
+ justify-content: center;
157
+ align-items: center;
158
+ fill: var(--trigger-text-color, #fff);
159
+ }
160
+ `];rt([ue({attribute:!1})],F.prototype,"symbol",2);rt([ue({attribute:!1})],F.prototype,"container",2);rt([pe()],F.prototype,"active",2);rt([pe()],F.prototype,"loaded",2);rt([pe()],F.prototype,"icon",2);var G=(n=>(n.LinkList="link-list",n.Separator="separator",n.ButtonList="button-list",n.ItemList="item-list",n.Text="text",n.HTML="html",n.VideoRequest="video-request",n))(G||{});const ui=({isUser:n,items:t=[],meta:e={}})=>{const s=M();return{id:s,isUser:n,items:t.map(r=>({id:r.id||M(),isUser:n,groupId:s,message:r.message||[]})),meta:e}},pi=n=>{var t,e;return!!((t=n==null?void 0:n.outputPayload)!=null&&t.textOutputContent)&&((e=n==null?void 0:n.outputPayload)==null?void 0:e.isFinal)},gi=n=>{var t,e;return!!((t=n==null?void 0:n.outputPayload)!=null&&t.textOutputContent)&&!((e=n==null?void 0:n.outputPayload)!=null&&e.isFinal)};class mi{constructor(t){this.isConnected=!1,this.ws=new WebSocket(t),this.ws.onopen=e=>{this.onConnected()},this.ws.onmessage=e=>{this.onMessage(e)},this.ws.onerror=e=>{this.onError(e)},this.ws.onclose=e=>{this.onClose(e)}}onConnected(){console.log("Connection established."),this.isConnected=!0;const t={sequenceNumber:1,initializeRequestPayload:{extension:"webconv2"}};this.sendMessage(t)}onMessage(t){if(!this.messageDelegate){console.warn("Not subscribed to message handler");return}const e=JSON.parse(t.data);pi(e)?this.messageDelegate({text:e.outputPayload.textOutputContent.text,isComplete:!0,sequenceNumber:e.sequenceNumber}):gi(e)?this.messageDelegate({text:e.outputPayload.textOutputContent.textPart,isComplete:!1,sequenceNumber:e.sequenceNumber}):this.unknownMessageDelegate&&this.unknownMessageDelegate(e)}onError(t){console.error("Connection error:",t)}onClose(t){console.log("Connection closed",t),this.isConnected=!1}sendMessage(t){if(!this.isConnected){console.warn("Message could not be sent, you are not connected.");return}this.ws.send(JSON.stringify(t))}subscribe(t){this.messageDelegate=t}subscribeUnknown(t){this.unknownMessageDelegate=t}}class vi{constructor(){this.store=new Map}get(t){return this.store.get(t)}getCompleteMessage(t){const e=this.get(t);return e!=null&&e.entry?{message:e.messages.map(s=>s.text).join(""),entry:e.entry}:null}put(t,e){const s=this.get(t);let i=[];const r=s==null?void 0:s.entry;s&&(i=s.messages),this.store.set(t,{entry:e.entry||r,messages:[...i,e.message]})}}class fi{constructor(t){this.settings=t,this.bucket=new vi,this.currentSequenceNumber=1,this.onMessage=e=>{if(this.handleIncomingSequenceNumber(e),this.messageSubscription){const s=this.bucket.getCompleteMessage(e.sequenceNumber);if(console.log(s),s!=null&&s.entry){const i=s.message+e.text;s.entry.update([[G.HTML,{body:i}]]),this.bucket.put(e.sequenceNumber,{message:e,entry:s.entry})}else{const i=this.messageSubscription(e);i&&this.bucket.put(e.sequenceNumber,{message:e,entry:i})}}},this.onUnknown=e=>{this.handleIncomingSequenceNumber(e)},this.connection=new mi(t.connectionUri),this.connection.subscribe(this.onMessage),this.connection.subscribeUnknown(this.onUnknown)}sendMessage(t){this.connection.sendMessage({sequenceNumber:this.currentSequenceNumber,inputPayload:{textInputContent:{text:t.text}}}),this.incrementSequenceNumber()}isConnected(){return this.connection.isConnected}subscribe(t){this.messageSubscription=t}handleIncomingSequenceNumber(t){t.sequenceNumber>this.currentSequenceNumber&&(this.currentSequenceNumber=t.sequenceNumber)}incrementSequenceNumber(){this.currentSequenceNumber=this.currentSequenceNumber+1}}class yi{constructor(t,e,s){this.container=t,this.conversation=e,this.groups=[],this.convOpen=!1,this.dialog=new fi({connectionUri:"wss://cso-ccs.labbn.se/convhub/webconnector/v2/dialog"}),this.onDialogMessage=i=>i.text&&this.agent.print([[G.HTML,{body:i.text}]])||null,this.agent=e.createAgent({id:"conversational-hub-bot-agent",name:"",avatar:void 0}),this.agent.print([[G.HTML,{body:"Hello worlds"}]]),this.user=e.user,this.dialog.subscribe(this.onDialogMessage)}async onInput(t){switch(typeof t=="string"?t:t.actionKey){default:typeof t!="string"&&t.label&&this.printUserMessage(t.label);break}}printUserMessage(t){const e=ui({isUser:!0,items:[{id:M(),isUser:!0,message:[G.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(i=>i.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onMessageSend(t){this.dialog.isConnected()&&(this.dialog.sendMessage({text:t}),this.printUserMessage(t))}}const bi=async n=>{setTimeout(async()=>{(await he.getInstance(n)).registerProvider("ace-conversational-hub-provider",(e,s)=>{const i=new yi(n,e,s),r=[];return r.push(s.actions.watch("conversation.user-submit",(o,a)=>{i.onMessageSend(o.text)})),()=>{r.forEach(o=>{o()})}})},0)};exports.ConversationalHubProviderPlugin=bi;