From b17c139f13f4529d4f974d853d894b43c8b92704 Mon Sep 17 00:00:00 2001 From: Anyelo Petit Date: Wed, 7 Oct 2026 21:14:15 -0400 Subject: [PATCH 1/4] Close the popup with the Escape key --- .../controllers/popup_controller_test.js | 39 +++++++++++++++++++ docs/popups.md | 2 +- src/controllers/popup_controller.js | 13 +++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/__tests__/controllers/popup_controller_test.js b/__tests__/controllers/popup_controller_test.js index a80684f..a0d9788 100644 --- a/__tests__/controllers/popup_controller_test.js +++ b/__tests__/controllers/popup_controller_test.js @@ -163,6 +163,45 @@ describe('PopupController', () => { expect(Hellotext.eventEmitter.dispatch).toHaveBeenNthCalledWith(3, 'popup:closed') }) + describe('closing with Escape', () => { + const escape = (init = {}) => new KeyboardEvent('keydown', { key: 'Escape', cancelable: true, ...init }) + + it('dismisses the popup while the dialog is showing', () => { + const { element, dialog } = buildController({ hasBubble: false }) + + controller.connect() + controller.closeOnEscape(escape()) + + expect(element.hidden).toBe(true) + expect(dialog.hidden).toBe(true) + expect(Hellotext.eventEmitter.dispatch).toHaveBeenLastCalledWith('popup:closed') + }) + + it('leaves a bubble popup alone until its dialog is open', () => { + const { element, bubble } = buildController({ hasBubble: true }) + + controller.connect() + controller.closeOnEscape(escape()) + + expect(element.hidden).toBe(false) + expect(bubble.hidden).toBe(false) + expect(Hellotext.eventEmitter.dispatch).not.toHaveBeenCalledWith('popup:closed') + }) + + it('ignores Escape already handled by another control or an input method', () => { + const { element } = buildController({ hasBubble: false }) + + controller.connect() + + const handled = escape() + handled.preventDefault() + controller.closeOnEscape(handled) + controller.closeOnEscape(escape({ isComposing: true })) + + expect(element.hidden).toBe(false) + }) + }) + it('validates the current step before moving to the next one', async () => { const { stepOne, stepTwo, emailInput } = buildController({ hasBubble: false }) diff --git a/docs/popups.md b/docs/popups.md index 85d73da..ea3e0bc 100644 --- a/docs/popups.md +++ b/docs/popups.md @@ -139,7 +139,7 @@ Use `Hellotext.on(event, callback)` to listen for popup events. Register listene - `popup:mounted` - Emitted when the popup is mounted, before any automatic `popup:opened` event. The dialog may remain hidden because of device targeting or bubble mode. - `popup:opened` - Emitted when the dialog becomes visible, either automatically or after a bubble click. Showing the bubble alone does not emit this event. -- `popup:closed` - Emitted when the visitor dismisses the popup. +- `popup:closed` - Emitted when the visitor dismisses the popup, with the close button or the Escape key. These events do not include a payload. diff --git a/src/controllers/popup_controller.js b/src/controllers/popup_controller.js index 232a908..f543a60 100644 --- a/src/controllers/popup_controller.js +++ b/src/controllers/popup_controller.js @@ -160,6 +160,19 @@ export default class extends Controller { Hellotext.eventEmitter.dispatch('popup:closed') } + /** + * Dismiss the popup with the Escape key, only while the dialog is showing, so Escape on the + * page never hides the launcher bubble or reacts to a key another control already handled. + * + * @param {KeyboardEvent} event - Escape keydown reaching the window. + * @returns {void} + */ + closeOnEscape(event) { + if (this.dialogTarget.hidden || event.defaultPrevented || event.isComposing) return + + this.close(event) + } + /** * Validate the current step before advancing, or submit if this is the final step. * Clear previous server validity errors first so corrected values can be checked. From 202417921f9555473af7cb64b3dd83593962d527 Mon Sep 17 00:00:00 2001 From: Anyelo Petit Date: Wed, 7 Oct 2026 21:14:18 -0400 Subject: [PATCH 2/4] Rebuild SDK artifacts --- dist/hellotext.js | 2 +- lib/controllers/popup_controller.cjs | 12 ++++++++++++ lib/controllers/popup_controller.js | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dist/hellotext.js b/dist/hellotext.js index d2666f9..9d43bff 100644 --- a/dist/hellotext.js +++ b/dist/hellotext.js @@ -1,2 +1,2 @@ /*! For license information please see hellotext.js.LICENSE.txt */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={891(e,t,s){s.d(t,{lg:()=>G,xI:()=>ne});class i{constructor(e,t,s){this.eventTarget=e,this.eventName=t,this.eventOptions=s,this.unorderedBindings=new Set}connect(){this.eventTarget.addEventListener(this.eventName,this,this.eventOptions)}disconnect(){this.eventTarget.removeEventListener(this.eventName,this,this.eventOptions)}bindingConnected(e){this.unorderedBindings.add(e)}bindingDisconnected(e){this.unorderedBindings.delete(e)}handleEvent(e){const t=function(e){if("immediatePropagationStopped"in e)return e;{const{stopImmediatePropagation:t}=e;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e);for(const e of this.bindings){if(t.immediatePropagationStopped)break;e.handleEvent(t)}}hasBindings(){return this.unorderedBindings.size>0}get bindings(){return Array.from(this.unorderedBindings).sort((e,t)=>{const s=e.index,i=t.index;return si?1:0})}}class n{constructor(e){this.application=e,this.eventListenerMaps=new Map,this.started=!1}start(){this.started||(this.started=!0,this.eventListeners.forEach(e=>e.connect()))}stop(){this.started&&(this.started=!1,this.eventListeners.forEach(e=>e.disconnect()))}get eventListeners(){return Array.from(this.eventListenerMaps.values()).reduce((e,t)=>e.concat(Array.from(t.values())),[])}bindingConnected(e){this.fetchEventListenerForBinding(e).bindingConnected(e)}bindingDisconnected(e,t=!1){this.fetchEventListenerForBinding(e).bindingDisconnected(e),t&&this.clearEventListenersForBinding(e)}handleError(e,t,s={}){this.application.handleError(e,`Error ${t}`,s)}clearEventListenersForBinding(e){const t=this.fetchEventListenerForBinding(e);t.hasBindings()||(t.disconnect(),this.removeMappedEventListenerFor(e))}removeMappedEventListenerFor(e){const{eventTarget:t,eventName:s,eventOptions:i}=e,n=this.fetchEventListenerMapForEventTarget(t),r=this.cacheKey(s,i);n.delete(r),0==n.size&&this.eventListenerMaps.delete(t)}fetchEventListenerForBinding(e){const{eventTarget:t,eventName:s,eventOptions:i}=e;return this.fetchEventListener(t,s,i)}fetchEventListener(e,t,s){const i=this.fetchEventListenerMapForEventTarget(e),n=this.cacheKey(t,s);let r=i.get(n);return r||(r=this.createEventListener(e,t,s),i.set(n,r)),r}createEventListener(e,t,s){const n=new i(e,t,s);return this.started&&n.connect(),n}fetchEventListenerMapForEventTarget(e){let t=this.eventListenerMaps.get(e);return t||(t=new Map,this.eventListenerMaps.set(e,t)),t}cacheKey(e,t){const s=[e];return Object.keys(t).sort().forEach(e=>{s.push(`${t[e]?"":"!"}${e}`)}),s.join(":")}}const r={stop:({event:e,value:t})=>(t&&e.stopPropagation(),!0),prevent:({event:e,value:t})=>(t&&e.preventDefault(),!0),self:({event:e,value:t,element:s})=>!t||s===e.target},o=/^(?:(?:([^.]+?)\+)?(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;function a(e){return e.replace(/(?:[_-])([a-z0-9])/g,(e,t)=>t.toUpperCase())}function c(e){return a(e.replace(/--/g,"-").replace(/__/g,"_"))}function l(e){return e.charAt(0).toUpperCase()+e.slice(1)}function h(e){return e.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`)}function u(e){return null!=e}function d(e,t){return Object.prototype.hasOwnProperty.call(e,t)}const p=["meta","ctrl","alt","shift"];class m{constructor(e,t,s,i){this.element=e,this.index=t,this.eventTarget=s.eventTarget||e,this.eventName=s.eventName||function(e){const t=e.tagName.toLowerCase();if(t in g)return g[t](e)}(e)||f("missing event name"),this.eventOptions=s.eventOptions||{},this.identifier=s.identifier||f("missing identifier"),this.methodName=s.methodName||f("missing method name"),this.keyFilter=s.keyFilter||"",this.schema=i}static forToken(e,t){return new this(e.element,e.index,function(e){const t=e.trim().match(o)||[];let s=t[2],i=t[3];return i&&!["keydown","keyup","keypress"].includes(s)&&(s+=`.${i}`,i=""),{eventTarget:(n=t[4],"window"==n?window:"document"==n?document:void 0),eventName:s,eventOptions:t[7]?(r=t[7],r.split(":").reduce((e,t)=>Object.assign(e,{[t.replace(/^!/,"")]:!/^!/.test(t)}),{})):{},identifier:t[5],methodName:t[6],keyFilter:t[1]||i};var n,r}(e.content),t)}toString(){const e=this.keyFilter?`.${this.keyFilter}`:"",t=this.eventTargetName?`@${this.eventTargetName}`:"";return`${this.eventName}${e}${t}->${this.identifier}#${this.methodName}`}shouldIgnoreKeyboardEvent(e){if(!this.keyFilter)return!1;const t=this.keyFilter.split("+");if(this.keyFilterDissatisfied(e,t))return!0;const s=t.filter(e=>!p.includes(e))[0];return!!s&&(d(this.keyMappings,s)||f(`contains unknown key filter: ${this.keyFilter}`),this.keyMappings[s].toLowerCase()!==e.key.toLowerCase())}shouldIgnoreMouseEvent(e){if(!this.keyFilter)return!1;const t=[this.keyFilter];return!!this.keyFilterDissatisfied(e,t)}get params(){const e={},t=new RegExp(`^data-${this.identifier}-(.+)-param$`,"i");for(const{name:s,value:i}of Array.from(this.element.attributes)){const n=s.match(t),r=n&&n[1];r&&(e[a(r)]=b(i))}return e}get eventTargetName(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e}get keyMappings(){return this.schema.keyMappings}keyFilterDissatisfied(e,t){const[s,i,n,r]=p.map(e=>t.includes(e));return e.metaKey!==s||e.ctrlKey!==i||e.altKey!==n||e.shiftKey!==r}}const g={a:()=>"click",button:()=>"click",form:()=>"submit",details:()=>"toggle",input:e=>"submit"==e.getAttribute("type")?"click":"input",select:()=>"change",textarea:()=>"input"};function f(e){throw new Error(e)}function b(e){try{return JSON.parse(e)}catch(t){return e}}class y{constructor(e,t){this.context=e,this.action=t}get index(){return this.action.index}get eventTarget(){return this.action.eventTarget}get eventOptions(){return this.action.eventOptions}get identifier(){return this.context.identifier}handleEvent(e){const t=this.prepareActionEvent(e);this.willBeInvokedByEvent(e)&&this.applyEventModifiers(t)&&this.invokeWithEvent(t)}get eventName(){return this.action.eventName}get method(){const e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`)}applyEventModifiers(e){const{element:t}=this.action,{actionDescriptorFilters:s}=this.context.application,{controller:i}=this.context;let n=!0;for(const[r,o]of Object.entries(this.eventOptions))if(r in s){const a=s[r];n=n&&a({name:r,value:o,event:e,element:t,controller:i})}return n}prepareActionEvent(e){return Object.assign(e,{params:this.action.params})}invokeWithEvent(e){const{target:t,currentTarget:s}=e;try{this.method.call(this.controller,e),this.context.logDebugActivity(this.methodName,{event:e,target:t,currentTarget:s,action:this.methodName})}catch(t){const{identifier:s,controller:i,element:n,index:r}=this,o={identifier:s,controller:i,element:n,index:r,event:e};this.context.handleError(t,`invoking action "${this.action}"`,o)}}willBeInvokedByEvent(e){const t=e.target;return!(e instanceof KeyboardEvent&&this.action.shouldIgnoreKeyboardEvent(e))&&!(e instanceof MouseEvent&&this.action.shouldIgnoreMouseEvent(e))&&(this.element===t||(t instanceof Element&&this.element.contains(t)?this.scope.containsElement(t):this.scope.containsElement(this.action.element)))}get controller(){return this.context.controller}get methodName(){return this.action.methodName}get element(){return this.scope.element}get scope(){return this.context.scope}}class v{constructor(e,t){this.mutationObserverInit={attributes:!0,childList:!0,subtree:!0},this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,this.mutationObserverInit),this.refresh())}pause(e){this.started&&(this.mutationObserver.disconnect(),this.started=!1),e(),this.started||(this.mutationObserver.observe(this.element,this.mutationObserverInit),this.started=!0)}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started){const e=new Set(this.matchElementsInTree());for(const t of Array.from(this.elements))e.has(t)||this.removeElement(t);for(const t of Array.from(e))this.addElement(t)}}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){"attributes"==e.type?this.processAttributeChange(e.target,e.attributeName):"childList"==e.type&&(this.processRemovedNodes(e.removedNodes),this.processAddedNodes(e.addedNodes))}processAttributeChange(e,t){this.elements.has(e)?this.delegate.elementAttributeChanged&&this.matchElement(e)?this.delegate.elementAttributeChanged(e,t):this.removeElement(e):this.matchElement(e)&&this.addElement(e)}processRemovedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.processTree(e,this.removeElement)}}processAddedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.elementIsActive(e)&&this.processTree(e,this.addElement)}}matchElement(e){return this.delegate.matchElement(e)}matchElementsInTree(e=this.element){return this.delegate.matchElementsInTree(e)}processTree(e,t){for(const s of this.matchElementsInTree(e))t.call(this,s)}elementFromNode(e){if(e.nodeType==Node.ELEMENT_NODE)return e}elementIsActive(e){return e.isConnected==this.element.isConnected&&this.element.contains(e)}addElement(e){this.elements.has(e)||this.elementIsActive(e)&&(this.elements.add(e),this.delegate.elementMatched&&this.delegate.elementMatched(e))}removeElement(e){this.elements.has(e)&&(this.elements.delete(e),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(e))}}class w{constructor(e,t,s){this.attributeName=t,this.delegate=s,this.elementObserver=new v(e,this)}get element(){return this.elementObserver.element}get selector(){return`[${this.attributeName}]`}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get started(){return this.elementObserver.started}matchElement(e){return e.hasAttribute(this.attributeName)}matchElementsInTree(e){const t=this.matchElement(e)?[e]:[],s=Array.from(e.querySelectorAll(this.selector));return t.concat(s)}elementMatched(e){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(e,this.attributeName)}elementUnmatched(e){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(e,this.attributeName)}elementAttributeChanged(e,t){this.delegate.elementAttributeValueChanged&&this.attributeName==t&&this.delegate.elementAttributeValueChanged(e,t)}}function T(e,t){let s=e.get(t);return s||(s=new Set,e.set(t,s)),s}class S{constructor(){this.valuesByKey=new Map}get keys(){return Array.from(this.valuesByKey.keys())}get values(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e.concat(Array.from(t)),[])}get size(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e+t.size,0)}add(e,t){!function(e,t,s){T(e,t).add(s)}(this.valuesByKey,e,t)}delete(e,t){!function(e,t,s){T(e,t).delete(s),function(e,t){const s=e.get(t);null!=s&&0==s.size&&e.delete(t)}(e,t)}(this.valuesByKey,e,t)}has(e,t){const s=this.valuesByKey.get(e);return null!=s&&s.has(t)}hasKey(e){return this.valuesByKey.has(e)}hasValue(e){return Array.from(this.valuesByKey.values()).some(t=>t.has(e))}getValuesForKey(e){const t=this.valuesByKey.get(e);return t?Array.from(t):[]}getKeysForValue(e){return Array.from(this.valuesByKey).filter(([t,s])=>s.has(e)).map(([e,t])=>e)}}class C{constructor(e,t,s,i){this._selector=t,this.details=i,this.elementObserver=new v(e,this),this.delegate=s,this.matchesByElement=new S}get started(){return this.elementObserver.started}get selector(){return this._selector}set selector(e){this._selector=e,this.refresh()}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get element(){return this.elementObserver.element}matchElement(e){const{selector:t}=this;if(t){const s=e.matches(t);return this.delegate.selectorMatchElement?s&&this.delegate.selectorMatchElement(e,this.details):s}return!1}matchElementsInTree(e){const{selector:t}=this;if(t){const s=this.matchElement(e)?[e]:[],i=Array.from(e.querySelectorAll(t)).filter(e=>this.matchElement(e));return s.concat(i)}return[]}elementMatched(e){const{selector:t}=this;t&&this.selectorMatched(e,t)}elementUnmatched(e){const t=this.matchesByElement.getKeysForValue(e);for(const s of t)this.selectorUnmatched(e,s)}elementAttributeChanged(e,t){const{selector:s}=this;if(s){const t=this.matchElement(e),i=this.matchesByElement.has(s,e);t&&!i?this.selectorMatched(e,s):!t&&i&&this.selectorUnmatched(e,s)}}selectorMatched(e,t){this.delegate.selectorMatched(e,t,this.details),this.matchesByElement.add(t,e)}selectorUnmatched(e,t){this.delegate.selectorUnmatched(e,t,this.details),this.matchesByElement.delete(t,e)}}class O{constructor(e,t){this.element=e,this.delegate=t,this.started=!1,this.stringMap=new Map,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,attributeOldValue:!0}),this.refresh())}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started)for(const e of this.knownAttributeNames)this.refreshAttribute(e,null)}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){const t=e.attributeName;t&&this.refreshAttribute(t,e.oldValue)}refreshAttribute(e,t){const s=this.delegate.getStringMapKeyForAttribute(e);if(null!=s){this.stringMap.has(e)||this.stringMapKeyAdded(s,e);const i=this.element.getAttribute(e);if(this.stringMap.get(e)!=i&&this.stringMapValueChanged(i,s,t),null==i){const t=this.stringMap.get(e);this.stringMap.delete(e),t&&this.stringMapKeyRemoved(s,e,t)}else this.stringMap.set(e,i)}}stringMapKeyAdded(e,t){this.delegate.stringMapKeyAdded&&this.delegate.stringMapKeyAdded(e,t)}stringMapValueChanged(e,t,s){this.delegate.stringMapValueChanged&&this.delegate.stringMapValueChanged(e,t,s)}stringMapKeyRemoved(e,t,s){this.delegate.stringMapKeyRemoved&&this.delegate.stringMapKeyRemoved(e,t,s)}get knownAttributeNames(){return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)))}get currentAttributeNames(){return Array.from(this.element.attributes).map(e=>e.name)}get recordedAttributeNames(){return Array.from(this.stringMap.keys())}}class E{constructor(e,t,s){this.attributeObserver=new w(e,t,this),this.delegate=s,this.tokensByElement=new S}get started(){return this.attributeObserver.started}start(){this.attributeObserver.start()}pause(e){this.attributeObserver.pause(e)}stop(){this.attributeObserver.stop()}refresh(){this.attributeObserver.refresh()}get element(){return this.attributeObserver.element}get attributeName(){return this.attributeObserver.attributeName}elementMatchedAttribute(e){this.tokensMatched(this.readTokensForElement(e))}elementAttributeValueChanged(e){const[t,s]=this.refreshTokensForElement(e);this.tokensUnmatched(t),this.tokensMatched(s)}elementUnmatchedAttribute(e){this.tokensUnmatched(this.tokensByElement.getValuesForKey(e))}tokensMatched(e){e.forEach(e=>this.tokenMatched(e))}tokensUnmatched(e){e.forEach(e=>this.tokenUnmatched(e))}tokenMatched(e){this.delegate.tokenMatched(e),this.tokensByElement.add(e.element,e)}tokenUnmatched(e){this.delegate.tokenUnmatched(e),this.tokensByElement.delete(e.element,e)}refreshTokensForElement(e){const t=this.tokensByElement.getValuesForKey(e),s=this.readTokensForElement(e),i=function(e,t){const s=Math.max(e.length,t.length);return Array.from({length:s},(s,i)=>[e[i],t[i]])}(t,s).findIndex(([e,t])=>{return i=t,!((s=e)&&i&&s.index==i.index&&s.content==i.content);var s,i});return-1==i?[[],[]]:[t.slice(i),s.slice(i)]}readTokensForElement(e){const t=this.attributeName;return function(e,t,s){return e.trim().split(/\s+/).filter(e=>e.length).map((e,i)=>({element:t,attributeName:s,content:e,index:i}))}(e.getAttribute(t)||"",e,t)}}class A{constructor(e,t,s){this.tokenListObserver=new E(e,t,this),this.delegate=s,this.parseResultsByToken=new WeakMap,this.valuesByTokenByElement=new WeakMap}get started(){return this.tokenListObserver.started}start(){this.tokenListObserver.start()}stop(){this.tokenListObserver.stop()}refresh(){this.tokenListObserver.refresh()}get element(){return this.tokenListObserver.element}get attributeName(){return this.tokenListObserver.attributeName}tokenMatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).set(e,s),this.delegate.elementMatchedValue(t,s))}tokenUnmatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).delete(e),this.delegate.elementUnmatchedValue(t,s))}fetchParseResultForToken(e){let t=this.parseResultsByToken.get(e);return t||(t=this.parseToken(e),this.parseResultsByToken.set(e,t)),t}fetchValuesByTokenForElement(e){let t=this.valuesByTokenByElement.get(e);return t||(t=new Map,this.valuesByTokenByElement.set(e,t)),t}parseToken(e){try{return{value:this.delegate.parseValueForToken(e)}}catch(e){return{error:e}}}}class x{constructor(e,t){this.context=e,this.delegate=t,this.bindingsByAction=new Map}start(){this.valueListObserver||(this.valueListObserver=new A(this.element,this.actionAttribute,this),this.valueListObserver.start())}stop(){this.valueListObserver&&(this.valueListObserver.stop(),delete this.valueListObserver,this.disconnectAllActions())}get element(){return this.context.element}get identifier(){return this.context.identifier}get actionAttribute(){return this.schema.actionAttribute}get schema(){return this.context.schema}get bindings(){return Array.from(this.bindingsByAction.values())}connectAction(e){const t=new y(this.context,e);this.bindingsByAction.set(e,t),this.delegate.bindingConnected(t)}disconnectAction(e){const t=this.bindingsByAction.get(e);t&&(this.bindingsByAction.delete(e),this.delegate.bindingDisconnected(t))}disconnectAllActions(){this.bindings.forEach(e=>this.delegate.bindingDisconnected(e,!0)),this.bindingsByAction.clear()}parseValueForToken(e){const t=m.forToken(e,this.schema);if(t.identifier==this.identifier)return t}elementMatchedValue(e,t){this.connectAction(t)}elementUnmatchedValue(e,t){this.disconnectAction(t)}}class M{constructor(e,t){this.context=e,this.receiver=t,this.stringMapObserver=new O(this.element,this),this.valueDescriptorMap=this.controller.valueDescriptorMap}start(){this.stringMapObserver.start(),this.invokeChangedCallbacksForDefaultValues()}stop(){this.stringMapObserver.stop()}get element(){return this.context.element}get controller(){return this.context.controller}getStringMapKeyForAttribute(e){if(e in this.valueDescriptorMap)return this.valueDescriptorMap[e].name}stringMapKeyAdded(e,t){const s=this.valueDescriptorMap[t];this.hasValue(e)||this.invokeChangedCallback(e,s.writer(this.receiver[e]),s.writer(s.defaultValue))}stringMapValueChanged(e,t,s){const i=this.valueDescriptorNameMap[t];null!==e&&(null===s&&(s=i.writer(i.defaultValue)),this.invokeChangedCallback(t,e,s))}stringMapKeyRemoved(e,t,s){const i=this.valueDescriptorNameMap[e];this.hasValue(e)?this.invokeChangedCallback(e,i.writer(this.receiver[e]),s):this.invokeChangedCallback(e,i.writer(i.defaultValue),s)}invokeChangedCallbacksForDefaultValues(){for(const{key:e,name:t,defaultValue:s,writer:i}of this.valueDescriptors)null==s||this.controller.data.has(e)||this.invokeChangedCallback(t,i(s),void 0)}invokeChangedCallback(e,t,s){const i=`${e}Changed`,n=this.receiver[i];if("function"==typeof n){const i=this.valueDescriptorNameMap[e];try{const e=i.reader(t);let r=s;s&&(r=i.reader(s)),n.call(this.receiver,e,r)}catch(e){throw e instanceof TypeError&&(e.message=`Stimulus Value "${this.context.identifier}.${i.name}" - ${e.message}`),e}}}get valueDescriptors(){const{valueDescriptorMap:e}=this;return Object.keys(e).map(t=>e[t])}get valueDescriptorNameMap(){const e={};return Object.keys(this.valueDescriptorMap).forEach(t=>{const s=this.valueDescriptorMap[t];e[s.name]=s}),e}hasValue(e){const t=`has${l(this.valueDescriptorNameMap[e].name)}`;return this.receiver[t]}}class k{constructor(e,t){this.context=e,this.delegate=t,this.targetsByName=new S}start(){this.tokenListObserver||(this.tokenListObserver=new E(this.element,this.attributeName,this),this.tokenListObserver.start())}stop(){this.tokenListObserver&&(this.disconnectAllTargets(),this.tokenListObserver.stop(),delete this.tokenListObserver)}tokenMatched({element:e,content:t}){this.scope.containsElement(e)&&this.connectTarget(e,t)}tokenUnmatched({element:e,content:t}){this.disconnectTarget(e,t)}connectTarget(e,t){var s;this.targetsByName.has(t,e)||(this.targetsByName.add(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetConnected(e,t)))}disconnectTarget(e,t){var s;this.targetsByName.has(t,e)&&(this.targetsByName.delete(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetDisconnected(e,t)))}disconnectAllTargets(){for(const e of this.targetsByName.keys)for(const t of this.targetsByName.getValuesForKey(e))this.disconnectTarget(t,e)}get attributeName(){return`data-${this.context.identifier}-target`}get element(){return this.context.element}get scope(){return this.context.scope}}function I(e,t){const s=L(e);return Array.from(s.reduce((e,s)=>(function(e,t){const s=e[t];return Array.isArray(s)?s:[]}(s,t).forEach(t=>e.add(t)),e),new Set))}function L(e){const t=[];for(;e;)t.push(e),e=Object.getPrototypeOf(e);return t.reverse()}class P{constructor(e,t){this.started=!1,this.context=e,this.delegate=t,this.outletsByName=new S,this.outletElementsByName=new S,this.selectorObserverMap=new Map,this.attributeObserverMap=new Map}start(){this.started||(this.outletDefinitions.forEach(e=>{this.setupSelectorObserverForOutlet(e),this.setupAttributeObserverForOutlet(e)}),this.started=!0,this.dependentContexts.forEach(e=>e.refresh()))}refresh(){this.selectorObserverMap.forEach(e=>e.refresh()),this.attributeObserverMap.forEach(e=>e.refresh())}stop(){this.started&&(this.started=!1,this.disconnectAllOutlets(),this.stopSelectorObservers(),this.stopAttributeObservers())}stopSelectorObservers(){this.selectorObserverMap.size>0&&(this.selectorObserverMap.forEach(e=>e.stop()),this.selectorObserverMap.clear())}stopAttributeObservers(){this.attributeObserverMap.size>0&&(this.attributeObserverMap.forEach(e=>e.stop()),this.attributeObserverMap.clear())}selectorMatched(e,t,{outletName:s}){const i=this.getOutlet(e,s);i&&this.connectOutlet(i,e,s)}selectorUnmatched(e,t,{outletName:s}){const i=this.getOutletFromMap(e,s);i&&this.disconnectOutlet(i,e,s)}selectorMatchElement(e,{outletName:t}){const s=this.selector(t),i=this.hasOutlet(e,t),n=e.matches(`[${this.schema.controllerAttribute}~=${t}]`);return!!s&&i&&n&&e.matches(s)}elementMatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementAttributeValueChanged(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementUnmatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}connectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)||(this.outletsByName.add(s,e),this.outletElementsByName.add(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletConnected(e,t,s)))}disconnectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)&&(this.outletsByName.delete(s,e),this.outletElementsByName.delete(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletDisconnected(e,t,s)))}disconnectAllOutlets(){for(const e of this.outletElementsByName.keys)for(const t of this.outletElementsByName.getValuesForKey(e))for(const s of this.outletsByName.getValuesForKey(e))this.disconnectOutlet(s,t,e)}updateSelectorObserverForOutlet(e){const t=this.selectorObserverMap.get(e);t&&(t.selector=this.selector(e))}setupSelectorObserverForOutlet(e){const t=this.selector(e),s=new C(document.body,t,this,{outletName:e});this.selectorObserverMap.set(e,s),s.start()}setupAttributeObserverForOutlet(e){const t=this.attributeNameForOutletName(e),s=new w(this.scope.element,t,this);this.attributeObserverMap.set(e,s),s.start()}selector(e){return this.scope.outlets.getSelectorForOutletName(e)}attributeNameForOutletName(e){return this.scope.schema.outletAttributeForScope(this.identifier,e)}getOutletNameFromOutletAttributeName(e){return this.outletDefinitions.find(t=>this.attributeNameForOutletName(t)===e)}get outletDependencies(){const e=new S;return this.router.modules.forEach(t=>{I(t.definition.controllerConstructor,"outlets").forEach(s=>e.add(s,t.identifier))}),e}get outletDefinitions(){return this.outletDependencies.getKeysForValue(this.identifier)}get dependentControllerIdentifiers(){return this.outletDependencies.getValuesForKey(this.identifier)}get dependentContexts(){const e=this.dependentControllerIdentifiers;return this.router.contexts.filter(t=>e.includes(t.identifier))}hasOutlet(e,t){return!!this.getOutlet(e,t)||!!this.getOutletFromMap(e,t)}getOutlet(e,t){return this.application.getControllerForElementAndIdentifier(e,t)}getOutletFromMap(e,t){return this.outletsByName.getValuesForKey(t).find(t=>t.element===e)}get scope(){return this.context.scope}get schema(){return this.context.schema}get identifier(){return this.context.identifier}get application(){return this.context.application}get router(){return this.application.router}}class _{constructor(e,t){this.logDebugActivity=(e,t={})=>{const{identifier:s,controller:i,element:n}=this;t=Object.assign({identifier:s,controller:i,element:n},t),this.application.logDebugActivity(this.identifier,e,t)},this.module=e,this.scope=t,this.controller=new e.controllerConstructor(this),this.bindingObserver=new x(this,this.dispatcher),this.valueObserver=new M(this,this.controller),this.targetObserver=new k(this,this),this.outletObserver=new P(this,this);try{this.controller.initialize(),this.logDebugActivity("initialize")}catch(e){this.handleError(e,"initializing controller")}}connect(){this.bindingObserver.start(),this.valueObserver.start(),this.targetObserver.start(),this.outletObserver.start();try{this.controller.connect(),this.logDebugActivity("connect")}catch(e){this.handleError(e,"connecting controller")}}refresh(){this.outletObserver.refresh()}disconnect(){try{this.controller.disconnect(),this.logDebugActivity("disconnect")}catch(e){this.handleError(e,"disconnecting controller")}this.outletObserver.stop(),this.targetObserver.stop(),this.valueObserver.stop(),this.bindingObserver.stop()}get application(){return this.module.application}get identifier(){return this.module.identifier}get schema(){return this.application.schema}get dispatcher(){return this.application.dispatcher}get element(){return this.scope.element}get parentElement(){return this.element.parentElement}handleError(e,t,s={}){const{identifier:i,controller:n,element:r}=this;s=Object.assign({identifier:i,controller:n,element:r},s),this.application.handleError(e,`Error ${t}`,s)}targetConnected(e,t){this.invokeControllerMethod(`${t}TargetConnected`,e)}targetDisconnected(e,t){this.invokeControllerMethod(`${t}TargetDisconnected`,e)}outletConnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletConnected`,e,t)}outletDisconnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletDisconnected`,e,t)}invokeControllerMethod(e,...t){const s=this.controller;"function"==typeof s[e]&&s[e](...t)}}const N="function"==typeof Object.getOwnPropertySymbols?e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)]:Object.getOwnPropertyNames,D=(()=>{function e(e){function t(){return Reflect.construct(e,arguments,new.target)}return t.prototype=Object.create(e.prototype,{constructor:{value:t}}),Reflect.setPrototypeOf(t,e),t}try{return function(){const t=e(function(){this.a.call(this)});t.prototype.a=function(){},new t}(),e}catch(e){return e=>class extends e{}}})();class F{constructor(e,t){this.application=e,this.definition=function(e){return{identifier:e.identifier,controllerConstructor:(t=e.controllerConstructor,function(e,t){const s=D(e),i=function(e,t){return N(t).reduce((s,i)=>{const n=function(e,t,s){const i=Object.getOwnPropertyDescriptor(e,s);if(!i||!("value"in i)){const e=Object.getOwnPropertyDescriptor(t,s).value;return i&&(e.get=i.get||e.get,e.set=i.set||e.set),e}}(e,t,i);return n&&Object.assign(s,{[i]:n}),s},{})}(e.prototype,t);return Object.defineProperties(s.prototype,i),s}(t,function(e){return I(e,"blessings").reduce((t,s)=>{const i=s(e);for(const e in i){const s=t[e]||{};t[e]=Object.assign(s,i[e])}return t},{})}(t)))};var t}(t),this.contextsByScope=new WeakMap,this.connectedContexts=new Set}get identifier(){return this.definition.identifier}get controllerConstructor(){return this.definition.controllerConstructor}get contexts(){return Array.from(this.connectedContexts)}connectContextForScope(e){const t=this.fetchContextForScope(e);this.connectedContexts.add(t),t.connect()}disconnectContextForScope(e){const t=this.contextsByScope.get(e);t&&(this.connectedContexts.delete(t),t.disconnect())}fetchContextForScope(e){let t=this.contextsByScope.get(e);return t||(t=new _(this,e),this.contextsByScope.set(e,t)),t}}class R{constructor(e){this.scope=e}has(e){return this.data.has(this.getDataKey(e))}get(e){return this.getAll(e)[0]}getAll(e){return(this.data.get(this.getDataKey(e))||"").match(/[^\s]+/g)||[]}getAttributeName(e){return this.data.getAttributeNameForKey(this.getDataKey(e))}getDataKey(e){return`${e}-class`}get data(){return this.scope.data}}class B{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get(e){const t=this.getAttributeNameForKey(e);return this.element.getAttribute(t)}set(e,t){const s=this.getAttributeNameForKey(e);return this.element.setAttribute(s,t),this.get(e)}has(e){const t=this.getAttributeNameForKey(e);return this.element.hasAttribute(t)}delete(e){if(this.has(e)){const t=this.getAttributeNameForKey(e);return this.element.removeAttribute(t),!0}return!1}getAttributeNameForKey(e){return`data-${this.identifier}-${h(e)}`}}class ${constructor(e){this.warnedKeysByObject=new WeakMap,this.logger=e}warn(e,t,s){let i=this.warnedKeysByObject.get(e);i||(i=new Set,this.warnedKeysByObject.set(e,i)),i.has(t)||(i.add(t),this.logger.warn(s,e))}}function j(e,t){return`[${e}~="${t}"]`}class V{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findTarget(t)||this.findLegacyTarget(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllTargets(t),...this.findAllLegacyTargets(t)],[])}findTarget(e){const t=this.getSelectorForTargetName(e);return this.scope.findElement(t)}findAllTargets(e){const t=this.getSelectorForTargetName(e);return this.scope.findAllElements(t)}getSelectorForTargetName(e){return j(this.schema.targetAttributeForScope(this.identifier),e)}findLegacyTarget(e){const t=this.getLegacySelectorForTargetName(e);return this.deprecate(this.scope.findElement(t),e)}findAllLegacyTargets(e){const t=this.getLegacySelectorForTargetName(e);return this.scope.findAllElements(t).map(t=>this.deprecate(t,e))}getLegacySelectorForTargetName(e){const t=`${this.identifier}.${e}`;return j(this.schema.targetAttribute,t)}deprecate(e,t){if(e){const{identifier:s}=this,i=this.schema.targetAttribute,n=this.schema.targetAttributeForScope(s);this.guide.warn(e,`target:${t}`,`Please replace ${i}="${s}.${t}" with ${n}="${t}". The ${i} attribute is deprecated and will be removed in a future version of Stimulus.`)}return e}get guide(){return this.scope.guide}}class q{constructor(e,t){this.scope=e,this.controllerElement=t}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findOutlet(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllOutlets(t)],[])}getSelectorForOutletName(e){const t=this.schema.outletAttributeForScope(this.identifier,e);return this.controllerElement.getAttribute(t)}findOutlet(e){const t=this.getSelectorForOutletName(e);if(t)return this.findElement(t,e)}findAllOutlets(e){const t=this.getSelectorForOutletName(e);return t?this.findAllElements(t,e):[]}findElement(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))[0]}findAllElements(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))}matchesElement(e,t,s){const i=e.getAttribute(this.scope.schema.controllerAttribute)||"";return e.matches(t)&&i.split(" ").includes(s)}}class U{constructor(e,t,s,i){this.targets=new V(this),this.classes=new R(this),this.data=new B(this),this.containsElement=e=>e.closest(this.controllerSelector)===this.element,this.schema=e,this.element=t,this.identifier=s,this.guide=new $(i),this.outlets=new q(this.documentScope,t)}findElement(e){return this.element.matches(e)?this.element:this.queryElements(e).find(this.containsElement)}findAllElements(e){return[...this.element.matches(e)?[this.element]:[],...this.queryElements(e).filter(this.containsElement)]}queryElements(e){return Array.from(this.element.querySelectorAll(e))}get controllerSelector(){return j(this.schema.controllerAttribute,this.identifier)}get isDocumentScope(){return this.element===document.documentElement}get documentScope(){return this.isDocumentScope?this:new U(this.schema,document.documentElement,this.identifier,this.guide.logger)}}class z{constructor(e,t,s){this.element=e,this.schema=t,this.delegate=s,this.valueListObserver=new A(this.element,this.controllerAttribute,this),this.scopesByIdentifierByElement=new WeakMap,this.scopeReferenceCounts=new WeakMap}start(){this.valueListObserver.start()}stop(){this.valueListObserver.stop()}get controllerAttribute(){return this.schema.controllerAttribute}parseValueForToken(e){const{element:t,content:s}=e;return this.parseValueForElementAndIdentifier(t,s)}parseValueForElementAndIdentifier(e,t){const s=this.fetchScopesByIdentifierForElement(e);let i=s.get(t);return i||(i=this.delegate.createScopeForElementAndIdentifier(e,t),s.set(t,i)),i}elementMatchedValue(e,t){const s=(this.scopeReferenceCounts.get(t)||0)+1;this.scopeReferenceCounts.set(t,s),1==s&&this.delegate.scopeConnected(t)}elementUnmatchedValue(e,t){const s=this.scopeReferenceCounts.get(t);s&&(this.scopeReferenceCounts.set(t,s-1),1==s&&this.delegate.scopeDisconnected(t))}fetchScopesByIdentifierForElement(e){let t=this.scopesByIdentifierByElement.get(e);return t||(t=new Map,this.scopesByIdentifierByElement.set(e,t)),t}}class W{constructor(e){this.application=e,this.scopeObserver=new z(this.element,this.schema,this),this.scopesByIdentifier=new S,this.modulesByIdentifier=new Map}get element(){return this.application.element}get schema(){return this.application.schema}get logger(){return this.application.logger}get controllerAttribute(){return this.schema.controllerAttribute}get modules(){return Array.from(this.modulesByIdentifier.values())}get contexts(){return this.modules.reduce((e,t)=>e.concat(t.contexts),[])}start(){this.scopeObserver.start()}stop(){this.scopeObserver.stop()}loadDefinition(e){this.unloadIdentifier(e.identifier);const t=new F(this.application,e);this.connectModule(t);const s=e.controllerConstructor.afterLoad;s&&s.call(e.controllerConstructor,e.identifier,this.application)}unloadIdentifier(e){const t=this.modulesByIdentifier.get(e);t&&this.disconnectModule(t)}getContextForElementAndIdentifier(e,t){const s=this.modulesByIdentifier.get(t);if(s)return s.contexts.find(t=>t.element==e)}proposeToConnectScopeForElementAndIdentifier(e,t){const s=this.scopeObserver.parseValueForElementAndIdentifier(e,t);s?this.scopeObserver.elementMatchedValue(s.element,s):console.error(`Couldn't find or create scope for identifier: "${t}" and element:`,e)}handleError(e,t,s){this.application.handleError(e,t,s)}createScopeForElementAndIdentifier(e,t){return new U(this.schema,e,t,this.logger)}scopeConnected(e){this.scopesByIdentifier.add(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.connectContextForScope(e)}scopeDisconnected(e){this.scopesByIdentifier.delete(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.disconnectContextForScope(e)}connectModule(e){this.modulesByIdentifier.set(e.identifier,e),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.connectContextForScope(t))}disconnectModule(e){this.modulesByIdentifier.delete(e.identifier),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.disconnectContextForScope(t))}}const K={controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target",targetAttributeForScope:e=>`data-${e}-target`,outletAttributeForScope:(e,t)=>`data-${e}-${t}-outlet`,keyMappings:Object.assign(Object.assign({enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"},H("abcdefghijklmnopqrstuvwxyz".split("").map(e=>[e,e]))),H("0123456789".split("").map(e=>[e,e])))};function H(e){return e.reduce((e,[t,s])=>Object.assign(Object.assign({},e),{[t]:s}),{})}class G{constructor(e=document.documentElement,t=K){this.logger=console,this.debug=!1,this.logDebugActivity=(e,t,s={})=>{this.debug&&this.logFormattedMessage(e,t,s)},this.element=e,this.schema=t,this.dispatcher=new n(this),this.router=new W(this),this.actionDescriptorFilters=Object.assign({},r)}static start(e,t){const s=new this(e,t);return s.start(),s}async start(){await new Promise(e=>{"loading"==document.readyState?document.addEventListener("DOMContentLoaded",()=>e()):e()}),this.logDebugActivity("application","starting"),this.dispatcher.start(),this.router.start(),this.logDebugActivity("application","start")}stop(){this.logDebugActivity("application","stopping"),this.dispatcher.stop(),this.router.stop(),this.logDebugActivity("application","stop")}register(e,t){this.load({identifier:e,controllerConstructor:t})}registerActionOption(e,t){this.actionDescriptorFilters[e]=t}load(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>{e.controllerConstructor.shouldLoad&&this.router.loadDefinition(e)})}unload(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>this.router.unloadIdentifier(e))}get controllers(){return this.router.contexts.map(e=>e.controller)}getControllerForElementAndIdentifier(e,t){const s=this.router.getContextForElementAndIdentifier(e,t);return s?s.controller:null}handleError(e,t,s){var i;this.logger.error("%s\n\n%o\n\n%o",t,e,s),null===(i=window.onerror)||void 0===i||i.call(window,t,"",0,0,e)}logFormattedMessage(e,t,s={}){s=Object.assign({application:this},s),this.logger.groupCollapsed(`${e} #${t}`),this.logger.log("details:",Object.assign({},s)),this.logger.groupEnd()}}function J(e,t,s){return e.application.getControllerForElementAndIdentifier(t,s)}function Y(e,t,s){let i=J(e,t,s);return i||(e.application.router.proposeToConnectScopeForElementAndIdentifier(t,s),i=J(e,t,s),i||void 0)}function Z([e,t],s){return function(e){const{token:t,typeDefinition:s}=e,i=`${h(t)}-value`,n=function(e){const{controller:t,token:s,typeDefinition:i}=e,n=function(e){const{controller:t,token:s,typeObject:i}=e,n=u(i.type),r=u(i.default),o=n&&r,a=n&&!r,c=!n&&r,l=X(i.type),h=Q(e.typeObject.default);if(a)return l;if(c)return h;if(l!==h)throw new Error(`The specified default value for the Stimulus Value "${t?`${t}.${s}`:s}" must match the defined type "${l}". The provided default value of "${i.default}" is of type "${h}".`);return o?l:void 0}({controller:t,token:s,typeObject:i}),r=Q(i),o=X(i),a=n||r||o;if(a)return a;throw new Error(`Unknown value type "${t?`${t}.${i}`:s}" for "${s}" value`)}(e);return{type:n,key:i,name:a(i),get defaultValue(){return function(e){const t=X(e);if(t)return ee[t];const s=d(e,"default"),i=d(e,"type"),n=e;if(s)return n.default;if(i){const{type:e}=n,t=X(e);if(t)return ee[t]}return e}(s)},get hasCustomDefaultValue(){return void 0!==Q(s)},reader:te[n],writer:se[n]||se.default}}({controller:s,token:e,typeDefinition:t})}function X(e){switch(e){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function Q(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}return Array.isArray(e)?"array":"[object Object]"===Object.prototype.toString.call(e)?"object":void 0}const ee={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},te={array(e){const t=JSON.parse(e);if(!Array.isArray(t))throw new TypeError(`expected value of type "array" but instead got value "${e}" of type "${Q(t)}"`);return t},boolean:e=>!("0"==e||"false"==String(e).toLowerCase()),number:e=>Number(e.replace(/_/g,"")),object(e){const t=JSON.parse(e);if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`expected value of type "object" but instead got value "${e}" of type "${Q(t)}"`);return t},string:e=>e},se={default:function(e){return`${e}`},array:ie,object:ie};function ie(e){return JSON.stringify(e)}class ne{constructor(e){this.context=e}static get shouldLoad(){return!0}static afterLoad(e,t){}get application(){return this.context.application}get scope(){return this.context.scope}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get targets(){return this.scope.targets}get outlets(){return this.scope.outlets}get classes(){return this.scope.classes}get data(){return this.scope.data}initialize(){}connect(){}disconnect(){}dispatch(e,{target:t=this.element,detail:s={},prefix:i=this.identifier,bubbles:n=!0,cancelable:r=!0}={}){const o=new CustomEvent(i?`${i}:${e}`:e,{detail:s,bubbles:n,cancelable:r});return t.dispatchEvent(o),o}}ne.blessings=[function(e){return I(e,"classes").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Class`]:{get(){const{classes:e}=this;if(e.has(s))return e.get(s);{const t=e.getAttributeName(s);throw new Error(`Missing attribute "${t}"`)}}},[`${s}Classes`]:{get(){return this.classes.getAll(s)}},[`has${l(s)}Class`]:{get(){return this.classes.has(s)}}}));var s},{})},function(e){return I(e,"targets").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Target`]:{get(){const e=this.targets.find(s);if(e)return e;throw new Error(`Missing target element "${s}" for "${this.identifier}" controller`)}},[`${s}Targets`]:{get(){return this.targets.findAll(s)}},[`has${l(s)}Target`]:{get(){return this.targets.has(s)}}}));var s},{})},function(e){const t=function(e,t){return L(e).reduce((e,s)=>(e.push(...function(e,t){const s=e[t];return s?Object.keys(s).map(e=>[e,s[e]]):[]}(s,t)),e),[])}(e,"values"),s={valueDescriptorMap:{get(){return t.reduce((e,t)=>{const s=Z(t,this.identifier),i=this.data.getAttributeNameForKey(s.key);return Object.assign(e,{[i]:s})},{})}}};return t.reduce((e,t)=>Object.assign(e,function(e){const t=Z(e,void 0),{key:s,name:i,reader:n,writer:r}=t;return{[i]:{get(){const e=this.data.get(s);return null!==e?n(e):t.defaultValue},set(e){void 0===e?this.data.delete(s):this.data.set(s,r(e))}},[`has${l(i)}`]:{get(){return this.data.has(s)||t.hasCustomDefaultValue}}}}(t)),s)},function(e){return I(e,"outlets").reduce((e,t)=>Object.assign(e,function(e){const t=c(e);return{[`${t}Outlet`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t){const s=Y(this,t,e);if(s)return s;throw new Error(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`)}throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}Outlets`]:{get(){const t=this.outlets.findAll(e);return t.length>0?t.map(t=>{const s=Y(this,t,e);if(s)return s;console.warn(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`,t)}).filter(e=>e):[]}},[`${t}OutletElement`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t)return t;throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}OutletElements`]:{get(){return this.outlets.findAll(e)}},[`has${l(t)}Outlet`]:{get(){return this.outlets.has(e)}}}}(t)),{})}],ne.targets=[],ne.outlets=[],ne.values={}},290(e,t,s){s.d(t,{default:()=>ci});var i=s(891);class n extends Error{constructor(e){super(`${e} is not valid. Please provide a valid event name`),this.name="InvalidEvent"}}class r{static events=["session-set","utm-set","forms:collected","form:completed","popup:mounted","popup:opened","popup:closed","alert:shown","alert:dismissed","alert:accepted","webchat:mounted","webchat:opened","webchat:closed","webchat:message:sent","webchat:message:received","cart.added"];static valid(e){return r.exists(e)}static invalid(e){return!this.valid(e)}static exists(e){return void 0!==this.events.find(t=>t===e)}constructor(){this.subscribers={}}addSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers={...this.subscribers,[e]:this.subscribers[e]?[...this.subscribers[e],t]:[t]}}removeSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers[e]&&(this.subscribers[e]=this.subscribers[e].filter(e=>e!==t))}dispatch(e,t){this.subscribers[e]?.forEach(e=>{e(t)})}get listeners(){return 0!==Object.keys(this.subscribers).length}}class o{static autoMount=!0;static successMessage=!0;static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static get shouldShowSuccessMessage(){return this.successMessage}}class a{static _identifier;static set identifier(e){this._identifier=e}static get identifier(){return this._identifier?this._identifier:this.#e||this.#t||this.#s||"en"}static toString(){return this.identifier}static get#e(){return"undefined"!=typeof document?document.documentElement?.lang:void 0}static get#t(){return"undefined"!=typeof document?document.querySelector('meta[name="locale"]')?.content:void 0}static get#s(){return"undefined"!=typeof navigator?navigator.language?.split("-")[0]:void 0}}class c{static _id;static _container="body";static _device="auto";static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set device(e){if(!["auto","mobile","desktop"].includes(e))throw new Error(`Invalid popup device value: ${e}`);this._device=e}static get device(){return this._device}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}}const l={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"},h={ABSOLUTE:"absolute",FIXED:"fixed"},u={MODAL:"modal",POPOVER:"popover"};class d{static _id;static _container="body";static _placement="bottom-right";static _style={};static _appearance={};static _whatsapp={};static _mode=u.POPOVER;static _behaviour=null;static _hasBehaviourOverride=!1;static _strategy=null;static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(l).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static set id(e){this._id=e}static get id(){return this._id}static get isSet(){return!!this._id}static get style(){return this._style}static set style(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(([e,t])=>{if(!["primaryColor","secondaryColor","typography"].includes(e))throw new Error(`Invalid style property: ${e}`);if("typography"!==e&&!this.isHexOrRgba(t))throw new Error(`Invalid color value: ${t} for ${e}. Colors must be hex or rgb/a.`)}),this._style=e}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if(!["header","launcher"].includes(e))throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("header"===e&&"name"!==t)throw new Error(`Invalid appearance header property: ${t}`);if("launcher"===e&&"iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get whatsapp(){return this._whatsapp}static set whatsapp(e){if(!this.isPlainObject(e))throw new Error("WhatsApp must be an object");Object.entries(e).forEach(([e,t])=>{if(!["number","restrictToChannel"].includes(e))throw new Error(`Invalid WhatsApp property: ${e}`);if(null!=t){if("number"===e&&"string"!=typeof t)throw new Error(`Invalid WhatsApp number value: ${t}`);if("restrictToChannel"===e&&"boolean"!=typeof t)throw new Error(`Invalid WhatsApp restrictToChannel value: ${t}`)}}),this._whatsapp=e}static get mode(){return this._mode}static set mode(e){if(!Object.values(u).includes(e))throw new Error(`Invalid mode value: ${e}`);this._mode=e}static get behaviour(){return this._behaviour}static set behaviour(e){if(null!=e){if("object"!=typeof e||Array.isArray(e))throw new Error(`Invalid behaviour value: ${e}`);this._behaviour=e}else this._behaviour=e}static get hasBehaviourOverride(){return this._hasBehaviourOverride}static set behaviourOverride(e){this._hasBehaviourOverride=!!e}static get strategy(){return this._strategy?this._strategy:"body"==this.container?h.FIXED:h.ABSOLUTE}static set strategy(e){if(e&&!Object.values(h).includes(e))throw new Error(`Invalid strategy value: ${e}`);this._strategy=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isHexOrRgba(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}const p={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"};class m{static _id;static _container="body";static _placement="bottom-right";static _appearance={};static _number=null;static _body=null;static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(p).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if("launcher"!==e)throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get number(){return this._number}static set number(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid number value: ${e}`);this._number=e}static get body(){return this._body}static set body(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid body value: ${e}`);this._body=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}class g{static serviceWorkerUrl=null;static channelId=null;static assign(e){return this.serviceWorkerUrl=e?.serviceWorkerUrl||null,this.channelId=e?.channelId||null,this}}class f{static apiRoot="https://api.hellotext.com/v1";static actionCableUrl="wss://www.hellotext.com/cable";static autoGenerateSession=!0;static session=null;static forms=o;static popup=c;static webchat=d;static whatsapp=m;static push=g;static assign(e){if(e){const t=Object.prototype.hasOwnProperty.call(e,"apiRoot")&&!Object.prototype.hasOwnProperty.call(e,"actionCableUrl");Object.entries(e).forEach(([e,t])=>{"forms"===e?this.forms=o.assign(t):"popup"===e?this.popup=c.assign(t):"webchat"===e?this.webchat=d.assign(t):"whatsappWidget"===e?this.whatsapp=m.assign(t):"push"===e?this.push=g.assign(t):this[e]=t}),t&&(this.actionCableUrl=this.actionCableUrlForApiRoot(this.apiRoot))}return this}static set locale(e){a.identifier=e}static get locale(){return a.toString()}static endpoint(e){return`${this.apiRoot}/${e}`}static actionCableUrlForApiRoot(e){try{const t=new URL(e),s="https:"===t.protocol?"wss:":"ws:";return t.protocol=s,t.pathname="/cable",t.search="",t.hash="",t.toString()}catch(e){return this.actionCableUrl}}}const b=class{static get endpoint(){return f.endpoint("public/businesses")}static async get(e){return fetch(`${this.endpoint}/${e}`,{method:"GET",headers:{Authorization:`Bearer ${e}`,Accept:"application/json","Content-Type":"application/json"}})}};class y{static get inPreviewMode(){return(new this).inPreviewMode}constructor(){this.urlSearchParams=new URLSearchParams(window.location.search)}get(e){return this.urlSearchParams.get(this.toHellotextParam(e))}has(e){return this.urlSearchParams.has(this.toHellotextParam(e))}get inPreviewMode(){return this.has("preview")}get session(){return this.get("session")}toHellotextParam(e){return`hello_${e}`}}class v{#i;constructor(e,t){this.response=t,this.#i=e}get data(){return this.response}async json(){return await this.response.json()}get failed(){return!1===this.#i}get succeeded(){return!0===this.#i}}class w{static get endpoint(){return f.endpoint("track/events")}static async create({headers:e,body:t,keepalive:s=!1}){if(y.inPreviewMode)return new v(!0,{received:!0});const i={method:"POST",headers:e,body:JSON.stringify(t)};s&&(i.keepalive=!0);const n=await fetch(this.endpoint,i);return new v(200===n.status,await n.json())}}class T{static get endpoint(){return f.endpoint("public/forms")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);return t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),fetch(t,{method:"GET",headers:vt.headers})}static async submit(e,t){const s=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...t})});return new v(s.ok,s)}}const S=class{static get endpoint(){return f.endpoint("public/identifications")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...e})});return new v(t.ok,t)}},C=class{static get endpoint(){return f.endpoint("public/popups")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),t.searchParams.append("device",this.runtimeDevice);const s=await this.fetchPopup(t);if(!s.ok)return null;const i=await this.parsePopupResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static async submit(e,t,s=this.idempotencyKey()){const i=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:{...vt.headers,"Idempotency-Key":s},body:JSON.stringify({session:vt.session,popup_submission:t})});return new v(i.ok,i)}static async resend(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/resend`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static async cancel(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/cancel`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static idempotencyKey(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}static async fetchPopup(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static get runtimeDevice(){return"auto"!==f.popup.device?f.popup.device:window.innerWidth<=767?"mobile":"desktop"}static async parsePopupResponse(e){try{return await e.json()}catch(e){return null}}},O=class{static get endpoint(){return f.endpoint("public/webchats")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),Object.entries(f.webchat.style).forEach(([e,s])=>{t.searchParams.append(`style[${e}]`,s)}),this.appendWebchatOverrides(t),t.searchParams.append("placement",f.webchat.placement);const s=await fetch(t,{method:"GET",headers:vt.headers}),i=await s.json();return vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")}static appendWebchatOverrides(e){const{appearance:t,whatsapp:s}=f.webchat;this.appendIfSupplied(e,"webchat[appearance][header][name]",t.header?.name),this.appendIfSupplied(e,"webchat[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"webchat[handoff][identifier]",s.number),this.appendIfSupplied(e,"webchat[handoff][restrict_to_channel]",s.restrictToChannel)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}},E=class{static get endpoint(){return f.endpoint("public/widgets/whatsapp")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("locale",a.toString()),t.searchParams.append("placement",f.whatsapp.placement),this.appendWhatsAppOverrides(t);const s=await this.fetchWidget(t);if(!s.ok)return null;const i=await this.parseWidgetResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static appendWhatsAppOverrides(e){const{appearance:t,body:s,number:i}=f.whatsapp;this.appendIfSupplied(e,"whatsapp[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"whatsapp[number]",i),this.appendIfSupplied(e,"whatsapp[body]",s)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}static async fetchWidget(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static async parseWidgetResponse(e){try{return await e.json()}catch(e){return null}}},A=class{static get endpoint(){return f.endpoint("public/acks")}static async send(e={}){const t={...e,session:vt.session,at:(new Date).toISOString()};fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify(t),keepalive:!0})}},x=class{static get endpoint(){return f.endpoint("public/push/identities")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}static async destroy(e={}){const t=await fetch(this.endpoint,{method:"DELETE",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}},M=class{static get endpoint(){return f.endpoint("public/push/alerts")}static async create({section:e,kind:t,page:s}){const i=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({session:vt.session,section:e,kind:t,page:s})});return new v(i.ok,i)}};function k(e){const t=JSON.stringify(e);return"undefined"==typeof Blob?t.length<6e4:new Blob([t]).size<6e4}class I{static get businesses(){return b}static get events(){return w}static get forms(){return T}static get popups(){return C}static get popups(){return C}static get webchats(){return O}static get whatsappWidgets(){return E}static get identifications(){return S}static get acks(){return A}static get pushAlerts(){return M}static get pushIdentities(){return x}}const L="data-hellotext-stylesheet";class P{constructor(e){this.id=e,this.data=null,this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1)}async hydrate(){try{const e=await b.get(this.id);if(!1===e.ok)return null;const t=await e.json();return t?(this.setData(t),this.setLocale(a.toString()),t):null}catch(e){return null}}setData(e){this.data=e,"undefined"!=typeof document&&e.style_url?(this.stylesheet=this.constructor.ensureStylesheet(e.style_url),this.stylesheetLoaded=this.constructor.waitForStylesheet(this.stylesheet)):(this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1))}static get stylesheetSelector(){return`link[rel="stylesheet"][${L}]`}static ensureStylesheet(e){const t=this.normalizedStylesheetUrl(e),s=this.stylesheetLinks.find(e=>e.href===t);if(s)return s.setAttribute(L,"true"),s;const i=document.createElement("link");return i.rel="stylesheet",i.href=e,i.setAttribute(L,"true"),this.waitForStylesheet(i),document.head.append(i),i}static get stylesheetLinks(){return"undefined"==typeof document?[]:Array.from(document.querySelectorAll(this.stylesheetSelector))}static get latestStylesheet(){return this.stylesheetLinks[this.stylesheetLinks.length-1]}static normalizedStylesheetUrl(e){try{return new URL(e,document.baseURI).href}catch(t){return e}}static waitForStylesheet(e){return e?this.stylesheetIsLoaded(e)?Promise.resolve(!0):"false"===e.dataset.hellotextStylesheetLoaded?Promise.resolve(!1):(e._hellotextStylesheetLoaded||(e._hellotextStylesheetLoaded=new Promise(t=>{let s;const i=i=>{clearTimeout(s),e.removeEventListener("load",n),e.removeEventListener("error",r),e.dataset.hellotextStylesheetLoaded=i?"true":"false",t(i)},n=()=>i(this.stylesheetIsLoaded(e)),r=()=>i(!1);e.addEventListener("load",n),e.addEventListener("error",r),s=setTimeout(()=>i(this.stylesheetIsLoaded(e)),1e4),s.unref&&s.unref()})),e._hellotextStylesheetLoaded):Promise.resolve(!1)}static stylesheetIsLoaded(e){return"true"===e.dataset.hellotextStylesheetLoaded||!!e.sheet}get subscription(){return this.data.subscription}get country(){return this.data.country}get enabledWhitelist(){return"disabled"!==this.data.whitelist}setLocale(e){this.data||(this.data={});const t=e?.toLowerCase().split("-")[0];this.data.locale=Object.prototype.hasOwnProperty.call(this.data.locales||{},t)?t:"en"}get locale(){const e=this.data?.locales;return e?.[this.data.locale]||e?.en}get features(){return this.data.features}}class _{static set(e,t){if("undefined"!=typeof document){const s="https:"===window.location.protocol?"; Secure":"",i=D.getRootDomain(),n=31536e4;document.cookie=i?`${e}=${t}; path=/${s}; domain=${i}; max-age=${n}; SameSite=Lax`:`${e}=${t}; path=/${s}; max-age=${n}; SameSite=Lax`}return"hello_session"===e&&vt.eventEmitter.dispatch("session-set",t),"hello_utm"===e&&vt.eventEmitter.dispatch("utm-set",t),t}static get(e){return"undefined"!=typeof document?document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)")?.pop():void 0}static delete(e){if("undefined"!=typeof document){const t=D.getRootDomain(),s="https:"===window.location.protocol?"; Secure":"";document.cookie=t?`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; domain=${t}; SameSite=Lax`:`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; SameSite=Lax`}}}class N{constructor(){const e=new URLSearchParams(window.location.search),t={source:e.get("utm_source"),medium:e.get("utm_medium"),campaign:e.get("utm_campaign"),term:e.get("utm_term"),content:e.get("utm_content")};this.save(t)}save(e){if(!e.source||!e.medium)return;const t=Object.fromEntries(Object.entries(e).filter(([e,t])=>t));t.observed_at=(new Date).toISOString(),_.set("hello_utm",JSON.stringify(t))}get current(){try{return JSON.parse(_.get("hello_utm"))||{}}catch(e){return{}}}}class D{constructor(e=null){this.utm=new N,this._url=e}get url(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}get title(){return document.title}get path(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}get utmParams(){return this.utm.current}get trackingData(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}get domain(){try{const e=this.url;if(!e)return null;const t=new URL(e).hostname;return D.getRootDomain(t)}catch(e){return null}}static getRootDomain(e=null){try{if(!e){if("undefined"==typeof window||!window.location?.hostname)return null;e=window.location.hostname}const t=e.split(".");if(t.length<=1)return e;const s=["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"];for(const e of s){const s=e.split(".");if(t.slice(-s.length).join(".")===e&&t.length>s.length)return`.${t.slice(-(s.length+1)).join(".")}`}const i=t[t.length-1],n=t[t.length-2];return t.length>2&&2===i.length&&n.length<=3?`.${t.slice(-3).join(".")}`:`.${t.slice(-2).join(".")}`}catch(e){return null}}}class F{static#n;static#r;static#o;static get session(){return this.#n}static get ackPayload(){return{utm_params:this.#o?.utmParams||{}}}static set session(e){const t=_.get("hello_session");return this.#n=e,_.set("hello_session",e),t!==e&&_.delete("hello_session_ack_at"),_.get("hello_session_ack_at")||(I.acks.send(this.ackPayload),_.set("hello_session_ack_at",(new Date).toISOString())),this.#n}static initialize(e=new D){this.#o=e,this.#r=new y,this.session=this.#r.session||f.session||_.get("hello_session"),!this.session&&f.autoGenerateSession&&(this.session=crypto.randomUUID())}}class R{static build(e){const t=document.createElement("article"),s=document.createElement("label"),i=document.createElement("input");s.innerText=e.label,i.type=e.type,i.required=e.required,i.placeholder=e.placeholder,["first_name","last_name"].includes(e.kind)?(i.type="text",i.id=i.name=e.kind,s.setAttribute("for",e.kind)):(i.type=e.type,"email"===e.type?(i.id=i.name="email",s.setAttribute("for","email")):"tel"===i.type?(i.id=i.name="phone",s.setAttribute("for","phone"),i.value=`+${vt.business.country.prefix}`,i.setAttribute("data-default-value",`+${vt.business.country.prefix}`)):(i.name=i.id=`property_by_id[${e.property}]`,s.setAttribute("for",`property_by_id[${e.property}]`)));const n=document.createElement("main");n.appendChild(s),n.appendChild(i),t.appendChild(n),t.setAttribute("data-hellotext--form-target","inputContainer"),i.setAttribute("data-hellotext--form-target","input");const r=document.createElement("div");return r.setAttribute("data-error-container",""),t.appendChild(r),t}}class B{static build(){const e=document.createElement("div");return e.innerHTML=this.#a(),e.firstElementChild}static#a(){const e=`https://www.hellotext.com?hello_session=${vt.session}`;return`\n
\n ${vt.business.locale.white_label.powered_by}\n\n \n \n Hellotext\n \n \n \n
\n `}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var s=0,i=Array(t);s2?s-2:0),n=2;n1?t-1:0),i=1;i1?s-1:0),n=1;n2&&void 0!==arguments[2]?arguments[2]:ne;if(q&&q(e,null),!ie(t))return e;let i=t.length;for(;i--;){let n=t[i];if("string"==typeof n){const e=s(n);e!==n&&(U(t)||(t[i]=e),n=e)}e[n]=!0}return e}function Te(e){for(let t=0;t/g),Re=H(/\${[\w\W]*/g),Be=H(/^data-[\-\w.\u00B7-\uFFFF]+$/),$e=H(/^aria-[\-\w]+$/),je=H(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Ve=H(/^(?:\w+script|data):/i),qe=H(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ue=H(/^html$/i),ze=H(/^[a-z][.\w]*(-[.\w]+)+$/i),We=H(/<[/\w!]/g),Ke=H(/<[/\w]/g),He=H(/<\/no(script|embed|frames)/i),Ge=H(/\/>/i),Je=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"],Ye=K(we({},Je)),Ze=function(){const e={};return X(Je,t=>{e[t]=H(new RegExp("])","i"))}),K(e)}(),Xe=function(){return"undefined"==typeof window?null:window},Qe=function(e,t,s,i){return me(e,t)&&ie(e[t])?we(i.base?Se(i.base):{},e[t],i.transform):s},et=function(e,t,s){const i=me(e,t)?e[t]:void 0;return i&&"object"==typeof i?Se(i):s()};var tt=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Xe();const s=t=>e(t);if(s.version="3.4.15",s.removed=[],!t||!t.document||9!==t.document.nodeType||!t.Element)return s.isSupported=!1,s;let i=t.document;const n=i,r=n.currentScript;t.DocumentFragment;const o=t.HTMLTemplateElement,a=t.Node,c=t.Element,l=t.NodeFilter;void 0===t.NamedNodeMap&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;const h=t.DOMParser,u=t.trustedTypes,d=c.prototype,p=Ce(d,"cloneNode"),m=Ce(d,"remove"),g=Ce(d,"removeAttributeNode"),f=Ce(d,"nextSibling"),b=Ce(d,"childNodes"),y=Ce(d,"parentNode"),v=Ce(d,"shadowRoot"),w=Ce(d,"attributes"),T=a&&a.prototype?Ce(a.prototype,"nodeType"):null,S=a&&a.prototype?Ce(a.prototype,"nodeName"):null,C=a&&a.prototype?Ce(a.prototype,"ownerDocument"):null,O=function(e){return T?T(e):e.nodeType},E=function(e){return S?S(e):e.nodeName};if("function"==typeof o){const e=i.createElement("template");e.content&&e.content.ownerDocument&&(i=e.content.ownerDocument)}let A,x,M="",k=!1,I=0;const L=function(){if(I>0)throw be('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},P=function(e){L(),I++;try{return A.createHTML(e)}finally{I--}},_=i,N=_.implementation,D=_.createNodeIterator,F=_.createDocumentFragment,R=_.getElementsByTagName,B=n.importNode;let $={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};s.isSupported="function"==typeof V&&"function"==typeof y&&N&&void 0!==N.createHTMLDocument;const j=De,q=Fe,U=Re,z=Be,W=$e,J=Ve,Y=qe,Z=ze;let ye=je,ve=null;const Te=we({},[...Oe,...Ee,...Ae,...Me,...Ie]);let Je=null;const tt=we({},[...Le,...Pe,..._e,...Ne]);let st=Object.seal(G(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),it=null,nt=null;const rt=Object.seal(G(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let ot=!0,at=!0,ct=!1,lt=!0,ht=!1,ut=!0,dt=!1,pt=!1,mt=null,gt=null,ft=!1,bt=!1,yt=!1,vt=!1,wt=!0,Tt=!1;const St="user-content-";let Ct=!0,Ot=!1,Et={},At=null;const xt=we({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let Mt=null;const kt=we({},["audio","video","img","source","image","track"]);let It=null;const Lt=we({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Pt="http://www.w3.org/1998/Math/MathML",_t="http://www.w3.org/2000/svg",Nt="http://www.w3.org/1999/xhtml";let Dt=Nt,Ft=!1,Rt=null;const Bt=we({},[Pt,_t,Nt],re),$t=K(["mi","mo","mn","ms","mtext"]);let jt=we({},$t);const Vt=K(["annotation-xml"]);let qt=we({},Vt);const Ut=we({},["title","style","font","a","script"]);let zt=null;const Wt=["application/xhtml+xml","text/html"];let Kt=null,Ht=null;const Gt=i.createElement("form"),Jt=function(e){return e instanceof RegExp||e instanceof Function},Yt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(Ht&&Ht===e)return;e&&"object"==typeof e||(e={}),e=Se(e),zt=-1===Wt.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,Kt="application/xhtml+xml"===zt?re:ne,ve=Qe(e,"ALLOWED_TAGS",Te,{transform:Kt}),Je=Qe(e,"ALLOWED_ATTR",tt,{transform:Kt}),Rt=Qe(e,"ALLOWED_NAMESPACES",Bt,{transform:re}),It=Qe(e,"ADD_URI_SAFE_ATTR",Lt,{transform:Kt,base:Lt}),Mt=Qe(e,"ADD_DATA_URI_TAGS",kt,{transform:Kt,base:kt}),At=Qe(e,"FORBID_CONTENTS",xt,{transform:Kt}),it=Qe(e,"FORBID_TAGS",Se({}),{transform:Kt}),nt=Qe(e,"FORBID_ATTR",Se({}),{transform:Kt}),Et=!!me(e,"USE_PROFILES")&&(e.USE_PROFILES&&"object"==typeof e.USE_PROFILES?Se(e.USE_PROFILES):e.USE_PROFILES),ot=!1!==e.ALLOW_ARIA_ATTR,at=!1!==e.ALLOW_DATA_ATTR,ct=e.ALLOW_UNKNOWN_PROTOCOLS||!1,lt=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,ht=e.SAFE_FOR_TEMPLATES||!1,ut=!1!==e.SAFE_FOR_XML,dt=e.WHOLE_DOCUMENT||!1,bt=e.RETURN_DOM||!1,yt=e.RETURN_DOM_FRAGMENT||!1,vt=e.RETURN_TRUSTED_TYPE||!1,ft=e.FORCE_BODY||!1,wt=!1!==e.SANITIZE_DOM,Tt=e.SANITIZE_NAMED_PROPS||!1,Ct=!1!==e.KEEP_CONTENT,Ot=e.IN_PLACE||!1,ye=function(e){try{return fe(e,""),!0}catch(e){return!1}}(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:je,Dt="string"==typeof e.NAMESPACE?e.NAMESPACE:Nt,jt=et(e,"MATHML_TEXT_INTEGRATION_POINTS",()=>we({},$t)),qt=et(e,"HTML_INTEGRATION_POINTS",()=>we({},Vt));const t=et(e,"CUSTOM_ELEMENT_HANDLING",()=>G(null));if(st=G(null),me(t,"tagNameCheck")&&Jt(t.tagNameCheck)&&(st.tagNameCheck=t.tagNameCheck),me(t,"attributeNameCheck")&&Jt(t.attributeNameCheck)&&(st.attributeNameCheck=t.attributeNameCheck),me(t,"allowCustomizedBuiltInElements")&&"boolean"==typeof t.allowCustomizedBuiltInElements&&(st.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),H(st),ht&&(at=!1),yt&&(bt=!0),Et&&(ve=we({},Ie),Je=G(null),!0===Et.html&&(we(ve,Oe),we(Je,Le)),!0===Et.svg&&(we(ve,Ee),we(Je,Pe),we(Je,Ne)),!0===Et.svgFilters&&(we(ve,Ae),we(Je,Pe),we(Je,Ne)),!0===Et.mathMl&&(we(ve,Me),we(Je,_e),we(Je,Ne))),rt.tagCheck=null,rt.attributeCheck=null,me(e,"ADD_TAGS")&&("function"==typeof e.ADD_TAGS?rt.tagCheck=e.ADD_TAGS:ie(e.ADD_TAGS)&&(ve===Te&&(ve=Se(ve)),we(ve,e.ADD_TAGS,Kt))),me(e,"ADD_ATTR")&&("function"==typeof e.ADD_ATTR?rt.attributeCheck=e.ADD_ATTR:ie(e.ADD_ATTR)&&(Je===tt&&(Je=Se(Je)),we(Je,e.ADD_ATTR,Kt))),me(e,"ADD_FORBID_CONTENTS")&&ie(e.ADD_FORBID_CONTENTS)&&(At===xt&&(At=Se(At)),we(At,e.ADD_FORBID_CONTENTS,Kt)),Ct&&(ve["#text"]=!0),dt&&we(ve,["html","head","body"]),ve.table&&(we(ve,["tbody"]),delete it.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const t=A;A=e.TRUSTED_TYPES_POLICY;try{M=P("")}catch(e){throw A=t,e}}else null===e.TRUSTED_TYPES_POLICY?(A=void 0,M=""):(void 0===A&&(k||(x=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let s=null;const i="data-tt-policy-suffix";t&&t.hasAttribute(i)&&(s=t.getAttribute(i));const n="dompurify"+(s?"#"+s:"");try{return e.createPolicy(n,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+n+" could not be created."),null}}(u,r),k=!0),A=x),A&&"string"==typeof M&&(M=P("")));K&&K(e),Ht=e},Zt=we({},[...Ee,...Ae,...xe]),Xt=we({},[...Me,...ke]),Qt=function(e){te(s.removed,{element:e});try{y(e).removeChild(e)}catch(t){if(m(e),!y(e))throw be("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},es=function(e,t,s){try{g(e,t)}catch(t){try{e.removeAttribute(s)}catch(e){}}},ts=function(e){ns(e);const t=b(e);if(t){const e=[];X(t,t=>{te(e,t)}),X(e,e=>{try{m(e)}catch(e){}})}const s=w(e);if(s)for(let t=s.length-1;t>=0;--t){const i=s[t],n=i&&i.name;"string"==typeof n&&es(e,i,n)}},ss=function(e,t,i){if(!i)try{i=t.getAttributeNode(e)}catch(e){i=null}te(s.removed,{attribute:i||null,from:t});try{i?g(t,i):t.removeAttribute(e)}catch(s){try{t.removeAttribute(e)}catch(e){}}if("is"===e)if(bt||yt)try{Qt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},is=function(e){const t=w(e);if(t)for(let s=t.length-1;s>=0;--s){const i=t[s],n=i&&i.name;"string"!=typeof n||Je[Kt(n)]||es(e,i,n)}},ns=function(e){const t=[e];for(;t.length>0;){const e=t.pop();1===O(e)&&is(e);const s=b(e);if(s)for(let e=s.length-1;e>=0;--e)t.push(s[e])}},rs=function(e,t){return!!ut&&("patchsrc"===e||"for"===e&&"label"!==t&&"output"!==t)},os=function(e){let t=null,s=null;if(ft)e=""+e;else{const t=oe(e,/^[\r\n\t ]+/);s=t&&t[0]}"application/xhtml+xml"===zt&&Dt===Nt&&(e=''+e+"");const n=A?P(e):e;if(Dt===Nt)try{t=(new h).parseFromString(n,zt)}catch(e){}if(!t||!t.documentElement){t=N.createDocument(Dt,"template",null);try{t.documentElement.innerHTML=Ft?M:n}catch(e){}}const r=t.body||t.documentElement;return e&&s&&r.insertBefore(i.createTextNode(s),r.childNodes[0]||null),Dt===Nt?R.call(t,dt?"html":"body")[0]:dt?t.documentElement:r},as=function(e){const t=C?C(e):e.ownerDocument;return D.call(t||e,e,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},cs=function(e){return e=ae(e,j," "),e=ae(e,q," "),ae(e,U," ")},ls=function(e){var t;e.normalize();const s=C?C(e):e.ownerDocument,i=D.call(s||e,e,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null);let n=i.nextNode();for(;n;)n.data=cs(n.data),n=i.nextNode();const r=null===(t=e.querySelectorAll)||void 0===t?void 0:t.call(e,"template");r&&X(r,e=>{us(e.content)&&ls(e.content)})},hs=function(e){const t=S?S(e):null;return"string"==typeof t&&"form"===Kt(t)&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||e.attributes!==w(e)||"function"!=typeof e.removeAttribute||"function"!=typeof e.removeAttributeNode||"function"!=typeof e.getAttributeNode||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes||e.nodeType!==T(e)||e.childNodes!==b(e))},us=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return 11===T(e)}catch(e){return!1}},ds=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return"number"==typeof T(e)}catch(e){return!1}};function ps(e,t,i){0!==e.length&&X(e,e=>{e.call(s,t,i,Ht)})}const ms=function(e,t){if(e instanceof RegExp)return fe(e,t);if(e instanceof Function){for(var s=arguments.length,i=new Array(s>2?s-2:0),n=2;n=0;--n){const r=e===s?p(i[n],!0):i[n];t.insertBefore(r,f(e))}}return Qt(e),!0}(e,i,t);return!1===s&&ps($.afterSanitizeElements,e,null),s}if(1===O(e)&&!function(e){let t=y(e);t&&t.tagName||(t={namespaceURI:Dt,tagName:"template"});const s=ne(e.tagName),i=ne(t.tagName);return!!Rt[e.namespaceURI]&&(e.namespaceURI===_t?function(e,t,s){return t.namespaceURI===Nt?"svg"===e:t.namespaceURI===Pt?"svg"===e&&("annotation-xml"===s||jt[s]):Boolean(Zt[e])}(s,t,i):e.namespaceURI===Pt?function(e,t,s){return t.namespaceURI===Nt?"math"===e:t.namespaceURI===_t?"math"===e&&qt[s]:Boolean(Xt[e])}(s,t,i):e.namespaceURI===Nt?function(e,t,s){return!(t.namespaceURI===_t&&!qt[s])&&!(t.namespaceURI===Pt&&!jt[s])&&!Xt[e]&&(Ut[e]||!Zt[e])}(s,t,i):!("application/xhtml+xml"!==zt||!Rt[e.namespaceURI]))}(e))return Qt(e),!0;if(("noscript"===i||"noembed"===i||"noframes"===i)&&fe(He,e.innerHTML))return Qt(e),!0;if(ht&&3===e.nodeType){const t=cs(e.textContent);e.textContent!==t&&(te(s.removed,{element:e.cloneNode()}),e.textContent=t)}return ps($.afterSanitizeElements,e,null),!1},ys=function(e,t,s){if(nt[t])return!1;if(rs(t,e))return!1;if(wt&&("id"===t||"name"===t)&&(s in i||s in Gt))return!1;const n=Je[t]||rt.attributeCheck instanceof Function&&rt.attributeCheck(t,e);return!(!at||!fe(z,t))||!(!ot||!fe(W,t))||(n?!(!It[t]&&!fe(ye,ae(s,Y,""))&&("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==ce(s,"data:")||!Mt[e])&&(!ct||fe(J,ae(s,Y,"")))&&s):ws(e)&&ms(st.tagNameCheck,e)&&ms(st.attributeNameCheck,t,e)||"is"===t&&st.allowCustomizedBuiltInElements&&ms(st.tagNameCheck,s))},vs=we({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),ws=function(e){return!vs[ne(e)]&&fe(Z,e)},Ts=function(e,t,s,i){if(A&&"object"==typeof u&&"function"==typeof u.getAttributeType&&!s)switch(u.getAttributeType(e,t)){case"TrustedHTML":return P(i);case"TrustedScriptURL":return function(e){L(),I++;try{return A.createScriptURL(e)}finally{I--}}(i)}return i},Ss=function(e,t,s,i){try{return s?e.setAttributeNS(s,t,i):e.setAttribute(t,i),!hs(e)||(Qt(e),!1)}catch(s){return ss(t,e),!1}},Cs=function(e){ps($.beforeSanitizeAttributes,e,null);const t=e.attributes;if(!t||hs(e))return;Je=gs($.uponSanitizeAttribute,Je,tt,gt);const i={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Je,forceKeepAttr:void 0};let n=t.length;const r=Kt(e.nodeName);for(;n--;){const o=t[n],a=o.name,c=o.namespaceURI,l=o.value,h=Kt(a),u=l;let d="value"===a?u:le(u),p=!1;i.attrName=h,i.attrValue=d,i.keepAttr=!0,i.forceKeepAttr=void 0,ps($.uponSanitizeAttribute,e,i),d=i.attrValue,!Tt||"id"!==h&&"name"!==h||0===ce(d,St)||(ss(a,e,o),d=St+d,p=!0),ut&&fe(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)||"attributename"===h&&oe(d,"href")?ss(a,e,o):i.forceKeepAttr||(i.keepAttr&&(lt||!fe(Ge,d))?(ht&&(d=cs(d)),ys(r,h,d)?(d=Ts(r,h,c,d),d!==u&&Ss(e,a,c,d)&&p&&ee(s.removed)):ss(a,e,o)):ss(a,e,o))}ps($.afterSanitizeAttributes,e,null)},Os=function(e){let t=null;const s=as(e);for(ps($.beforeSanitizeShadowDOM,e,null);t=s.nextNode();)if(ps($.uponSanitizeShadowNode,t,null),bs(t,e),Cs(t),us(t.content)&&Os(t.content),1===O(t)){const e=v(t);us(e)&&(Es(e),Os(e))}ps($.afterSanitizeShadowDOM,e,null)},Es=function(e){const t=[{node:e,shadow:null}];for(;t.length>0;){const e=t.pop();if(e.shadow){Os(e.shadow);continue}const s=e.node,i=1===O(s),n=b(s);if(n)for(let e=n.length-1;e>=0;--e)t.push({node:n[e],shadow:null});if(i){const e=S?S(s):null;if("string"==typeof e&&"template"===Kt(e)){const e=s.content;us(e)&&t.push({node:e,shadow:null})}}if(i){const e=v(s);us(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return s.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=null,r=null,o=null,a=null;if(Ft=!e,Ft&&(e="\x3c!--\x3e"),"string"!=typeof e&&!ds(e)&&"string"!=typeof(e=function(e){switch(typeof e){case"string":return e;case"number":return he(e);case"boolean":return ue(e);case"bigint":return de?de(e):"0";case"symbol":return pe?pe(e):"Symbol()";case"undefined":default:return ge(e);case"function":case"object":{if(null===e)return ge(e);const t=e,s=Ce(t,"toString");if("function"==typeof s){const e=s(t);return"string"==typeof e?e:ge(e)}return ge(e)}}}(e)))throw be("dirty is not a string, aborting");if(!s.isSupported)return e;pt?(ve=mt,Je=gt):Yt(t),($.uponSanitizeElement.length>0||$.uponSanitizeAttribute.length>0)&&(ve=Se(ve)),$.uponSanitizeAttribute.length>0&&(Je=Se(Je)),s.removed=[];const c=Ot&&"string"!=typeof e&&ds(e);if(c){!function(e){if(!ut)return;const t=[e];for(;t.length>0;){const e=t.pop(),s=O(e);if(7===s||8===s&&fe(Ke,e.data)){try{m(e)}catch(e){}continue}if(1===s){const t=e,s=Kt(E(e));try{t.hasAttribute&&t.hasAttribute("patchsrc")&&t.removeAttribute("patchsrc"),t.hasAttribute&&t.hasAttribute("for")&&rs("for",s)&&t.removeAttribute("for")}catch(e){}}const i=b(e);if(i)for(let e=i.length-1;e>=0;--e)t.push(i[e])}}(e);const t=E(e);if("string"==typeof t){const s=Kt(t);if(!ve[s]||it[s])throw ts(e),be("root node is forbidden and cannot be sanitized in-place")}if(hs(e))throw ts(e),be("root node is clobbered and cannot be sanitized in-place");try{Es(e)}catch(t){throw ts(e),t}}else if(ds(e))i=os("\x3c!----\x3e"),r=i.ownerDocument.importNode(e,!0),1===r.nodeType&&"BODY"===r.nodeName||"HTML"===r.nodeName?i=r:i.appendChild(r),Es(i);else{if(!bt&&!ht&&!dt&&-1===e.indexOf("<"))return A&&vt?P(e):e;if(i=os(e),!i)return bt?null:vt?M:""}i&&ft&&Qt(i.firstChild);const l=c?e:i;try{const e=as(l);for(;o=e.nextNode();)bs(o,l),Cs(o),us(o.content)&&Os(o.content)}catch(t){throw c&&(ts(e),X(s.removed,e=>{e.element&&ns(e.element)})),t}if(c)return X(s.removed,e=>{e.element&&ns(e.element)}),ht&&ls(e),e;if(bt){if(ht&&ls(i),yt)for(a=F.call(i.ownerDocument);i.firstChild;)a.appendChild(i.firstChild);else a=i;return(Je.shadowroot||Je.shadowrootmode)&&(a=B.call(n,a,!0)),a}let h=dt?i.outerHTML:i.innerHTML;return dt&&ve["!doctype"]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&fe(Ue,i.ownerDocument.doctype.name)&&(h="\n"+h),ht&&(h=cs(h)),A&&vt?P(h):h},s.setConfig=function(){Yt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),pt=!0,mt=ve,gt=Je},s.clearConfig=function(){Ht=null,pt=!1,mt=null,gt=null,A=x,M=""},s.isValidAttribute=function(e,t,s){Ht||Yt({});const i=Kt(e),n=Kt(t);return ys(i,n,s)},s.addHook=function(e,t){"function"==typeof t&&me($,e)&&te($[e],t)},s.removeHook=function(e,t){if(me($,e)){if(void 0!==t){const s=Q($[e],t);return-1===s?void 0:se($[e],s,1)[0]}return ee($[e])}},s.removeHooks=function(e){me($,e)&&($[e]=[])},s.removeAllHooks=function(){$={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},s}();const st={ADD_ATTR:["target"],ALLOW_DATA_ATTR:!1,RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0}},it={ADD_ATTR:["target"],ADD_TAGS:["hellotext-icon"],RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0,svg:!0}};function nt(e,t){const s=tt.sanitize(e,t);return s.querySelectorAll('a[target="_blank"]').forEach(e=>{const t=new Set(e.rel.split(/\s+/).filter(Boolean));t.add("noopener"),t.add("noreferrer"),e.rel=Array.from(t).join(" ")}),s}function rt(e,t){e.replaceChildren(function(e){return nt(e,st)}(t))}class ot{constructor(e,t=null){this.data=e,this.element=t||document.querySelector(`[data-hello-form="${this.id}"]`)||document.createElement("form")}async mount({ifCompleted:e=!0}={}){if(e&&this.hasBeenCompleted)return this.element?.remove(),vt.eventEmitter.dispatch("form:completed",{id:this.id,...JSON.parse(localStorage.getItem(`hello-form-${this.id}`))});const t=this.data.steps[0];this.buildHeader(t.header),this.buildInputs(t.inputs),this.buildButton(t.button),this.buildFooter(t.footer),this.elementAttributes.forEach(e=>{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),vt.business.features.white_label||this.element.prepend(B.build())}buildHeader(e){const t=this.#c("[data-form-header]","header");rt(t,e.content),this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}buildInputs(e){const t=this.#c("[data-form-inputs]","main");e.map(e=>R.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}buildButton(e){const t=this.#c("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}buildFooter(e){const t=this.#c("[data-form-footer]","footer");rt(t,e.content),this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}markAsCompleted(e){const t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem(`hello-form-${this.id}`,JSON.stringify(t)),vt.eventEmitter.dispatch("form:completed",t)}get hasBeenCompleted(){return null!==localStorage.getItem(`hello-form-${this.id}`)}get id(){return this.data.id}get localeAuthKey(){const e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}get elementAttributes(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}#c(e,t){const s=this.element.querySelector(e);if(s)return s.cloneNode(!0);const i=document.createElement(t);return i.setAttribute(e.replace("[","").replace("]",""),""),i}}class at extends Error{constructor(){super("You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id"),this.name="NotInitializedError"}}class ct{constructor(){this.forms=[],this.includes=this.includes.bind(this),this.excludes=this.excludes.bind(this),this.add=this.add.bind(this),"undefined"!=typeof MutationObserver&&(this.mutationObserver=new MutationObserver(this.formMutationObserver.bind(this)),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0}))}collectExistingFormsOnPage(){Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}formMutationObserver(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}async collect(){if(vt.notInitialized)throw new at;if(this.fetching)return;if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");const e=this.#l;if(0===e.length)return;const t=e.map(e=>T.get(e).then(e=>e.json()));this.fetching=!0,await Promise.all(t).then(e=>e.forEach(this.add)).then(()=>vt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),f.forms.autoMount&&this.forms.forEach(e=>e.mount())}forEach(e){this.forms.forEach(e)}map(e){return this.forms.map(e)}add(e){this.includes(e.id)||(vt.business.data||(vt.business.setData(e.business),vt.business.setLocale(a.toString())),vt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new ot(e)))}getById(e){return this.forms.find(t=>t.id===e)}getByIndex(e){return this.forms[e]}includes(e){return this.forms.some(t=>t.id===e)}excludes(e){return!this.includes(e)}get length(){return this.forms.length}get#l(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}}class lt{constructor(e){this.publicKey=e.public_key,this.serviceWorkerUrl=f.push.serviceWorkerUrl,this.channelId=f.push.channelId,this.ready=null,this.registrationPromise=null,this.subscribePromise=null,this.unsubscribePromise=null,this.syncPromise=null,this.subscription=null,this.retryTimeout=null,this.retryAttempts=0,this.disposed=!1}initialize(){return this.ready=this.restoreSubscription(),this.ready}async restoreSubscription(){const e=await this.getRegistration(),t=await e.pushManager.getSubscription();!this.disposed&&!this.unsubscribePromise&&t&&this.owns(t)&&(this.subscription=t,await this.sync())}subscribe(){if(this.disposed)return Promise.resolve();if(this.unsubscribePromise)return Promise.reject(new Error("Push unsubscribe is in progress"));if(this.subscribePromise)return this.subscribePromise;const e="default"===Notification.permission?Notification.requestPermission():Promise.resolve(Notification.permission);return this.subscribePromise=this.createSubscription(e).finally(()=>{this.subscribePromise=null}),this.subscribePromise}async createSubscription(e){if("granted"!==await e)throw new Error("Push permission was not granted");const t=await this.getRegistration();if(this.disposed)return;let s=await t.pushManager.getSubscription();if(!this.disposed){if(s&&!this.owns(s))throw new Error("The existing Push subscription belongs to a different application");if(s||=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:this.applicationServerKey}),!this.disposed)return this.subscription=s,this.sync()}}unsubscribe(){return this.disposed?Promise.resolve():(this.unsubscribePromise||(this.clearRetryTimeout(),this.unsubscribePromise=this.removeSubscription().finally(()=>{this.unsubscribePromise=null})),this.unsubscribePromise)}async removeSubscription(){await(this.ready?.catch(()=>{})),await(this.subscribePromise?.catch(()=>{})),await(this.syncPromise?.catch(()=>{}));const e=await this.getRegistration(),t=await e.pushManager.getSubscription()||this.subscription;if(this.disposed)return;if(!t)return null;if(!this.owns(t))throw new Error("The existing Push subscription belongs to a different application");this.subscription=t;const s=await I.pushIdentities.destroy({subscription:t.toJSON()});return s.failed?s:this.disposed?void 0:(await t.unsubscribe(),this.subscription=null,this.clearRetryTimeout(),s)}sync(){return this.disposed?Promise.resolve():(this.syncPromise||(this.clearRetryTimeout(),this.syncPromise=this.registerIdentity().finally(()=>{this.syncPromise=null})),this.syncPromise)}async registerIdentity(){try{const e=await I.pushIdentities.create({subscription:this.subscription.toJSON(),...this.channelId?{channel_id:this.channelId}:{}});return e.succeeded?this.retryAttempts=0:this.scheduleRetry(),e}catch(e){throw this.scheduleRetry(),e}}scheduleRetry(){this.disposed||this.unsubscribePromise||this.retryTimeout||this.retryAttempts>=3||(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.sync().catch(()=>{})},1e3*2**this.retryAttempts),this.retryAttempts+=1)}clearRetryTimeout(){clearTimeout(this.retryTimeout),this.retryTimeout=null}dispose(){this.disposed=!0,this.clearRetryTimeout()}get subscribed(){return!!this.subscription}get applicationServerKey(){const e=this.publicKey.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e.padEnd(4*Math.ceil(e.length/4),"=")),e=>e.charCodeAt(0))}owns(e){const t=e.options?.applicationServerKey;if(!t)return!1;const s=new Uint8Array(t),i=this.applicationServerKey;return s.length===i.length&&s.every((e,t)=>e===i[t])}getRegistration(){return this.registrationPromise||(this.registrationPromise=this.loadRegistration().catch(e=>{throw this.registrationPromise=null,e})),this.registrationPromise}async loadRegistration(){if(this.serviceWorkerUrl){const e=await navigator.serviceWorker.register(this.serviceWorkerUrl);!e.active||e.installing||e.waiting||await e.update();const t=e.installing||e.waiting||e.active;return"activated"===t?.state?e:new Promise((s,i)=>{const n=setTimeout(()=>r(new Error("Push service worker did not become active")),1e4),r=r=>{clearTimeout(n),t?.removeEventListener("statechange",o),r?i(r):s(e)},o=()=>{"activated"===t?.state&&r(),"redundant"===t?.state&&r(new Error("Push service worker installation failed"))};t?.addEventListener("statechange",o),o()})}return new Promise((e,t)=>{const s=setTimeout(()=>t(new Error("Push service worker is not available")),1e4);navigator.serviceWorker.ready.then(t=>{clearTimeout(s),e(t)},e=>{clearTimeout(s),t(e)})})}static get supported(){return"undefined"!=typeof window&&!0===window.isSecureContext&&"undefined"!=typeof navigator&&"serviceWorker"in navigator&&"undefined"!=typeof PushManager&&"undefined"!=typeof Notification}}class ht{constructor(e,t,s){this.business=t,this.push=s,this.disposed=!1,this.showRequest=0,this.controller=null,this.element=(new DOMParser).parseFromString(e.html,"text/html").querySelector('[data-controller~="hellotext--alert"]'),this.connected=new Promise(e=>{this.resolveConnected=e}),this.onConnect=this.onConnect.bind(this),this.ready=this.render()}onConnect(e){this.controller=e.detail.controller,this.controller.alert=this,this.resolveConnected(!0)}async render(){return!!this.element&&(this.element.addEventListener("hellotext--alert:connected",this.onConnect),!(!await this.business.stylesheetLoaded||this.disposed)&&(document.body.appendChild(this.element),this.connected))}async show(e,t={}){const s=++this.showRequest;return!(!await this.ready||this.disposed||s!==this.showRequest)&&this.controller.show(e,t)}hide(){this.showRequest+=1,this.controller?.close()}dispose(){this.disposed=!0,this.hide(),this.resolveConnected(!1),this.element?.removeEventListener("hellotext--alert:connected",this.onConnect),this.element?.remove()}}class ut{static async load(e){const t=new ut({id:e,html:await I.webchats.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){return this.applyBehaviourOverride(),await this.stylesheetLoaded?(this.containerToAppendTo.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext webchat was not mounted because its stylesheet failed to load."),!1)}applyBehaviourOverride(){f.webchat.hasBehaviourOverride&&f.webchat.behaviour&&this.data.html.setAttribute("data-hellotext--webchat-behaviour-value",JSON.stringify(this.serializedBehaviour))}get serializedBehaviour(){const e=f.webchat.behaviour;return{trigger:this.serializeTrigger(e.trigger),delay_seconds:e.delaySeconds,first_visit_only:e.firstVisitOnly,once_per_session:e.oncePerSession}}serializeTrigger(e){return"onLoad"===e?"on_load":"onClick"===e?"on_click":e}get containerToAppendTo(){return document.querySelector(f.webchat.container)}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=this.data.html,t=document.querySelector(".hellotext--whatsapp-widget");e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class dt{static async load(e){const t=new dt({id:e,html:await I.whatsappWidgets.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){if(!this.data.html)return!1;const e=this.containerToAppendTo;return e?await this.stylesheetLoaded?(e.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext WhatsApp widget was not mounted because its stylesheet failed to load."),!1):(console.warn(`Hellotext WhatsApp widget was not mounted because the container ${f.whatsapp.container} was not found.`),!1)}get containerToAppendTo(){try{return document.querySelector(f.whatsapp.container)}catch(e){return null}}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=document.querySelector(".hellotext--webchat:not(.hellotext--whatsapp-widget)"),t=this.data.html;e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class pt{static async load(e,t={}){const s=new pt({id:e,html:await I.popups.get(e)},t);return s.rendered=s.render(),s}constructor(e,{container:t=f.popup.container,shouldMount:s=()=>!0}={}){this.data=e,this.container=t,this.mounted=!1,this.rendered=Promise.resolve(!1),this.shouldMount=s}async render(){if(!this.data.html||!this.shouldMount())return!1;const e=this.containerToAppendTo;return e?!!this.shouldMount()&&(e.appendChild(this.data.html),this.mounted=!0,this.shouldMount()||this.unmount(),this.mounted):(console.warn(`Hellotext popup was not mounted because the container ${this.container} was not found.`),!1)}unmount(){this.data.html?.remove(),this.mounted=!1}get containerToAppendTo(){try{return document.querySelector(this.container)}catch(e){return null}}}class mt{static get id(){return _.get("hello_user_id")}static get source(){return _.get("hello_user_source")}static get fingerprint(){return _.get("hello_user_identification_hash")}static remember(e,t,s){t&&_.set("hello_user_source",t),s&&_.set("hello_user_identification_hash",s),_.set("hello_user_id",e)}static forget(){_.delete("hello_user_id"),_.delete("hello_user_source"),_.delete("hello_user_identification_hash")}static get identificationData(){return this.id?{id:this.id,source:this.source}:{}}}function gt(e){if(null!=e){if("string"==typeof e){const t=e.trim();return""===t?void 0:t}if(Array.isArray(e))return e.map(e=>gt(e)).filter(e=>void 0!==e);if(e instanceof Date)return e.toISOString();if("object"==typeof e){const t=Object.keys(e).sort((e,t)=>e.localeCompare(t)).reduce((t,s)=>{const i=gt(e[s]);return void 0!==i&&(t[s]=i),t},{});return Object.keys(t).length>0?t:void 0}return"number"==typeof e||"boolean"==typeof e?e:void 0}}function ft(e,t,s={}){const i=gt({session:e,user_id:t,...s})||{};return JSON.stringify(i)}class bt{static matches(e,t){return!!e&&e===t}static async generate(e,t,s={}){return await async function(e){if(!globalThis.crypto?.subtle||"undefined"==typeof TextEncoder)return function(e){let t=5381;for(let s=0;s>>0).toString(16)}`}(e);const t=await globalThis.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e));return`v1:${Array.from(new Uint8Array(t)).map(e=>e.toString(16).padStart(2,"0")).join("")}`}(ft(e,t,s))}}class yt{static eventEmitter=new r;static forms;static business;static popup;static webchat;static whatsapp;static push;static alert;static initializationVersion=0;static async initialize(e,t={}){const s=++this.initializationVersion;this.popup?.unmount?.(),this.popup=void 0,this.alert?.dispose(),this.alert=null,this.push?.dispose(),this.push=null;const i=new P(e);this.business=i,this.page=new D,f.assign({push:{},...t}),F.initialize(this.page),this.forms=new ct,this.query=new y;const n=await i.hydrate();if(this.business!==i)return;!1!==t.push&&n?.push?.public_key&<.supported&&(this.push=new lt(n.push),this.push.initialize().catch(e=>{console.warn("Hellotext Push initialization failed:",e)}),n.alert?.html&&(this.alert=new ht(n.alert,i,this.push)));const r=!1!==t.popup&&this.deepMergePlainObjects(n&&n.popup||{},t.popup||{}),o=!1!==t.webchat&&this.mergeWebchatConfig(n&&n.webchat||{},t.webchat||{}),a=!1!==t.whatsappWidget&&this.mergeWhatsAppConfig(n&&n.whatsapp||{},t.whatsappWidget||{}),c=t.webchat&&!1!==t.webchat&&Object.prototype.hasOwnProperty.call(t.webchat,"behaviour");f.webchat.behaviourOverride=c;const l=[];if(o&&o.id&&(f.webchat.assign(o),l.push(ut.load(o.id).then(e=>{this.business===i&&(this.webchat=e)}))),a&&a.id&&(f.whatsapp.assign(a),l.push(dt.load(a.id).then(e=>{this.business===i&&(this.whatsapp=e)}))),r&&r.id){const e={container:"body",device:"auto",...r};f.popup.assign(e),l.push(pt.load(e.id,{container:e.container,shouldMount:()=>this.business===i&&this.initializationVersion===s}).then(e=>{this.business===i&&this.initializationVersion===s&&(this.popup=e)}))}await Promise.all(l),this.business===i&&this.initializationVersion===s&&"undefined"!=typeof MutationObserver&&this.forms.collectExistingFormsOnPage()}static mergeWebchatConfig(e,t){return this.deepMergePlainObjects(e,t)}static mergeWhatsAppConfig(e,t){return this.deepMergePlainObjects(e,t)}static deepMergePlainObjects(e,t){const s={...e};return Object.entries(t).forEach(([e,t])=>{this.isPlainObject(t)&&this.isPlainObject(s[e])?s[e]=this.deepMergePlainObjects(s[e],t):s[e]=t}),s}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}static async track(e,t={}){if(this.notInitialized)throw new at;const s={...t&&t.headers||{},...this.headers},i={...mt.identificationData,...t.user_parameters||{}},n=t&&t.url?new D(t.url):this.page,r={session:this.session,user_parameters:i,action:e,...t,...n.trackingData};return delete r.headers,await I.events.create({headers:s,body:r,keepalive:k(r)})}static async identify(e,t={}){const s=await bt.generate(this.session,e,t);if(bt.matches(mt.fingerprint,s))return new v(!0,{json:async()=>({already_identified:!0})});const i=await I.identifications.create({user_id:e,...t});return i.succeeded&&mt.remember(e,t.source,s),i}static forget(){mt.forget()}static on(e,t){this.eventEmitter.addSubscriber(e,t)}static removeEventListener(e,t){this.eventEmitter.removeSubscriber(e,t)}static get session(){return F.session}static get isInitialized(){return void 0!==F.session}static get notInitialized(){return!this.business||void 0===this.business.id}static get headers(){if(this.notInitialized)throw new at;return{Authorization:`Bearer ${this.business.id}`,Accept:"application/json","Content-Type":"application/json"}}}const vt=yt,wt=new Map,Tt=class extends i.xI{static values={sections:Array};static targets=["title","description","primaryAction","secondaryAction"];initialize(){this.showRequest=0,this.submitting=!1,this.onStorage=this.onStorage.bind(this)}connect(){this.dispatch("connected",{detail:{controller:this}}),window.addEventListener("storage",this.onStorage)}disconnect(){this.close(),window.removeEventListener("storage",this.onStorage)}onStorage(e){e.key===this.storageKey&&this.dismissal.dismissedUntil>Date.now()&&this.close()}async show(e,{force:t=!1,title:s,description:i,primaryAction:n,secondaryAction:r}={}){const o=++this.showRequest,a=this.sectionsValue.find(t=>t.kind===e);return a?(await(this.alert.push.ready?.catch(()=>{})),!(o!==this.showRequest||this.alert.disposed||!this.element.isConnected||(this.unavailable||!t&&this.dismissal.dismissedUntil>Date.now()?(this.close(),1):(this.titleTarget.textContent=s??a.title,this.descriptionTarget.textContent=i??a.description,this.primaryActionTarget.textContent=n??a.primary_action,this.secondaryActionTarget.textContent=r??a.secondary_action,this.kind=e,this.page=vt.page.trackingData.page,this.element.hidden=!1,this.record("shown"),vt.eventEmitter.dispatch("alert:shown",{kind:e}),0)))):(this.close(),!1)}hide(){if(this.element.hidden||this.submitting)return;const e=this.dismissal.dismissals+1,t={dismissals:e,dismissedUntil:Date.now()+864e5*(1===e?7:30)};wt.set(this.storageKey,t);try{localStorage.setItem(this.storageKey,JSON.stringify(t))}catch(e){}this.close(),this.record("dismissed"),vt.eventEmitter.dispatch("alert:dismissed",{kind:this.kind})}close(){this.showRequest+=1,this.element.hidden=!0}async subscribe(){if(!this.submitting&&!this.element.hidden){if(this.unavailable)return this.close();this.submitting=!0,this.primaryActionTarget.disabled=!0,this.secondaryActionTarget.disabled=!0,this.element.setAttribute("aria-busy","true");try{this.record("accepted"),vt.eventEmitter.dispatch("alert:accepted",{kind:this.kind});const e=await this.alert.push.subscribe();return this.unavailable&&this.close(),e?.failed&&this.dispatch("error",{detail:{response:e}}),e}catch(e){this.unavailable&&this.close(),this.dispatch("error",{detail:{error:e}})}finally{this.submitting=!1,this.primaryActionTarget.disabled=!1,this.secondaryActionTarget.disabled=!1,this.element.removeAttribute("aria-busy")}}}async record(e){try{const t=await I.pushAlerts.create({section:this.kind,kind:e,page:this.page});t.failed&&console.warn("Hellotext Smart Alert submission failed:",t)}catch(e){console.warn("Hellotext Smart Alert submission failed:",e)}}get unavailable(){return this.alert.push.disposed||this.alert.push.subscribed||"undefined"==typeof Notification||"denied"===Notification.permission}get storageKey(){return`hellotext:alert:${this.alert.business.id}`}get dismissal(){try{const e=JSON.parse(localStorage.getItem(this.storageKey));Number.isSafeInteger(e?.dismissals)&&e.dismissals>0&&Number.isFinite(e.dismissedUntil)&&e.dismissedUntil>=0&&wt.set(this.storageKey,e)}catch(e){}return wt.get(this.storageKey)||{dismissals:0,dismissedUntil:0}}},St=class extends i.xI{static values={data:Object,step:{type:Number,default:1}};static targets=["inputContainer","input","button","otpContainer"];initialize(){this.form=new ot(this.dataValue,this.element)}connect(){super.connect(),this.element.addEventListener("submit",this.submit.bind(this)),"INPUT"!==document.activeElement.tagName&&this.inputTargets[0].focus()}async submit(e){if(e.preventDefault(),this.invalid)return this.showErrorMessages();this.clearErrorMessages(),this.formData=Object.fromEntries(new FormData(this.element)),this.buttonTarget.disabled=!0;const t=await T.submit(this.form.id,this.formData);this.buttonTarget.disabled=!1;const s=await t.json();if(t.failed)return s.errors.forEach(e=>{const{type:t,parameter:s}=e,i=this.inputTargets.find(e=>e.name===s);i.setCustomValidity(vt.business.locale.errors[t]),i.reportValidity(),i.addEventListener("input",()=>{i.setCustomValidity(""),i.reportValidity()})}),this.showErrorMessages();this.buttonTarget.style.display="none",this.element.querySelectorAll("input").forEach(e=>e.disabled=!0),this.completed()}completed(){if(this.form.markAsCompleted(this.formData),!f.forms.shouldShowSuccessMessage)return this.element.remove();"string"==typeof f.forms.successMessage?this.element.innerHTML=f.forms.successMessage:this.element.innerHTML=vt.business.locale.forms[this.form.localeAuthKey]}showErrorMessages(){this.inputTargets.forEach(e=>{const t=e.closest("article").querySelector("[data-error-container]");e.validity.valid?t.innerText="":t.innerText=e.validationMessage})}clearErrorMessages(){this.inputTargets.forEach(e=>{e.setCustomValidity(""),e.closest("article").querySelector("[data-error-container]").innerText=""})}inputTargetConnected(e){e.getAttribute("data-default-value")&&(e.value=e.getAttribute("data-default-value"))}get requiredInputs(){return this.inputTargets.filter(e=>e.required)}get invalid(){return!this.element.checkValidity()}},Ct=class extends i.xI{static values={fadeDistance:{type:Number,default:64},id:String,kind:String,pageStartOffset:{type:Number,default:0},utm:Object};static targets=["carouselContainer","leftFade","rightFade","carouselCard"];connect(){this.updateFades(),this.observeContainerSize()}disconnect(){this.resizeObserver?.disconnect()}setId({detail:e}){this.idValue=e,this.element.id=e}onScroll(){this.updateFades()}quickReply({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),s=e.closest('[data-controller~="hellotext--message"]'),i=e.dataset.text||e.textContent.trim();this.dispatch("quickReply",{detail:{id:this.idValue,product:t?.dataset.id,buttonId:e.dataset.id,body:i,cardElement:t||s||e}})}addToCart({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),{id:s,reference:i,source:n}=t.dataset,r={product:s,quantity:1};this.hasUtmValue&&vt.page.utm.save(this.utmValue),vt.eventEmitter.dispatch("cart.added",{object_parameters:{items:[{...r,...i&&{reference:i},...n&&{source:n}}]},source:{kind:this.kindValue,message_id:this.idValue,button_id:e.dataset.id}})}moveToLeft(){if(!this.hasCarouselContainerTarget)return;const e=this.getPreviousPageScrollLeft(),t=this.carouselContainerTarget.scrollLeft-e;t<1||this.carouselContainerTarget.scrollBy({left:-t,behavior:"smooth"})}moveToRight(){if(!this.hasCarouselContainerTarget)return;const e=this.getNextPageScrollLeft()-this.carouselContainerTarget.scrollLeft;e<1||this.carouselContainerTarget.scrollBy({left:e,behavior:"smooth"})}getScrollAmount(){return this.getCardScrollAmount()}getCardScrollAmount(){const e=this.carouselContainerTarget.querySelector(".message__carousel_card");return e?e.offsetWidth+this.getGap():280}getPageScrollAmount(){const e=this.carouselContainerTarget.clientWidth-this.getGap();return e>0?e:this.getCardScrollAmount()}getNextPageScrollLeft(){const e=this.getCurrentScrollLeft(),t=e+this.carouselContainerTarget.clientWidth,s=this.getCardMetrics().find(e=>e.end>t+1),i=s?this.getPageAlignedScrollLeft(s.start):e+this.getPageScrollAmount(),n=e+this.getPageScrollAmount();return this.clampScrollLeft(i>e+1?i:n)}getPreviousPageScrollLeft(){const e=this.getCurrentScrollLeft();if(e<=1)return 0;const t=Math.max(e-this.getPageScrollAmount(),0);if(t<=1)return 0;const s=this.getCardMetrics(),i=s.find(s=>s.start>=t-1&&s.startt.start{const t=this.getCardScrollLeft(e);return{start:t,end:t+e.offsetWidth}})}getCardScrollLeft(e){const t=e.getBoundingClientRect(),s=this.carouselContainerTarget.getBoundingClientRect();return t.left||t.width||s.left||s.width?t.left-s.left+this.carouselContainerTarget.scrollLeft:e.offsetLeft||0}getCurrentScrollLeft(){return this.clampScrollLeft(this.carouselContainerTarget.scrollLeft)}clampScrollLeft(e){const t=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);return Math.min(Math.max(e,0),t)}getGap(){const e=window.getComputedStyle(this.carouselContainerTarget),t=Number.parseFloat(e.columnGap||e.gap);return Number.isFinite(t)?t:16}getFadeDistance(){return Number.isFinite(this.fadeDistanceValue)?this.fadeDistanceValue:64}getPageStartOffset(){return Number.isFinite(this.pageStartOffsetValue)?this.pageStartOffsetValue:0}observeContainerSize(){this.hasCarouselContainerTarget&&window.ResizeObserver&&(this.resizeObserver=new ResizeObserver(()=>this.updateFades()),this.resizeObserver.observe(this.carouselContainerTarget))}updateFades(){if(!this.hasCarouselContainerTarget)return;const e=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);if(e<=1)return this.hideFade(this.leftFadeTarget),void this.hideFade(this.rightFadeTarget);const t=Math.min(Math.max(this.carouselContainerTarget.scrollLeft,0),e),s=this.getFadeDistance();this.setFadeOpacity(this.leftFadeTarget,t/s),this.setFadeOpacity(this.rightFadeTarget,(e-t)/s)}setFadeOpacity(e,t){const s=Math.min(Math.max(t,0),1);s<=.05?this.hideFade(e):(e.classList.remove("hidden"),e.removeAttribute("disabled"),e.removeAttribute("tabindex"),e.setAttribute("aria-hidden","false"),e.style.opacity=s.toFixed(3),e.style.pointerEvents="auto")}hideFade(e){e.style.opacity="0",e.style.pointerEvents="none",e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1"),"disabled"in e&&(e.disabled=!0),e.classList.add("hidden")}},Ot=class extends i.xI{static targets=["bubble","dialog","step","completed","input","submitButton","globalError","resendButton","changeDestinationButton","deliveryCopy","noDeliveryCopy"];static values={capture:Object,device:String,hasBubble:Boolean,id:String};initialize(){this.stepIndex=0,this.resendLabel=this.hasResendButtonTarget?this.resendButtonTarget.textContent.trim():""}connect(){vt.eventEmitter.dispatch("popup:mounted"),this.evaluateDisplay()}disconnect(){this.stopResendCooldown()}open(e){e&&e.preventDefault(),this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}close(e){e&&e.preventDefault(),this.dismissed=!0,this.dialogTarget.hidden=!0,this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.element.hidden=!0,vt.eventEmitter.dispatch("popup:closed")}async next(e){e&&e.preventDefault(),this.clearCustomValidity(),this.currentStepValid()?(this.clearErrorMessages(this.currentStepInputs),this.stepIndex{e.disabled=!0});try{const e=this.submissionPayload(),t=await C.submit(this.idValue,e,this.idempotencyKeyFor(e));if(t.failed)return void await this.handleSubmissionError(t);const s=await t.json();this.submissionId=s.id,this.submissionVerificationState=s.verification_state,this.submissionActionToken=s.action_token,this.submissionDeliveryStatus=s.delivery_status,this.submissionDeliveryChannel=s.delivery_channel,this.submissionDestination=s.destination,this.resetSubmissionRequest()}catch(e){return void this.showGlobalError()}finally{this.submitButtonTargets.forEach(e=>{e.disabled=!1})}this.showCompleted()}else this.showErrorMessages(this.currentStepInputs)}evaluateDisplay(){!this.dismissed&&this.matchesDevice()?this.showInitialState():this.element.hidden=!0}showInitialState(){if(this.element.hidden=!1,this.hasBubbleValue&&this.hasBubbleTarget)return this.bubbleTarget.hidden=!1,void(this.dialogTarget.hidden=!0);this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}showStep(e){this.stepIndex=e,this.stepTargets.forEach((t,s)=>{t.hidden=s!==e}),this.completedTarget.hidden=!0}showCompleted(){this.stepTargets.forEach(e=>{e.hidden=!0}),this.interpolateCompletionCopy(),this.configureCompletionActions(),this.completedTarget.hidden=!1}interpolateCompletionCopy(){const e=this.completedIdentity;if(!e)return;const t={destination:e.value,channel:this.submissionDeliveryChannel||e.kind};this.completionTextTemplates.forEach(({node:e,template:s})=>{e.nodeValue=s.replace(/\{(destination|channel)\}/g,(e,s)=>t[s]||e)})}identityValue(e){const t=this.inputValue(e).trim();if("phone"!==e.dataset.popupFieldKind||t.startsWith("+"))return t;const s=this.phoneCountryPrefix(e);if(s)return`${s}${this.phoneDigits(t)}`;const i=e.dataset.popupPhonePrefix;return i?`${i}${t.replace(/^0+/,"")}`:t}asciiDigits(e){const t=e=>/\p{Nd}/u.test(e);return e.replace(/\p{Nd}/gu,e=>{let s=e.codePointAt(0);const i=s;for(;t(String.fromCodePoint(s-1));)s-=1;return(i-s)%10})}phoneDigits(e){return this.asciiDigits(e).replace(/\D/g,"")}phoneCountryPrefix(e){const t=e.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country]");return t?.selectedOptions?.[0]?.dataset.prefix}selectPhoneCountry(e){const t=e.target,s=t.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country-label]");s&&(s.textContent=t.selectedOptions[0]?.dataset.label||"")}submissionValue(e){const t=this.inputValue(e),s="phone"===e.dataset.popupFieldKind&&this.phoneCountryPrefix(e),i="string"==typeof t?t.trim():"";return s&&i?i.startsWith("+")?this.asciiDigits(t):`${s}${this.phoneDigits(i)}`:t}configureCompletionActions(){const e="not_required"!==this.submissionDeliveryStatus;if(this.revealCompletionCopy(e),!e)return void this.completedTarget.querySelector("[data-delivery-actions]")?.setAttribute("hidden","");const t=this.completedIdentity;t&&(this.hasChangeDestinationButtonTarget&&(this.changeDestinationButtonTarget.textContent=this.changeDestinationButtonTarget.dataset[`${t.kind}Label`],this.changeDestinationButtonTarget.hidden=!1),this.submissionId&&this.submissionActionToken&&"queued"===this.submissionDeliveryStatus&&"unverified"===this.submissionVerificationState&&this.hasResendButtonTarget&&(this.resendButtonTarget.hidden=!1,this.startResendCooldown(60)))}async resend(e){if(e&&e.preventDefault(),this.submissionId&&this.submissionActionToken&&!this.resendPending&&!this.resendCooldownActive&&this.completedIdentity){this.resendPending=!0,this.resendButtonTarget.disabled=!0;try{const e=await C.resend(this.idValue,this.submissionId,this.submissionActionToken),t=Number(e.data.headers?.get("Retry-After"))||60;e.succeeded||429===e.data.status?this.startResendCooldown(t):this.resendButtonTarget.disabled=!1}catch(e){this.resendButtonTarget.disabled=!1}finally{this.resendPending=!1}}}async changeDestination(e){if(e&&e.preventDefault(),!this.submissionId||!this.submissionActionToken||this.changeDestinationPending)return;const t=this.completedIdentity?.input;if(!t)return;const s=this.stepTargets.findIndex(e=>e.dataset.stepId===t.dataset.popupStepId);if(!(s<0)){this.changeDestinationPending=!0,this.changeDestinationButtonTarget.disabled=!0;try{if((await C.cancel(this.idValue,this.submissionId,this.submissionActionToken)).failed)return;this.stopResendCooldown(),this.submissionId=null,this.submissionActionToken=null,this.submissionVerificationState=null,this.submissionDeliveryStatus=null,this.submissionDeliveryChannel=null,this.submissionDestination=null,this.resetSubmissionRequest(),this.showStep(s),t.focus()}catch(e){}finally{this.changeDestinationPending=!1,this.changeDestinationButtonTarget.disabled=!1}}}startResendCooldown(e){this.stopResendCooldown(),this.resendCooldownEndsAt=Date.now()+1e3*Math.max(e,1),this.updateResendCountdown(),this.resendTimer=window.setInterval(()=>this.updateResendCountdown(),1e3)}stopResendCooldown(){this.resendTimer&&window.clearInterval(this.resendTimer),this.resendTimer=null,this.resendCooldownEndsAt=null}updateResendCountdown(){const e=Math.max(0,Math.ceil((this.resendCooldownEndsAt-Date.now())/1e3));if(0===e)return this.stopResendCooldown(),this.resendButtonTarget.textContent=this.resendLabel,void(this.resendButtonTarget.disabled=!1);const t=`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`,s=this.resendButtonTarget.dataset.countdownLabel||`${this.resendLabel} %{time}`;this.resendButtonTarget.textContent=s.replace("%{time}",t),this.resendButtonTarget.disabled=!0}get resendCooldownActive(){return this.resendCooldownEndsAt>Date.now()}get completionIdentity(){return this.identityInputs.map(e=>({input:e,kind:e.dataset.popupFieldKind,value:this.identityValue(e)})).find(({value:e})=>e)}get completedIdentity(){if(this.submissionDestination&&this.submissionDeliveryChannel){const e="email"===this.submissionDeliveryChannel?"email":"phone";return{input:this.identityInputs.find(t=>t.dataset.popupFieldKind===e),kind:e,value:this.submissionDestination}}return this.completionIdentity}revealCompletionCopy(e){this.hasDeliveryCopyTarget&&this.deliveryCopyTargets.forEach(t=>{t.hidden=!e}),this.hasNoDeliveryCopyTarget&&this.noDeliveryCopyTargets.forEach(t=>{t.hidden=e})}currentStepValid(){return this.currentStepInputs.every(e=>e.checkValidity())}showErrorMessages(e){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent=e.validity.valid?"":e.validationMessage)})}clearErrorMessages(e=this.inputTargets){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent="")})}clearCustomValidity(){this.inputTargets.forEach(e=>e.setCustomValidity(""))}clearGlobalError(){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent="",this.globalErrorTarget.hidden=!0)}showGlobalError(e=null){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent=e||this.globalErrorTarget.dataset.submitError||"Unable to submit. Please try again.",this.globalErrorTarget.hidden=!1)}async handleSubmissionError(e){let t;try{t=await e.json()}catch(e){return void this.showGlobalError()}const s=t.errors||[],i=[];s.forEach(e=>{const t=this.inputForError(e);t?(t.setCustomValidity(e.description||t.validationMessage),t.reportValidity()):e.description&&i.push(e.description)}),this.showErrorMessages(this.inputTargets),i.length?this.showGlobalError(i.join(" ")):s.length||this.showGlobalError()}inputForError(e){const t=e.parameter;return t?this.inputTargets.find(e=>e.dataset.popupFieldKind===t||e.dataset.popupFieldKey===t):null}submissionPayload(){const e={metadata:{capture:this.captureValue||{},fields:{},steps:[]}};return this.stepTargets.forEach(t=>{const s={};this.inputsForStep(t).forEach(t=>{const i=this.submissionValue(t),n=t.dataset.popupFieldKey||t.name;s[n]=i,e.metadata.fields[n]=i,"email"===t.dataset.popupFieldKind&&(e.email=i),"phone"===t.dataset.popupFieldKind&&(e.phone=i)}),e.metadata.steps.push({id:t.dataset.stepId,name:t.dataset.stepName,fields:s})}),e}idempotencyKeyFor(e){const t=JSON.stringify(e);return this.submissionPayloadSnapshot!==t&&(this.submissionPayloadSnapshot=t,this.submissionIdempotencyKey=C.idempotencyKey()),this.submissionIdempotencyKey}resetSubmissionRequest(){this.submissionPayloadSnapshot=null,this.submissionIdempotencyKey=null}inputValue(e){return"checkbox"===e.type?e.checked:e.value}inputsForStep(e){return this.inputTargets.filter(t=>t.dataset.popupStepId===e.dataset.stepId)}get identityInputs(){const e=this.inputTargets.filter(e=>["email","phone"].includes(e.dataset.popupFieldKind));return e.filter(e=>e.required).concat(e.filter(e=>!e.required))}get completionTextTemplates(){if(this._completionTextTemplates)return this._completionTextTemplates;const e=document.createTreeWalker(this.completedTarget,NodeFilter.SHOW_TEXT);for(this._completionTextTemplates=[];e.nextNode();)this._completionTextTemplates.push({node:e.currentNode,template:e.currentNode.nodeValue});return this._completionTextTemplates}matchesDevice(){return"all"===this.deviceValue||("mobile"===this.deviceValue?window.innerWidth<768:"desktop"!==this.deviceValue||window.innerWidth>=768)}get currentStep(){return this.stepTargets[this.stepIndex]}get currentStepInputs(){return this.inputsForStep(this.currentStep)}},Et=["start","end"],At=["top","right","bottom","left"].reduce((e,t)=>e.concat(t,t+"-"+Et[0],t+"-"+Et[1]),[]),xt=Math.min,Mt=Math.max,kt=Math.round,It=Math.floor,Lt=e=>({x:e,y:e}),Pt={left:"right",right:"left",bottom:"top",top:"bottom"},_t={start:"end",end:"start"};function Nt(e,t,s){return Mt(e,xt(t,s))}function Dt(e,t){return"function"==typeof e?e(t):e}function Ft(e){return e.split("-")[0]}function Rt(e){return e.split("-")[1]}function Bt(e){return"x"===e?"y":"x"}function $t(e){return"y"===e?"height":"width"}const jt=new Set(["top","bottom"]);function Vt(e){return jt.has(Ft(e))?"y":"x"}function qt(e){return Bt(Vt(e))}function Ut(e,t,s){void 0===s&&(s=!1);const i=Rt(e),n=qt(e),r=$t(n);let o="x"===n?i===(s?"end":"start")?"right":"left":"start"===i?"bottom":"top";return t.reference[r]>t.floating[r]&&(o=Jt(o)),[o,Jt(o)]}function zt(e){return e.replace(/start|end/g,e=>_t[e])}const Wt=["left","right"],Kt=["right","left"],Ht=["top","bottom"],Gt=["bottom","top"];function Jt(e){return e.replace(/left|right|bottom|top/g,e=>Pt[e])}function Yt(e){const{x:t,y:s,width:i,height:n}=e;return{width:i,height:n,top:s,left:t,right:t+i,bottom:s+n,x:t,y:s}}function Zt(e,t,s){let{reference:i,floating:n}=e;const r=Vt(t),o=qt(t),a=$t(o),c=Ft(t),l="y"===r,h=i.x+i.width/2-n.width/2,u=i.y+i.height/2-n.height/2,d=i[a]/2-n[a]/2;let p;switch(c){case"top":p={x:h,y:i.y-n.height};break;case"bottom":p={x:h,y:i.y+i.height};break;case"right":p={x:i.x+i.width,y:u};break;case"left":p={x:i.x-n.width,y:u};break;default:p={x:i.x,y:i.y}}switch(Rt(t)){case"start":p[o]-=d*(s&&l?-1:1);break;case"end":p[o]+=d*(s&&l?-1:1)}return p}async function Xt(e,t){var s;void 0===t&&(t={});const{x:i,y:n,platform:r,rects:o,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:h="viewport",elementContext:u="floating",altBoundary:d=!1,padding:p=0}=Dt(t,e),m=function(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}(p),g=a[d?"floating"===u?"reference":"floating":u],f=Yt(await r.getClippingRect({element:null==(s=await(null==r.isElement?void 0:r.isElement(g)))||s?g:g.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(a.floating)),boundary:l,rootBoundary:h,strategy:c})),b="floating"===u?{x:i,y:n,width:o.floating.width,height:o.floating.height}:o.reference,y=await(null==r.getOffsetParent?void 0:r.getOffsetParent(a.floating)),v=await(null==r.isElement?void 0:r.isElement(y))&&await(null==r.getScale?void 0:r.getScale(y))||{x:1,y:1},w=Yt(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:y,strategy:c}):b);return{top:(f.top-w.top+m.top)/v.y,bottom:(w.bottom-f.bottom+m.bottom)/v.y,left:(f.left-w.left+m.left)/v.x,right:(w.right-f.right+m.right)/v.x}}const Qt=new Set(["left","top"]);function es(){return"undefined"!=typeof window}function ts(e){return ns(e)?(e.nodeName||"").toLowerCase():"#document"}function ss(e){var t;return(null==e||null==(t=e.ownerDocument)?void 0:t.defaultView)||window}function is(e){var t;return null==(t=(ns(e)?e.ownerDocument:e.document)||window.document)?void 0:t.documentElement}function ns(e){return!!es()&&(e instanceof Node||e instanceof ss(e).Node)}function rs(e){return!!es()&&(e instanceof Element||e instanceof ss(e).Element)}function os(e){return!!es()&&(e instanceof HTMLElement||e instanceof ss(e).HTMLElement)}function as(e){return!(!es()||"undefined"==typeof ShadowRoot)&&(e instanceof ShadowRoot||e instanceof ss(e).ShadowRoot)}const cs=new Set(["inline","contents"]);function ls(e){const{overflow:t,overflowX:s,overflowY:i,display:n}=Ts(e);return/auto|scroll|overlay|hidden|clip/.test(t+i+s)&&!cs.has(n)}const hs=new Set(["table","td","th"]);function us(e){return hs.has(ts(e))}const ds=[":popover-open",":modal"];function ps(e){return ds.some(t=>{try{return e.matches(t)}catch(e){return!1}})}const ms=["transform","translate","scale","rotate","perspective"],gs=["transform","translate","scale","rotate","perspective","filter"],fs=["paint","layout","strict","content"];function bs(e){const t=ys(),s=rs(e)?Ts(e):e;return ms.some(e=>!!s[e]&&"none"!==s[e])||!!s.containerType&&"normal"!==s.containerType||!t&&!!s.backdropFilter&&"none"!==s.backdropFilter||!t&&!!s.filter&&"none"!==s.filter||gs.some(e=>(s.willChange||"").includes(e))||fs.some(e=>(s.contain||"").includes(e))}function ys(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}const vs=new Set(["html","body","#document"]);function ws(e){return vs.has(ts(e))}function Ts(e){return ss(e).getComputedStyle(e)}function Ss(e){return rs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Cs(e){if("html"===ts(e))return e;const t=e.assignedSlot||e.parentNode||as(e)&&e.host||is(e);return as(t)?t.host:t}function Os(e){const t=Cs(e);return ws(t)?e.ownerDocument?e.ownerDocument.body:e.body:os(t)&&ls(t)?t:Os(t)}function Es(e,t,s){var i;void 0===t&&(t=[]),void 0===s&&(s=!0);const n=Os(e),r=n===(null==(i=e.ownerDocument)?void 0:i.body),o=ss(n);if(r){const e=As(o);return t.concat(o,o.visualViewport||[],ls(n)?n:[],e&&s?Es(e):[])}return t.concat(n,Es(n,[],s))}function As(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function xs(e){const t=Ts(e);let s=parseFloat(t.width)||0,i=parseFloat(t.height)||0;const n=os(e),r=n?e.offsetWidth:s,o=n?e.offsetHeight:i,a=kt(s)!==r||kt(i)!==o;return a&&(s=r,i=o),{width:s,height:i,$:a}}function Ms(e){return rs(e)?e:e.contextElement}function ks(e){const t=Ms(e);if(!os(t))return Lt(1);const s=t.getBoundingClientRect(),{width:i,height:n,$:r}=xs(t);let o=(r?kt(s.width):s.width)/i,a=(r?kt(s.height):s.height)/n;return o&&Number.isFinite(o)||(o=1),a&&Number.isFinite(a)||(a=1),{x:o,y:a}}const Is=Lt(0);function Ls(e){const t=ss(e);return ys()&&t.visualViewport?{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}:Is}function Ps(e,t,s,i){void 0===t&&(t=!1),void 0===s&&(s=!1);const n=e.getBoundingClientRect(),r=Ms(e);let o=Lt(1);t&&(i?rs(i)&&(o=ks(i)):o=ks(e));const a=function(e,t,s){return void 0===t&&(t=!1),!(!s||t&&s!==ss(e))&&t}(r,s,i)?Ls(r):Lt(0);let c=(n.left+a.x)/o.x,l=(n.top+a.y)/o.y,h=n.width/o.x,u=n.height/o.y;if(r){const e=ss(r),t=i&&rs(i)?ss(i):i;let s=e,n=As(s);for(;n&&i&&t!==s;){const e=ks(n),t=n.getBoundingClientRect(),i=Ts(n),r=t.left+(n.clientLeft+parseFloat(i.paddingLeft))*e.x,o=t.top+(n.clientTop+parseFloat(i.paddingTop))*e.y;c*=e.x,l*=e.y,h*=e.x,u*=e.y,c+=r,l+=o,s=ss(n),n=As(s)}}return Yt({width:h,height:u,x:c,y:l})}function _s(e,t){const s=Ss(e).scrollLeft;return t?t.left+s:Ps(is(e)).left+s}function Ns(e,t,s){void 0===s&&(s=!1);const i=e.getBoundingClientRect();return{x:i.left+t.scrollLeft-(s?0:_s(e,i)),y:i.top+t.scrollTop}}const Ds=new Set(["absolute","fixed"]);function Fs(e,t,s){let i;if("viewport"===t)i=function(e,t){const s=ss(e),i=is(e),n=s.visualViewport;let r=i.clientWidth,o=i.clientHeight,a=0,c=0;if(n){r=n.width,o=n.height;const e=ys();(!e||e&&"fixed"===t)&&(a=n.offsetLeft,c=n.offsetTop)}return{width:r,height:o,x:a,y:c}}(e,s);else if("document"===t)i=function(e){const t=is(e),s=Ss(e),i=e.ownerDocument.body,n=Mt(t.scrollWidth,t.clientWidth,i.scrollWidth,i.clientWidth),r=Mt(t.scrollHeight,t.clientHeight,i.scrollHeight,i.clientHeight);let o=-s.scrollLeft+_s(e);const a=-s.scrollTop;return"rtl"===Ts(i).direction&&(o+=Mt(t.clientWidth,i.clientWidth)-n),{width:n,height:r,x:o,y:a}}(is(e));else if(rs(t))i=function(e,t){const s=Ps(e,!0,"fixed"===t),i=s.top+e.clientTop,n=s.left+e.clientLeft,r=os(e)?ks(e):Lt(1);return{width:e.clientWidth*r.x,height:e.clientHeight*r.y,x:n*r.x,y:i*r.y}}(t,s);else{const s=Ls(e);i={x:t.x-s.x,y:t.y-s.y,width:t.width,height:t.height}}return Yt(i)}function Rs(e,t){const s=Cs(e);return!(s===t||!rs(s)||ws(s))&&("fixed"===Ts(s).position||Rs(s,t))}function Bs(e,t,s){const i=os(t),n=is(t),r="fixed"===s,o=Ps(e,!0,r,t);let a={scrollLeft:0,scrollTop:0};const c=Lt(0);function l(){c.x=_s(n)}if(i||!i&&!r)if(("body"!==ts(t)||ls(n))&&(a=Ss(t)),i){const e=Ps(t,!0,r,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else n&&l();r&&!i&&n&&l();const h=!n||i||r?Lt(0):Ns(n,a);return{x:o.left+a.scrollLeft-c.x-h.x,y:o.top+a.scrollTop-c.y-h.y,width:o.width,height:o.height}}function $s(e){return"static"===Ts(e).position}function js(e,t){if(!os(e)||"fixed"===Ts(e).position)return null;if(t)return t(e);let s=e.offsetParent;return is(e)===s&&(s=s.ownerDocument.body),s}function Vs(e,t){const s=ss(e);if(ps(e))return s;if(!os(e)){let t=Cs(e);for(;t&&!ws(t);){if(rs(t)&&!$s(t))return t;t=Cs(t)}return s}let i=js(e,t);for(;i&&us(i)&&$s(i);)i=js(i,t);return i&&ws(i)&&$s(i)&&!bs(i)?s:i||function(e){let t=Cs(e);for(;os(t)&&!ws(t);){if(bs(t))return t;if(ps(t))return null;t=Cs(t)}return null}(e)||s}const qs={convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{elements:t,rect:s,offsetParent:i,strategy:n}=e;const r="fixed"===n,o=is(i),a=!!t&&ps(t.floating);if(i===o||a&&r)return s;let c={scrollLeft:0,scrollTop:0},l=Lt(1);const h=Lt(0),u=os(i);if((u||!u&&!r)&&(("body"!==ts(i)||ls(o))&&(c=Ss(i)),os(i))){const e=Ps(i);l=ks(i),h.x=e.x+i.clientLeft,h.y=e.y+i.clientTop}const d=!o||u||r?Lt(0):Ns(o,c,!0);return{width:s.width*l.x,height:s.height*l.y,x:s.x*l.x-c.scrollLeft*l.x+h.x+d.x,y:s.y*l.y-c.scrollTop*l.y+h.y+d.y}},getDocumentElement:is,getClippingRect:function(e){let{element:t,boundary:s,rootBoundary:i,strategy:n}=e;const r=[..."clippingAncestors"===s?ps(t)?[]:function(e,t){const s=t.get(e);if(s)return s;let i=Es(e,[],!1).filter(e=>rs(e)&&"body"!==ts(e)),n=null;const r="fixed"===Ts(e).position;let o=r?Cs(e):e;for(;rs(o)&&!ws(o);){const t=Ts(o),s=bs(o);s||"fixed"!==t.position||(n=null),(r?!s&&!n:!s&&"static"===t.position&&n&&Ds.has(n.position)||ls(o)&&!s&&Rs(e,o))?i=i.filter(e=>e!==o):n=t,o=Cs(o)}return t.set(e,i),i}(t,this._c):[].concat(s),i],o=r[0],a=r.reduce((e,s)=>{const i=Fs(t,s,n);return e.top=Mt(i.top,e.top),e.right=xt(i.right,e.right),e.bottom=xt(i.bottom,e.bottom),e.left=Mt(i.left,e.left),e},Fs(t,o,n));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}},getOffsetParent:Vs,getElementRects:async function(e){const t=this.getOffsetParent||Vs,s=this.getDimensions,i=await s(e.floating);return{reference:Bs(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}},getClientRects:function(e){return Array.from(e.getClientRects())},getDimensions:function(e){const{width:t,height:s}=xs(e);return{width:t,height:s}},getScale:ks,isElement:rs,isRTL:function(e){return"rtl"===Ts(e).direction}};function Us(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}const zs=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){var s,i;const{x:n,y:r,placement:o,middlewareData:a}=t,c=await async function(e,t){const{placement:s,platform:i,elements:n}=e,r=await(null==i.isRTL?void 0:i.isRTL(n.floating)),o=Ft(s),a=Rt(s),c="y"===Vt(s),l=Qt.has(o)?-1:1,h=r&&c?-1:1,u=Dt(t,e);let{mainAxis:d,crossAxis:p,alignmentAxis:m}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return a&&"number"==typeof m&&(p="end"===a?-1*m:m),c?{x:p*h,y:d*l}:{x:d*l,y:p*h}}(t,e);return o===(null==(s=a.offset)?void 0:s.placement)&&null!=(i=a.arrow)&&i.alignmentOffset?{}:{x:n+c.x,y:r+c.y,data:{...c,placement:o}}}}},Ws=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:i,placement:n}=t,{mainAxis:r=!0,crossAxis:o=!1,limiter:a={fn:e=>{let{x:t,y:s}=e;return{x:t,y:s}}},...c}=Dt(e,t),l={x:s,y:i},h=await Xt(t,c),u=Vt(Ft(n)),d=Bt(u);let p=l[d],m=l[u];if(r){const e="y"===d?"bottom":"right";p=Nt(p+h["y"===d?"top":"left"],p,p-h[e])}if(o){const e="y"===u?"bottom":"right";m=Nt(m+h["y"===u?"top":"left"],m,m-h[e])}const g=a.fn({...t,[d]:p,[u]:m});return{...g,data:{x:g.x-s,y:g.y-i,enabled:{[d]:r,[u]:o}}}}}},Ks=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var s,i;const{placement:n,middlewareData:r,rects:o,initialPlacement:a,platform:c,elements:l}=t,{mainAxis:h=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...f}=Dt(e,t);if(null!=(s=r.arrow)&&s.alignmentOffset)return{};const b=Ft(n),y=Vt(a),v=Ft(a)===a,w=await(null==c.isRTL?void 0:c.isRTL(l.floating)),T=d||(v||!g?[Jt(a)]:function(e){const t=Jt(e);return[zt(e),t,zt(t)]}(a)),S="none"!==m;!d&&S&&T.push(...function(e,t,s,i){const n=Rt(e);let r=function(e,t,s){switch(e){case"top":case"bottom":return s?t?Kt:Wt:t?Wt:Kt;case"left":case"right":return t?Ht:Gt;default:return[]}}(Ft(e),"start"===s,i);return n&&(r=r.map(e=>e+"-"+n),t&&(r=r.concat(r.map(zt)))),r}(a,g,m,w));const C=[a,...T],O=await Xt(t,f),E=[];let A=(null==(i=r.flip)?void 0:i.overflows)||[];if(h&&E.push(O[b]),u){const e=Ut(n,o,w);E.push(O[e[0]],O[e[1]])}if(A=[...A,{placement:n,overflows:E}],!E.every(e=>e<=0)){var x,M;const e=((null==(x=r.flip)?void 0:x.index)||0)+1,t=C[e];if(t&&("alignment"!==u||y===Vt(t)||A.every(e=>Vt(e.placement)!==y||e.overflows[0]>0)))return{data:{index:e,overflows:A},reset:{placement:t}};let s=null==(M=A.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0])?void 0:M.placement;if(!s)switch(p){case"bestFit":{var k;const e=null==(k=A.filter(e=>{if(S){const t=Vt(e.placement);return t===y||"y"===t}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0])?void 0:k[0];e&&(s=e);break}case"initialPlacement":s=a}if(n!==s)return{reset:{placement:s}}}return{}}}},Hs=e=>{Object.assign(e,{show(){this.cancelBehaviourOpen?.(),this.openValue=!0},hide(){this.openValue=!1},toggle(){this.cancelBehaviourOpen?.(),this.openValue=!this.openValue},setupFloatingUI({trigger:e,popover:t,strategy:s}){this.floatingUICleanup=function(e,t,s,i){void 0===i&&(i={});const{ancestorScroll:n=!0,ancestorResize:r=!0,elementResize:o="function"==typeof ResizeObserver,layoutShift:a="function"==typeof IntersectionObserver,animationFrame:c=!1}=i,l=Ms(e),h=n||r?[...l?Es(l):[],...Es(t)]:[];h.forEach(e=>{n&&e.addEventListener("scroll",s,{passive:!0}),r&&e.addEventListener("resize",s)});const u=l&&a?function(e,t){let s,i=null;const n=is(e);function r(){var e;clearTimeout(s),null==(e=i)||e.disconnect(),i=null}return function o(a,c){void 0===a&&(a=!1),void 0===c&&(c=1),r();const l=e.getBoundingClientRect(),{left:h,top:u,width:d,height:p}=l;if(a||t(),!d||!p)return;const m={rootMargin:-It(u)+"px "+-It(n.clientWidth-(h+d))+"px "+-It(n.clientHeight-(u+p))+"px "+-It(h)+"px",threshold:Mt(0,xt(1,c))||1};let g=!0;function f(t){const i=t[0].intersectionRatio;if(i!==c){if(!g)return o();i?o(!1,i):s=setTimeout(()=>{o(!1,1e-7)},1e3)}1!==i||Us(l,e.getBoundingClientRect())||o(),g=!1}try{i=new IntersectionObserver(f,{...m,root:n.ownerDocument})}catch(e){i=new IntersectionObserver(f,m)}i.observe(e)}(!0),r}(l,s):null;let d,p=-1,m=null;o&&(m=new ResizeObserver(e=>{let[i]=e;i&&i.target===l&&m&&(m.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var e;null==(e=m)||e.observe(t)})),s()}),l&&!c&&m.observe(l),m.observe(t));let g=c?Ps(e):null;return c&&function t(){const i=Ps(e);g&&!Us(g,i)&&s(),g=i,d=requestAnimationFrame(t)}(),s(),()=>{var e;h.forEach(e=>{n&&e.removeEventListener("scroll",s),r&&e.removeEventListener("resize",s)}),null==u||u(),null==(e=m)||e.disconnect(),m=null,c&&cancelAnimationFrame(d)}}(e,t,()=>{((e,t,s)=>{const i=new Map,n={platform:qs,...s},r={...n.platform,_c:i};return(async(e,t,s)=>{const{placement:i="bottom",strategy:n="absolute",middleware:r=[],platform:o}=s,a=r.filter(Boolean),c=await(null==o.isRTL?void 0:o.isRTL(t));let l=await o.getElementRects({reference:e,floating:t,strategy:n}),{x:h,y:u}=Zt(l,i,c),d=i,p={},m=0;for(let s=0;s{const n={left:`${e}px`,top:`${s}px`,position:i};Object.assign(t.style,n)})})},openValueChanged(){this.disabledValue||(this.openValue?(this.preparePopoverOpenAnimation?.(),this.popoverTarget.showPopover(),this.popoverTarget.setAttribute("aria-expanded","true"),this.onPopoverOpened&&this.onPopoverOpened()):(this.popoverTarget.hidePopover(),this.popoverTarget.removeAttribute("aria-expanded"),this.onPopoverClosed&&this.onPopoverClosed()))}})},Gs=class extends i.xI{static targets=["button","popover"];static values={placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},size:{type:Number,default:24},perLine:{type:Number,default:9}};initialize(){this.onEmojiSelect=this.onEmojiSelect.bind(this),this.pickerLoaded=!1,this.pickerLoadPromise=null,this.connected=!1,super.initialize()}connect(){this.connected=!0,Hs(this),this.setupFloatingUI({trigger:this.buttonTarget,popover:this.popoverTarget,strategy:"absolute"}),super.connect()}disconnect(){this.connected=!1,this.pickerLoadPromise=null,this.floatingUICleanup(),super.disconnect()}onEmojiSelect(e){this.dispatch("selected",{detail:e.native}),this.hide()}onClickOutside(e){this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}async onPopoverOpened(){await this.loadPicker()}async loadPicker(){if(this.pickerLoaded)return;this.pickerLoadPromise||=this.loadPickerDependencies();const{Picker:e,i18n:t}=await this.pickerLoadPromise;this.connected&&!this.pickerLoaded&&(this.popoverTarget.appendChild(this.buildPicker(e,t)),this.pickerLoaded=!0)}async loadPickerDependencies(){const[e,t]=await Promise.all([s.e(160).then(s.bind(s,405)),this.loadI18n()]);return{Picker:e.Picker,i18n:t.default||t}}loadI18n(){return"es"===Hellotext.business.locale?s.e(437).then(s.t.bind(s,9,19)):s.e(200).then(s.t.bind(s,714,19))}buildPicker(e,t){return new e({onEmojiSelect:this.onEmojiSelect,theme:"light",dynamicWidth:!0,previewPosition:"none",skinTonePosition:"none",emojiSize:this.sizeValue,perLine:this.perLineValue,i18n:t})}get middlewares(){return[zs(5),Ws({padding:24}),(e={allowedPlacements:["top","bottom"]},void 0===e&&(e={}),{name:"autoPlacement",options:e,async fn(t){var s,i,n;const{rects:r,middlewareData:o,placement:a,platform:c,elements:l}=t,{crossAxis:h=!1,alignment:u,allowedPlacements:d=At,autoAlignment:p=!0,...m}=Dt(e,t),g=void 0!==u||d===At?function(e,t,s){return(e?[...s.filter(t=>Rt(t)===e),...s.filter(t=>Rt(t)!==e)]:s.filter(e=>Ft(e)===e)).filter(s=>!e||Rt(s)===e||!!t&&zt(s)!==s)}(u||null,p,d):d,f=await Xt(t,m),b=(null==(s=o.autoPlacement)?void 0:s.index)||0,y=g[b];if(null==y)return{};const v=Ut(y,r,await(null==c.isRTL?void 0:c.isRTL(l.floating)));if(a!==y)return{reset:{placement:g[0]}};const w=[f[Ft(y)],f[v[0]],f[v[1]]],T=[...(null==(i=o.autoPlacement)?void 0:i.overflows)||[],{placement:y,overflows:w}],S=g[b+1];if(S)return{data:{index:b+1,overflows:T},reset:{placement:S}};const C=T.map(e=>{const t=Rt(e.placement);return[e.placement,t&&h?e.overflows.slice(0,2).reduce((e,t)=>e+t,0):e.overflows[0],e.overflows]}).sort((e,t)=>e[1]-t[1]),O=(null==(n=C.filter(e=>e[2].slice(0,Rt(e[0])?2:3).every(e=>e<=0))[0])?void 0:n[0])||C[0][0];return O!==a?{data:{index:b+1,overflows:T},reset:{placement:O}}:{}}})];var e}};class Js{static get endpoint(){return f.endpoint("public/webchats/:id/messages")}constructor(e){this.webchatId=e}async index(e){const t=new URL(this.url);return Object.entries(e).forEach(([e,s])=>{t.searchParams.append(e,s)}),await fetch(t,{method:"GET",headers:vt.headers})}catchUp(e){return this.index({after_id:e,session:vt.session})}async create(e){const t=await fetch(this.url,{method:"POST",headers:{Authorization:`Bearer ${vt.business.id}`},body:e});return new v(t.ok,t)}markAsSeen(e=null){const t=e?this.url+`/${e}`:this.url+"/seen";fetch(t,{method:"PATCH",headers:vt.headers,body:JSON.stringify({session:vt.session})})}get url(){return Js.endpoint.replace(":id",this.webchatId)}}const Ys=Js;class Zs{static webSocket;static channels=new Set;static messageHandlers=new Set;static disconnectHandlers=new Set;static subscriptionConfirmHandlers=new Set;static reconnectTimeout=null;static reconnectAttempts=0;static reconnectBaseDelay=500;static reconnectMaxDelay=1e4;static reconnectJitter=.3;static needsResubscribe=!1;constructor(){Zs.channels.add(this)}send({command:e,identifier:t,data:s}){const i={command:e,identifier:JSON.stringify(t),data:JSON.stringify(s||{})},n=Zs.ensureWebSocket(),r=JSON.stringify(i);n.readyState===WebSocket.OPEN?n.send(r):n.addEventListener("open",()=>{n.send(r)})}onMessage(e){const t=t=>{const s=JSON.parse(t.data),{type:i,message:n}=s;this.ignoredEvents.includes(i)||e(n)};Zs.messageHandlers.add(t),Zs.ensureWebSocket().addEventListener("message",t)}onDisconnect(e){Zs.disconnectHandlers.add(e)}onSubscriptionConfirmed(e){Zs.subscriptionConfirmHandlers.add(e)}get webSocket(){return Zs.ensureWebSocket()}static ensureWebSocket(){return this.webSocket&&!this.closedWebSocket(this.webSocket)?this.webSocket:(this.webSocket&&(this.needsResubscribe=!0),this.openWebSocket())}static openWebSocket(){this.clearReconnectTimeout();const e=new WebSocket(f.actionCableUrl);return this.webSocket=e,this.installWebSocketHandlers(e),e}static installWebSocketHandlers(e){e.addEventListener("open",()=>this.handleOpen(e)),e.addEventListener("close",()=>this.handleDisconnect(e)),e.addEventListener("error",()=>this.handleDisconnect(e)),e.addEventListener("message",e=>this.handleControlMessage(e)),this.messageHandlers.forEach(t=>{e.addEventListener("message",t)})}static handleOpen(e){e===this.webSocket&&(this.reconnectAttempts=0,this.needsResubscribe&&(this.needsResubscribe=!1,this.resubscribeChannels()))}static handleControlMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}"confirm_subscription"===t.type&&this.subscriptionConfirmHandlers.forEach(e=>e(t.identifier))}static handleDisconnect(e){e===this.webSocket&&(this.disconnectHandlers.forEach(e=>e()),this.webSocket=null,this.needsResubscribe=!0,this.scheduleReconnect())}static scheduleReconnect(){this.reconnectTimeout||(this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts+=1,this.openWebSocket()},this.reconnectDelay))}static clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}static resubscribeChannels(){this.channels.forEach(e=>{const t=e.resubscribe||e.subscribe;"function"==typeof t&&t.call(e)})}static closedWebSocket(e){return e.readyState===WebSocket.CLOSED||e.readyState===WebSocket.CLOSING}static get reconnectDelay(){const e=Math.min(this.reconnectMaxDelay,this.reconnectBaseDelay*2**this.reconnectAttempts);return e+Math.round(e*this.reconnectJitter*Math.random())}get ignoredEvents(){return["ping","confirm_subscription","welcome"]}}const Xs=Zs,Qs=class extends Xs{constructor(e,t,s){super(),this.id=e,this.session=t,this.conversation=s,this.subscribed=!1,this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks=new Set,this.onSubscriptionConfirmed(e=>this.handleSubscriptionConfirmed(e)),this.subscribe()}subscribe(){this.subscribed=!0;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"subscribe",identifier:e})}unsubscribe(){this.subscribed=!1;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"unsubscribe",identifier:e})}resubscribe(){!1!==this.subscribed&&(this.awaitingReconnectConfirmation=!0,this.subscribe())}onReconnect(e){this.reconnectCallbacks.add(e)}handleSubscriptionConfirmed(e){this.awaitingReconnectConfirmation&&this.matchesIdentifier(e)&&(this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks.forEach(e=>e()))}matchesIdentifier(e){let t;try{t="string"==typeof e?JSON.parse(e):e}catch{return!1}return"WebchatChannel"===t.channel&&t.id===this.id&&t.session===this.session&&t.conversation===this.conversation}startTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"message",identifier:e,data:{action:"started_typing"}})}stopTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"typing:stop",identifier:e,data:{action:"stopped_typing"}})}onMessage(e){super.onMessage(t=>{"message"===t.type&&e(t)})}onReaction(e){super.onMessage(t=>{"reaction.create"!==t.type&&"reaction.destroy"!==t.type||e(t)})}onTypingStart(e){super.onMessage(t=>{"started_typing"===t.type&&e(t)})}updateSubscriptionWith(e){this.unsubscribe(),setTimeout(()=>{this.conversation=e,this.subscribe()},1e3)}},ei=e=>{Object.assign(e,{scheduleBehaviourOpen(){if(!this.shouldAutoOpenFromBehaviour())return;const e=1e3*Number(this.behaviourValue.delay_seconds||0);this.behaviourOpenTimeout=window.setTimeout(()=>{this.behaviourOpenTimeout=null,this.openValue||(this.openValue=!0,this.markBehaviourAutoOpened())},e)},cancelBehaviourOpen(){window.clearTimeout(this.behaviourOpenTimeout),this.behaviourOpenTimeout=null},shouldAutoOpenFromBehaviour(){const e=this.behaviourValue;return!(!e||"on_load"!==e.trigger||e.first_visit_only&&localStorage.getItem(this.firstVisitKey())||e.once_per_session&&sessionStorage.getItem(this.sessionKey()))},markBehaviourAutoOpened(){this.behaviourValue.first_visit_only&&localStorage.setItem(this.firstVisitKey(),"1"),this.behaviourValue.once_per_session&&sessionStorage.setItem(this.sessionKey(),"1")},firstVisitKey(){return`hellotext--webchat--${this.idValue}--auto-opened`},sessionKey(){return`hellotext--webchat--${this.idValue}--auto-opened-session`}})},ti=e=>{Object.assign(e,{setupOpeningSequence(){this.openingSequenceStarted=!1,this.openingSequenceCancelled=!1,this.openingSequenceTimeout=null,this.openingSequenceMessages=[],this.revealedOpeningSequenceMessageIds=[]},teardownOpeningSequence(){this.cancelOpeningSequence()},startOpeningSequence(){this.openingSequenceMessages=Array.from(this.openingSequenceMessageTargets||[]),this.openingSequenceCanStart()&&(this.openingSequenceStarted=!0,this.openingSequenceCancelled=!1,this.revealedOpeningSequenceMessageIds=[],this.playOpeningSequenceMessageAt(0))},openingSequenceCanStart(){return!this.conversationIdValue&&this.hasOpeningSequenceTarget&&this.openingSequenceMessages.length>0&&!this.openingSequenceStarted},playOpeningSequenceMessageAt(e){const t=this.openingSequenceMessages[e];if(!t)return;const s=1e3*this.openingSequenceMessageDelay(t);this.openingSequenceTimeout=window.setTimeout(()=>{this.openingSequenceTimeout=null,this.openingSequenceCancelled||(this.revealOpeningSequenceMessage(t),this.playOpeningSequenceMessageAt(e+1))},s)},revealOpeningSequenceMessage(e){this.messagesContainerTarget.insertBefore(e,this.messageTemplateTarget),e.hidden=!1,this.recordOpeningSequenceMessage(e),this.scrollOpeningSequenceToBottom()},recordOpeningSequenceMessage(e){const t=e.dataset.openingSequenceMessageId;t&&!this.revealedOpeningSequenceMessageIds.includes(t)&&this.revealedOpeningSequenceMessageIds.push(t)},openingSequenceMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},scrollOpeningSequenceToBottom(){this.messagesContainerTarget.scroll&&this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"smooth"})},cancelOpeningSequence(){this.openingSequenceCancelled=!0,null!==this.openingSequenceTimeout&&void 0!==this.openingSequenceTimeout&&(window.clearTimeout(this.openingSequenceTimeout),this.openingSequenceTimeout=null)},appendOpeningSequenceMessageIds(e){this.cancelOpeningSequence(),(this.revealedOpeningSequenceMessageIds||[]).forEach(t=>{e.append("message[opening_sequence_message_ids][]",t)})},clearRevealedOpeningSequenceMessageIds(){this.revealedOpeningSequenceMessageIds=[]}})},si=e=>{Object.assign(e,{setupTeaser(){this.teaserCycleTimeout=null,this.teaserMessages=[],this.boundOnTeaserClick=this.boundOnTeaserClick||this.onTeaserClick.bind(this),this.hasTeaserTarget&&(this.teaserTarget.addEventListener("click",this.boundOnTeaserClick),this.startTeaserPresentation())},teardownTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.boundOnTeaserClick&&this.teaserTarget.removeEventListener("click",this.boundOnTeaserClick)},collectTeaserMessages(){return this.hasTeaserTarget?Array.from(this.teaserTarget.querySelectorAll("[data-teaser-message]")):[]},startTeaserPresentation(){this.stopTeaserCycle(),this.teaserMessages=this.collectTeaserMessages(),this.hasTeaserTarget&&(0!==this.teaserMessages.length?this.openValue||this.conversationIdValue||this.hasRenderedConversationMessages()?this.dismissTeaserForSession():this.teaserSeenForSession()?this.hideTeaser():this.teaserMessageDelay(this.teaserMessages[0])>0?this.scheduleTeaserMessage(0):(this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(0),this.scheduleTeaserMessage(1)):this.hideTeaser())},scheduleTeaserMessage(e){const t=this.teaserMessages[e];if(!t)return;const s=this.teaserPresentationDelay(t);this.teaserCycleTimeout=window.setTimeout(()=>{this.teaserCycleTimeout=null,this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(e),this.scheduleTeaserMessage(e+1)},s)},showTeaserMessage(e){this.teaserMessages.forEach((t,s)=>{t.classList.toggle("hidden",s!==e)})},stopTeaserCycle(){null!==this.teaserCycleTimeout&&void 0!==this.teaserCycleTimeout&&(window.clearTimeout(this.teaserCycleTimeout),this.teaserCycleTimeout=null)},teaserMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},teaserPresentationDelay(e){return Math.max(1e3*this.teaserMessageDelay(e),250)},hasRenderedConversationMessages(){let e=[];try{e=Array.from(this.messageTargets||[])}catch(t){e=[]}return e.some(e=>e!==this.messageTemplateTarget)},teaserSeenKey(){const e=this.hasTeaserTarget?this.teaserTarget.dataset.teaserVersion:"",t=e?`:${e}`:"";return`hellotext:webchat:${this.idValue||this.element.id}:teaser-seen${t}`},teaserSeenForSession(){try{return"true"===window.sessionStorage.getItem(this.teaserSeenKey())}catch(e){return!1}},markTeaserSeenForSession(){try{window.sessionStorage.setItem(this.teaserSeenKey(),"true")}catch(e){}},dismissTeaserForSession(){this.markTeaserSeenForSession(),this.hideTeaser()},hideTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.teaserTarget.classList.add("invisible")},onTeaserClick(e){e.target.closest("a")||(this.dismissTeaserForSession(),this.show())}})},ii={hour:"numeric",minute:"2-digit"},ni=/Android|iPhone|iPad|iPod/i,ri={capture:!0,passive:!0},oi=class extends i.xI{static messageTimestampFormatters={};static values={id:String,conversationId:String,media:Object,fileSizeErrorMessage:String,placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},nextPage:{type:Number,default:void 0},fullScreenThreshold:{type:Number,default:1024},typingIndicatorKeepAlive:{type:Number,default:3e4},offset:{type:Number,default:24},padding:{type:Number,default:24},optimisticTypingIndicatorWait:{type:Number,default:1e3},teaser:Object,messageTeaser:String,behaviour:Object};static classes=["fadeOut"];static targets=["trigger","popover","input","attachmentInput","attachmentButton","errorMessageContainer","attachmentTemplate","attachmentContainer","attachment","messageTemplate","messagesContainer","title","attachmentImage","footer","toolbar","message","unreadCounter","typingIndicator","typingIndicatorTemplate","teaser","teaserMessage","inboundMessageTeaser","inboundMessageTeaserBody","openingSequence","openingSequenceMessage"];initialize(){this.messagesAPI=new Ys(this.idValue),this.webChatChannel=new Qs(this.idValue,vt.session,this.conversationIdValue),this.files=[],this.messageIds=new Set,this.catchUpAfterMessageId=null,this.fetchingCatchUpMessages=!1,this.onMessageReceived=this.onMessageReceived.bind(this),this.onMessageReaction=this.onMessageReaction.bind(this),this.onTypingStart=this.onTypingStart.bind(this),this.captureCatchUpCursor=this.captureCatchUpCursor.bind(this),this.catchUpMessages=this.catchUpMessages.bind(this),this.onScroll=this.onScroll.bind(this),this.onOutboundMessageSent=this.onOutboundMessageSent.bind(this),this.closePopoverOnEscape=this.closePopoverOnEscape.bind(this),this.broadcastChannel=new BroadcastChannel(`hellotext--webchat--${this.idValue}`),this.webChatChannel.onDisconnect(this.captureCatchUpCursor),this.webChatChannel.onReconnect(this.catchUpMessages),super.initialize()}connect(){ei(this),Hs(this),ti(this),si(this),this.setupFloatingUI({trigger:this.triggerTarget,popover:this.popoverTarget}),this.hasTeaserTarget&&this.setupFloatingUI({trigger:this.triggerTarget,popover:this.teaserTarget,strategy:"absolute"}),this.setupTeaser(),this.setupOpeningSequence(),this.localizeMessageTimestamps(),this.webChatChannel.onMessage(this.onMessageReceived),this.webChatChannel.onTypingStart(this.onTypingStart),this.webChatChannel.onReaction(this.onMessageReaction),this.setupMessagesContainerScrollIsolation(),this.messagesContainerTarget.addEventListener("scroll",this.onScroll),this.messagesContainerTarget.addEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.addEventListener("touchmove",this.stopHostScrollPropagation,ri),this.shouldOpenOnMount&&(this.openValue=!0),vt.eventEmitter.dispatch("webchat:mounted"),this.broadcastChannel.addEventListener("message",this.onOutboundMessageSent),window.addEventListener("keydown",this.closePopoverOnEscape,!0),this.scheduleBehaviourOpen(),super.connect()}disconnect(){this.cancelBehaviourOpen(),this.clearPopoverOpenAnimation(),this.teardownTeaser(),this.teardownOpeningSequence(),this.broadcastChannel.removeEventListener("message",this.onOutboundMessageSent),this.messagesContainerTarget.removeEventListener("scroll",this.onScroll),this.messagesContainerTarget.removeEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.removeEventListener("touchmove",this.stopHostScrollPropagation,ri),window.removeEventListener("keydown",this.closePopoverOnEscape,!0),this.clearTypingIndicator(),this.broadcastChannel.close(),this.floatingUICleanup(),super.disconnect()}setupMessagesContainerScrollIsolation(){this.messagesContainerTarget.style.overscrollBehavior="contain",this.messagesContainerTarget.style.webkitOverflowScrolling="touch",this.messagesContainerTarget.style.touchAction="pan-y",this.messagesContainerTarget.setAttribute("data-lenis-prevent",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-wheel",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-touch","")}stopHostScrollPropagation(e){e.stopPropagation()}onTypingStart(){if(this.typingIndicatorVisible)return this.resetTypingIndicatorTimer();this.showTypingIndicator()}showOptimisticTypingIndicator(){this.typingIndicatorVisible||this.showTypingIndicator()}showTypingIndicator(){this.clearTypingIndicator(),this.typingIndicatorVisible=!0;const e=this.typingIndicatorTemplateTarget.cloneNode(!0);e.setAttribute("data-hellotext--webchat-target","typingIndicator"),e.style.display="flex",this.messagesContainerTarget.appendChild(e),requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})});const t=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},t)}resetTypingIndicatorTimer(){if(!this.typingIndicatorVisible)return;clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout);const e=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},e)}clearTypingIndicator(){this.hasTypingIndicatorTarget&&this.typingIndicatorTarget.remove(),this.typingIndicatorVisible=!1,clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout)}onMessageInputChange(){this.resizeInput(),clearTimeout(this.typingIndicatorTimeout),this.hasSentTypingIndicator||(this.webChatChannel.startTypingIndicator(),this.hasSentTypingIndicator=!0),this.typingIndicatorTimeout=setTimeout(()=>{this.hasSentTypingIndicator=!1},3e3)}onOutboundMessageSent(e){const{data:t}=e,s={"message:sent":e=>{const t=(new DOMParser).parseFromString(e.element,"text/html").body.firstElementChild;this.localizeMessageTimestamps(t),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(t,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(t),t.scrollIntoView({behavior:"instant"})},"message:failed":e=>{const t=this.messagesContainerTarget.querySelector(`#${e.id}`);this.markMessageFailed(t,e.reason)}};s[t.type]?s[t.type](t):console.log(`Unhandled message event: ${t.type}`)}async onScroll(){if(this.messagesContainerTarget.scrollTop>300||!this.nextPageValue||this.fetchingNextPage)return;this.fetchingNextPage=!0;const e=await this.messagesAPI.index({page:this.nextPageValue,session:vt.session}),{next:t,messages:s}=await e.json();this.nextPageValue=t,this.oldScrollHeight=this.messagesContainerTarget.scrollHeight,s.forEach(e=>{const{body:t,attachments:s}=e,i=e.created_at||e.createdAt,n=this.messageTemplateTarget.cloneNode(!0);n.classList.add("hellotext--webchat-message"),n.setAttribute("data-hellotext--webchat-target","message"),n.setAttribute("data-id",e.id),i&&n.setAttribute("data-created-at",i),n.style.removeProperty("display"),rt(n.querySelector("[data-body]"),t),"received"===e.state?n.classList.add("received"):n.classList.remove("received"),s&&s.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.removeAttribute("data-hellotext--webchat-target"),t.src=e,t.style.display="block",this.messageAttachmentsContainer(n)?.appendChild(t)}),n.setAttribute("data-body",t),this.localizeMessageTimestamp(n.querySelector("[data-message-timestamp]"),i),this.messagesContainerTarget.prepend(n)}),this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight-this.oldScrollHeight,behavior:"instant"}),this.fetchingNextPage=!1}onClickOutside(e){d.mode===u.POPOVER&&this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}closePopover(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.openValue=!1}preparePopoverOpenAnimation(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.popoverTarget.classList.add("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=setTimeout(()=>{this.popoverTarget.classList.remove("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=null},120)}clearPopoverOpenAnimation(){this.popoverOpenAnimationTimeout&&(clearTimeout(this.popoverOpenAnimationTimeout),this.popoverOpenAnimationTimeout=null),this.popoverTarget?.classList.remove("hellotext--webchat-popover-opening")}onPopoverOpened(){this.popoverTarget.classList.remove(...this.fadeOutClasses),this.dismissTeaserForSession?.(),this.onMobile||this.focusComposeInput(),this.scrolled||(requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})}),this.scrolled=!0),vt.eventEmitter.dispatch("webchat:opened"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"opened"),this.messageTeaserValue&&(this.messageTeaserValue=null),this.startOpeningSequence(),"none"!==this.unreadCounterTarget.style.display&&(this.unreadCounterTarget.style.display="none",this.unreadCounterTarget.innerText="0",this.messagesAPI.markAsSeen())}onPopoverClosed(){this.clearPopoverOpenAnimation(),vt.eventEmitter.dispatch("webchat:closed"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"closed")}onMessageReaction(e){const{message:t,reaction:s,type:i}=e,n=this.messageTargets.find(e=>e.dataset.id===t).querySelector("[data-reactions]");if("reaction.destroy"===i)return n.querySelector(`[data-id="${s.id}"]`).remove();if(n.querySelector(`[data-id="${s.id}"]`))n.querySelector(`[data-id="${s.id}"]`).innerText=s.emoji;else{const e=document.createElement("span");e.innerText=s.emoji,e.setAttribute("data-id",s.id),n.appendChild(e)}}onMessageReceived(e,t={}){const{id:s,body:i,attachments:n,teaser:r}=e,o=e.created_at||e.createdAt;if(!this.claimMessageId(s))return;if(this.hideTeaser?.(),e.carousel)return this.insertCarouselMessage(e,t);const a=this.messageTemplateTarget.cloneNode(!0);a.classList.add("hellotext--webchat-message"),a.style.display="flex",rt(a.querySelector("[data-body]"),i),a.setAttribute("data-id",s),a.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(a,o),this.localizeMessageTimestamp(a.querySelector("[data-message-timestamp]"),o),n&&n.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.src=e,t.style.display="block",this.messageAttachmentsContainer(a)?.appendChild(t)}),this.clearTypingIndicator(),this.insertMessageElement(a),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:a.querySelector("[data-body]").innerText}),!1!==t.scroll&&a.scrollIntoView({behavior:"smooth"}),this.updateMessageTeaser(r),this.openValue?this.messagesAPI.markAsSeen(s):this.incrementUnreadCounter()}claimMessageId(e){const t=this.messageTargets||[];return!this.messageIds.has(e)&&(this.messageIds.add(e),!t.some(t=>t.dataset.id===e))}captureCatchUpCursor(){this.catchUpAfterMessageId=this.lastRenderedMessageId}async catchUpMessages(){const e=this.catchUpAfterMessageId;if(e&&!this.fetchingCatchUpMessages){this.fetchingCatchUpMessages=!0;try{const t=await this.messagesAPI.catchUp(e),{messages:s=[]}=await t.json();s.forEach(e=>this.onMessageReceived(e,{scroll:!1})),this.catchUpAfterMessageId=this.lastRenderedMessageId}finally{this.fetchingCatchUpMessages=!1}}}get lastRenderedMessageId(){const e=this.persistedMessageElements;return e[e.length-1]?.dataset.id||null}get persistedMessageElements(){return Array.from(this.messagesContainerTarget.querySelectorAll(".hellotext--webchat-message[data-id]"))}setMessageCreatedAt(e,t){t&&e.setAttribute("data-created-at",t)}insertMessageElement(e){const t=this.nextMessageElementFor(e);t?this.messagesContainerTarget.insertBefore(e,t):this.messagesContainerTarget.appendChild(e)}nextMessageElementFor(e){const t=Date.parse(e.dataset.createdAt);return Number.isNaN(t)?null:this.persistedMessageElements.find(s=>{if(s===e)return!1;const i=Date.parse(s.dataset.createdAt);return!Number.isNaN(i)&&i>t})}updateMessageTeaser(e){this.messageTeaserValue=e,this.messageTeaserValue&&this.hasTeaserTarget&&this.hasInboundMessageTeaserTarget&&this.hasInboundMessageTeaserBodyTarget&&(this.teaserMessageTargets.forEach(e=>e.classList.add("hidden")),this.inboundMessageTeaserBodyTarget.textContent=this.messageTeaserValue,this.inboundMessageTeaserTarget.classList.remove("hidden"),this.teaserTarget.classList.toggle("invisible",this.openValue))}insertCarouselMessage(e,t={}){const s=e.html,i=e.created_at||e.createdAt,n=function(e){return nt(e,it)}(s).firstElementChild;n.classList.add("hellotext--webchat-message"),n.setAttribute("data-id",e.id),n.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(n,i),this.localizeMessageTimestamps(n),this.clearTypingIndicator(),this.insertMessageElement(n),!1!==t.scroll&&n.scrollIntoView({behavior:"smooth"}),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:n.querySelector("[data-body]")?.innerText||""}),this.updateMessageTeaser(e.teaser),this.openValue?this.messagesAPI.markAsSeen(e.id):this.incrementUnreadCounter()}resizeInput(){this.inputTarget.style.height="auto";const e=this.inputTarget.scrollHeight;this.inputTarget.style.height=`${Math.min(e,96)}px`}async sendQuickReplyMessage({detail:{id:e,product:t,buttonId:s,body:i,cardElement:n}}){this.dismissTeaserForSession?.();const r=new FormData;r.append("message[body]",i),e&&r.append("message[replied_to]",e),t&&r.append("message[product]",t),s&&r.append("message[button]",s),r.append("session",vt.session),r.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(r);const o=this.buildMessageElement(),c=n?.querySelector("img")?.cloneNode(!0);o.querySelector("[data-body]").innerText=i,c&&(c.removeAttribute("width"),c.removeAttribute("height"),this.messageAttachmentsContainer(o)?.appendChild(c)),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(o,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(o),o.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:o.outerHTML});const l=await this.messagesAPI.create(r);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,o);const h=await l.json();this.dispatch("set:id",{target:o,detail:h.id}),this.localizeMessageTimestamp(o.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds();const u={id:h.id,body:i,attachments:c?[c.src]:[],replied_to:e,product:t,button:s,type:"quick_reply"};vt.eventEmitter.dispatch("webchat:message:sent",u)}async sendTeaserQuickReply(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=(t.dataset.value||"").trim(),i=[t.dataset.text,t.textContent].map(e=>(e||"").trim()).find(e=>e.length>0),n=s||i;if(!n)return;this.dismissTeaserForSession?.(),this.show();const r=(t.dataset.type||"").trim()||"quick_reply",o=new FormData;o.append("message[body]",n),o.append("session",vt.session),o.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(o);const c=this.buildMessageElement();c.querySelector("[data-body]").innerText=n,this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(c,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(c),c.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:c.outerHTML}),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const l=await this.messagesAPI.create(o);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,c);const h=await l.json();c.setAttribute("data-id",h.id),this.localizeMessageTimestamp(c.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",{id:h.id,body:n,attachments:[],type:"quick_reply",teaser:{text:i||n,value:s||n,type:r}}),h.conversation&&h.conversation!==this.conversationIdValue&&(this.conversationIdValue=h.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer()}async sendMessage(e){const t={body:this.inputTarget.value,attachments:this.files};if(0===this.inputTarget.value.trim().length&&0===this.files.length)return void(e&&e.target&&e.preventDefault());this.dismissTeaserForSession?.();const s=new FormData;this.inputTarget.value.trim().length>0?s.append("message[body]",this.inputTarget.value):delete t.body,this.files.forEach(e=>{s.append("message[attachments][]",e)}),s.append("session",vt.session),s.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(s);const i=this.buildMessageElement();this.inputTarget.value.trim().length>0?i.querySelector("[data-body]").innerText=this.inputTarget.value:i.querySelector("[data-message-bubble]").remove();const n=this.attachmentContainerTarget.querySelectorAll("img");n.length>0&&n.forEach(e=>{this.messageAttachmentsContainer(i)?.appendChild(e.cloneNode(!0))}),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(i,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(i),i.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:i.outerHTML}),this.inputTarget.value="",this.resizeInput(),this.files=[],this.attachmentInputTarget.value="",this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none",this.errorMessageContainerTarget.style.display="none",this.focusComposeInput(),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const r=await this.messagesAPI.create(s);if(r.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(r,i);const o=await r.json();i.setAttribute("data-id",o.id),t.id=o.id,this.localizeMessageTimestamp(i.querySelector("[data-message-timestamp]"),o.created_at||o.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",t),o.conversation!==this.conversationIdValue&&(this.conversationIdValue=o.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer(),this.attachmentContainerTarget.style.display=""}buildMessageElement(){const e=this.messageTemplateTarget.cloneNode(!0);return e.id=`hellotext--webchat--${this.idValue}--message--${Date.now()}`,e.classList.add("received"),e.style.removeProperty("display"),e.setAttribute("data-controller","hellotext--message"),e.setAttribute("data-hellotext--webchat-target","message"),this.localizeMessageTimestamp(e.querySelector("[data-message-timestamp]"),new Date),e}focusCompose(e){const{target:t}=e,s=["button","a","input","textarea","select","label",'[role="button"]',"em-emoji-picker",'[data-hellotext--webchat--emoji-target~="popover"]','[data-controller~="hellotext--webchat--emoji"]'].join(", ");this.hasInputTarget&&!t.closest(s)&&this.focusComposeInput({moveCursorToEnd:!0})&&e.preventDefault()}closePopoverFromHeader(e){const{target:t}=e;t.closest(".hellotext--webchat-header-channel-button, .hellotext--webchat-close-button")||(e.preventDefault(),this.closePopover())}closePopoverOnEscape(e){"Escape"===e.key&&this.openValue&&(e.preventDefault(),e.stopPropagation(),this.closePopover(),this.triggerTarget?.focus?.())}async markMessageFailedFromResponse(e,t){const s=await this.messageFailureReason(e);this.markMessageFailed(t,s),this.broadcastChannel.postMessage({type:"message:failed",id:t.id,reason:s})}markMessageFailed(e,t){if(!e)return;if(e.classList.add("failed"),!t)return;const s=e.querySelector("[data-message-timestamp]");s&&(s.textContent=t)}localizeMessageTimestamps(e=this.element){e&&(e.matches?.("time[datetime][data-message-timestamp]")?[e]:Array.from(e.querySelectorAll?.("time[datetime][data-message-timestamp]")||[])).forEach(e=>this.localizeMessageTimestamp(e))}localizeMessageTimestamp(e,t=e?.getAttribute("datetime")){if(!e||!t)return;const s=t instanceof Date?t:new Date(t);Number.isNaN(s.getTime())||(e.setAttribute("datetime",s.toISOString()),e.textContent=this.formatMessageTimestamp(s))}formatMessageTimestamp(e){return this.constructor.messageTimestampFormatterFor(a.toString()).format(e)}static messageTimestampFormatterFor(e){const t=e||"default";return this.messageTimestampFormatters[t]||(this.messageTimestampFormatters[t]=this.buildMessageTimestampFormatter(e)),this.messageTimestampFormatters[t]}static buildMessageTimestampFormatter(e){try{return new Intl.DateTimeFormat(e||void 0,ii)}catch(e){return new Intl.DateTimeFormat(void 0,ii)}}async messageFailureReason(e){const t=e?.data||e?.response,s=t?.statusText||"Message failed";try{const e=t?.clone?t.clone():t,s=await(e?.json?.()),i=this.messageFailureReasonFromPayload(s);if(i)return i}catch(e){}try{const e=t?.clone?t.clone():t,i=await(e?.text?.());return this.messageFailureReasonFromText(i)||s}catch(e){return s}}messageFailureReasonFromText(e){if("string"!=typeof e)return null;const t=e.trim();if(!t||t.startsWith("<"))return null;try{return this.messageFailureReasonFromPayload(JSON.parse(t))||t}catch(e){return t}}messageFailureReasonFromPayload(e){return e?[e.error?.message,e.message,e.errors?.message,e.errors?.[0]?.message,e.errors?.[0]?.description].find(e=>"string"==typeof e&&e.trim().length>0):null}messageAttachmentsContainer(e){return e.querySelector("[data-attachments-container], [data-attachment-container]")}incrementUnreadCounter(){this.unreadCounterTarget.style.display="flex";const e=(parseInt(this.unreadCounterTarget.innerText)||0)+1;this.unreadCounterTarget.innerText=Math.min(e,9)}openAttachment(){this.attachmentInputTarget.click()}onFileInputChange(){this.errorMessageContainerTarget.style.display="none";const e=Array.from(this.attachmentInputTarget.files);this.attachmentInputTarget.value="";const t=e.find(e=>{const t=e.type.split("/")[0];return["image","video","audio"].includes(t)?this.mediaValue[t].max_sizethis.createAttachmentElement(e)),this.focusComposeInput()}createAttachmentElement(e){const t=this.attachmentElement();if(this.attachmentContainerTarget.style.display="",t.setAttribute("data-name",e.name),e.type.startsWith("image/")){const s=this.attachmentImageTarget.cloneNode(!0);s.src=URL.createObjectURL(e),s.style.display="block",t.appendChild(s),this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}else{const s=t.querySelector("main");s.style.height="5rem",s.style.borderRadius="0.375rem",s.style.backgroundColor="#e5e7eb",s.style.padding="0.25rem",t.querySelector("p[data-attachment-name]").innerText=e.name,this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}}removeAttachment({currentTarget:e}){const t=e.closest("[data-hellotext--webchat-target='attachment']");this.files=this.files.filter(e=>e.name!==t.dataset.name),this.attachmentInputTarget.value="",t.remove(),this.focusComposeInput()}attachmentTargetDisconnected(){0===this.attachmentTargets.length&&(this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none")}attachmentElement(){const e=this.attachmentTemplateTarget.cloneNode(!0);return e.removeAttribute("hidden"),e.style.display="flex",e.setAttribute("data-hellotext--webchat-target","attachment"),e}onEmojiSelect({detail:e}){const t=this.inputTarget.value,s=this.inputTarget.selectionStart,i=this.inputTarget.selectionEnd;this.inputTarget.value=t.slice(0,s)+e+t.slice(i),this.inputTarget.selectionStart=this.inputTarget.selectionEnd=s+e.length,this.focusComposeInput()}focusComposeInput({moveCursorToEnd:e=!1}={}){if(!this.shouldAutofocusCompose)return!1;if(!1===this.hasInputTarget)return!1;if(void 0===this.hasInputTarget&&!this.inputTarget)return!1;if(this.inputTarget.focus(),e&&"number"==typeof this.inputTarget.selectionStart){const e=this.inputTarget.value.length;this.inputTarget.setSelectionRange(e,e)}return!0}byteToMegabyte(e){return Math.ceil(e/1024/1024)}get middlewares(){return[zs(this.offsetValue),Ws({padding:this.paddingValue}),Ks()]}get shouldOpenOnMount(){return"opened"===localStorage.getItem(`hellotext--webchat--${this.idValue}`)&&!this.onMobile}get shouldAutofocusCompose(){return!this.usesVirtualKeyboard}get usesVirtualKeyboard(){if("undefined"==typeof navigator)return!1;const e=navigator.userAgent||"",t="MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,s=ni.test(e),i=!0===navigator.userAgentData?.mobile;return s||t||i||this.hasTouchOnlyPointer}get hasTouchOnlyPointer(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches&&window.matchMedia("(hover: none)").matches}get onMobile(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(`(max-width: ${this.fullScreenThresholdValue}px)`).matches}},ai=i.lg.start();ai.register("hellotext--alert",Tt),ai.register("hellotext--form",St),ai.register("hellotext--popup",Ot),ai.register("hellotext--webchat",oi),ai.register("hellotext--webchat--emoji",Gs),ai.register("hellotext--message",Ct),window.Hellotext=vt;const ci=vt}};const t={};function s(i){const n=t[i];if(void 0!==n)return n.exports;const r=t[i]={exports:{}};return e[i](r,r.exports,s),r.exports}s.m=e,(()=>{const e=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;let t;s.t=function(i,n){if(1&n&&(i=this(i)),8&n)return i;if("object"==typeof i&&i){if(4&n&&i.__esModule)return i;if(16&n&&"function"==typeof i.then)return i}const r=Object.create(null);s.r(r);const o={};t=t||[null,e({}),e([]),e(e)];for(var a=2&n&&i;("object"==typeof a||"function"==typeof a)&&!~t.indexOf(a);a=e(a))Object.getOwnPropertyNames(a).forEach(e=>o[e]=()=>i[e]);return o.default=()=>i,s.d(r,o),r}})(),s.d=(e,t)=>{if(Array.isArray(t))for(var i=0;iPromise.all(Object.keys(s.f).reduce((t,i)=>(s.f[i](e,t),t),[])),s.u=e=>({160:"webchat-emoji",200:"webchat-emoji-en",437:"webchat-emoji-es"}[e]+".js"),s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{const e={},t="Hellotext:";s.l=(i,n,r,o)=>{if(e[i])return void e[i].push(n);let a,c;if(void 0!==r){const e=document.getElementsByTagName("script");for(var l=0;l{a.onerror=a.onload=null,clearTimeout(u);const n=e[i];if(delete e[i],a.parentNode?.removeChild(a),n?.forEach(e=>e(s)),t)return t(s)},u=setTimeout(h.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=h.bind(null,a.onerror),a.onload=h.bind(null,a.onload),c&&document.head.appendChild(a)}})(),s.r=e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{let e;s.g.importScripts&&(e=s.g.location+"");const t=s.g.document;if(!e&&t&&("SCRIPT"===t.currentScript?.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){const s=t.getElementsByTagName("script");if(s.length){let t=s.length-1;for(;t>-1&&(!e||!/^http(s?):/.test(e));)e=s[t--].src}}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})(),(()=>{const e={792:0};s.f.j=(t,i)=>{let n=s.o(e,t)?e[t]:void 0;if(0!==n)if(n)i.push(n[2]);else{const r=new Promise((s,i)=>n=e[t]=[s,i]);i.push(n[2]=r);const o=s.p+s.u(t),a=new Error,c=i=>{if(s.o(e,t)&&(n=e[t],0!==n&&(e[t]=void 0),n)){const e=i&&("load"===i.type?"missing":i.type),s=i&&i.target&&i.target.src;a.message="Loading chunk "+t+" failed.\n("+e+": "+s+")",a.name="ChunkLoadError",a.type=e,a.request=s,n[1](a)}};s.l(o,c,"chunk-"+t,t)}};const t=(t,i)=>{let[n,r,o]=i;var a,c,l=0;if(n.some(t=>0!==e[t])){for(a in r)s.o(r,a)&&(s.m[a]=r[a]);o&&o(s)}for(t&&t(i);l(()=>{"use strict";var e={891(e,t,s){s.d(t,{lg:()=>G,xI:()=>ne});class i{constructor(e,t,s){this.eventTarget=e,this.eventName=t,this.eventOptions=s,this.unorderedBindings=new Set}connect(){this.eventTarget.addEventListener(this.eventName,this,this.eventOptions)}disconnect(){this.eventTarget.removeEventListener(this.eventName,this,this.eventOptions)}bindingConnected(e){this.unorderedBindings.add(e)}bindingDisconnected(e){this.unorderedBindings.delete(e)}handleEvent(e){const t=function(e){if("immediatePropagationStopped"in e)return e;{const{stopImmediatePropagation:t}=e;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e);for(const e of this.bindings){if(t.immediatePropagationStopped)break;e.handleEvent(t)}}hasBindings(){return this.unorderedBindings.size>0}get bindings(){return Array.from(this.unorderedBindings).sort((e,t)=>{const s=e.index,i=t.index;return si?1:0})}}class n{constructor(e){this.application=e,this.eventListenerMaps=new Map,this.started=!1}start(){this.started||(this.started=!0,this.eventListeners.forEach(e=>e.connect()))}stop(){this.started&&(this.started=!1,this.eventListeners.forEach(e=>e.disconnect()))}get eventListeners(){return Array.from(this.eventListenerMaps.values()).reduce((e,t)=>e.concat(Array.from(t.values())),[])}bindingConnected(e){this.fetchEventListenerForBinding(e).bindingConnected(e)}bindingDisconnected(e,t=!1){this.fetchEventListenerForBinding(e).bindingDisconnected(e),t&&this.clearEventListenersForBinding(e)}handleError(e,t,s={}){this.application.handleError(e,`Error ${t}`,s)}clearEventListenersForBinding(e){const t=this.fetchEventListenerForBinding(e);t.hasBindings()||(t.disconnect(),this.removeMappedEventListenerFor(e))}removeMappedEventListenerFor(e){const{eventTarget:t,eventName:s,eventOptions:i}=e,n=this.fetchEventListenerMapForEventTarget(t),r=this.cacheKey(s,i);n.delete(r),0==n.size&&this.eventListenerMaps.delete(t)}fetchEventListenerForBinding(e){const{eventTarget:t,eventName:s,eventOptions:i}=e;return this.fetchEventListener(t,s,i)}fetchEventListener(e,t,s){const i=this.fetchEventListenerMapForEventTarget(e),n=this.cacheKey(t,s);let r=i.get(n);return r||(r=this.createEventListener(e,t,s),i.set(n,r)),r}createEventListener(e,t,s){const n=new i(e,t,s);return this.started&&n.connect(),n}fetchEventListenerMapForEventTarget(e){let t=this.eventListenerMaps.get(e);return t||(t=new Map,this.eventListenerMaps.set(e,t)),t}cacheKey(e,t){const s=[e];return Object.keys(t).sort().forEach(e=>{s.push(`${t[e]?"":"!"}${e}`)}),s.join(":")}}const r={stop:({event:e,value:t})=>(t&&e.stopPropagation(),!0),prevent:({event:e,value:t})=>(t&&e.preventDefault(),!0),self:({event:e,value:t,element:s})=>!t||s===e.target},o=/^(?:(?:([^.]+?)\+)?(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;function a(e){return e.replace(/(?:[_-])([a-z0-9])/g,(e,t)=>t.toUpperCase())}function c(e){return a(e.replace(/--/g,"-").replace(/__/g,"_"))}function l(e){return e.charAt(0).toUpperCase()+e.slice(1)}function h(e){return e.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`)}function u(e){return null!=e}function d(e,t){return Object.prototype.hasOwnProperty.call(e,t)}const p=["meta","ctrl","alt","shift"];class m{constructor(e,t,s,i){this.element=e,this.index=t,this.eventTarget=s.eventTarget||e,this.eventName=s.eventName||function(e){const t=e.tagName.toLowerCase();if(t in g)return g[t](e)}(e)||f("missing event name"),this.eventOptions=s.eventOptions||{},this.identifier=s.identifier||f("missing identifier"),this.methodName=s.methodName||f("missing method name"),this.keyFilter=s.keyFilter||"",this.schema=i}static forToken(e,t){return new this(e.element,e.index,function(e){const t=e.trim().match(o)||[];let s=t[2],i=t[3];return i&&!["keydown","keyup","keypress"].includes(s)&&(s+=`.${i}`,i=""),{eventTarget:(n=t[4],"window"==n?window:"document"==n?document:void 0),eventName:s,eventOptions:t[7]?(r=t[7],r.split(":").reduce((e,t)=>Object.assign(e,{[t.replace(/^!/,"")]:!/^!/.test(t)}),{})):{},identifier:t[5],methodName:t[6],keyFilter:t[1]||i};var n,r}(e.content),t)}toString(){const e=this.keyFilter?`.${this.keyFilter}`:"",t=this.eventTargetName?`@${this.eventTargetName}`:"";return`${this.eventName}${e}${t}->${this.identifier}#${this.methodName}`}shouldIgnoreKeyboardEvent(e){if(!this.keyFilter)return!1;const t=this.keyFilter.split("+");if(this.keyFilterDissatisfied(e,t))return!0;const s=t.filter(e=>!p.includes(e))[0];return!!s&&(d(this.keyMappings,s)||f(`contains unknown key filter: ${this.keyFilter}`),this.keyMappings[s].toLowerCase()!==e.key.toLowerCase())}shouldIgnoreMouseEvent(e){if(!this.keyFilter)return!1;const t=[this.keyFilter];return!!this.keyFilterDissatisfied(e,t)}get params(){const e={},t=new RegExp(`^data-${this.identifier}-(.+)-param$`,"i");for(const{name:s,value:i}of Array.from(this.element.attributes)){const n=s.match(t),r=n&&n[1];r&&(e[a(r)]=b(i))}return e}get eventTargetName(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e}get keyMappings(){return this.schema.keyMappings}keyFilterDissatisfied(e,t){const[s,i,n,r]=p.map(e=>t.includes(e));return e.metaKey!==s||e.ctrlKey!==i||e.altKey!==n||e.shiftKey!==r}}const g={a:()=>"click",button:()=>"click",form:()=>"submit",details:()=>"toggle",input:e=>"submit"==e.getAttribute("type")?"click":"input",select:()=>"change",textarea:()=>"input"};function f(e){throw new Error(e)}function b(e){try{return JSON.parse(e)}catch(t){return e}}class y{constructor(e,t){this.context=e,this.action=t}get index(){return this.action.index}get eventTarget(){return this.action.eventTarget}get eventOptions(){return this.action.eventOptions}get identifier(){return this.context.identifier}handleEvent(e){const t=this.prepareActionEvent(e);this.willBeInvokedByEvent(e)&&this.applyEventModifiers(t)&&this.invokeWithEvent(t)}get eventName(){return this.action.eventName}get method(){const e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`)}applyEventModifiers(e){const{element:t}=this.action,{actionDescriptorFilters:s}=this.context.application,{controller:i}=this.context;let n=!0;for(const[r,o]of Object.entries(this.eventOptions))if(r in s){const a=s[r];n=n&&a({name:r,value:o,event:e,element:t,controller:i})}return n}prepareActionEvent(e){return Object.assign(e,{params:this.action.params})}invokeWithEvent(e){const{target:t,currentTarget:s}=e;try{this.method.call(this.controller,e),this.context.logDebugActivity(this.methodName,{event:e,target:t,currentTarget:s,action:this.methodName})}catch(t){const{identifier:s,controller:i,element:n,index:r}=this,o={identifier:s,controller:i,element:n,index:r,event:e};this.context.handleError(t,`invoking action "${this.action}"`,o)}}willBeInvokedByEvent(e){const t=e.target;return!(e instanceof KeyboardEvent&&this.action.shouldIgnoreKeyboardEvent(e))&&!(e instanceof MouseEvent&&this.action.shouldIgnoreMouseEvent(e))&&(this.element===t||(t instanceof Element&&this.element.contains(t)?this.scope.containsElement(t):this.scope.containsElement(this.action.element)))}get controller(){return this.context.controller}get methodName(){return this.action.methodName}get element(){return this.scope.element}get scope(){return this.context.scope}}class v{constructor(e,t){this.mutationObserverInit={attributes:!0,childList:!0,subtree:!0},this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,this.mutationObserverInit),this.refresh())}pause(e){this.started&&(this.mutationObserver.disconnect(),this.started=!1),e(),this.started||(this.mutationObserver.observe(this.element,this.mutationObserverInit),this.started=!0)}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started){const e=new Set(this.matchElementsInTree());for(const t of Array.from(this.elements))e.has(t)||this.removeElement(t);for(const t of Array.from(e))this.addElement(t)}}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){"attributes"==e.type?this.processAttributeChange(e.target,e.attributeName):"childList"==e.type&&(this.processRemovedNodes(e.removedNodes),this.processAddedNodes(e.addedNodes))}processAttributeChange(e,t){this.elements.has(e)?this.delegate.elementAttributeChanged&&this.matchElement(e)?this.delegate.elementAttributeChanged(e,t):this.removeElement(e):this.matchElement(e)&&this.addElement(e)}processRemovedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.processTree(e,this.removeElement)}}processAddedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.elementIsActive(e)&&this.processTree(e,this.addElement)}}matchElement(e){return this.delegate.matchElement(e)}matchElementsInTree(e=this.element){return this.delegate.matchElementsInTree(e)}processTree(e,t){for(const s of this.matchElementsInTree(e))t.call(this,s)}elementFromNode(e){if(e.nodeType==Node.ELEMENT_NODE)return e}elementIsActive(e){return e.isConnected==this.element.isConnected&&this.element.contains(e)}addElement(e){this.elements.has(e)||this.elementIsActive(e)&&(this.elements.add(e),this.delegate.elementMatched&&this.delegate.elementMatched(e))}removeElement(e){this.elements.has(e)&&(this.elements.delete(e),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(e))}}class w{constructor(e,t,s){this.attributeName=t,this.delegate=s,this.elementObserver=new v(e,this)}get element(){return this.elementObserver.element}get selector(){return`[${this.attributeName}]`}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get started(){return this.elementObserver.started}matchElement(e){return e.hasAttribute(this.attributeName)}matchElementsInTree(e){const t=this.matchElement(e)?[e]:[],s=Array.from(e.querySelectorAll(this.selector));return t.concat(s)}elementMatched(e){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(e,this.attributeName)}elementUnmatched(e){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(e,this.attributeName)}elementAttributeChanged(e,t){this.delegate.elementAttributeValueChanged&&this.attributeName==t&&this.delegate.elementAttributeValueChanged(e,t)}}function T(e,t){let s=e.get(t);return s||(s=new Set,e.set(t,s)),s}class S{constructor(){this.valuesByKey=new Map}get keys(){return Array.from(this.valuesByKey.keys())}get values(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e.concat(Array.from(t)),[])}get size(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e+t.size,0)}add(e,t){!function(e,t,s){T(e,t).add(s)}(this.valuesByKey,e,t)}delete(e,t){!function(e,t,s){T(e,t).delete(s),function(e,t){const s=e.get(t);null!=s&&0==s.size&&e.delete(t)}(e,t)}(this.valuesByKey,e,t)}has(e,t){const s=this.valuesByKey.get(e);return null!=s&&s.has(t)}hasKey(e){return this.valuesByKey.has(e)}hasValue(e){return Array.from(this.valuesByKey.values()).some(t=>t.has(e))}getValuesForKey(e){const t=this.valuesByKey.get(e);return t?Array.from(t):[]}getKeysForValue(e){return Array.from(this.valuesByKey).filter(([t,s])=>s.has(e)).map(([e,t])=>e)}}class C{constructor(e,t,s,i){this._selector=t,this.details=i,this.elementObserver=new v(e,this),this.delegate=s,this.matchesByElement=new S}get started(){return this.elementObserver.started}get selector(){return this._selector}set selector(e){this._selector=e,this.refresh()}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get element(){return this.elementObserver.element}matchElement(e){const{selector:t}=this;if(t){const s=e.matches(t);return this.delegate.selectorMatchElement?s&&this.delegate.selectorMatchElement(e,this.details):s}return!1}matchElementsInTree(e){const{selector:t}=this;if(t){const s=this.matchElement(e)?[e]:[],i=Array.from(e.querySelectorAll(t)).filter(e=>this.matchElement(e));return s.concat(i)}return[]}elementMatched(e){const{selector:t}=this;t&&this.selectorMatched(e,t)}elementUnmatched(e){const t=this.matchesByElement.getKeysForValue(e);for(const s of t)this.selectorUnmatched(e,s)}elementAttributeChanged(e,t){const{selector:s}=this;if(s){const t=this.matchElement(e),i=this.matchesByElement.has(s,e);t&&!i?this.selectorMatched(e,s):!t&&i&&this.selectorUnmatched(e,s)}}selectorMatched(e,t){this.delegate.selectorMatched(e,t,this.details),this.matchesByElement.add(t,e)}selectorUnmatched(e,t){this.delegate.selectorUnmatched(e,t,this.details),this.matchesByElement.delete(t,e)}}class O{constructor(e,t){this.element=e,this.delegate=t,this.started=!1,this.stringMap=new Map,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,attributeOldValue:!0}),this.refresh())}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started)for(const e of this.knownAttributeNames)this.refreshAttribute(e,null)}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){const t=e.attributeName;t&&this.refreshAttribute(t,e.oldValue)}refreshAttribute(e,t){const s=this.delegate.getStringMapKeyForAttribute(e);if(null!=s){this.stringMap.has(e)||this.stringMapKeyAdded(s,e);const i=this.element.getAttribute(e);if(this.stringMap.get(e)!=i&&this.stringMapValueChanged(i,s,t),null==i){const t=this.stringMap.get(e);this.stringMap.delete(e),t&&this.stringMapKeyRemoved(s,e,t)}else this.stringMap.set(e,i)}}stringMapKeyAdded(e,t){this.delegate.stringMapKeyAdded&&this.delegate.stringMapKeyAdded(e,t)}stringMapValueChanged(e,t,s){this.delegate.stringMapValueChanged&&this.delegate.stringMapValueChanged(e,t,s)}stringMapKeyRemoved(e,t,s){this.delegate.stringMapKeyRemoved&&this.delegate.stringMapKeyRemoved(e,t,s)}get knownAttributeNames(){return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)))}get currentAttributeNames(){return Array.from(this.element.attributes).map(e=>e.name)}get recordedAttributeNames(){return Array.from(this.stringMap.keys())}}class E{constructor(e,t,s){this.attributeObserver=new w(e,t,this),this.delegate=s,this.tokensByElement=new S}get started(){return this.attributeObserver.started}start(){this.attributeObserver.start()}pause(e){this.attributeObserver.pause(e)}stop(){this.attributeObserver.stop()}refresh(){this.attributeObserver.refresh()}get element(){return this.attributeObserver.element}get attributeName(){return this.attributeObserver.attributeName}elementMatchedAttribute(e){this.tokensMatched(this.readTokensForElement(e))}elementAttributeValueChanged(e){const[t,s]=this.refreshTokensForElement(e);this.tokensUnmatched(t),this.tokensMatched(s)}elementUnmatchedAttribute(e){this.tokensUnmatched(this.tokensByElement.getValuesForKey(e))}tokensMatched(e){e.forEach(e=>this.tokenMatched(e))}tokensUnmatched(e){e.forEach(e=>this.tokenUnmatched(e))}tokenMatched(e){this.delegate.tokenMatched(e),this.tokensByElement.add(e.element,e)}tokenUnmatched(e){this.delegate.tokenUnmatched(e),this.tokensByElement.delete(e.element,e)}refreshTokensForElement(e){const t=this.tokensByElement.getValuesForKey(e),s=this.readTokensForElement(e),i=function(e,t){const s=Math.max(e.length,t.length);return Array.from({length:s},(s,i)=>[e[i],t[i]])}(t,s).findIndex(([e,t])=>{return i=t,!((s=e)&&i&&s.index==i.index&&s.content==i.content);var s,i});return-1==i?[[],[]]:[t.slice(i),s.slice(i)]}readTokensForElement(e){const t=this.attributeName;return function(e,t,s){return e.trim().split(/\s+/).filter(e=>e.length).map((e,i)=>({element:t,attributeName:s,content:e,index:i}))}(e.getAttribute(t)||"",e,t)}}class A{constructor(e,t,s){this.tokenListObserver=new E(e,t,this),this.delegate=s,this.parseResultsByToken=new WeakMap,this.valuesByTokenByElement=new WeakMap}get started(){return this.tokenListObserver.started}start(){this.tokenListObserver.start()}stop(){this.tokenListObserver.stop()}refresh(){this.tokenListObserver.refresh()}get element(){return this.tokenListObserver.element}get attributeName(){return this.tokenListObserver.attributeName}tokenMatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).set(e,s),this.delegate.elementMatchedValue(t,s))}tokenUnmatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).delete(e),this.delegate.elementUnmatchedValue(t,s))}fetchParseResultForToken(e){let t=this.parseResultsByToken.get(e);return t||(t=this.parseToken(e),this.parseResultsByToken.set(e,t)),t}fetchValuesByTokenForElement(e){let t=this.valuesByTokenByElement.get(e);return t||(t=new Map,this.valuesByTokenByElement.set(e,t)),t}parseToken(e){try{return{value:this.delegate.parseValueForToken(e)}}catch(e){return{error:e}}}}class x{constructor(e,t){this.context=e,this.delegate=t,this.bindingsByAction=new Map}start(){this.valueListObserver||(this.valueListObserver=new A(this.element,this.actionAttribute,this),this.valueListObserver.start())}stop(){this.valueListObserver&&(this.valueListObserver.stop(),delete this.valueListObserver,this.disconnectAllActions())}get element(){return this.context.element}get identifier(){return this.context.identifier}get actionAttribute(){return this.schema.actionAttribute}get schema(){return this.context.schema}get bindings(){return Array.from(this.bindingsByAction.values())}connectAction(e){const t=new y(this.context,e);this.bindingsByAction.set(e,t),this.delegate.bindingConnected(t)}disconnectAction(e){const t=this.bindingsByAction.get(e);t&&(this.bindingsByAction.delete(e),this.delegate.bindingDisconnected(t))}disconnectAllActions(){this.bindings.forEach(e=>this.delegate.bindingDisconnected(e,!0)),this.bindingsByAction.clear()}parseValueForToken(e){const t=m.forToken(e,this.schema);if(t.identifier==this.identifier)return t}elementMatchedValue(e,t){this.connectAction(t)}elementUnmatchedValue(e,t){this.disconnectAction(t)}}class M{constructor(e,t){this.context=e,this.receiver=t,this.stringMapObserver=new O(this.element,this),this.valueDescriptorMap=this.controller.valueDescriptorMap}start(){this.stringMapObserver.start(),this.invokeChangedCallbacksForDefaultValues()}stop(){this.stringMapObserver.stop()}get element(){return this.context.element}get controller(){return this.context.controller}getStringMapKeyForAttribute(e){if(e in this.valueDescriptorMap)return this.valueDescriptorMap[e].name}stringMapKeyAdded(e,t){const s=this.valueDescriptorMap[t];this.hasValue(e)||this.invokeChangedCallback(e,s.writer(this.receiver[e]),s.writer(s.defaultValue))}stringMapValueChanged(e,t,s){const i=this.valueDescriptorNameMap[t];null!==e&&(null===s&&(s=i.writer(i.defaultValue)),this.invokeChangedCallback(t,e,s))}stringMapKeyRemoved(e,t,s){const i=this.valueDescriptorNameMap[e];this.hasValue(e)?this.invokeChangedCallback(e,i.writer(this.receiver[e]),s):this.invokeChangedCallback(e,i.writer(i.defaultValue),s)}invokeChangedCallbacksForDefaultValues(){for(const{key:e,name:t,defaultValue:s,writer:i}of this.valueDescriptors)null==s||this.controller.data.has(e)||this.invokeChangedCallback(t,i(s),void 0)}invokeChangedCallback(e,t,s){const i=`${e}Changed`,n=this.receiver[i];if("function"==typeof n){const i=this.valueDescriptorNameMap[e];try{const e=i.reader(t);let r=s;s&&(r=i.reader(s)),n.call(this.receiver,e,r)}catch(e){throw e instanceof TypeError&&(e.message=`Stimulus Value "${this.context.identifier}.${i.name}" - ${e.message}`),e}}}get valueDescriptors(){const{valueDescriptorMap:e}=this;return Object.keys(e).map(t=>e[t])}get valueDescriptorNameMap(){const e={};return Object.keys(this.valueDescriptorMap).forEach(t=>{const s=this.valueDescriptorMap[t];e[s.name]=s}),e}hasValue(e){const t=`has${l(this.valueDescriptorNameMap[e].name)}`;return this.receiver[t]}}class k{constructor(e,t){this.context=e,this.delegate=t,this.targetsByName=new S}start(){this.tokenListObserver||(this.tokenListObserver=new E(this.element,this.attributeName,this),this.tokenListObserver.start())}stop(){this.tokenListObserver&&(this.disconnectAllTargets(),this.tokenListObserver.stop(),delete this.tokenListObserver)}tokenMatched({element:e,content:t}){this.scope.containsElement(e)&&this.connectTarget(e,t)}tokenUnmatched({element:e,content:t}){this.disconnectTarget(e,t)}connectTarget(e,t){var s;this.targetsByName.has(t,e)||(this.targetsByName.add(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetConnected(e,t)))}disconnectTarget(e,t){var s;this.targetsByName.has(t,e)&&(this.targetsByName.delete(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetDisconnected(e,t)))}disconnectAllTargets(){for(const e of this.targetsByName.keys)for(const t of this.targetsByName.getValuesForKey(e))this.disconnectTarget(t,e)}get attributeName(){return`data-${this.context.identifier}-target`}get element(){return this.context.element}get scope(){return this.context.scope}}function I(e,t){const s=L(e);return Array.from(s.reduce((e,s)=>(function(e,t){const s=e[t];return Array.isArray(s)?s:[]}(s,t).forEach(t=>e.add(t)),e),new Set))}function L(e){const t=[];for(;e;)t.push(e),e=Object.getPrototypeOf(e);return t.reverse()}class P{constructor(e,t){this.started=!1,this.context=e,this.delegate=t,this.outletsByName=new S,this.outletElementsByName=new S,this.selectorObserverMap=new Map,this.attributeObserverMap=new Map}start(){this.started||(this.outletDefinitions.forEach(e=>{this.setupSelectorObserverForOutlet(e),this.setupAttributeObserverForOutlet(e)}),this.started=!0,this.dependentContexts.forEach(e=>e.refresh()))}refresh(){this.selectorObserverMap.forEach(e=>e.refresh()),this.attributeObserverMap.forEach(e=>e.refresh())}stop(){this.started&&(this.started=!1,this.disconnectAllOutlets(),this.stopSelectorObservers(),this.stopAttributeObservers())}stopSelectorObservers(){this.selectorObserverMap.size>0&&(this.selectorObserverMap.forEach(e=>e.stop()),this.selectorObserverMap.clear())}stopAttributeObservers(){this.attributeObserverMap.size>0&&(this.attributeObserverMap.forEach(e=>e.stop()),this.attributeObserverMap.clear())}selectorMatched(e,t,{outletName:s}){const i=this.getOutlet(e,s);i&&this.connectOutlet(i,e,s)}selectorUnmatched(e,t,{outletName:s}){const i=this.getOutletFromMap(e,s);i&&this.disconnectOutlet(i,e,s)}selectorMatchElement(e,{outletName:t}){const s=this.selector(t),i=this.hasOutlet(e,t),n=e.matches(`[${this.schema.controllerAttribute}~=${t}]`);return!!s&&i&&n&&e.matches(s)}elementMatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementAttributeValueChanged(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementUnmatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}connectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)||(this.outletsByName.add(s,e),this.outletElementsByName.add(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletConnected(e,t,s)))}disconnectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)&&(this.outletsByName.delete(s,e),this.outletElementsByName.delete(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletDisconnected(e,t,s)))}disconnectAllOutlets(){for(const e of this.outletElementsByName.keys)for(const t of this.outletElementsByName.getValuesForKey(e))for(const s of this.outletsByName.getValuesForKey(e))this.disconnectOutlet(s,t,e)}updateSelectorObserverForOutlet(e){const t=this.selectorObserverMap.get(e);t&&(t.selector=this.selector(e))}setupSelectorObserverForOutlet(e){const t=this.selector(e),s=new C(document.body,t,this,{outletName:e});this.selectorObserverMap.set(e,s),s.start()}setupAttributeObserverForOutlet(e){const t=this.attributeNameForOutletName(e),s=new w(this.scope.element,t,this);this.attributeObserverMap.set(e,s),s.start()}selector(e){return this.scope.outlets.getSelectorForOutletName(e)}attributeNameForOutletName(e){return this.scope.schema.outletAttributeForScope(this.identifier,e)}getOutletNameFromOutletAttributeName(e){return this.outletDefinitions.find(t=>this.attributeNameForOutletName(t)===e)}get outletDependencies(){const e=new S;return this.router.modules.forEach(t=>{I(t.definition.controllerConstructor,"outlets").forEach(s=>e.add(s,t.identifier))}),e}get outletDefinitions(){return this.outletDependencies.getKeysForValue(this.identifier)}get dependentControllerIdentifiers(){return this.outletDependencies.getValuesForKey(this.identifier)}get dependentContexts(){const e=this.dependentControllerIdentifiers;return this.router.contexts.filter(t=>e.includes(t.identifier))}hasOutlet(e,t){return!!this.getOutlet(e,t)||!!this.getOutletFromMap(e,t)}getOutlet(e,t){return this.application.getControllerForElementAndIdentifier(e,t)}getOutletFromMap(e,t){return this.outletsByName.getValuesForKey(t).find(t=>t.element===e)}get scope(){return this.context.scope}get schema(){return this.context.schema}get identifier(){return this.context.identifier}get application(){return this.context.application}get router(){return this.application.router}}class _{constructor(e,t){this.logDebugActivity=(e,t={})=>{const{identifier:s,controller:i,element:n}=this;t=Object.assign({identifier:s,controller:i,element:n},t),this.application.logDebugActivity(this.identifier,e,t)},this.module=e,this.scope=t,this.controller=new e.controllerConstructor(this),this.bindingObserver=new x(this,this.dispatcher),this.valueObserver=new M(this,this.controller),this.targetObserver=new k(this,this),this.outletObserver=new P(this,this);try{this.controller.initialize(),this.logDebugActivity("initialize")}catch(e){this.handleError(e,"initializing controller")}}connect(){this.bindingObserver.start(),this.valueObserver.start(),this.targetObserver.start(),this.outletObserver.start();try{this.controller.connect(),this.logDebugActivity("connect")}catch(e){this.handleError(e,"connecting controller")}}refresh(){this.outletObserver.refresh()}disconnect(){try{this.controller.disconnect(),this.logDebugActivity("disconnect")}catch(e){this.handleError(e,"disconnecting controller")}this.outletObserver.stop(),this.targetObserver.stop(),this.valueObserver.stop(),this.bindingObserver.stop()}get application(){return this.module.application}get identifier(){return this.module.identifier}get schema(){return this.application.schema}get dispatcher(){return this.application.dispatcher}get element(){return this.scope.element}get parentElement(){return this.element.parentElement}handleError(e,t,s={}){const{identifier:i,controller:n,element:r}=this;s=Object.assign({identifier:i,controller:n,element:r},s),this.application.handleError(e,`Error ${t}`,s)}targetConnected(e,t){this.invokeControllerMethod(`${t}TargetConnected`,e)}targetDisconnected(e,t){this.invokeControllerMethod(`${t}TargetDisconnected`,e)}outletConnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletConnected`,e,t)}outletDisconnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletDisconnected`,e,t)}invokeControllerMethod(e,...t){const s=this.controller;"function"==typeof s[e]&&s[e](...t)}}const N="function"==typeof Object.getOwnPropertySymbols?e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)]:Object.getOwnPropertyNames,D=(()=>{function e(e){function t(){return Reflect.construct(e,arguments,new.target)}return t.prototype=Object.create(e.prototype,{constructor:{value:t}}),Reflect.setPrototypeOf(t,e),t}try{return function(){const t=e(function(){this.a.call(this)});t.prototype.a=function(){},new t}(),e}catch(e){return e=>class extends e{}}})();class F{constructor(e,t){this.application=e,this.definition=function(e){return{identifier:e.identifier,controllerConstructor:(t=e.controllerConstructor,function(e,t){const s=D(e),i=function(e,t){return N(t).reduce((s,i)=>{const n=function(e,t,s){const i=Object.getOwnPropertyDescriptor(e,s);if(!i||!("value"in i)){const e=Object.getOwnPropertyDescriptor(t,s).value;return i&&(e.get=i.get||e.get,e.set=i.set||e.set),e}}(e,t,i);return n&&Object.assign(s,{[i]:n}),s},{})}(e.prototype,t);return Object.defineProperties(s.prototype,i),s}(t,function(e){return I(e,"blessings").reduce((t,s)=>{const i=s(e);for(const e in i){const s=t[e]||{};t[e]=Object.assign(s,i[e])}return t},{})}(t)))};var t}(t),this.contextsByScope=new WeakMap,this.connectedContexts=new Set}get identifier(){return this.definition.identifier}get controllerConstructor(){return this.definition.controllerConstructor}get contexts(){return Array.from(this.connectedContexts)}connectContextForScope(e){const t=this.fetchContextForScope(e);this.connectedContexts.add(t),t.connect()}disconnectContextForScope(e){const t=this.contextsByScope.get(e);t&&(this.connectedContexts.delete(t),t.disconnect())}fetchContextForScope(e){let t=this.contextsByScope.get(e);return t||(t=new _(this,e),this.contextsByScope.set(e,t)),t}}class R{constructor(e){this.scope=e}has(e){return this.data.has(this.getDataKey(e))}get(e){return this.getAll(e)[0]}getAll(e){return(this.data.get(this.getDataKey(e))||"").match(/[^\s]+/g)||[]}getAttributeName(e){return this.data.getAttributeNameForKey(this.getDataKey(e))}getDataKey(e){return`${e}-class`}get data(){return this.scope.data}}class B{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get(e){const t=this.getAttributeNameForKey(e);return this.element.getAttribute(t)}set(e,t){const s=this.getAttributeNameForKey(e);return this.element.setAttribute(s,t),this.get(e)}has(e){const t=this.getAttributeNameForKey(e);return this.element.hasAttribute(t)}delete(e){if(this.has(e)){const t=this.getAttributeNameForKey(e);return this.element.removeAttribute(t),!0}return!1}getAttributeNameForKey(e){return`data-${this.identifier}-${h(e)}`}}class ${constructor(e){this.warnedKeysByObject=new WeakMap,this.logger=e}warn(e,t,s){let i=this.warnedKeysByObject.get(e);i||(i=new Set,this.warnedKeysByObject.set(e,i)),i.has(t)||(i.add(t),this.logger.warn(s,e))}}function j(e,t){return`[${e}~="${t}"]`}class V{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findTarget(t)||this.findLegacyTarget(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllTargets(t),...this.findAllLegacyTargets(t)],[])}findTarget(e){const t=this.getSelectorForTargetName(e);return this.scope.findElement(t)}findAllTargets(e){const t=this.getSelectorForTargetName(e);return this.scope.findAllElements(t)}getSelectorForTargetName(e){return j(this.schema.targetAttributeForScope(this.identifier),e)}findLegacyTarget(e){const t=this.getLegacySelectorForTargetName(e);return this.deprecate(this.scope.findElement(t),e)}findAllLegacyTargets(e){const t=this.getLegacySelectorForTargetName(e);return this.scope.findAllElements(t).map(t=>this.deprecate(t,e))}getLegacySelectorForTargetName(e){const t=`${this.identifier}.${e}`;return j(this.schema.targetAttribute,t)}deprecate(e,t){if(e){const{identifier:s}=this,i=this.schema.targetAttribute,n=this.schema.targetAttributeForScope(s);this.guide.warn(e,`target:${t}`,`Please replace ${i}="${s}.${t}" with ${n}="${t}". The ${i} attribute is deprecated and will be removed in a future version of Stimulus.`)}return e}get guide(){return this.scope.guide}}class q{constructor(e,t){this.scope=e,this.controllerElement=t}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findOutlet(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllOutlets(t)],[])}getSelectorForOutletName(e){const t=this.schema.outletAttributeForScope(this.identifier,e);return this.controllerElement.getAttribute(t)}findOutlet(e){const t=this.getSelectorForOutletName(e);if(t)return this.findElement(t,e)}findAllOutlets(e){const t=this.getSelectorForOutletName(e);return t?this.findAllElements(t,e):[]}findElement(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))[0]}findAllElements(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))}matchesElement(e,t,s){const i=e.getAttribute(this.scope.schema.controllerAttribute)||"";return e.matches(t)&&i.split(" ").includes(s)}}class U{constructor(e,t,s,i){this.targets=new V(this),this.classes=new R(this),this.data=new B(this),this.containsElement=e=>e.closest(this.controllerSelector)===this.element,this.schema=e,this.element=t,this.identifier=s,this.guide=new $(i),this.outlets=new q(this.documentScope,t)}findElement(e){return this.element.matches(e)?this.element:this.queryElements(e).find(this.containsElement)}findAllElements(e){return[...this.element.matches(e)?[this.element]:[],...this.queryElements(e).filter(this.containsElement)]}queryElements(e){return Array.from(this.element.querySelectorAll(e))}get controllerSelector(){return j(this.schema.controllerAttribute,this.identifier)}get isDocumentScope(){return this.element===document.documentElement}get documentScope(){return this.isDocumentScope?this:new U(this.schema,document.documentElement,this.identifier,this.guide.logger)}}class z{constructor(e,t,s){this.element=e,this.schema=t,this.delegate=s,this.valueListObserver=new A(this.element,this.controllerAttribute,this),this.scopesByIdentifierByElement=new WeakMap,this.scopeReferenceCounts=new WeakMap}start(){this.valueListObserver.start()}stop(){this.valueListObserver.stop()}get controllerAttribute(){return this.schema.controllerAttribute}parseValueForToken(e){const{element:t,content:s}=e;return this.parseValueForElementAndIdentifier(t,s)}parseValueForElementAndIdentifier(e,t){const s=this.fetchScopesByIdentifierForElement(e);let i=s.get(t);return i||(i=this.delegate.createScopeForElementAndIdentifier(e,t),s.set(t,i)),i}elementMatchedValue(e,t){const s=(this.scopeReferenceCounts.get(t)||0)+1;this.scopeReferenceCounts.set(t,s),1==s&&this.delegate.scopeConnected(t)}elementUnmatchedValue(e,t){const s=this.scopeReferenceCounts.get(t);s&&(this.scopeReferenceCounts.set(t,s-1),1==s&&this.delegate.scopeDisconnected(t))}fetchScopesByIdentifierForElement(e){let t=this.scopesByIdentifierByElement.get(e);return t||(t=new Map,this.scopesByIdentifierByElement.set(e,t)),t}}class W{constructor(e){this.application=e,this.scopeObserver=new z(this.element,this.schema,this),this.scopesByIdentifier=new S,this.modulesByIdentifier=new Map}get element(){return this.application.element}get schema(){return this.application.schema}get logger(){return this.application.logger}get controllerAttribute(){return this.schema.controllerAttribute}get modules(){return Array.from(this.modulesByIdentifier.values())}get contexts(){return this.modules.reduce((e,t)=>e.concat(t.contexts),[])}start(){this.scopeObserver.start()}stop(){this.scopeObserver.stop()}loadDefinition(e){this.unloadIdentifier(e.identifier);const t=new F(this.application,e);this.connectModule(t);const s=e.controllerConstructor.afterLoad;s&&s.call(e.controllerConstructor,e.identifier,this.application)}unloadIdentifier(e){const t=this.modulesByIdentifier.get(e);t&&this.disconnectModule(t)}getContextForElementAndIdentifier(e,t){const s=this.modulesByIdentifier.get(t);if(s)return s.contexts.find(t=>t.element==e)}proposeToConnectScopeForElementAndIdentifier(e,t){const s=this.scopeObserver.parseValueForElementAndIdentifier(e,t);s?this.scopeObserver.elementMatchedValue(s.element,s):console.error(`Couldn't find or create scope for identifier: "${t}" and element:`,e)}handleError(e,t,s){this.application.handleError(e,t,s)}createScopeForElementAndIdentifier(e,t){return new U(this.schema,e,t,this.logger)}scopeConnected(e){this.scopesByIdentifier.add(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.connectContextForScope(e)}scopeDisconnected(e){this.scopesByIdentifier.delete(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.disconnectContextForScope(e)}connectModule(e){this.modulesByIdentifier.set(e.identifier,e),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.connectContextForScope(t))}disconnectModule(e){this.modulesByIdentifier.delete(e.identifier),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.disconnectContextForScope(t))}}const K={controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target",targetAttributeForScope:e=>`data-${e}-target`,outletAttributeForScope:(e,t)=>`data-${e}-${t}-outlet`,keyMappings:Object.assign(Object.assign({enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"},H("abcdefghijklmnopqrstuvwxyz".split("").map(e=>[e,e]))),H("0123456789".split("").map(e=>[e,e])))};function H(e){return e.reduce((e,[t,s])=>Object.assign(Object.assign({},e),{[t]:s}),{})}class G{constructor(e=document.documentElement,t=K){this.logger=console,this.debug=!1,this.logDebugActivity=(e,t,s={})=>{this.debug&&this.logFormattedMessage(e,t,s)},this.element=e,this.schema=t,this.dispatcher=new n(this),this.router=new W(this),this.actionDescriptorFilters=Object.assign({},r)}static start(e,t){const s=new this(e,t);return s.start(),s}async start(){await new Promise(e=>{"loading"==document.readyState?document.addEventListener("DOMContentLoaded",()=>e()):e()}),this.logDebugActivity("application","starting"),this.dispatcher.start(),this.router.start(),this.logDebugActivity("application","start")}stop(){this.logDebugActivity("application","stopping"),this.dispatcher.stop(),this.router.stop(),this.logDebugActivity("application","stop")}register(e,t){this.load({identifier:e,controllerConstructor:t})}registerActionOption(e,t){this.actionDescriptorFilters[e]=t}load(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>{e.controllerConstructor.shouldLoad&&this.router.loadDefinition(e)})}unload(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>this.router.unloadIdentifier(e))}get controllers(){return this.router.contexts.map(e=>e.controller)}getControllerForElementAndIdentifier(e,t){const s=this.router.getContextForElementAndIdentifier(e,t);return s?s.controller:null}handleError(e,t,s){var i;this.logger.error("%s\n\n%o\n\n%o",t,e,s),null===(i=window.onerror)||void 0===i||i.call(window,t,"",0,0,e)}logFormattedMessage(e,t,s={}){s=Object.assign({application:this},s),this.logger.groupCollapsed(`${e} #${t}`),this.logger.log("details:",Object.assign({},s)),this.logger.groupEnd()}}function J(e,t,s){return e.application.getControllerForElementAndIdentifier(t,s)}function Y(e,t,s){let i=J(e,t,s);return i||(e.application.router.proposeToConnectScopeForElementAndIdentifier(t,s),i=J(e,t,s),i||void 0)}function Z([e,t],s){return function(e){const{token:t,typeDefinition:s}=e,i=`${h(t)}-value`,n=function(e){const{controller:t,token:s,typeDefinition:i}=e,n=function(e){const{controller:t,token:s,typeObject:i}=e,n=u(i.type),r=u(i.default),o=n&&r,a=n&&!r,c=!n&&r,l=X(i.type),h=Q(e.typeObject.default);if(a)return l;if(c)return h;if(l!==h)throw new Error(`The specified default value for the Stimulus Value "${t?`${t}.${s}`:s}" must match the defined type "${l}". The provided default value of "${i.default}" is of type "${h}".`);return o?l:void 0}({controller:t,token:s,typeObject:i}),r=Q(i),o=X(i),a=n||r||o;if(a)return a;throw new Error(`Unknown value type "${t?`${t}.${i}`:s}" for "${s}" value`)}(e);return{type:n,key:i,name:a(i),get defaultValue(){return function(e){const t=X(e);if(t)return ee[t];const s=d(e,"default"),i=d(e,"type"),n=e;if(s)return n.default;if(i){const{type:e}=n,t=X(e);if(t)return ee[t]}return e}(s)},get hasCustomDefaultValue(){return void 0!==Q(s)},reader:te[n],writer:se[n]||se.default}}({controller:s,token:e,typeDefinition:t})}function X(e){switch(e){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function Q(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}return Array.isArray(e)?"array":"[object Object]"===Object.prototype.toString.call(e)?"object":void 0}const ee={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},te={array(e){const t=JSON.parse(e);if(!Array.isArray(t))throw new TypeError(`expected value of type "array" but instead got value "${e}" of type "${Q(t)}"`);return t},boolean:e=>!("0"==e||"false"==String(e).toLowerCase()),number:e=>Number(e.replace(/_/g,"")),object(e){const t=JSON.parse(e);if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`expected value of type "object" but instead got value "${e}" of type "${Q(t)}"`);return t},string:e=>e},se={default:function(e){return`${e}`},array:ie,object:ie};function ie(e){return JSON.stringify(e)}class ne{constructor(e){this.context=e}static get shouldLoad(){return!0}static afterLoad(e,t){}get application(){return this.context.application}get scope(){return this.context.scope}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get targets(){return this.scope.targets}get outlets(){return this.scope.outlets}get classes(){return this.scope.classes}get data(){return this.scope.data}initialize(){}connect(){}disconnect(){}dispatch(e,{target:t=this.element,detail:s={},prefix:i=this.identifier,bubbles:n=!0,cancelable:r=!0}={}){const o=new CustomEvent(i?`${i}:${e}`:e,{detail:s,bubbles:n,cancelable:r});return t.dispatchEvent(o),o}}ne.blessings=[function(e){return I(e,"classes").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Class`]:{get(){const{classes:e}=this;if(e.has(s))return e.get(s);{const t=e.getAttributeName(s);throw new Error(`Missing attribute "${t}"`)}}},[`${s}Classes`]:{get(){return this.classes.getAll(s)}},[`has${l(s)}Class`]:{get(){return this.classes.has(s)}}}));var s},{})},function(e){return I(e,"targets").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Target`]:{get(){const e=this.targets.find(s);if(e)return e;throw new Error(`Missing target element "${s}" for "${this.identifier}" controller`)}},[`${s}Targets`]:{get(){return this.targets.findAll(s)}},[`has${l(s)}Target`]:{get(){return this.targets.has(s)}}}));var s},{})},function(e){const t=function(e,t){return L(e).reduce((e,s)=>(e.push(...function(e,t){const s=e[t];return s?Object.keys(s).map(e=>[e,s[e]]):[]}(s,t)),e),[])}(e,"values"),s={valueDescriptorMap:{get(){return t.reduce((e,t)=>{const s=Z(t,this.identifier),i=this.data.getAttributeNameForKey(s.key);return Object.assign(e,{[i]:s})},{})}}};return t.reduce((e,t)=>Object.assign(e,function(e){const t=Z(e,void 0),{key:s,name:i,reader:n,writer:r}=t;return{[i]:{get(){const e=this.data.get(s);return null!==e?n(e):t.defaultValue},set(e){void 0===e?this.data.delete(s):this.data.set(s,r(e))}},[`has${l(i)}`]:{get(){return this.data.has(s)||t.hasCustomDefaultValue}}}}(t)),s)},function(e){return I(e,"outlets").reduce((e,t)=>Object.assign(e,function(e){const t=c(e);return{[`${t}Outlet`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t){const s=Y(this,t,e);if(s)return s;throw new Error(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`)}throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}Outlets`]:{get(){const t=this.outlets.findAll(e);return t.length>0?t.map(t=>{const s=Y(this,t,e);if(s)return s;console.warn(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`,t)}).filter(e=>e):[]}},[`${t}OutletElement`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t)return t;throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}OutletElements`]:{get(){return this.outlets.findAll(e)}},[`has${l(t)}Outlet`]:{get(){return this.outlets.has(e)}}}}(t)),{})}],ne.targets=[],ne.outlets=[],ne.values={}},290(e,t,s){s.d(t,{default:()=>ci});var i=s(891);class n extends Error{constructor(e){super(`${e} is not valid. Please provide a valid event name`),this.name="InvalidEvent"}}class r{static events=["session-set","utm-set","forms:collected","form:completed","popup:mounted","popup:opened","popup:closed","alert:shown","alert:dismissed","alert:accepted","webchat:mounted","webchat:opened","webchat:closed","webchat:message:sent","webchat:message:received","cart.added"];static valid(e){return r.exists(e)}static invalid(e){return!this.valid(e)}static exists(e){return void 0!==this.events.find(t=>t===e)}constructor(){this.subscribers={}}addSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers={...this.subscribers,[e]:this.subscribers[e]?[...this.subscribers[e],t]:[t]}}removeSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers[e]&&(this.subscribers[e]=this.subscribers[e].filter(e=>e!==t))}dispatch(e,t){this.subscribers[e]?.forEach(e=>{e(t)})}get listeners(){return 0!==Object.keys(this.subscribers).length}}class o{static autoMount=!0;static successMessage=!0;static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static get shouldShowSuccessMessage(){return this.successMessage}}class a{static _identifier;static set identifier(e){this._identifier=e}static get identifier(){return this._identifier?this._identifier:this.#e||this.#t||this.#s||"en"}static toString(){return this.identifier}static get#e(){return"undefined"!=typeof document?document.documentElement?.lang:void 0}static get#t(){return"undefined"!=typeof document?document.querySelector('meta[name="locale"]')?.content:void 0}static get#s(){return"undefined"!=typeof navigator?navigator.language?.split("-")[0]:void 0}}class c{static _id;static _container="body";static _device="auto";static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set device(e){if(!["auto","mobile","desktop"].includes(e))throw new Error(`Invalid popup device value: ${e}`);this._device=e}static get device(){return this._device}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}}const l={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"},h={ABSOLUTE:"absolute",FIXED:"fixed"},u={MODAL:"modal",POPOVER:"popover"};class d{static _id;static _container="body";static _placement="bottom-right";static _style={};static _appearance={};static _whatsapp={};static _mode=u.POPOVER;static _behaviour=null;static _hasBehaviourOverride=!1;static _strategy=null;static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(l).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static set id(e){this._id=e}static get id(){return this._id}static get isSet(){return!!this._id}static get style(){return this._style}static set style(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(([e,t])=>{if(!["primaryColor","secondaryColor","typography"].includes(e))throw new Error(`Invalid style property: ${e}`);if("typography"!==e&&!this.isHexOrRgba(t))throw new Error(`Invalid color value: ${t} for ${e}. Colors must be hex or rgb/a.`)}),this._style=e}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if(!["header","launcher"].includes(e))throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("header"===e&&"name"!==t)throw new Error(`Invalid appearance header property: ${t}`);if("launcher"===e&&"iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get whatsapp(){return this._whatsapp}static set whatsapp(e){if(!this.isPlainObject(e))throw new Error("WhatsApp must be an object");Object.entries(e).forEach(([e,t])=>{if(!["number","restrictToChannel"].includes(e))throw new Error(`Invalid WhatsApp property: ${e}`);if(null!=t){if("number"===e&&"string"!=typeof t)throw new Error(`Invalid WhatsApp number value: ${t}`);if("restrictToChannel"===e&&"boolean"!=typeof t)throw new Error(`Invalid WhatsApp restrictToChannel value: ${t}`)}}),this._whatsapp=e}static get mode(){return this._mode}static set mode(e){if(!Object.values(u).includes(e))throw new Error(`Invalid mode value: ${e}`);this._mode=e}static get behaviour(){return this._behaviour}static set behaviour(e){if(null!=e){if("object"!=typeof e||Array.isArray(e))throw new Error(`Invalid behaviour value: ${e}`);this._behaviour=e}else this._behaviour=e}static get hasBehaviourOverride(){return this._hasBehaviourOverride}static set behaviourOverride(e){this._hasBehaviourOverride=!!e}static get strategy(){return this._strategy?this._strategy:"body"==this.container?h.FIXED:h.ABSOLUTE}static set strategy(e){if(e&&!Object.values(h).includes(e))throw new Error(`Invalid strategy value: ${e}`);this._strategy=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isHexOrRgba(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}const p={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"};class m{static _id;static _container="body";static _placement="bottom-right";static _appearance={};static _number=null;static _body=null;static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(p).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if("launcher"!==e)throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get number(){return this._number}static set number(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid number value: ${e}`);this._number=e}static get body(){return this._body}static set body(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid body value: ${e}`);this._body=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}class g{static serviceWorkerUrl=null;static channelId=null;static assign(e){return this.serviceWorkerUrl=e?.serviceWorkerUrl||null,this.channelId=e?.channelId||null,this}}class f{static apiRoot="https://api.hellotext.com/v1";static actionCableUrl="wss://www.hellotext.com/cable";static autoGenerateSession=!0;static session=null;static forms=o;static popup=c;static webchat=d;static whatsapp=m;static push=g;static assign(e){if(e){const t=Object.prototype.hasOwnProperty.call(e,"apiRoot")&&!Object.prototype.hasOwnProperty.call(e,"actionCableUrl");Object.entries(e).forEach(([e,t])=>{"forms"===e?this.forms=o.assign(t):"popup"===e?this.popup=c.assign(t):"webchat"===e?this.webchat=d.assign(t):"whatsappWidget"===e?this.whatsapp=m.assign(t):"push"===e?this.push=g.assign(t):this[e]=t}),t&&(this.actionCableUrl=this.actionCableUrlForApiRoot(this.apiRoot))}return this}static set locale(e){a.identifier=e}static get locale(){return a.toString()}static endpoint(e){return`${this.apiRoot}/${e}`}static actionCableUrlForApiRoot(e){try{const t=new URL(e),s="https:"===t.protocol?"wss:":"ws:";return t.protocol=s,t.pathname="/cable",t.search="",t.hash="",t.toString()}catch(e){return this.actionCableUrl}}}const b=class{static get endpoint(){return f.endpoint("public/businesses")}static async get(e){return fetch(`${this.endpoint}/${e}`,{method:"GET",headers:{Authorization:`Bearer ${e}`,Accept:"application/json","Content-Type":"application/json"}})}};class y{static get inPreviewMode(){return(new this).inPreviewMode}constructor(){this.urlSearchParams=new URLSearchParams(window.location.search)}get(e){return this.urlSearchParams.get(this.toHellotextParam(e))}has(e){return this.urlSearchParams.has(this.toHellotextParam(e))}get inPreviewMode(){return this.has("preview")}get session(){return this.get("session")}toHellotextParam(e){return`hello_${e}`}}class v{#i;constructor(e,t){this.response=t,this.#i=e}get data(){return this.response}async json(){return await this.response.json()}get failed(){return!1===this.#i}get succeeded(){return!0===this.#i}}class w{static get endpoint(){return f.endpoint("track/events")}static async create({headers:e,body:t,keepalive:s=!1}){if(y.inPreviewMode)return new v(!0,{received:!0});const i={method:"POST",headers:e,body:JSON.stringify(t)};s&&(i.keepalive=!0);const n=await fetch(this.endpoint,i);return new v(200===n.status,await n.json())}}class T{static get endpoint(){return f.endpoint("public/forms")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);return t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),fetch(t,{method:"GET",headers:vt.headers})}static async submit(e,t){const s=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...t})});return new v(s.ok,s)}}const S=class{static get endpoint(){return f.endpoint("public/identifications")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...e})});return new v(t.ok,t)}},C=class{static get endpoint(){return f.endpoint("public/popups")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),t.searchParams.append("device",this.runtimeDevice);const s=await this.fetchPopup(t);if(!s.ok)return null;const i=await this.parsePopupResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static async submit(e,t,s=this.idempotencyKey()){const i=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:{...vt.headers,"Idempotency-Key":s},body:JSON.stringify({session:vt.session,popup_submission:t})});return new v(i.ok,i)}static async resend(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/resend`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static async cancel(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/cancel`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static idempotencyKey(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}static async fetchPopup(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static get runtimeDevice(){return"auto"!==f.popup.device?f.popup.device:window.innerWidth<=767?"mobile":"desktop"}static async parsePopupResponse(e){try{return await e.json()}catch(e){return null}}},O=class{static get endpoint(){return f.endpoint("public/webchats")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),Object.entries(f.webchat.style).forEach(([e,s])=>{t.searchParams.append(`style[${e}]`,s)}),this.appendWebchatOverrides(t),t.searchParams.append("placement",f.webchat.placement);const s=await fetch(t,{method:"GET",headers:vt.headers}),i=await s.json();return vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")}static appendWebchatOverrides(e){const{appearance:t,whatsapp:s}=f.webchat;this.appendIfSupplied(e,"webchat[appearance][header][name]",t.header?.name),this.appendIfSupplied(e,"webchat[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"webchat[handoff][identifier]",s.number),this.appendIfSupplied(e,"webchat[handoff][restrict_to_channel]",s.restrictToChannel)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}},E=class{static get endpoint(){return f.endpoint("public/widgets/whatsapp")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("locale",a.toString()),t.searchParams.append("placement",f.whatsapp.placement),this.appendWhatsAppOverrides(t);const s=await this.fetchWidget(t);if(!s.ok)return null;const i=await this.parseWidgetResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static appendWhatsAppOverrides(e){const{appearance:t,body:s,number:i}=f.whatsapp;this.appendIfSupplied(e,"whatsapp[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"whatsapp[number]",i),this.appendIfSupplied(e,"whatsapp[body]",s)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}static async fetchWidget(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static async parseWidgetResponse(e){try{return await e.json()}catch(e){return null}}},A=class{static get endpoint(){return f.endpoint("public/acks")}static async send(e={}){const t={...e,session:vt.session,at:(new Date).toISOString()};fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify(t),keepalive:!0})}},x=class{static get endpoint(){return f.endpoint("public/push/identities")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}static async destroy(e={}){const t=await fetch(this.endpoint,{method:"DELETE",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}},M=class{static get endpoint(){return f.endpoint("public/push/alerts")}static async create({section:e,kind:t,page:s}){const i=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({session:vt.session,section:e,kind:t,page:s})});return new v(i.ok,i)}};function k(e){const t=JSON.stringify(e);return"undefined"==typeof Blob?t.length<6e4:new Blob([t]).size<6e4}class I{static get businesses(){return b}static get events(){return w}static get forms(){return T}static get popups(){return C}static get popups(){return C}static get webchats(){return O}static get whatsappWidgets(){return E}static get identifications(){return S}static get acks(){return A}static get pushAlerts(){return M}static get pushIdentities(){return x}}const L="data-hellotext-stylesheet";class P{constructor(e){this.id=e,this.data=null,this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1)}async hydrate(){try{const e=await b.get(this.id);if(!1===e.ok)return null;const t=await e.json();return t?(this.setData(t),this.setLocale(a.toString()),t):null}catch(e){return null}}setData(e){this.data=e,"undefined"!=typeof document&&e.style_url?(this.stylesheet=this.constructor.ensureStylesheet(e.style_url),this.stylesheetLoaded=this.constructor.waitForStylesheet(this.stylesheet)):(this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1))}static get stylesheetSelector(){return`link[rel="stylesheet"][${L}]`}static ensureStylesheet(e){const t=this.normalizedStylesheetUrl(e),s=this.stylesheetLinks.find(e=>e.href===t);if(s)return s.setAttribute(L,"true"),s;const i=document.createElement("link");return i.rel="stylesheet",i.href=e,i.setAttribute(L,"true"),this.waitForStylesheet(i),document.head.append(i),i}static get stylesheetLinks(){return"undefined"==typeof document?[]:Array.from(document.querySelectorAll(this.stylesheetSelector))}static get latestStylesheet(){return this.stylesheetLinks[this.stylesheetLinks.length-1]}static normalizedStylesheetUrl(e){try{return new URL(e,document.baseURI).href}catch(t){return e}}static waitForStylesheet(e){return e?this.stylesheetIsLoaded(e)?Promise.resolve(!0):"false"===e.dataset.hellotextStylesheetLoaded?Promise.resolve(!1):(e._hellotextStylesheetLoaded||(e._hellotextStylesheetLoaded=new Promise(t=>{let s;const i=i=>{clearTimeout(s),e.removeEventListener("load",n),e.removeEventListener("error",r),e.dataset.hellotextStylesheetLoaded=i?"true":"false",t(i)},n=()=>i(this.stylesheetIsLoaded(e)),r=()=>i(!1);e.addEventListener("load",n),e.addEventListener("error",r),s=setTimeout(()=>i(this.stylesheetIsLoaded(e)),1e4),s.unref&&s.unref()})),e._hellotextStylesheetLoaded):Promise.resolve(!1)}static stylesheetIsLoaded(e){return"true"===e.dataset.hellotextStylesheetLoaded||!!e.sheet}get subscription(){return this.data.subscription}get country(){return this.data.country}get enabledWhitelist(){return"disabled"!==this.data.whitelist}setLocale(e){this.data||(this.data={});const t=e?.toLowerCase().split("-")[0];this.data.locale=Object.prototype.hasOwnProperty.call(this.data.locales||{},t)?t:"en"}get locale(){const e=this.data?.locales;return e?.[this.data.locale]||e?.en}get features(){return this.data.features}}class _{static set(e,t){if("undefined"!=typeof document){const s="https:"===window.location.protocol?"; Secure":"",i=D.getRootDomain(),n=31536e4;document.cookie=i?`${e}=${t}; path=/${s}; domain=${i}; max-age=${n}; SameSite=Lax`:`${e}=${t}; path=/${s}; max-age=${n}; SameSite=Lax`}return"hello_session"===e&&vt.eventEmitter.dispatch("session-set",t),"hello_utm"===e&&vt.eventEmitter.dispatch("utm-set",t),t}static get(e){return"undefined"!=typeof document?document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)")?.pop():void 0}static delete(e){if("undefined"!=typeof document){const t=D.getRootDomain(),s="https:"===window.location.protocol?"; Secure":"";document.cookie=t?`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; domain=${t}; SameSite=Lax`:`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; SameSite=Lax`}}}class N{constructor(){const e=new URLSearchParams(window.location.search),t={source:e.get("utm_source"),medium:e.get("utm_medium"),campaign:e.get("utm_campaign"),term:e.get("utm_term"),content:e.get("utm_content")};this.save(t)}save(e){if(!e.source||!e.medium)return;const t=Object.fromEntries(Object.entries(e).filter(([e,t])=>t));t.observed_at=(new Date).toISOString(),_.set("hello_utm",JSON.stringify(t))}get current(){try{return JSON.parse(_.get("hello_utm"))||{}}catch(e){return{}}}}class D{constructor(e=null){this.utm=new N,this._url=e}get url(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}get title(){return document.title}get path(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}get utmParams(){return this.utm.current}get trackingData(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}get domain(){try{const e=this.url;if(!e)return null;const t=new URL(e).hostname;return D.getRootDomain(t)}catch(e){return null}}static getRootDomain(e=null){try{if(!e){if("undefined"==typeof window||!window.location?.hostname)return null;e=window.location.hostname}const t=e.split(".");if(t.length<=1)return e;const s=["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"];for(const e of s){const s=e.split(".");if(t.slice(-s.length).join(".")===e&&t.length>s.length)return`.${t.slice(-(s.length+1)).join(".")}`}const i=t[t.length-1],n=t[t.length-2];return t.length>2&&2===i.length&&n.length<=3?`.${t.slice(-3).join(".")}`:`.${t.slice(-2).join(".")}`}catch(e){return null}}}class F{static#n;static#r;static#o;static get session(){return this.#n}static get ackPayload(){return{utm_params:this.#o?.utmParams||{}}}static set session(e){const t=_.get("hello_session");return this.#n=e,_.set("hello_session",e),t!==e&&_.delete("hello_session_ack_at"),_.get("hello_session_ack_at")||(I.acks.send(this.ackPayload),_.set("hello_session_ack_at",(new Date).toISOString())),this.#n}static initialize(e=new D){this.#o=e,this.#r=new y,this.session=this.#r.session||f.session||_.get("hello_session"),!this.session&&f.autoGenerateSession&&(this.session=crypto.randomUUID())}}class R{static build(e){const t=document.createElement("article"),s=document.createElement("label"),i=document.createElement("input");s.innerText=e.label,i.type=e.type,i.required=e.required,i.placeholder=e.placeholder,["first_name","last_name"].includes(e.kind)?(i.type="text",i.id=i.name=e.kind,s.setAttribute("for",e.kind)):(i.type=e.type,"email"===e.type?(i.id=i.name="email",s.setAttribute("for","email")):"tel"===i.type?(i.id=i.name="phone",s.setAttribute("for","phone"),i.value=`+${vt.business.country.prefix}`,i.setAttribute("data-default-value",`+${vt.business.country.prefix}`)):(i.name=i.id=`property_by_id[${e.property}]`,s.setAttribute("for",`property_by_id[${e.property}]`)));const n=document.createElement("main");n.appendChild(s),n.appendChild(i),t.appendChild(n),t.setAttribute("data-hellotext--form-target","inputContainer"),i.setAttribute("data-hellotext--form-target","input");const r=document.createElement("div");return r.setAttribute("data-error-container",""),t.appendChild(r),t}}class B{static build(){const e=document.createElement("div");return e.innerHTML=this.#a(),e.firstElementChild}static#a(){const e=`https://www.hellotext.com?hello_session=${vt.session}`;return`\n
\n ${vt.business.locale.white_label.powered_by}\n\n \n \n Hellotext\n \n \n \n
\n `}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var s=0,i=Array(t);s2?s-2:0),n=2;n1?t-1:0),i=1;i1?s-1:0),n=1;n2&&void 0!==arguments[2]?arguments[2]:ne;if(q&&q(e,null),!ie(t))return e;let i=t.length;for(;i--;){let n=t[i];if("string"==typeof n){const e=s(n);e!==n&&(U(t)||(t[i]=e),n=e)}e[n]=!0}return e}function Te(e){for(let t=0;t/g),Re=H(/\${[\w\W]*/g),Be=H(/^data-[\-\w.\u00B7-\uFFFF]+$/),$e=H(/^aria-[\-\w]+$/),je=H(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Ve=H(/^(?:\w+script|data):/i),qe=H(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ue=H(/^html$/i),ze=H(/^[a-z][.\w]*(-[.\w]+)+$/i),We=H(/<[/\w!]/g),Ke=H(/<[/\w]/g),He=H(/<\/no(script|embed|frames)/i),Ge=H(/\/>/i),Je=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"],Ye=K(we({},Je)),Ze=function(){const e={};return X(Je,t=>{e[t]=H(new RegExp("])","i"))}),K(e)}(),Xe=function(){return"undefined"==typeof window?null:window},Qe=function(e,t,s,i){return me(e,t)&&ie(e[t])?we(i.base?Se(i.base):{},e[t],i.transform):s},et=function(e,t,s){const i=me(e,t)?e[t]:void 0;return i&&"object"==typeof i?Se(i):s()};var tt=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Xe();const s=t=>e(t);if(s.version="3.4.15",s.removed=[],!t||!t.document||9!==t.document.nodeType||!t.Element)return s.isSupported=!1,s;let i=t.document;const n=i,r=n.currentScript;t.DocumentFragment;const o=t.HTMLTemplateElement,a=t.Node,c=t.Element,l=t.NodeFilter;void 0===t.NamedNodeMap&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;const h=t.DOMParser,u=t.trustedTypes,d=c.prototype,p=Ce(d,"cloneNode"),m=Ce(d,"remove"),g=Ce(d,"removeAttributeNode"),f=Ce(d,"nextSibling"),b=Ce(d,"childNodes"),y=Ce(d,"parentNode"),v=Ce(d,"shadowRoot"),w=Ce(d,"attributes"),T=a&&a.prototype?Ce(a.prototype,"nodeType"):null,S=a&&a.prototype?Ce(a.prototype,"nodeName"):null,C=a&&a.prototype?Ce(a.prototype,"ownerDocument"):null,O=function(e){return T?T(e):e.nodeType},E=function(e){return S?S(e):e.nodeName};if("function"==typeof o){const e=i.createElement("template");e.content&&e.content.ownerDocument&&(i=e.content.ownerDocument)}let A,x,M="",k=!1,I=0;const L=function(){if(I>0)throw be('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},P=function(e){L(),I++;try{return A.createHTML(e)}finally{I--}},_=i,N=_.implementation,D=_.createNodeIterator,F=_.createDocumentFragment,R=_.getElementsByTagName,B=n.importNode;let $={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};s.isSupported="function"==typeof V&&"function"==typeof y&&N&&void 0!==N.createHTMLDocument;const j=De,q=Fe,U=Re,z=Be,W=$e,J=Ve,Y=qe,Z=ze;let ye=je,ve=null;const Te=we({},[...Oe,...Ee,...Ae,...Me,...Ie]);let Je=null;const tt=we({},[...Le,...Pe,..._e,...Ne]);let st=Object.seal(G(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),it=null,nt=null;const rt=Object.seal(G(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let ot=!0,at=!0,ct=!1,lt=!0,ht=!1,ut=!0,dt=!1,pt=!1,mt=null,gt=null,ft=!1,bt=!1,yt=!1,vt=!1,wt=!0,Tt=!1;const St="user-content-";let Ct=!0,Ot=!1,Et={},At=null;const xt=we({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let Mt=null;const kt=we({},["audio","video","img","source","image","track"]);let It=null;const Lt=we({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Pt="http://www.w3.org/1998/Math/MathML",_t="http://www.w3.org/2000/svg",Nt="http://www.w3.org/1999/xhtml";let Dt=Nt,Ft=!1,Rt=null;const Bt=we({},[Pt,_t,Nt],re),$t=K(["mi","mo","mn","ms","mtext"]);let jt=we({},$t);const Vt=K(["annotation-xml"]);let qt=we({},Vt);const Ut=we({},["title","style","font","a","script"]);let zt=null;const Wt=["application/xhtml+xml","text/html"];let Kt=null,Ht=null;const Gt=i.createElement("form"),Jt=function(e){return e instanceof RegExp||e instanceof Function},Yt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(Ht&&Ht===e)return;e&&"object"==typeof e||(e={}),e=Se(e),zt=-1===Wt.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,Kt="application/xhtml+xml"===zt?re:ne,ve=Qe(e,"ALLOWED_TAGS",Te,{transform:Kt}),Je=Qe(e,"ALLOWED_ATTR",tt,{transform:Kt}),Rt=Qe(e,"ALLOWED_NAMESPACES",Bt,{transform:re}),It=Qe(e,"ADD_URI_SAFE_ATTR",Lt,{transform:Kt,base:Lt}),Mt=Qe(e,"ADD_DATA_URI_TAGS",kt,{transform:Kt,base:kt}),At=Qe(e,"FORBID_CONTENTS",xt,{transform:Kt}),it=Qe(e,"FORBID_TAGS",Se({}),{transform:Kt}),nt=Qe(e,"FORBID_ATTR",Se({}),{transform:Kt}),Et=!!me(e,"USE_PROFILES")&&(e.USE_PROFILES&&"object"==typeof e.USE_PROFILES?Se(e.USE_PROFILES):e.USE_PROFILES),ot=!1!==e.ALLOW_ARIA_ATTR,at=!1!==e.ALLOW_DATA_ATTR,ct=e.ALLOW_UNKNOWN_PROTOCOLS||!1,lt=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,ht=e.SAFE_FOR_TEMPLATES||!1,ut=!1!==e.SAFE_FOR_XML,dt=e.WHOLE_DOCUMENT||!1,bt=e.RETURN_DOM||!1,yt=e.RETURN_DOM_FRAGMENT||!1,vt=e.RETURN_TRUSTED_TYPE||!1,ft=e.FORCE_BODY||!1,wt=!1!==e.SANITIZE_DOM,Tt=e.SANITIZE_NAMED_PROPS||!1,Ct=!1!==e.KEEP_CONTENT,Ot=e.IN_PLACE||!1,ye=function(e){try{return fe(e,""),!0}catch(e){return!1}}(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:je,Dt="string"==typeof e.NAMESPACE?e.NAMESPACE:Nt,jt=et(e,"MATHML_TEXT_INTEGRATION_POINTS",()=>we({},$t)),qt=et(e,"HTML_INTEGRATION_POINTS",()=>we({},Vt));const t=et(e,"CUSTOM_ELEMENT_HANDLING",()=>G(null));if(st=G(null),me(t,"tagNameCheck")&&Jt(t.tagNameCheck)&&(st.tagNameCheck=t.tagNameCheck),me(t,"attributeNameCheck")&&Jt(t.attributeNameCheck)&&(st.attributeNameCheck=t.attributeNameCheck),me(t,"allowCustomizedBuiltInElements")&&"boolean"==typeof t.allowCustomizedBuiltInElements&&(st.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),H(st),ht&&(at=!1),yt&&(bt=!0),Et&&(ve=we({},Ie),Je=G(null),!0===Et.html&&(we(ve,Oe),we(Je,Le)),!0===Et.svg&&(we(ve,Ee),we(Je,Pe),we(Je,Ne)),!0===Et.svgFilters&&(we(ve,Ae),we(Je,Pe),we(Je,Ne)),!0===Et.mathMl&&(we(ve,Me),we(Je,_e),we(Je,Ne))),rt.tagCheck=null,rt.attributeCheck=null,me(e,"ADD_TAGS")&&("function"==typeof e.ADD_TAGS?rt.tagCheck=e.ADD_TAGS:ie(e.ADD_TAGS)&&(ve===Te&&(ve=Se(ve)),we(ve,e.ADD_TAGS,Kt))),me(e,"ADD_ATTR")&&("function"==typeof e.ADD_ATTR?rt.attributeCheck=e.ADD_ATTR:ie(e.ADD_ATTR)&&(Je===tt&&(Je=Se(Je)),we(Je,e.ADD_ATTR,Kt))),me(e,"ADD_FORBID_CONTENTS")&&ie(e.ADD_FORBID_CONTENTS)&&(At===xt&&(At=Se(At)),we(At,e.ADD_FORBID_CONTENTS,Kt)),Ct&&(ve["#text"]=!0),dt&&we(ve,["html","head","body"]),ve.table&&(we(ve,["tbody"]),delete it.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const t=A;A=e.TRUSTED_TYPES_POLICY;try{M=P("")}catch(e){throw A=t,e}}else null===e.TRUSTED_TYPES_POLICY?(A=void 0,M=""):(void 0===A&&(k||(x=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let s=null;const i="data-tt-policy-suffix";t&&t.hasAttribute(i)&&(s=t.getAttribute(i));const n="dompurify"+(s?"#"+s:"");try{return e.createPolicy(n,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+n+" could not be created."),null}}(u,r),k=!0),A=x),A&&"string"==typeof M&&(M=P("")));K&&K(e),Ht=e},Zt=we({},[...Ee,...Ae,...xe]),Xt=we({},[...Me,...ke]),Qt=function(e){te(s.removed,{element:e});try{y(e).removeChild(e)}catch(t){if(m(e),!y(e))throw be("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},es=function(e,t,s){try{g(e,t)}catch(t){try{e.removeAttribute(s)}catch(e){}}},ts=function(e){ns(e);const t=b(e);if(t){const e=[];X(t,t=>{te(e,t)}),X(e,e=>{try{m(e)}catch(e){}})}const s=w(e);if(s)for(let t=s.length-1;t>=0;--t){const i=s[t],n=i&&i.name;"string"==typeof n&&es(e,i,n)}},ss=function(e,t,i){if(!i)try{i=t.getAttributeNode(e)}catch(e){i=null}te(s.removed,{attribute:i||null,from:t});try{i?g(t,i):t.removeAttribute(e)}catch(s){try{t.removeAttribute(e)}catch(e){}}if("is"===e)if(bt||yt)try{Qt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},is=function(e){const t=w(e);if(t)for(let s=t.length-1;s>=0;--s){const i=t[s],n=i&&i.name;"string"!=typeof n||Je[Kt(n)]||es(e,i,n)}},ns=function(e){const t=[e];for(;t.length>0;){const e=t.pop();1===O(e)&&is(e);const s=b(e);if(s)for(let e=s.length-1;e>=0;--e)t.push(s[e])}},rs=function(e,t){return!!ut&&("patchsrc"===e||"for"===e&&"label"!==t&&"output"!==t)},os=function(e){let t=null,s=null;if(ft)e=""+e;else{const t=oe(e,/^[\r\n\t ]+/);s=t&&t[0]}"application/xhtml+xml"===zt&&Dt===Nt&&(e=''+e+"");const n=A?P(e):e;if(Dt===Nt)try{t=(new h).parseFromString(n,zt)}catch(e){}if(!t||!t.documentElement){t=N.createDocument(Dt,"template",null);try{t.documentElement.innerHTML=Ft?M:n}catch(e){}}const r=t.body||t.documentElement;return e&&s&&r.insertBefore(i.createTextNode(s),r.childNodes[0]||null),Dt===Nt?R.call(t,dt?"html":"body")[0]:dt?t.documentElement:r},as=function(e){const t=C?C(e):e.ownerDocument;return D.call(t||e,e,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},cs=function(e){return e=ae(e,j," "),e=ae(e,q," "),ae(e,U," ")},ls=function(e){var t;e.normalize();const s=C?C(e):e.ownerDocument,i=D.call(s||e,e,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null);let n=i.nextNode();for(;n;)n.data=cs(n.data),n=i.nextNode();const r=null===(t=e.querySelectorAll)||void 0===t?void 0:t.call(e,"template");r&&X(r,e=>{us(e.content)&&ls(e.content)})},hs=function(e){const t=S?S(e):null;return"string"==typeof t&&"form"===Kt(t)&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||e.attributes!==w(e)||"function"!=typeof e.removeAttribute||"function"!=typeof e.removeAttributeNode||"function"!=typeof e.getAttributeNode||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes||e.nodeType!==T(e)||e.childNodes!==b(e))},us=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return 11===T(e)}catch(e){return!1}},ds=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return"number"==typeof T(e)}catch(e){return!1}};function ps(e,t,i){0!==e.length&&X(e,e=>{e.call(s,t,i,Ht)})}const ms=function(e,t){if(e instanceof RegExp)return fe(e,t);if(e instanceof Function){for(var s=arguments.length,i=new Array(s>2?s-2:0),n=2;n=0;--n){const r=e===s?p(i[n],!0):i[n];t.insertBefore(r,f(e))}}return Qt(e),!0}(e,i,t);return!1===s&&ps($.afterSanitizeElements,e,null),s}if(1===O(e)&&!function(e){let t=y(e);t&&t.tagName||(t={namespaceURI:Dt,tagName:"template"});const s=ne(e.tagName),i=ne(t.tagName);return!!Rt[e.namespaceURI]&&(e.namespaceURI===_t?function(e,t,s){return t.namespaceURI===Nt?"svg"===e:t.namespaceURI===Pt?"svg"===e&&("annotation-xml"===s||jt[s]):Boolean(Zt[e])}(s,t,i):e.namespaceURI===Pt?function(e,t,s){return t.namespaceURI===Nt?"math"===e:t.namespaceURI===_t?"math"===e&&qt[s]:Boolean(Xt[e])}(s,t,i):e.namespaceURI===Nt?function(e,t,s){return!(t.namespaceURI===_t&&!qt[s])&&!(t.namespaceURI===Pt&&!jt[s])&&!Xt[e]&&(Ut[e]||!Zt[e])}(s,t,i):!("application/xhtml+xml"!==zt||!Rt[e.namespaceURI]))}(e))return Qt(e),!0;if(("noscript"===i||"noembed"===i||"noframes"===i)&&fe(He,e.innerHTML))return Qt(e),!0;if(ht&&3===e.nodeType){const t=cs(e.textContent);e.textContent!==t&&(te(s.removed,{element:e.cloneNode()}),e.textContent=t)}return ps($.afterSanitizeElements,e,null),!1},ys=function(e,t,s){if(nt[t])return!1;if(rs(t,e))return!1;if(wt&&("id"===t||"name"===t)&&(s in i||s in Gt))return!1;const n=Je[t]||rt.attributeCheck instanceof Function&&rt.attributeCheck(t,e);return!(!at||!fe(z,t))||!(!ot||!fe(W,t))||(n?!(!It[t]&&!fe(ye,ae(s,Y,""))&&("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==ce(s,"data:")||!Mt[e])&&(!ct||fe(J,ae(s,Y,"")))&&s):ws(e)&&ms(st.tagNameCheck,e)&&ms(st.attributeNameCheck,t,e)||"is"===t&&st.allowCustomizedBuiltInElements&&ms(st.tagNameCheck,s))},vs=we({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),ws=function(e){return!vs[ne(e)]&&fe(Z,e)},Ts=function(e,t,s,i){if(A&&"object"==typeof u&&"function"==typeof u.getAttributeType&&!s)switch(u.getAttributeType(e,t)){case"TrustedHTML":return P(i);case"TrustedScriptURL":return function(e){L(),I++;try{return A.createScriptURL(e)}finally{I--}}(i)}return i},Ss=function(e,t,s,i){try{return s?e.setAttributeNS(s,t,i):e.setAttribute(t,i),!hs(e)||(Qt(e),!1)}catch(s){return ss(t,e),!1}},Cs=function(e){ps($.beforeSanitizeAttributes,e,null);const t=e.attributes;if(!t||hs(e))return;Je=gs($.uponSanitizeAttribute,Je,tt,gt);const i={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Je,forceKeepAttr:void 0};let n=t.length;const r=Kt(e.nodeName);for(;n--;){const o=t[n],a=o.name,c=o.namespaceURI,l=o.value,h=Kt(a),u=l;let d="value"===a?u:le(u),p=!1;i.attrName=h,i.attrValue=d,i.keepAttr=!0,i.forceKeepAttr=void 0,ps($.uponSanitizeAttribute,e,i),d=i.attrValue,!Tt||"id"!==h&&"name"!==h||0===ce(d,St)||(ss(a,e,o),d=St+d,p=!0),ut&&fe(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)||"attributename"===h&&oe(d,"href")?ss(a,e,o):i.forceKeepAttr||(i.keepAttr&&(lt||!fe(Ge,d))?(ht&&(d=cs(d)),ys(r,h,d)?(d=Ts(r,h,c,d),d!==u&&Ss(e,a,c,d)&&p&&ee(s.removed)):ss(a,e,o)):ss(a,e,o))}ps($.afterSanitizeAttributes,e,null)},Os=function(e){let t=null;const s=as(e);for(ps($.beforeSanitizeShadowDOM,e,null);t=s.nextNode();)if(ps($.uponSanitizeShadowNode,t,null),bs(t,e),Cs(t),us(t.content)&&Os(t.content),1===O(t)){const e=v(t);us(e)&&(Es(e),Os(e))}ps($.afterSanitizeShadowDOM,e,null)},Es=function(e){const t=[{node:e,shadow:null}];for(;t.length>0;){const e=t.pop();if(e.shadow){Os(e.shadow);continue}const s=e.node,i=1===O(s),n=b(s);if(n)for(let e=n.length-1;e>=0;--e)t.push({node:n[e],shadow:null});if(i){const e=S?S(s):null;if("string"==typeof e&&"template"===Kt(e)){const e=s.content;us(e)&&t.push({node:e,shadow:null})}}if(i){const e=v(s);us(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return s.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=null,r=null,o=null,a=null;if(Ft=!e,Ft&&(e="\x3c!--\x3e"),"string"!=typeof e&&!ds(e)&&"string"!=typeof(e=function(e){switch(typeof e){case"string":return e;case"number":return he(e);case"boolean":return ue(e);case"bigint":return de?de(e):"0";case"symbol":return pe?pe(e):"Symbol()";case"undefined":default:return ge(e);case"function":case"object":{if(null===e)return ge(e);const t=e,s=Ce(t,"toString");if("function"==typeof s){const e=s(t);return"string"==typeof e?e:ge(e)}return ge(e)}}}(e)))throw be("dirty is not a string, aborting");if(!s.isSupported)return e;pt?(ve=mt,Je=gt):Yt(t),($.uponSanitizeElement.length>0||$.uponSanitizeAttribute.length>0)&&(ve=Se(ve)),$.uponSanitizeAttribute.length>0&&(Je=Se(Je)),s.removed=[];const c=Ot&&"string"!=typeof e&&ds(e);if(c){!function(e){if(!ut)return;const t=[e];for(;t.length>0;){const e=t.pop(),s=O(e);if(7===s||8===s&&fe(Ke,e.data)){try{m(e)}catch(e){}continue}if(1===s){const t=e,s=Kt(E(e));try{t.hasAttribute&&t.hasAttribute("patchsrc")&&t.removeAttribute("patchsrc"),t.hasAttribute&&t.hasAttribute("for")&&rs("for",s)&&t.removeAttribute("for")}catch(e){}}const i=b(e);if(i)for(let e=i.length-1;e>=0;--e)t.push(i[e])}}(e);const t=E(e);if("string"==typeof t){const s=Kt(t);if(!ve[s]||it[s])throw ts(e),be("root node is forbidden and cannot be sanitized in-place")}if(hs(e))throw ts(e),be("root node is clobbered and cannot be sanitized in-place");try{Es(e)}catch(t){throw ts(e),t}}else if(ds(e))i=os("\x3c!----\x3e"),r=i.ownerDocument.importNode(e,!0),1===r.nodeType&&"BODY"===r.nodeName||"HTML"===r.nodeName?i=r:i.appendChild(r),Es(i);else{if(!bt&&!ht&&!dt&&-1===e.indexOf("<"))return A&&vt?P(e):e;if(i=os(e),!i)return bt?null:vt?M:""}i&&ft&&Qt(i.firstChild);const l=c?e:i;try{const e=as(l);for(;o=e.nextNode();)bs(o,l),Cs(o),us(o.content)&&Os(o.content)}catch(t){throw c&&(ts(e),X(s.removed,e=>{e.element&&ns(e.element)})),t}if(c)return X(s.removed,e=>{e.element&&ns(e.element)}),ht&&ls(e),e;if(bt){if(ht&&ls(i),yt)for(a=F.call(i.ownerDocument);i.firstChild;)a.appendChild(i.firstChild);else a=i;return(Je.shadowroot||Je.shadowrootmode)&&(a=B.call(n,a,!0)),a}let h=dt?i.outerHTML:i.innerHTML;return dt&&ve["!doctype"]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&fe(Ue,i.ownerDocument.doctype.name)&&(h="\n"+h),ht&&(h=cs(h)),A&&vt?P(h):h},s.setConfig=function(){Yt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),pt=!0,mt=ve,gt=Je},s.clearConfig=function(){Ht=null,pt=!1,mt=null,gt=null,A=x,M=""},s.isValidAttribute=function(e,t,s){Ht||Yt({});const i=Kt(e),n=Kt(t);return ys(i,n,s)},s.addHook=function(e,t){"function"==typeof t&&me($,e)&&te($[e],t)},s.removeHook=function(e,t){if(me($,e)){if(void 0!==t){const s=Q($[e],t);return-1===s?void 0:se($[e],s,1)[0]}return ee($[e])}},s.removeHooks=function(e){me($,e)&&($[e]=[])},s.removeAllHooks=function(){$={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},s}();const st={ADD_ATTR:["target"],ALLOW_DATA_ATTR:!1,RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0}},it={ADD_ATTR:["target"],ADD_TAGS:["hellotext-icon"],RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0,svg:!0}};function nt(e,t){const s=tt.sanitize(e,t);return s.querySelectorAll('a[target="_blank"]').forEach(e=>{const t=new Set(e.rel.split(/\s+/).filter(Boolean));t.add("noopener"),t.add("noreferrer"),e.rel=Array.from(t).join(" ")}),s}function rt(e,t){e.replaceChildren(function(e){return nt(e,st)}(t))}class ot{constructor(e,t=null){this.data=e,this.element=t||document.querySelector(`[data-hello-form="${this.id}"]`)||document.createElement("form")}async mount({ifCompleted:e=!0}={}){if(e&&this.hasBeenCompleted)return this.element?.remove(),vt.eventEmitter.dispatch("form:completed",{id:this.id,...JSON.parse(localStorage.getItem(`hello-form-${this.id}`))});const t=this.data.steps[0];this.buildHeader(t.header),this.buildInputs(t.inputs),this.buildButton(t.button),this.buildFooter(t.footer),this.elementAttributes.forEach(e=>{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),vt.business.features.white_label||this.element.prepend(B.build())}buildHeader(e){const t=this.#c("[data-form-header]","header");rt(t,e.content),this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}buildInputs(e){const t=this.#c("[data-form-inputs]","main");e.map(e=>R.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}buildButton(e){const t=this.#c("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}buildFooter(e){const t=this.#c("[data-form-footer]","footer");rt(t,e.content),this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}markAsCompleted(e){const t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem(`hello-form-${this.id}`,JSON.stringify(t)),vt.eventEmitter.dispatch("form:completed",t)}get hasBeenCompleted(){return null!==localStorage.getItem(`hello-form-${this.id}`)}get id(){return this.data.id}get localeAuthKey(){const e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}get elementAttributes(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}#c(e,t){const s=this.element.querySelector(e);if(s)return s.cloneNode(!0);const i=document.createElement(t);return i.setAttribute(e.replace("[","").replace("]",""),""),i}}class at extends Error{constructor(){super("You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id"),this.name="NotInitializedError"}}class ct{constructor(){this.forms=[],this.includes=this.includes.bind(this),this.excludes=this.excludes.bind(this),this.add=this.add.bind(this),"undefined"!=typeof MutationObserver&&(this.mutationObserver=new MutationObserver(this.formMutationObserver.bind(this)),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0}))}collectExistingFormsOnPage(){Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}formMutationObserver(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}async collect(){if(vt.notInitialized)throw new at;if(this.fetching)return;if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");const e=this.#l;if(0===e.length)return;const t=e.map(e=>T.get(e).then(e=>e.json()));this.fetching=!0,await Promise.all(t).then(e=>e.forEach(this.add)).then(()=>vt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),f.forms.autoMount&&this.forms.forEach(e=>e.mount())}forEach(e){this.forms.forEach(e)}map(e){return this.forms.map(e)}add(e){this.includes(e.id)||(vt.business.data||(vt.business.setData(e.business),vt.business.setLocale(a.toString())),vt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new ot(e)))}getById(e){return this.forms.find(t=>t.id===e)}getByIndex(e){return this.forms[e]}includes(e){return this.forms.some(t=>t.id===e)}excludes(e){return!this.includes(e)}get length(){return this.forms.length}get#l(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}}class lt{constructor(e){this.publicKey=e.public_key,this.serviceWorkerUrl=f.push.serviceWorkerUrl,this.channelId=f.push.channelId,this.ready=null,this.registrationPromise=null,this.subscribePromise=null,this.unsubscribePromise=null,this.syncPromise=null,this.subscription=null,this.retryTimeout=null,this.retryAttempts=0,this.disposed=!1}initialize(){return this.ready=this.restoreSubscription(),this.ready}async restoreSubscription(){const e=await this.getRegistration(),t=await e.pushManager.getSubscription();!this.disposed&&!this.unsubscribePromise&&t&&this.owns(t)&&(this.subscription=t,await this.sync())}subscribe(){if(this.disposed)return Promise.resolve();if(this.unsubscribePromise)return Promise.reject(new Error("Push unsubscribe is in progress"));if(this.subscribePromise)return this.subscribePromise;const e="default"===Notification.permission?Notification.requestPermission():Promise.resolve(Notification.permission);return this.subscribePromise=this.createSubscription(e).finally(()=>{this.subscribePromise=null}),this.subscribePromise}async createSubscription(e){if("granted"!==await e)throw new Error("Push permission was not granted");const t=await this.getRegistration();if(this.disposed)return;let s=await t.pushManager.getSubscription();if(!this.disposed){if(s&&!this.owns(s))throw new Error("The existing Push subscription belongs to a different application");if(s||=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:this.applicationServerKey}),!this.disposed)return this.subscription=s,this.sync()}}unsubscribe(){return this.disposed?Promise.resolve():(this.unsubscribePromise||(this.clearRetryTimeout(),this.unsubscribePromise=this.removeSubscription().finally(()=>{this.unsubscribePromise=null})),this.unsubscribePromise)}async removeSubscription(){await(this.ready?.catch(()=>{})),await(this.subscribePromise?.catch(()=>{})),await(this.syncPromise?.catch(()=>{}));const e=await this.getRegistration(),t=await e.pushManager.getSubscription()||this.subscription;if(this.disposed)return;if(!t)return null;if(!this.owns(t))throw new Error("The existing Push subscription belongs to a different application");this.subscription=t;const s=await I.pushIdentities.destroy({subscription:t.toJSON()});return s.failed?s:this.disposed?void 0:(await t.unsubscribe(),this.subscription=null,this.clearRetryTimeout(),s)}sync(){return this.disposed?Promise.resolve():(this.syncPromise||(this.clearRetryTimeout(),this.syncPromise=this.registerIdentity().finally(()=>{this.syncPromise=null})),this.syncPromise)}async registerIdentity(){try{const e=await I.pushIdentities.create({subscription:this.subscription.toJSON(),...this.channelId?{channel_id:this.channelId}:{}});return e.succeeded?this.retryAttempts=0:this.scheduleRetry(),e}catch(e){throw this.scheduleRetry(),e}}scheduleRetry(){this.disposed||this.unsubscribePromise||this.retryTimeout||this.retryAttempts>=3||(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.sync().catch(()=>{})},1e3*2**this.retryAttempts),this.retryAttempts+=1)}clearRetryTimeout(){clearTimeout(this.retryTimeout),this.retryTimeout=null}dispose(){this.disposed=!0,this.clearRetryTimeout()}get subscribed(){return!!this.subscription}get applicationServerKey(){const e=this.publicKey.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e.padEnd(4*Math.ceil(e.length/4),"=")),e=>e.charCodeAt(0))}owns(e){const t=e.options?.applicationServerKey;if(!t)return!1;const s=new Uint8Array(t),i=this.applicationServerKey;return s.length===i.length&&s.every((e,t)=>e===i[t])}getRegistration(){return this.registrationPromise||(this.registrationPromise=this.loadRegistration().catch(e=>{throw this.registrationPromise=null,e})),this.registrationPromise}async loadRegistration(){if(this.serviceWorkerUrl){const e=await navigator.serviceWorker.register(this.serviceWorkerUrl);!e.active||e.installing||e.waiting||await e.update();const t=e.installing||e.waiting||e.active;return"activated"===t?.state?e:new Promise((s,i)=>{const n=setTimeout(()=>r(new Error("Push service worker did not become active")),1e4),r=r=>{clearTimeout(n),t?.removeEventListener("statechange",o),r?i(r):s(e)},o=()=>{"activated"===t?.state&&r(),"redundant"===t?.state&&r(new Error("Push service worker installation failed"))};t?.addEventListener("statechange",o),o()})}return new Promise((e,t)=>{const s=setTimeout(()=>t(new Error("Push service worker is not available")),1e4);navigator.serviceWorker.ready.then(t=>{clearTimeout(s),e(t)},e=>{clearTimeout(s),t(e)})})}static get supported(){return"undefined"!=typeof window&&!0===window.isSecureContext&&"undefined"!=typeof navigator&&"serviceWorker"in navigator&&"undefined"!=typeof PushManager&&"undefined"!=typeof Notification}}class ht{constructor(e,t,s){this.business=t,this.push=s,this.disposed=!1,this.showRequest=0,this.controller=null,this.element=(new DOMParser).parseFromString(e.html,"text/html").querySelector('[data-controller~="hellotext--alert"]'),this.connected=new Promise(e=>{this.resolveConnected=e}),this.onConnect=this.onConnect.bind(this),this.ready=this.render()}onConnect(e){this.controller=e.detail.controller,this.controller.alert=this,this.resolveConnected(!0)}async render(){return!!this.element&&(this.element.addEventListener("hellotext--alert:connected",this.onConnect),!(!await this.business.stylesheetLoaded||this.disposed)&&(document.body.appendChild(this.element),this.connected))}async show(e,t={}){const s=++this.showRequest;return!(!await this.ready||this.disposed||s!==this.showRequest)&&this.controller.show(e,t)}hide(){this.showRequest+=1,this.controller?.close()}dispose(){this.disposed=!0,this.hide(),this.resolveConnected(!1),this.element?.removeEventListener("hellotext--alert:connected",this.onConnect),this.element?.remove()}}class ut{static async load(e){const t=new ut({id:e,html:await I.webchats.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){return this.applyBehaviourOverride(),await this.stylesheetLoaded?(this.containerToAppendTo.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext webchat was not mounted because its stylesheet failed to load."),!1)}applyBehaviourOverride(){f.webchat.hasBehaviourOverride&&f.webchat.behaviour&&this.data.html.setAttribute("data-hellotext--webchat-behaviour-value",JSON.stringify(this.serializedBehaviour))}get serializedBehaviour(){const e=f.webchat.behaviour;return{trigger:this.serializeTrigger(e.trigger),delay_seconds:e.delaySeconds,first_visit_only:e.firstVisitOnly,once_per_session:e.oncePerSession}}serializeTrigger(e){return"onLoad"===e?"on_load":"onClick"===e?"on_click":e}get containerToAppendTo(){return document.querySelector(f.webchat.container)}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=this.data.html,t=document.querySelector(".hellotext--whatsapp-widget");e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class dt{static async load(e){const t=new dt({id:e,html:await I.whatsappWidgets.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){if(!this.data.html)return!1;const e=this.containerToAppendTo;return e?await this.stylesheetLoaded?(e.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext WhatsApp widget was not mounted because its stylesheet failed to load."),!1):(console.warn(`Hellotext WhatsApp widget was not mounted because the container ${f.whatsapp.container} was not found.`),!1)}get containerToAppendTo(){try{return document.querySelector(f.whatsapp.container)}catch(e){return null}}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=document.querySelector(".hellotext--webchat:not(.hellotext--whatsapp-widget)"),t=this.data.html;e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class pt{static async load(e,t={}){const s=new pt({id:e,html:await I.popups.get(e)},t);return s.rendered=s.render(),s}constructor(e,{container:t=f.popup.container,shouldMount:s=()=>!0}={}){this.data=e,this.container=t,this.mounted=!1,this.rendered=Promise.resolve(!1),this.shouldMount=s}async render(){if(!this.data.html||!this.shouldMount())return!1;const e=this.containerToAppendTo;return e?!!this.shouldMount()&&(e.appendChild(this.data.html),this.mounted=!0,this.shouldMount()||this.unmount(),this.mounted):(console.warn(`Hellotext popup was not mounted because the container ${this.container} was not found.`),!1)}unmount(){this.data.html?.remove(),this.mounted=!1}get containerToAppendTo(){try{return document.querySelector(this.container)}catch(e){return null}}}class mt{static get id(){return _.get("hello_user_id")}static get source(){return _.get("hello_user_source")}static get fingerprint(){return _.get("hello_user_identification_hash")}static remember(e,t,s){t&&_.set("hello_user_source",t),s&&_.set("hello_user_identification_hash",s),_.set("hello_user_id",e)}static forget(){_.delete("hello_user_id"),_.delete("hello_user_source"),_.delete("hello_user_identification_hash")}static get identificationData(){return this.id?{id:this.id,source:this.source}:{}}}function gt(e){if(null!=e){if("string"==typeof e){const t=e.trim();return""===t?void 0:t}if(Array.isArray(e))return e.map(e=>gt(e)).filter(e=>void 0!==e);if(e instanceof Date)return e.toISOString();if("object"==typeof e){const t=Object.keys(e).sort((e,t)=>e.localeCompare(t)).reduce((t,s)=>{const i=gt(e[s]);return void 0!==i&&(t[s]=i),t},{});return Object.keys(t).length>0?t:void 0}return"number"==typeof e||"boolean"==typeof e?e:void 0}}function ft(e,t,s={}){const i=gt({session:e,user_id:t,...s})||{};return JSON.stringify(i)}class bt{static matches(e,t){return!!e&&e===t}static async generate(e,t,s={}){return await async function(e){if(!globalThis.crypto?.subtle||"undefined"==typeof TextEncoder)return function(e){let t=5381;for(let s=0;s>>0).toString(16)}`}(e);const t=await globalThis.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e));return`v1:${Array.from(new Uint8Array(t)).map(e=>e.toString(16).padStart(2,"0")).join("")}`}(ft(e,t,s))}}class yt{static eventEmitter=new r;static forms;static business;static popup;static webchat;static whatsapp;static push;static alert;static initializationVersion=0;static async initialize(e,t={}){const s=++this.initializationVersion;this.popup?.unmount?.(),this.popup=void 0,this.alert?.dispose(),this.alert=null,this.push?.dispose(),this.push=null;const i=new P(e);this.business=i,this.page=new D,f.assign({push:{},...t}),F.initialize(this.page),this.forms=new ct,this.query=new y;const n=await i.hydrate();if(this.business!==i)return;!1!==t.push&&n?.push?.public_key&<.supported&&(this.push=new lt(n.push),this.push.initialize().catch(e=>{console.warn("Hellotext Push initialization failed:",e)}),n.alert?.html&&(this.alert=new ht(n.alert,i,this.push)));const r=!1!==t.popup&&this.deepMergePlainObjects(n&&n.popup||{},t.popup||{}),o=!1!==t.webchat&&this.mergeWebchatConfig(n&&n.webchat||{},t.webchat||{}),a=!1!==t.whatsappWidget&&this.mergeWhatsAppConfig(n&&n.whatsapp||{},t.whatsappWidget||{}),c=t.webchat&&!1!==t.webchat&&Object.prototype.hasOwnProperty.call(t.webchat,"behaviour");f.webchat.behaviourOverride=c;const l=[];if(o&&o.id&&(f.webchat.assign(o),l.push(ut.load(o.id).then(e=>{this.business===i&&(this.webchat=e)}))),a&&a.id&&(f.whatsapp.assign(a),l.push(dt.load(a.id).then(e=>{this.business===i&&(this.whatsapp=e)}))),r&&r.id){const e={container:"body",device:"auto",...r};f.popup.assign(e),l.push(pt.load(e.id,{container:e.container,shouldMount:()=>this.business===i&&this.initializationVersion===s}).then(e=>{this.business===i&&this.initializationVersion===s&&(this.popup=e)}))}await Promise.all(l),this.business===i&&this.initializationVersion===s&&"undefined"!=typeof MutationObserver&&this.forms.collectExistingFormsOnPage()}static mergeWebchatConfig(e,t){return this.deepMergePlainObjects(e,t)}static mergeWhatsAppConfig(e,t){return this.deepMergePlainObjects(e,t)}static deepMergePlainObjects(e,t){const s={...e};return Object.entries(t).forEach(([e,t])=>{this.isPlainObject(t)&&this.isPlainObject(s[e])?s[e]=this.deepMergePlainObjects(s[e],t):s[e]=t}),s}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}static async track(e,t={}){if(this.notInitialized)throw new at;const s={...t&&t.headers||{},...this.headers},i={...mt.identificationData,...t.user_parameters||{}},n=t&&t.url?new D(t.url):this.page,r={session:this.session,user_parameters:i,action:e,...t,...n.trackingData};return delete r.headers,await I.events.create({headers:s,body:r,keepalive:k(r)})}static async identify(e,t={}){const s=await bt.generate(this.session,e,t);if(bt.matches(mt.fingerprint,s))return new v(!0,{json:async()=>({already_identified:!0})});const i=await I.identifications.create({user_id:e,...t});return i.succeeded&&mt.remember(e,t.source,s),i}static forget(){mt.forget()}static on(e,t){this.eventEmitter.addSubscriber(e,t)}static removeEventListener(e,t){this.eventEmitter.removeSubscriber(e,t)}static get session(){return F.session}static get isInitialized(){return void 0!==F.session}static get notInitialized(){return!this.business||void 0===this.business.id}static get headers(){if(this.notInitialized)throw new at;return{Authorization:`Bearer ${this.business.id}`,Accept:"application/json","Content-Type":"application/json"}}}const vt=yt,wt=new Map,Tt=class extends i.xI{static values={sections:Array};static targets=["title","description","primaryAction","secondaryAction"];initialize(){this.showRequest=0,this.submitting=!1,this.onStorage=this.onStorage.bind(this)}connect(){this.dispatch("connected",{detail:{controller:this}}),window.addEventListener("storage",this.onStorage)}disconnect(){this.close(),window.removeEventListener("storage",this.onStorage)}onStorage(e){e.key===this.storageKey&&this.dismissal.dismissedUntil>Date.now()&&this.close()}async show(e,{force:t=!1,title:s,description:i,primaryAction:n,secondaryAction:r}={}){const o=++this.showRequest,a=this.sectionsValue.find(t=>t.kind===e);return a?(await(this.alert.push.ready?.catch(()=>{})),!(o!==this.showRequest||this.alert.disposed||!this.element.isConnected||(this.unavailable||!t&&this.dismissal.dismissedUntil>Date.now()?(this.close(),1):(this.titleTarget.textContent=s??a.title,this.descriptionTarget.textContent=i??a.description,this.primaryActionTarget.textContent=n??a.primary_action,this.secondaryActionTarget.textContent=r??a.secondary_action,this.kind=e,this.page=vt.page.trackingData.page,this.element.hidden=!1,this.record("shown"),vt.eventEmitter.dispatch("alert:shown",{kind:e}),0)))):(this.close(),!1)}hide(){if(this.element.hidden||this.submitting)return;const e=this.dismissal.dismissals+1,t={dismissals:e,dismissedUntil:Date.now()+864e5*(1===e?7:30)};wt.set(this.storageKey,t);try{localStorage.setItem(this.storageKey,JSON.stringify(t))}catch(e){}this.close(),this.record("dismissed"),vt.eventEmitter.dispatch("alert:dismissed",{kind:this.kind})}close(){this.showRequest+=1,this.element.hidden=!0}async subscribe(){if(!this.submitting&&!this.element.hidden){if(this.unavailable)return this.close();this.submitting=!0,this.primaryActionTarget.disabled=!0,this.secondaryActionTarget.disabled=!0,this.element.setAttribute("aria-busy","true");try{this.record("accepted"),vt.eventEmitter.dispatch("alert:accepted",{kind:this.kind});const e=await this.alert.push.subscribe();return this.unavailable&&this.close(),e?.failed&&this.dispatch("error",{detail:{response:e}}),e}catch(e){this.unavailable&&this.close(),this.dispatch("error",{detail:{error:e}})}finally{this.submitting=!1,this.primaryActionTarget.disabled=!1,this.secondaryActionTarget.disabled=!1,this.element.removeAttribute("aria-busy")}}}async record(e){try{const t=await I.pushAlerts.create({section:this.kind,kind:e,page:this.page});t.failed&&console.warn("Hellotext Smart Alert submission failed:",t)}catch(e){console.warn("Hellotext Smart Alert submission failed:",e)}}get unavailable(){return this.alert.push.disposed||this.alert.push.subscribed||"undefined"==typeof Notification||"denied"===Notification.permission}get storageKey(){return`hellotext:alert:${this.alert.business.id}`}get dismissal(){try{const e=JSON.parse(localStorage.getItem(this.storageKey));Number.isSafeInteger(e?.dismissals)&&e.dismissals>0&&Number.isFinite(e.dismissedUntil)&&e.dismissedUntil>=0&&wt.set(this.storageKey,e)}catch(e){}return wt.get(this.storageKey)||{dismissals:0,dismissedUntil:0}}},St=class extends i.xI{static values={data:Object,step:{type:Number,default:1}};static targets=["inputContainer","input","button","otpContainer"];initialize(){this.form=new ot(this.dataValue,this.element)}connect(){super.connect(),this.element.addEventListener("submit",this.submit.bind(this)),"INPUT"!==document.activeElement.tagName&&this.inputTargets[0].focus()}async submit(e){if(e.preventDefault(),this.invalid)return this.showErrorMessages();this.clearErrorMessages(),this.formData=Object.fromEntries(new FormData(this.element)),this.buttonTarget.disabled=!0;const t=await T.submit(this.form.id,this.formData);this.buttonTarget.disabled=!1;const s=await t.json();if(t.failed)return s.errors.forEach(e=>{const{type:t,parameter:s}=e,i=this.inputTargets.find(e=>e.name===s);i.setCustomValidity(vt.business.locale.errors[t]),i.reportValidity(),i.addEventListener("input",()=>{i.setCustomValidity(""),i.reportValidity()})}),this.showErrorMessages();this.buttonTarget.style.display="none",this.element.querySelectorAll("input").forEach(e=>e.disabled=!0),this.completed()}completed(){if(this.form.markAsCompleted(this.formData),!f.forms.shouldShowSuccessMessage)return this.element.remove();"string"==typeof f.forms.successMessage?this.element.innerHTML=f.forms.successMessage:this.element.innerHTML=vt.business.locale.forms[this.form.localeAuthKey]}showErrorMessages(){this.inputTargets.forEach(e=>{const t=e.closest("article").querySelector("[data-error-container]");e.validity.valid?t.innerText="":t.innerText=e.validationMessage})}clearErrorMessages(){this.inputTargets.forEach(e=>{e.setCustomValidity(""),e.closest("article").querySelector("[data-error-container]").innerText=""})}inputTargetConnected(e){e.getAttribute("data-default-value")&&(e.value=e.getAttribute("data-default-value"))}get requiredInputs(){return this.inputTargets.filter(e=>e.required)}get invalid(){return!this.element.checkValidity()}},Ct=class extends i.xI{static values={fadeDistance:{type:Number,default:64},id:String,kind:String,pageStartOffset:{type:Number,default:0},utm:Object};static targets=["carouselContainer","leftFade","rightFade","carouselCard"];connect(){this.updateFades(),this.observeContainerSize()}disconnect(){this.resizeObserver?.disconnect()}setId({detail:e}){this.idValue=e,this.element.id=e}onScroll(){this.updateFades()}quickReply({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),s=e.closest('[data-controller~="hellotext--message"]'),i=e.dataset.text||e.textContent.trim();this.dispatch("quickReply",{detail:{id:this.idValue,product:t?.dataset.id,buttonId:e.dataset.id,body:i,cardElement:t||s||e}})}addToCart({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),{id:s,reference:i,source:n}=t.dataset,r={product:s,quantity:1};this.hasUtmValue&&vt.page.utm.save(this.utmValue),vt.eventEmitter.dispatch("cart.added",{object_parameters:{items:[{...r,...i&&{reference:i},...n&&{source:n}}]},source:{kind:this.kindValue,message_id:this.idValue,button_id:e.dataset.id}})}moveToLeft(){if(!this.hasCarouselContainerTarget)return;const e=this.getPreviousPageScrollLeft(),t=this.carouselContainerTarget.scrollLeft-e;t<1||this.carouselContainerTarget.scrollBy({left:-t,behavior:"smooth"})}moveToRight(){if(!this.hasCarouselContainerTarget)return;const e=this.getNextPageScrollLeft()-this.carouselContainerTarget.scrollLeft;e<1||this.carouselContainerTarget.scrollBy({left:e,behavior:"smooth"})}getScrollAmount(){return this.getCardScrollAmount()}getCardScrollAmount(){const e=this.carouselContainerTarget.querySelector(".message__carousel_card");return e?e.offsetWidth+this.getGap():280}getPageScrollAmount(){const e=this.carouselContainerTarget.clientWidth-this.getGap();return e>0?e:this.getCardScrollAmount()}getNextPageScrollLeft(){const e=this.getCurrentScrollLeft(),t=e+this.carouselContainerTarget.clientWidth,s=this.getCardMetrics().find(e=>e.end>t+1),i=s?this.getPageAlignedScrollLeft(s.start):e+this.getPageScrollAmount(),n=e+this.getPageScrollAmount();return this.clampScrollLeft(i>e+1?i:n)}getPreviousPageScrollLeft(){const e=this.getCurrentScrollLeft();if(e<=1)return 0;const t=Math.max(e-this.getPageScrollAmount(),0);if(t<=1)return 0;const s=this.getCardMetrics(),i=s.find(s=>s.start>=t-1&&s.startt.start{const t=this.getCardScrollLeft(e);return{start:t,end:t+e.offsetWidth}})}getCardScrollLeft(e){const t=e.getBoundingClientRect(),s=this.carouselContainerTarget.getBoundingClientRect();return t.left||t.width||s.left||s.width?t.left-s.left+this.carouselContainerTarget.scrollLeft:e.offsetLeft||0}getCurrentScrollLeft(){return this.clampScrollLeft(this.carouselContainerTarget.scrollLeft)}clampScrollLeft(e){const t=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);return Math.min(Math.max(e,0),t)}getGap(){const e=window.getComputedStyle(this.carouselContainerTarget),t=Number.parseFloat(e.columnGap||e.gap);return Number.isFinite(t)?t:16}getFadeDistance(){return Number.isFinite(this.fadeDistanceValue)?this.fadeDistanceValue:64}getPageStartOffset(){return Number.isFinite(this.pageStartOffsetValue)?this.pageStartOffsetValue:0}observeContainerSize(){this.hasCarouselContainerTarget&&window.ResizeObserver&&(this.resizeObserver=new ResizeObserver(()=>this.updateFades()),this.resizeObserver.observe(this.carouselContainerTarget))}updateFades(){if(!this.hasCarouselContainerTarget)return;const e=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);if(e<=1)return this.hideFade(this.leftFadeTarget),void this.hideFade(this.rightFadeTarget);const t=Math.min(Math.max(this.carouselContainerTarget.scrollLeft,0),e),s=this.getFadeDistance();this.setFadeOpacity(this.leftFadeTarget,t/s),this.setFadeOpacity(this.rightFadeTarget,(e-t)/s)}setFadeOpacity(e,t){const s=Math.min(Math.max(t,0),1);s<=.05?this.hideFade(e):(e.classList.remove("hidden"),e.removeAttribute("disabled"),e.removeAttribute("tabindex"),e.setAttribute("aria-hidden","false"),e.style.opacity=s.toFixed(3),e.style.pointerEvents="auto")}hideFade(e){e.style.opacity="0",e.style.pointerEvents="none",e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1"),"disabled"in e&&(e.disabled=!0),e.classList.add("hidden")}},Ot=class extends i.xI{static targets=["bubble","dialog","step","completed","input","submitButton","globalError","resendButton","changeDestinationButton","deliveryCopy","noDeliveryCopy"];static values={capture:Object,device:String,hasBubble:Boolean,id:String};initialize(){this.stepIndex=0,this.resendLabel=this.hasResendButtonTarget?this.resendButtonTarget.textContent.trim():""}connect(){vt.eventEmitter.dispatch("popup:mounted"),this.evaluateDisplay()}disconnect(){this.stopResendCooldown()}open(e){e&&e.preventDefault(),this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}close(e){e&&e.preventDefault(),this.dismissed=!0,this.dialogTarget.hidden=!0,this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.element.hidden=!0,vt.eventEmitter.dispatch("popup:closed")}closeOnEscape(e){this.dialogTarget.hidden||e.defaultPrevented||e.isComposing||this.close(e)}async next(e){e&&e.preventDefault(),this.clearCustomValidity(),this.currentStepValid()?(this.clearErrorMessages(this.currentStepInputs),this.stepIndex{e.disabled=!0});try{const e=this.submissionPayload(),t=await C.submit(this.idValue,e,this.idempotencyKeyFor(e));if(t.failed)return void await this.handleSubmissionError(t);const s=await t.json();this.submissionId=s.id,this.submissionVerificationState=s.verification_state,this.submissionActionToken=s.action_token,this.submissionDeliveryStatus=s.delivery_status,this.submissionDeliveryChannel=s.delivery_channel,this.submissionDestination=s.destination,this.resetSubmissionRequest()}catch(e){return void this.showGlobalError()}finally{this.submitButtonTargets.forEach(e=>{e.disabled=!1})}this.showCompleted()}else this.showErrorMessages(this.currentStepInputs)}evaluateDisplay(){!this.dismissed&&this.matchesDevice()?this.showInitialState():this.element.hidden=!0}showInitialState(){if(this.element.hidden=!1,this.hasBubbleValue&&this.hasBubbleTarget)return this.bubbleTarget.hidden=!1,void(this.dialogTarget.hidden=!0);this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}showStep(e){this.stepIndex=e,this.stepTargets.forEach((t,s)=>{t.hidden=s!==e}),this.completedTarget.hidden=!0}showCompleted(){this.stepTargets.forEach(e=>{e.hidden=!0}),this.interpolateCompletionCopy(),this.configureCompletionActions(),this.completedTarget.hidden=!1}interpolateCompletionCopy(){const e=this.completedIdentity;if(!e)return;const t={destination:e.value,channel:this.submissionDeliveryChannel||e.kind};this.completionTextTemplates.forEach(({node:e,template:s})=>{e.nodeValue=s.replace(/\{(destination|channel)\}/g,(e,s)=>t[s]||e)})}identityValue(e){const t=this.inputValue(e).trim();if("phone"!==e.dataset.popupFieldKind||t.startsWith("+"))return t;const s=this.phoneCountryPrefix(e);if(s)return`${s}${this.phoneDigits(t)}`;const i=e.dataset.popupPhonePrefix;return i?`${i}${t.replace(/^0+/,"")}`:t}asciiDigits(e){const t=e=>/\p{Nd}/u.test(e);return e.replace(/\p{Nd}/gu,e=>{let s=e.codePointAt(0);const i=s;for(;t(String.fromCodePoint(s-1));)s-=1;return(i-s)%10})}phoneDigits(e){return this.asciiDigits(e).replace(/\D/g,"")}phoneCountryPrefix(e){const t=e.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country]");return t?.selectedOptions?.[0]?.dataset.prefix}selectPhoneCountry(e){const t=e.target,s=t.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country-label]");s&&(s.textContent=t.selectedOptions[0]?.dataset.label||"")}submissionValue(e){const t=this.inputValue(e),s="phone"===e.dataset.popupFieldKind&&this.phoneCountryPrefix(e),i="string"==typeof t?t.trim():"";return s&&i?i.startsWith("+")?this.asciiDigits(t):`${s}${this.phoneDigits(i)}`:t}configureCompletionActions(){const e="not_required"!==this.submissionDeliveryStatus;if(this.revealCompletionCopy(e),!e)return void this.completedTarget.querySelector("[data-delivery-actions]")?.setAttribute("hidden","");const t=this.completedIdentity;t&&(this.hasChangeDestinationButtonTarget&&(this.changeDestinationButtonTarget.textContent=this.changeDestinationButtonTarget.dataset[`${t.kind}Label`],this.changeDestinationButtonTarget.hidden=!1),this.submissionId&&this.submissionActionToken&&"queued"===this.submissionDeliveryStatus&&"unverified"===this.submissionVerificationState&&this.hasResendButtonTarget&&(this.resendButtonTarget.hidden=!1,this.startResendCooldown(60)))}async resend(e){if(e&&e.preventDefault(),this.submissionId&&this.submissionActionToken&&!this.resendPending&&!this.resendCooldownActive&&this.completedIdentity){this.resendPending=!0,this.resendButtonTarget.disabled=!0;try{const e=await C.resend(this.idValue,this.submissionId,this.submissionActionToken),t=Number(e.data.headers?.get("Retry-After"))||60;e.succeeded||429===e.data.status?this.startResendCooldown(t):this.resendButtonTarget.disabled=!1}catch(e){this.resendButtonTarget.disabled=!1}finally{this.resendPending=!1}}}async changeDestination(e){if(e&&e.preventDefault(),!this.submissionId||!this.submissionActionToken||this.changeDestinationPending)return;const t=this.completedIdentity?.input;if(!t)return;const s=this.stepTargets.findIndex(e=>e.dataset.stepId===t.dataset.popupStepId);if(!(s<0)){this.changeDestinationPending=!0,this.changeDestinationButtonTarget.disabled=!0;try{if((await C.cancel(this.idValue,this.submissionId,this.submissionActionToken)).failed)return;this.stopResendCooldown(),this.submissionId=null,this.submissionActionToken=null,this.submissionVerificationState=null,this.submissionDeliveryStatus=null,this.submissionDeliveryChannel=null,this.submissionDestination=null,this.resetSubmissionRequest(),this.showStep(s),t.focus()}catch(e){}finally{this.changeDestinationPending=!1,this.changeDestinationButtonTarget.disabled=!1}}}startResendCooldown(e){this.stopResendCooldown(),this.resendCooldownEndsAt=Date.now()+1e3*Math.max(e,1),this.updateResendCountdown(),this.resendTimer=window.setInterval(()=>this.updateResendCountdown(),1e3)}stopResendCooldown(){this.resendTimer&&window.clearInterval(this.resendTimer),this.resendTimer=null,this.resendCooldownEndsAt=null}updateResendCountdown(){const e=Math.max(0,Math.ceil((this.resendCooldownEndsAt-Date.now())/1e3));if(0===e)return this.stopResendCooldown(),this.resendButtonTarget.textContent=this.resendLabel,void(this.resendButtonTarget.disabled=!1);const t=`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`,s=this.resendButtonTarget.dataset.countdownLabel||`${this.resendLabel} %{time}`;this.resendButtonTarget.textContent=s.replace("%{time}",t),this.resendButtonTarget.disabled=!0}get resendCooldownActive(){return this.resendCooldownEndsAt>Date.now()}get completionIdentity(){return this.identityInputs.map(e=>({input:e,kind:e.dataset.popupFieldKind,value:this.identityValue(e)})).find(({value:e})=>e)}get completedIdentity(){if(this.submissionDestination&&this.submissionDeliveryChannel){const e="email"===this.submissionDeliveryChannel?"email":"phone";return{input:this.identityInputs.find(t=>t.dataset.popupFieldKind===e),kind:e,value:this.submissionDestination}}return this.completionIdentity}revealCompletionCopy(e){this.hasDeliveryCopyTarget&&this.deliveryCopyTargets.forEach(t=>{t.hidden=!e}),this.hasNoDeliveryCopyTarget&&this.noDeliveryCopyTargets.forEach(t=>{t.hidden=e})}currentStepValid(){return this.currentStepInputs.every(e=>e.checkValidity())}showErrorMessages(e){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent=e.validity.valid?"":e.validationMessage)})}clearErrorMessages(e=this.inputTargets){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent="")})}clearCustomValidity(){this.inputTargets.forEach(e=>e.setCustomValidity(""))}clearGlobalError(){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent="",this.globalErrorTarget.hidden=!0)}showGlobalError(e=null){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent=e||this.globalErrorTarget.dataset.submitError||"Unable to submit. Please try again.",this.globalErrorTarget.hidden=!1)}async handleSubmissionError(e){let t;try{t=await e.json()}catch(e){return void this.showGlobalError()}const s=t.errors||[],i=[];s.forEach(e=>{const t=this.inputForError(e);t?(t.setCustomValidity(e.description||t.validationMessage),t.reportValidity()):e.description&&i.push(e.description)}),this.showErrorMessages(this.inputTargets),i.length?this.showGlobalError(i.join(" ")):s.length||this.showGlobalError()}inputForError(e){const t=e.parameter;return t?this.inputTargets.find(e=>e.dataset.popupFieldKind===t||e.dataset.popupFieldKey===t):null}submissionPayload(){const e={metadata:{capture:this.captureValue||{},fields:{},steps:[]}};return this.stepTargets.forEach(t=>{const s={};this.inputsForStep(t).forEach(t=>{const i=this.submissionValue(t),n=t.dataset.popupFieldKey||t.name;s[n]=i,e.metadata.fields[n]=i,"email"===t.dataset.popupFieldKind&&(e.email=i),"phone"===t.dataset.popupFieldKind&&(e.phone=i)}),e.metadata.steps.push({id:t.dataset.stepId,name:t.dataset.stepName,fields:s})}),e}idempotencyKeyFor(e){const t=JSON.stringify(e);return this.submissionPayloadSnapshot!==t&&(this.submissionPayloadSnapshot=t,this.submissionIdempotencyKey=C.idempotencyKey()),this.submissionIdempotencyKey}resetSubmissionRequest(){this.submissionPayloadSnapshot=null,this.submissionIdempotencyKey=null}inputValue(e){return"checkbox"===e.type?e.checked:e.value}inputsForStep(e){return this.inputTargets.filter(t=>t.dataset.popupStepId===e.dataset.stepId)}get identityInputs(){const e=this.inputTargets.filter(e=>["email","phone"].includes(e.dataset.popupFieldKind));return e.filter(e=>e.required).concat(e.filter(e=>!e.required))}get completionTextTemplates(){if(this._completionTextTemplates)return this._completionTextTemplates;const e=document.createTreeWalker(this.completedTarget,NodeFilter.SHOW_TEXT);for(this._completionTextTemplates=[];e.nextNode();)this._completionTextTemplates.push({node:e.currentNode,template:e.currentNode.nodeValue});return this._completionTextTemplates}matchesDevice(){return"all"===this.deviceValue||("mobile"===this.deviceValue?window.innerWidth<768:"desktop"!==this.deviceValue||window.innerWidth>=768)}get currentStep(){return this.stepTargets[this.stepIndex]}get currentStepInputs(){return this.inputsForStep(this.currentStep)}},Et=["start","end"],At=["top","right","bottom","left"].reduce((e,t)=>e.concat(t,t+"-"+Et[0],t+"-"+Et[1]),[]),xt=Math.min,Mt=Math.max,kt=Math.round,It=Math.floor,Lt=e=>({x:e,y:e}),Pt={left:"right",right:"left",bottom:"top",top:"bottom"},_t={start:"end",end:"start"};function Nt(e,t,s){return Mt(e,xt(t,s))}function Dt(e,t){return"function"==typeof e?e(t):e}function Ft(e){return e.split("-")[0]}function Rt(e){return e.split("-")[1]}function Bt(e){return"x"===e?"y":"x"}function $t(e){return"y"===e?"height":"width"}const jt=new Set(["top","bottom"]);function Vt(e){return jt.has(Ft(e))?"y":"x"}function qt(e){return Bt(Vt(e))}function Ut(e,t,s){void 0===s&&(s=!1);const i=Rt(e),n=qt(e),r=$t(n);let o="x"===n?i===(s?"end":"start")?"right":"left":"start"===i?"bottom":"top";return t.reference[r]>t.floating[r]&&(o=Jt(o)),[o,Jt(o)]}function zt(e){return e.replace(/start|end/g,e=>_t[e])}const Wt=["left","right"],Kt=["right","left"],Ht=["top","bottom"],Gt=["bottom","top"];function Jt(e){return e.replace(/left|right|bottom|top/g,e=>Pt[e])}function Yt(e){const{x:t,y:s,width:i,height:n}=e;return{width:i,height:n,top:s,left:t,right:t+i,bottom:s+n,x:t,y:s}}function Zt(e,t,s){let{reference:i,floating:n}=e;const r=Vt(t),o=qt(t),a=$t(o),c=Ft(t),l="y"===r,h=i.x+i.width/2-n.width/2,u=i.y+i.height/2-n.height/2,d=i[a]/2-n[a]/2;let p;switch(c){case"top":p={x:h,y:i.y-n.height};break;case"bottom":p={x:h,y:i.y+i.height};break;case"right":p={x:i.x+i.width,y:u};break;case"left":p={x:i.x-n.width,y:u};break;default:p={x:i.x,y:i.y}}switch(Rt(t)){case"start":p[o]-=d*(s&&l?-1:1);break;case"end":p[o]+=d*(s&&l?-1:1)}return p}async function Xt(e,t){var s;void 0===t&&(t={});const{x:i,y:n,platform:r,rects:o,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:h="viewport",elementContext:u="floating",altBoundary:d=!1,padding:p=0}=Dt(t,e),m=function(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}(p),g=a[d?"floating"===u?"reference":"floating":u],f=Yt(await r.getClippingRect({element:null==(s=await(null==r.isElement?void 0:r.isElement(g)))||s?g:g.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(a.floating)),boundary:l,rootBoundary:h,strategy:c})),b="floating"===u?{x:i,y:n,width:o.floating.width,height:o.floating.height}:o.reference,y=await(null==r.getOffsetParent?void 0:r.getOffsetParent(a.floating)),v=await(null==r.isElement?void 0:r.isElement(y))&&await(null==r.getScale?void 0:r.getScale(y))||{x:1,y:1},w=Yt(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:y,strategy:c}):b);return{top:(f.top-w.top+m.top)/v.y,bottom:(w.bottom-f.bottom+m.bottom)/v.y,left:(f.left-w.left+m.left)/v.x,right:(w.right-f.right+m.right)/v.x}}const Qt=new Set(["left","top"]);function es(){return"undefined"!=typeof window}function ts(e){return ns(e)?(e.nodeName||"").toLowerCase():"#document"}function ss(e){var t;return(null==e||null==(t=e.ownerDocument)?void 0:t.defaultView)||window}function is(e){var t;return null==(t=(ns(e)?e.ownerDocument:e.document)||window.document)?void 0:t.documentElement}function ns(e){return!!es()&&(e instanceof Node||e instanceof ss(e).Node)}function rs(e){return!!es()&&(e instanceof Element||e instanceof ss(e).Element)}function os(e){return!!es()&&(e instanceof HTMLElement||e instanceof ss(e).HTMLElement)}function as(e){return!(!es()||"undefined"==typeof ShadowRoot)&&(e instanceof ShadowRoot||e instanceof ss(e).ShadowRoot)}const cs=new Set(["inline","contents"]);function ls(e){const{overflow:t,overflowX:s,overflowY:i,display:n}=Ts(e);return/auto|scroll|overlay|hidden|clip/.test(t+i+s)&&!cs.has(n)}const hs=new Set(["table","td","th"]);function us(e){return hs.has(ts(e))}const ds=[":popover-open",":modal"];function ps(e){return ds.some(t=>{try{return e.matches(t)}catch(e){return!1}})}const ms=["transform","translate","scale","rotate","perspective"],gs=["transform","translate","scale","rotate","perspective","filter"],fs=["paint","layout","strict","content"];function bs(e){const t=ys(),s=rs(e)?Ts(e):e;return ms.some(e=>!!s[e]&&"none"!==s[e])||!!s.containerType&&"normal"!==s.containerType||!t&&!!s.backdropFilter&&"none"!==s.backdropFilter||!t&&!!s.filter&&"none"!==s.filter||gs.some(e=>(s.willChange||"").includes(e))||fs.some(e=>(s.contain||"").includes(e))}function ys(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}const vs=new Set(["html","body","#document"]);function ws(e){return vs.has(ts(e))}function Ts(e){return ss(e).getComputedStyle(e)}function Ss(e){return rs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Cs(e){if("html"===ts(e))return e;const t=e.assignedSlot||e.parentNode||as(e)&&e.host||is(e);return as(t)?t.host:t}function Os(e){const t=Cs(e);return ws(t)?e.ownerDocument?e.ownerDocument.body:e.body:os(t)&&ls(t)?t:Os(t)}function Es(e,t,s){var i;void 0===t&&(t=[]),void 0===s&&(s=!0);const n=Os(e),r=n===(null==(i=e.ownerDocument)?void 0:i.body),o=ss(n);if(r){const e=As(o);return t.concat(o,o.visualViewport||[],ls(n)?n:[],e&&s?Es(e):[])}return t.concat(n,Es(n,[],s))}function As(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function xs(e){const t=Ts(e);let s=parseFloat(t.width)||0,i=parseFloat(t.height)||0;const n=os(e),r=n?e.offsetWidth:s,o=n?e.offsetHeight:i,a=kt(s)!==r||kt(i)!==o;return a&&(s=r,i=o),{width:s,height:i,$:a}}function Ms(e){return rs(e)?e:e.contextElement}function ks(e){const t=Ms(e);if(!os(t))return Lt(1);const s=t.getBoundingClientRect(),{width:i,height:n,$:r}=xs(t);let o=(r?kt(s.width):s.width)/i,a=(r?kt(s.height):s.height)/n;return o&&Number.isFinite(o)||(o=1),a&&Number.isFinite(a)||(a=1),{x:o,y:a}}const Is=Lt(0);function Ls(e){const t=ss(e);return ys()&&t.visualViewport?{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}:Is}function Ps(e,t,s,i){void 0===t&&(t=!1),void 0===s&&(s=!1);const n=e.getBoundingClientRect(),r=Ms(e);let o=Lt(1);t&&(i?rs(i)&&(o=ks(i)):o=ks(e));const a=function(e,t,s){return void 0===t&&(t=!1),!(!s||t&&s!==ss(e))&&t}(r,s,i)?Ls(r):Lt(0);let c=(n.left+a.x)/o.x,l=(n.top+a.y)/o.y,h=n.width/o.x,u=n.height/o.y;if(r){const e=ss(r),t=i&&rs(i)?ss(i):i;let s=e,n=As(s);for(;n&&i&&t!==s;){const e=ks(n),t=n.getBoundingClientRect(),i=Ts(n),r=t.left+(n.clientLeft+parseFloat(i.paddingLeft))*e.x,o=t.top+(n.clientTop+parseFloat(i.paddingTop))*e.y;c*=e.x,l*=e.y,h*=e.x,u*=e.y,c+=r,l+=o,s=ss(n),n=As(s)}}return Yt({width:h,height:u,x:c,y:l})}function _s(e,t){const s=Ss(e).scrollLeft;return t?t.left+s:Ps(is(e)).left+s}function Ns(e,t,s){void 0===s&&(s=!1);const i=e.getBoundingClientRect();return{x:i.left+t.scrollLeft-(s?0:_s(e,i)),y:i.top+t.scrollTop}}const Ds=new Set(["absolute","fixed"]);function Fs(e,t,s){let i;if("viewport"===t)i=function(e,t){const s=ss(e),i=is(e),n=s.visualViewport;let r=i.clientWidth,o=i.clientHeight,a=0,c=0;if(n){r=n.width,o=n.height;const e=ys();(!e||e&&"fixed"===t)&&(a=n.offsetLeft,c=n.offsetTop)}return{width:r,height:o,x:a,y:c}}(e,s);else if("document"===t)i=function(e){const t=is(e),s=Ss(e),i=e.ownerDocument.body,n=Mt(t.scrollWidth,t.clientWidth,i.scrollWidth,i.clientWidth),r=Mt(t.scrollHeight,t.clientHeight,i.scrollHeight,i.clientHeight);let o=-s.scrollLeft+_s(e);const a=-s.scrollTop;return"rtl"===Ts(i).direction&&(o+=Mt(t.clientWidth,i.clientWidth)-n),{width:n,height:r,x:o,y:a}}(is(e));else if(rs(t))i=function(e,t){const s=Ps(e,!0,"fixed"===t),i=s.top+e.clientTop,n=s.left+e.clientLeft,r=os(e)?ks(e):Lt(1);return{width:e.clientWidth*r.x,height:e.clientHeight*r.y,x:n*r.x,y:i*r.y}}(t,s);else{const s=Ls(e);i={x:t.x-s.x,y:t.y-s.y,width:t.width,height:t.height}}return Yt(i)}function Rs(e,t){const s=Cs(e);return!(s===t||!rs(s)||ws(s))&&("fixed"===Ts(s).position||Rs(s,t))}function Bs(e,t,s){const i=os(t),n=is(t),r="fixed"===s,o=Ps(e,!0,r,t);let a={scrollLeft:0,scrollTop:0};const c=Lt(0);function l(){c.x=_s(n)}if(i||!i&&!r)if(("body"!==ts(t)||ls(n))&&(a=Ss(t)),i){const e=Ps(t,!0,r,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else n&&l();r&&!i&&n&&l();const h=!n||i||r?Lt(0):Ns(n,a);return{x:o.left+a.scrollLeft-c.x-h.x,y:o.top+a.scrollTop-c.y-h.y,width:o.width,height:o.height}}function $s(e){return"static"===Ts(e).position}function js(e,t){if(!os(e)||"fixed"===Ts(e).position)return null;if(t)return t(e);let s=e.offsetParent;return is(e)===s&&(s=s.ownerDocument.body),s}function Vs(e,t){const s=ss(e);if(ps(e))return s;if(!os(e)){let t=Cs(e);for(;t&&!ws(t);){if(rs(t)&&!$s(t))return t;t=Cs(t)}return s}let i=js(e,t);for(;i&&us(i)&&$s(i);)i=js(i,t);return i&&ws(i)&&$s(i)&&!bs(i)?s:i||function(e){let t=Cs(e);for(;os(t)&&!ws(t);){if(bs(t))return t;if(ps(t))return null;t=Cs(t)}return null}(e)||s}const qs={convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{elements:t,rect:s,offsetParent:i,strategy:n}=e;const r="fixed"===n,o=is(i),a=!!t&&ps(t.floating);if(i===o||a&&r)return s;let c={scrollLeft:0,scrollTop:0},l=Lt(1);const h=Lt(0),u=os(i);if((u||!u&&!r)&&(("body"!==ts(i)||ls(o))&&(c=Ss(i)),os(i))){const e=Ps(i);l=ks(i),h.x=e.x+i.clientLeft,h.y=e.y+i.clientTop}const d=!o||u||r?Lt(0):Ns(o,c,!0);return{width:s.width*l.x,height:s.height*l.y,x:s.x*l.x-c.scrollLeft*l.x+h.x+d.x,y:s.y*l.y-c.scrollTop*l.y+h.y+d.y}},getDocumentElement:is,getClippingRect:function(e){let{element:t,boundary:s,rootBoundary:i,strategy:n}=e;const r=[..."clippingAncestors"===s?ps(t)?[]:function(e,t){const s=t.get(e);if(s)return s;let i=Es(e,[],!1).filter(e=>rs(e)&&"body"!==ts(e)),n=null;const r="fixed"===Ts(e).position;let o=r?Cs(e):e;for(;rs(o)&&!ws(o);){const t=Ts(o),s=bs(o);s||"fixed"!==t.position||(n=null),(r?!s&&!n:!s&&"static"===t.position&&n&&Ds.has(n.position)||ls(o)&&!s&&Rs(e,o))?i=i.filter(e=>e!==o):n=t,o=Cs(o)}return t.set(e,i),i}(t,this._c):[].concat(s),i],o=r[0],a=r.reduce((e,s)=>{const i=Fs(t,s,n);return e.top=Mt(i.top,e.top),e.right=xt(i.right,e.right),e.bottom=xt(i.bottom,e.bottom),e.left=Mt(i.left,e.left),e},Fs(t,o,n));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}},getOffsetParent:Vs,getElementRects:async function(e){const t=this.getOffsetParent||Vs,s=this.getDimensions,i=await s(e.floating);return{reference:Bs(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}},getClientRects:function(e){return Array.from(e.getClientRects())},getDimensions:function(e){const{width:t,height:s}=xs(e);return{width:t,height:s}},getScale:ks,isElement:rs,isRTL:function(e){return"rtl"===Ts(e).direction}};function Us(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}const zs=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){var s,i;const{x:n,y:r,placement:o,middlewareData:a}=t,c=await async function(e,t){const{placement:s,platform:i,elements:n}=e,r=await(null==i.isRTL?void 0:i.isRTL(n.floating)),o=Ft(s),a=Rt(s),c="y"===Vt(s),l=Qt.has(o)?-1:1,h=r&&c?-1:1,u=Dt(t,e);let{mainAxis:d,crossAxis:p,alignmentAxis:m}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return a&&"number"==typeof m&&(p="end"===a?-1*m:m),c?{x:p*h,y:d*l}:{x:d*l,y:p*h}}(t,e);return o===(null==(s=a.offset)?void 0:s.placement)&&null!=(i=a.arrow)&&i.alignmentOffset?{}:{x:n+c.x,y:r+c.y,data:{...c,placement:o}}}}},Ws=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:i,placement:n}=t,{mainAxis:r=!0,crossAxis:o=!1,limiter:a={fn:e=>{let{x:t,y:s}=e;return{x:t,y:s}}},...c}=Dt(e,t),l={x:s,y:i},h=await Xt(t,c),u=Vt(Ft(n)),d=Bt(u);let p=l[d],m=l[u];if(r){const e="y"===d?"bottom":"right";p=Nt(p+h["y"===d?"top":"left"],p,p-h[e])}if(o){const e="y"===u?"bottom":"right";m=Nt(m+h["y"===u?"top":"left"],m,m-h[e])}const g=a.fn({...t,[d]:p,[u]:m});return{...g,data:{x:g.x-s,y:g.y-i,enabled:{[d]:r,[u]:o}}}}}},Ks=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var s,i;const{placement:n,middlewareData:r,rects:o,initialPlacement:a,platform:c,elements:l}=t,{mainAxis:h=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...f}=Dt(e,t);if(null!=(s=r.arrow)&&s.alignmentOffset)return{};const b=Ft(n),y=Vt(a),v=Ft(a)===a,w=await(null==c.isRTL?void 0:c.isRTL(l.floating)),T=d||(v||!g?[Jt(a)]:function(e){const t=Jt(e);return[zt(e),t,zt(t)]}(a)),S="none"!==m;!d&&S&&T.push(...function(e,t,s,i){const n=Rt(e);let r=function(e,t,s){switch(e){case"top":case"bottom":return s?t?Kt:Wt:t?Wt:Kt;case"left":case"right":return t?Ht:Gt;default:return[]}}(Ft(e),"start"===s,i);return n&&(r=r.map(e=>e+"-"+n),t&&(r=r.concat(r.map(zt)))),r}(a,g,m,w));const C=[a,...T],O=await Xt(t,f),E=[];let A=(null==(i=r.flip)?void 0:i.overflows)||[];if(h&&E.push(O[b]),u){const e=Ut(n,o,w);E.push(O[e[0]],O[e[1]])}if(A=[...A,{placement:n,overflows:E}],!E.every(e=>e<=0)){var x,M;const e=((null==(x=r.flip)?void 0:x.index)||0)+1,t=C[e];if(t&&("alignment"!==u||y===Vt(t)||A.every(e=>Vt(e.placement)!==y||e.overflows[0]>0)))return{data:{index:e,overflows:A},reset:{placement:t}};let s=null==(M=A.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0])?void 0:M.placement;if(!s)switch(p){case"bestFit":{var k;const e=null==(k=A.filter(e=>{if(S){const t=Vt(e.placement);return t===y||"y"===t}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0])?void 0:k[0];e&&(s=e);break}case"initialPlacement":s=a}if(n!==s)return{reset:{placement:s}}}return{}}}},Hs=e=>{Object.assign(e,{show(){this.cancelBehaviourOpen?.(),this.openValue=!0},hide(){this.openValue=!1},toggle(){this.cancelBehaviourOpen?.(),this.openValue=!this.openValue},setupFloatingUI({trigger:e,popover:t,strategy:s}){this.floatingUICleanup=function(e,t,s,i){void 0===i&&(i={});const{ancestorScroll:n=!0,ancestorResize:r=!0,elementResize:o="function"==typeof ResizeObserver,layoutShift:a="function"==typeof IntersectionObserver,animationFrame:c=!1}=i,l=Ms(e),h=n||r?[...l?Es(l):[],...Es(t)]:[];h.forEach(e=>{n&&e.addEventListener("scroll",s,{passive:!0}),r&&e.addEventListener("resize",s)});const u=l&&a?function(e,t){let s,i=null;const n=is(e);function r(){var e;clearTimeout(s),null==(e=i)||e.disconnect(),i=null}return function o(a,c){void 0===a&&(a=!1),void 0===c&&(c=1),r();const l=e.getBoundingClientRect(),{left:h,top:u,width:d,height:p}=l;if(a||t(),!d||!p)return;const m={rootMargin:-It(u)+"px "+-It(n.clientWidth-(h+d))+"px "+-It(n.clientHeight-(u+p))+"px "+-It(h)+"px",threshold:Mt(0,xt(1,c))||1};let g=!0;function f(t){const i=t[0].intersectionRatio;if(i!==c){if(!g)return o();i?o(!1,i):s=setTimeout(()=>{o(!1,1e-7)},1e3)}1!==i||Us(l,e.getBoundingClientRect())||o(),g=!1}try{i=new IntersectionObserver(f,{...m,root:n.ownerDocument})}catch(e){i=new IntersectionObserver(f,m)}i.observe(e)}(!0),r}(l,s):null;let d,p=-1,m=null;o&&(m=new ResizeObserver(e=>{let[i]=e;i&&i.target===l&&m&&(m.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var e;null==(e=m)||e.observe(t)})),s()}),l&&!c&&m.observe(l),m.observe(t));let g=c?Ps(e):null;return c&&function t(){const i=Ps(e);g&&!Us(g,i)&&s(),g=i,d=requestAnimationFrame(t)}(),s(),()=>{var e;h.forEach(e=>{n&&e.removeEventListener("scroll",s),r&&e.removeEventListener("resize",s)}),null==u||u(),null==(e=m)||e.disconnect(),m=null,c&&cancelAnimationFrame(d)}}(e,t,()=>{((e,t,s)=>{const i=new Map,n={platform:qs,...s},r={...n.platform,_c:i};return(async(e,t,s)=>{const{placement:i="bottom",strategy:n="absolute",middleware:r=[],platform:o}=s,a=r.filter(Boolean),c=await(null==o.isRTL?void 0:o.isRTL(t));let l=await o.getElementRects({reference:e,floating:t,strategy:n}),{x:h,y:u}=Zt(l,i,c),d=i,p={},m=0;for(let s=0;s{const n={left:`${e}px`,top:`${s}px`,position:i};Object.assign(t.style,n)})})},openValueChanged(){this.disabledValue||(this.openValue?(this.preparePopoverOpenAnimation?.(),this.popoverTarget.showPopover(),this.popoverTarget.setAttribute("aria-expanded","true"),this.onPopoverOpened&&this.onPopoverOpened()):(this.popoverTarget.hidePopover(),this.popoverTarget.removeAttribute("aria-expanded"),this.onPopoverClosed&&this.onPopoverClosed()))}})},Gs=class extends i.xI{static targets=["button","popover"];static values={placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},size:{type:Number,default:24},perLine:{type:Number,default:9}};initialize(){this.onEmojiSelect=this.onEmojiSelect.bind(this),this.pickerLoaded=!1,this.pickerLoadPromise=null,this.connected=!1,super.initialize()}connect(){this.connected=!0,Hs(this),this.setupFloatingUI({trigger:this.buttonTarget,popover:this.popoverTarget,strategy:"absolute"}),super.connect()}disconnect(){this.connected=!1,this.pickerLoadPromise=null,this.floatingUICleanup(),super.disconnect()}onEmojiSelect(e){this.dispatch("selected",{detail:e.native}),this.hide()}onClickOutside(e){this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}async onPopoverOpened(){await this.loadPicker()}async loadPicker(){if(this.pickerLoaded)return;this.pickerLoadPromise||=this.loadPickerDependencies();const{Picker:e,i18n:t}=await this.pickerLoadPromise;this.connected&&!this.pickerLoaded&&(this.popoverTarget.appendChild(this.buildPicker(e,t)),this.pickerLoaded=!0)}async loadPickerDependencies(){const[e,t]=await Promise.all([s.e(160).then(s.bind(s,405)),this.loadI18n()]);return{Picker:e.Picker,i18n:t.default||t}}loadI18n(){return"es"===Hellotext.business.locale?s.e(437).then(s.t.bind(s,9,19)):s.e(200).then(s.t.bind(s,714,19))}buildPicker(e,t){return new e({onEmojiSelect:this.onEmojiSelect,theme:"light",dynamicWidth:!0,previewPosition:"none",skinTonePosition:"none",emojiSize:this.sizeValue,perLine:this.perLineValue,i18n:t})}get middlewares(){return[zs(5),Ws({padding:24}),(e={allowedPlacements:["top","bottom"]},void 0===e&&(e={}),{name:"autoPlacement",options:e,async fn(t){var s,i,n;const{rects:r,middlewareData:o,placement:a,platform:c,elements:l}=t,{crossAxis:h=!1,alignment:u,allowedPlacements:d=At,autoAlignment:p=!0,...m}=Dt(e,t),g=void 0!==u||d===At?function(e,t,s){return(e?[...s.filter(t=>Rt(t)===e),...s.filter(t=>Rt(t)!==e)]:s.filter(e=>Ft(e)===e)).filter(s=>!e||Rt(s)===e||!!t&&zt(s)!==s)}(u||null,p,d):d,f=await Xt(t,m),b=(null==(s=o.autoPlacement)?void 0:s.index)||0,y=g[b];if(null==y)return{};const v=Ut(y,r,await(null==c.isRTL?void 0:c.isRTL(l.floating)));if(a!==y)return{reset:{placement:g[0]}};const w=[f[Ft(y)],f[v[0]],f[v[1]]],T=[...(null==(i=o.autoPlacement)?void 0:i.overflows)||[],{placement:y,overflows:w}],S=g[b+1];if(S)return{data:{index:b+1,overflows:T},reset:{placement:S}};const C=T.map(e=>{const t=Rt(e.placement);return[e.placement,t&&h?e.overflows.slice(0,2).reduce((e,t)=>e+t,0):e.overflows[0],e.overflows]}).sort((e,t)=>e[1]-t[1]),O=(null==(n=C.filter(e=>e[2].slice(0,Rt(e[0])?2:3).every(e=>e<=0))[0])?void 0:n[0])||C[0][0];return O!==a?{data:{index:b+1,overflows:T},reset:{placement:O}}:{}}})];var e}};class Js{static get endpoint(){return f.endpoint("public/webchats/:id/messages")}constructor(e){this.webchatId=e}async index(e){const t=new URL(this.url);return Object.entries(e).forEach(([e,s])=>{t.searchParams.append(e,s)}),await fetch(t,{method:"GET",headers:vt.headers})}catchUp(e){return this.index({after_id:e,session:vt.session})}async create(e){const t=await fetch(this.url,{method:"POST",headers:{Authorization:`Bearer ${vt.business.id}`},body:e});return new v(t.ok,t)}markAsSeen(e=null){const t=e?this.url+`/${e}`:this.url+"/seen";fetch(t,{method:"PATCH",headers:vt.headers,body:JSON.stringify({session:vt.session})})}get url(){return Js.endpoint.replace(":id",this.webchatId)}}const Ys=Js;class Zs{static webSocket;static channels=new Set;static messageHandlers=new Set;static disconnectHandlers=new Set;static subscriptionConfirmHandlers=new Set;static reconnectTimeout=null;static reconnectAttempts=0;static reconnectBaseDelay=500;static reconnectMaxDelay=1e4;static reconnectJitter=.3;static needsResubscribe=!1;constructor(){Zs.channels.add(this)}send({command:e,identifier:t,data:s}){const i={command:e,identifier:JSON.stringify(t),data:JSON.stringify(s||{})},n=Zs.ensureWebSocket(),r=JSON.stringify(i);n.readyState===WebSocket.OPEN?n.send(r):n.addEventListener("open",()=>{n.send(r)})}onMessage(e){const t=t=>{const s=JSON.parse(t.data),{type:i,message:n}=s;this.ignoredEvents.includes(i)||e(n)};Zs.messageHandlers.add(t),Zs.ensureWebSocket().addEventListener("message",t)}onDisconnect(e){Zs.disconnectHandlers.add(e)}onSubscriptionConfirmed(e){Zs.subscriptionConfirmHandlers.add(e)}get webSocket(){return Zs.ensureWebSocket()}static ensureWebSocket(){return this.webSocket&&!this.closedWebSocket(this.webSocket)?this.webSocket:(this.webSocket&&(this.needsResubscribe=!0),this.openWebSocket())}static openWebSocket(){this.clearReconnectTimeout();const e=new WebSocket(f.actionCableUrl);return this.webSocket=e,this.installWebSocketHandlers(e),e}static installWebSocketHandlers(e){e.addEventListener("open",()=>this.handleOpen(e)),e.addEventListener("close",()=>this.handleDisconnect(e)),e.addEventListener("error",()=>this.handleDisconnect(e)),e.addEventListener("message",e=>this.handleControlMessage(e)),this.messageHandlers.forEach(t=>{e.addEventListener("message",t)})}static handleOpen(e){e===this.webSocket&&(this.reconnectAttempts=0,this.needsResubscribe&&(this.needsResubscribe=!1,this.resubscribeChannels()))}static handleControlMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}"confirm_subscription"===t.type&&this.subscriptionConfirmHandlers.forEach(e=>e(t.identifier))}static handleDisconnect(e){e===this.webSocket&&(this.disconnectHandlers.forEach(e=>e()),this.webSocket=null,this.needsResubscribe=!0,this.scheduleReconnect())}static scheduleReconnect(){this.reconnectTimeout||(this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts+=1,this.openWebSocket()},this.reconnectDelay))}static clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}static resubscribeChannels(){this.channels.forEach(e=>{const t=e.resubscribe||e.subscribe;"function"==typeof t&&t.call(e)})}static closedWebSocket(e){return e.readyState===WebSocket.CLOSED||e.readyState===WebSocket.CLOSING}static get reconnectDelay(){const e=Math.min(this.reconnectMaxDelay,this.reconnectBaseDelay*2**this.reconnectAttempts);return e+Math.round(e*this.reconnectJitter*Math.random())}get ignoredEvents(){return["ping","confirm_subscription","welcome"]}}const Xs=Zs,Qs=class extends Xs{constructor(e,t,s){super(),this.id=e,this.session=t,this.conversation=s,this.subscribed=!1,this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks=new Set,this.onSubscriptionConfirmed(e=>this.handleSubscriptionConfirmed(e)),this.subscribe()}subscribe(){this.subscribed=!0;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"subscribe",identifier:e})}unsubscribe(){this.subscribed=!1;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"unsubscribe",identifier:e})}resubscribe(){!1!==this.subscribed&&(this.awaitingReconnectConfirmation=!0,this.subscribe())}onReconnect(e){this.reconnectCallbacks.add(e)}handleSubscriptionConfirmed(e){this.awaitingReconnectConfirmation&&this.matchesIdentifier(e)&&(this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks.forEach(e=>e()))}matchesIdentifier(e){let t;try{t="string"==typeof e?JSON.parse(e):e}catch{return!1}return"WebchatChannel"===t.channel&&t.id===this.id&&t.session===this.session&&t.conversation===this.conversation}startTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"message",identifier:e,data:{action:"started_typing"}})}stopTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"typing:stop",identifier:e,data:{action:"stopped_typing"}})}onMessage(e){super.onMessage(t=>{"message"===t.type&&e(t)})}onReaction(e){super.onMessage(t=>{"reaction.create"!==t.type&&"reaction.destroy"!==t.type||e(t)})}onTypingStart(e){super.onMessage(t=>{"started_typing"===t.type&&e(t)})}updateSubscriptionWith(e){this.unsubscribe(),setTimeout(()=>{this.conversation=e,this.subscribe()},1e3)}},ei=e=>{Object.assign(e,{scheduleBehaviourOpen(){if(!this.shouldAutoOpenFromBehaviour())return;const e=1e3*Number(this.behaviourValue.delay_seconds||0);this.behaviourOpenTimeout=window.setTimeout(()=>{this.behaviourOpenTimeout=null,this.openValue||(this.openValue=!0,this.markBehaviourAutoOpened())},e)},cancelBehaviourOpen(){window.clearTimeout(this.behaviourOpenTimeout),this.behaviourOpenTimeout=null},shouldAutoOpenFromBehaviour(){const e=this.behaviourValue;return!(!e||"on_load"!==e.trigger||e.first_visit_only&&localStorage.getItem(this.firstVisitKey())||e.once_per_session&&sessionStorage.getItem(this.sessionKey()))},markBehaviourAutoOpened(){this.behaviourValue.first_visit_only&&localStorage.setItem(this.firstVisitKey(),"1"),this.behaviourValue.once_per_session&&sessionStorage.setItem(this.sessionKey(),"1")},firstVisitKey(){return`hellotext--webchat--${this.idValue}--auto-opened`},sessionKey(){return`hellotext--webchat--${this.idValue}--auto-opened-session`}})},ti=e=>{Object.assign(e,{setupOpeningSequence(){this.openingSequenceStarted=!1,this.openingSequenceCancelled=!1,this.openingSequenceTimeout=null,this.openingSequenceMessages=[],this.revealedOpeningSequenceMessageIds=[]},teardownOpeningSequence(){this.cancelOpeningSequence()},startOpeningSequence(){this.openingSequenceMessages=Array.from(this.openingSequenceMessageTargets||[]),this.openingSequenceCanStart()&&(this.openingSequenceStarted=!0,this.openingSequenceCancelled=!1,this.revealedOpeningSequenceMessageIds=[],this.playOpeningSequenceMessageAt(0))},openingSequenceCanStart(){return!this.conversationIdValue&&this.hasOpeningSequenceTarget&&this.openingSequenceMessages.length>0&&!this.openingSequenceStarted},playOpeningSequenceMessageAt(e){const t=this.openingSequenceMessages[e];if(!t)return;const s=1e3*this.openingSequenceMessageDelay(t);this.openingSequenceTimeout=window.setTimeout(()=>{this.openingSequenceTimeout=null,this.openingSequenceCancelled||(this.revealOpeningSequenceMessage(t),this.playOpeningSequenceMessageAt(e+1))},s)},revealOpeningSequenceMessage(e){this.messagesContainerTarget.insertBefore(e,this.messageTemplateTarget),e.hidden=!1,this.recordOpeningSequenceMessage(e),this.scrollOpeningSequenceToBottom()},recordOpeningSequenceMessage(e){const t=e.dataset.openingSequenceMessageId;t&&!this.revealedOpeningSequenceMessageIds.includes(t)&&this.revealedOpeningSequenceMessageIds.push(t)},openingSequenceMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},scrollOpeningSequenceToBottom(){this.messagesContainerTarget.scroll&&this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"smooth"})},cancelOpeningSequence(){this.openingSequenceCancelled=!0,null!==this.openingSequenceTimeout&&void 0!==this.openingSequenceTimeout&&(window.clearTimeout(this.openingSequenceTimeout),this.openingSequenceTimeout=null)},appendOpeningSequenceMessageIds(e){this.cancelOpeningSequence(),(this.revealedOpeningSequenceMessageIds||[]).forEach(t=>{e.append("message[opening_sequence_message_ids][]",t)})},clearRevealedOpeningSequenceMessageIds(){this.revealedOpeningSequenceMessageIds=[]}})},si=e=>{Object.assign(e,{setupTeaser(){this.teaserCycleTimeout=null,this.teaserMessages=[],this.boundOnTeaserClick=this.boundOnTeaserClick||this.onTeaserClick.bind(this),this.hasTeaserTarget&&(this.teaserTarget.addEventListener("click",this.boundOnTeaserClick),this.startTeaserPresentation())},teardownTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.boundOnTeaserClick&&this.teaserTarget.removeEventListener("click",this.boundOnTeaserClick)},collectTeaserMessages(){return this.hasTeaserTarget?Array.from(this.teaserTarget.querySelectorAll("[data-teaser-message]")):[]},startTeaserPresentation(){this.stopTeaserCycle(),this.teaserMessages=this.collectTeaserMessages(),this.hasTeaserTarget&&(0!==this.teaserMessages.length?this.openValue||this.conversationIdValue||this.hasRenderedConversationMessages()?this.dismissTeaserForSession():this.teaserSeenForSession()?this.hideTeaser():this.teaserMessageDelay(this.teaserMessages[0])>0?this.scheduleTeaserMessage(0):(this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(0),this.scheduleTeaserMessage(1)):this.hideTeaser())},scheduleTeaserMessage(e){const t=this.teaserMessages[e];if(!t)return;const s=this.teaserPresentationDelay(t);this.teaserCycleTimeout=window.setTimeout(()=>{this.teaserCycleTimeout=null,this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(e),this.scheduleTeaserMessage(e+1)},s)},showTeaserMessage(e){this.teaserMessages.forEach((t,s)=>{t.classList.toggle("hidden",s!==e)})},stopTeaserCycle(){null!==this.teaserCycleTimeout&&void 0!==this.teaserCycleTimeout&&(window.clearTimeout(this.teaserCycleTimeout),this.teaserCycleTimeout=null)},teaserMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},teaserPresentationDelay(e){return Math.max(1e3*this.teaserMessageDelay(e),250)},hasRenderedConversationMessages(){let e=[];try{e=Array.from(this.messageTargets||[])}catch(t){e=[]}return e.some(e=>e!==this.messageTemplateTarget)},teaserSeenKey(){const e=this.hasTeaserTarget?this.teaserTarget.dataset.teaserVersion:"",t=e?`:${e}`:"";return`hellotext:webchat:${this.idValue||this.element.id}:teaser-seen${t}`},teaserSeenForSession(){try{return"true"===window.sessionStorage.getItem(this.teaserSeenKey())}catch(e){return!1}},markTeaserSeenForSession(){try{window.sessionStorage.setItem(this.teaserSeenKey(),"true")}catch(e){}},dismissTeaserForSession(){this.markTeaserSeenForSession(),this.hideTeaser()},hideTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.teaserTarget.classList.add("invisible")},onTeaserClick(e){e.target.closest("a")||(this.dismissTeaserForSession(),this.show())}})},ii={hour:"numeric",minute:"2-digit"},ni=/Android|iPhone|iPad|iPod/i,ri={capture:!0,passive:!0},oi=class extends i.xI{static messageTimestampFormatters={};static values={id:String,conversationId:String,media:Object,fileSizeErrorMessage:String,placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},nextPage:{type:Number,default:void 0},fullScreenThreshold:{type:Number,default:1024},typingIndicatorKeepAlive:{type:Number,default:3e4},offset:{type:Number,default:24},padding:{type:Number,default:24},optimisticTypingIndicatorWait:{type:Number,default:1e3},teaser:Object,messageTeaser:String,behaviour:Object};static classes=["fadeOut"];static targets=["trigger","popover","input","attachmentInput","attachmentButton","errorMessageContainer","attachmentTemplate","attachmentContainer","attachment","messageTemplate","messagesContainer","title","attachmentImage","footer","toolbar","message","unreadCounter","typingIndicator","typingIndicatorTemplate","teaser","teaserMessage","inboundMessageTeaser","inboundMessageTeaserBody","openingSequence","openingSequenceMessage"];initialize(){this.messagesAPI=new Ys(this.idValue),this.webChatChannel=new Qs(this.idValue,vt.session,this.conversationIdValue),this.files=[],this.messageIds=new Set,this.catchUpAfterMessageId=null,this.fetchingCatchUpMessages=!1,this.onMessageReceived=this.onMessageReceived.bind(this),this.onMessageReaction=this.onMessageReaction.bind(this),this.onTypingStart=this.onTypingStart.bind(this),this.captureCatchUpCursor=this.captureCatchUpCursor.bind(this),this.catchUpMessages=this.catchUpMessages.bind(this),this.onScroll=this.onScroll.bind(this),this.onOutboundMessageSent=this.onOutboundMessageSent.bind(this),this.closePopoverOnEscape=this.closePopoverOnEscape.bind(this),this.broadcastChannel=new BroadcastChannel(`hellotext--webchat--${this.idValue}`),this.webChatChannel.onDisconnect(this.captureCatchUpCursor),this.webChatChannel.onReconnect(this.catchUpMessages),super.initialize()}connect(){ei(this),Hs(this),ti(this),si(this),this.setupFloatingUI({trigger:this.triggerTarget,popover:this.popoverTarget}),this.hasTeaserTarget&&this.setupFloatingUI({trigger:this.triggerTarget,popover:this.teaserTarget,strategy:"absolute"}),this.setupTeaser(),this.setupOpeningSequence(),this.localizeMessageTimestamps(),this.webChatChannel.onMessage(this.onMessageReceived),this.webChatChannel.onTypingStart(this.onTypingStart),this.webChatChannel.onReaction(this.onMessageReaction),this.setupMessagesContainerScrollIsolation(),this.messagesContainerTarget.addEventListener("scroll",this.onScroll),this.messagesContainerTarget.addEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.addEventListener("touchmove",this.stopHostScrollPropagation,ri),this.shouldOpenOnMount&&(this.openValue=!0),vt.eventEmitter.dispatch("webchat:mounted"),this.broadcastChannel.addEventListener("message",this.onOutboundMessageSent),window.addEventListener("keydown",this.closePopoverOnEscape,!0),this.scheduleBehaviourOpen(),super.connect()}disconnect(){this.cancelBehaviourOpen(),this.clearPopoverOpenAnimation(),this.teardownTeaser(),this.teardownOpeningSequence(),this.broadcastChannel.removeEventListener("message",this.onOutboundMessageSent),this.messagesContainerTarget.removeEventListener("scroll",this.onScroll),this.messagesContainerTarget.removeEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.removeEventListener("touchmove",this.stopHostScrollPropagation,ri),window.removeEventListener("keydown",this.closePopoverOnEscape,!0),this.clearTypingIndicator(),this.broadcastChannel.close(),this.floatingUICleanup(),super.disconnect()}setupMessagesContainerScrollIsolation(){this.messagesContainerTarget.style.overscrollBehavior="contain",this.messagesContainerTarget.style.webkitOverflowScrolling="touch",this.messagesContainerTarget.style.touchAction="pan-y",this.messagesContainerTarget.setAttribute("data-lenis-prevent",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-wheel",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-touch","")}stopHostScrollPropagation(e){e.stopPropagation()}onTypingStart(){if(this.typingIndicatorVisible)return this.resetTypingIndicatorTimer();this.showTypingIndicator()}showOptimisticTypingIndicator(){this.typingIndicatorVisible||this.showTypingIndicator()}showTypingIndicator(){this.clearTypingIndicator(),this.typingIndicatorVisible=!0;const e=this.typingIndicatorTemplateTarget.cloneNode(!0);e.setAttribute("data-hellotext--webchat-target","typingIndicator"),e.style.display="flex",this.messagesContainerTarget.appendChild(e),requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})});const t=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},t)}resetTypingIndicatorTimer(){if(!this.typingIndicatorVisible)return;clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout);const e=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},e)}clearTypingIndicator(){this.hasTypingIndicatorTarget&&this.typingIndicatorTarget.remove(),this.typingIndicatorVisible=!1,clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout)}onMessageInputChange(){this.resizeInput(),clearTimeout(this.typingIndicatorTimeout),this.hasSentTypingIndicator||(this.webChatChannel.startTypingIndicator(),this.hasSentTypingIndicator=!0),this.typingIndicatorTimeout=setTimeout(()=>{this.hasSentTypingIndicator=!1},3e3)}onOutboundMessageSent(e){const{data:t}=e,s={"message:sent":e=>{const t=(new DOMParser).parseFromString(e.element,"text/html").body.firstElementChild;this.localizeMessageTimestamps(t),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(t,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(t),t.scrollIntoView({behavior:"instant"})},"message:failed":e=>{const t=this.messagesContainerTarget.querySelector(`#${e.id}`);this.markMessageFailed(t,e.reason)}};s[t.type]?s[t.type](t):console.log(`Unhandled message event: ${t.type}`)}async onScroll(){if(this.messagesContainerTarget.scrollTop>300||!this.nextPageValue||this.fetchingNextPage)return;this.fetchingNextPage=!0;const e=await this.messagesAPI.index({page:this.nextPageValue,session:vt.session}),{next:t,messages:s}=await e.json();this.nextPageValue=t,this.oldScrollHeight=this.messagesContainerTarget.scrollHeight,s.forEach(e=>{const{body:t,attachments:s}=e,i=e.created_at||e.createdAt,n=this.messageTemplateTarget.cloneNode(!0);n.classList.add("hellotext--webchat-message"),n.setAttribute("data-hellotext--webchat-target","message"),n.setAttribute("data-id",e.id),i&&n.setAttribute("data-created-at",i),n.style.removeProperty("display"),rt(n.querySelector("[data-body]"),t),"received"===e.state?n.classList.add("received"):n.classList.remove("received"),s&&s.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.removeAttribute("data-hellotext--webchat-target"),t.src=e,t.style.display="block",this.messageAttachmentsContainer(n)?.appendChild(t)}),n.setAttribute("data-body",t),this.localizeMessageTimestamp(n.querySelector("[data-message-timestamp]"),i),this.messagesContainerTarget.prepend(n)}),this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight-this.oldScrollHeight,behavior:"instant"}),this.fetchingNextPage=!1}onClickOutside(e){d.mode===u.POPOVER&&this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}closePopover(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.openValue=!1}preparePopoverOpenAnimation(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.popoverTarget.classList.add("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=setTimeout(()=>{this.popoverTarget.classList.remove("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=null},120)}clearPopoverOpenAnimation(){this.popoverOpenAnimationTimeout&&(clearTimeout(this.popoverOpenAnimationTimeout),this.popoverOpenAnimationTimeout=null),this.popoverTarget?.classList.remove("hellotext--webchat-popover-opening")}onPopoverOpened(){this.popoverTarget.classList.remove(...this.fadeOutClasses),this.dismissTeaserForSession?.(),this.onMobile||this.focusComposeInput(),this.scrolled||(requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})}),this.scrolled=!0),vt.eventEmitter.dispatch("webchat:opened"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"opened"),this.messageTeaserValue&&(this.messageTeaserValue=null),this.startOpeningSequence(),"none"!==this.unreadCounterTarget.style.display&&(this.unreadCounterTarget.style.display="none",this.unreadCounterTarget.innerText="0",this.messagesAPI.markAsSeen())}onPopoverClosed(){this.clearPopoverOpenAnimation(),vt.eventEmitter.dispatch("webchat:closed"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"closed")}onMessageReaction(e){const{message:t,reaction:s,type:i}=e,n=this.messageTargets.find(e=>e.dataset.id===t).querySelector("[data-reactions]");if("reaction.destroy"===i)return n.querySelector(`[data-id="${s.id}"]`).remove();if(n.querySelector(`[data-id="${s.id}"]`))n.querySelector(`[data-id="${s.id}"]`).innerText=s.emoji;else{const e=document.createElement("span");e.innerText=s.emoji,e.setAttribute("data-id",s.id),n.appendChild(e)}}onMessageReceived(e,t={}){const{id:s,body:i,attachments:n,teaser:r}=e,o=e.created_at||e.createdAt;if(!this.claimMessageId(s))return;if(this.hideTeaser?.(),e.carousel)return this.insertCarouselMessage(e,t);const a=this.messageTemplateTarget.cloneNode(!0);a.classList.add("hellotext--webchat-message"),a.style.display="flex",rt(a.querySelector("[data-body]"),i),a.setAttribute("data-id",s),a.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(a,o),this.localizeMessageTimestamp(a.querySelector("[data-message-timestamp]"),o),n&&n.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.src=e,t.style.display="block",this.messageAttachmentsContainer(a)?.appendChild(t)}),this.clearTypingIndicator(),this.insertMessageElement(a),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:a.querySelector("[data-body]").innerText}),!1!==t.scroll&&a.scrollIntoView({behavior:"smooth"}),this.updateMessageTeaser(r),this.openValue?this.messagesAPI.markAsSeen(s):this.incrementUnreadCounter()}claimMessageId(e){const t=this.messageTargets||[];return!this.messageIds.has(e)&&(this.messageIds.add(e),!t.some(t=>t.dataset.id===e))}captureCatchUpCursor(){this.catchUpAfterMessageId=this.lastRenderedMessageId}async catchUpMessages(){const e=this.catchUpAfterMessageId;if(e&&!this.fetchingCatchUpMessages){this.fetchingCatchUpMessages=!0;try{const t=await this.messagesAPI.catchUp(e),{messages:s=[]}=await t.json();s.forEach(e=>this.onMessageReceived(e,{scroll:!1})),this.catchUpAfterMessageId=this.lastRenderedMessageId}finally{this.fetchingCatchUpMessages=!1}}}get lastRenderedMessageId(){const e=this.persistedMessageElements;return e[e.length-1]?.dataset.id||null}get persistedMessageElements(){return Array.from(this.messagesContainerTarget.querySelectorAll(".hellotext--webchat-message[data-id]"))}setMessageCreatedAt(e,t){t&&e.setAttribute("data-created-at",t)}insertMessageElement(e){const t=this.nextMessageElementFor(e);t?this.messagesContainerTarget.insertBefore(e,t):this.messagesContainerTarget.appendChild(e)}nextMessageElementFor(e){const t=Date.parse(e.dataset.createdAt);return Number.isNaN(t)?null:this.persistedMessageElements.find(s=>{if(s===e)return!1;const i=Date.parse(s.dataset.createdAt);return!Number.isNaN(i)&&i>t})}updateMessageTeaser(e){this.messageTeaserValue=e,this.messageTeaserValue&&this.hasTeaserTarget&&this.hasInboundMessageTeaserTarget&&this.hasInboundMessageTeaserBodyTarget&&(this.teaserMessageTargets.forEach(e=>e.classList.add("hidden")),this.inboundMessageTeaserBodyTarget.textContent=this.messageTeaserValue,this.inboundMessageTeaserTarget.classList.remove("hidden"),this.teaserTarget.classList.toggle("invisible",this.openValue))}insertCarouselMessage(e,t={}){const s=e.html,i=e.created_at||e.createdAt,n=function(e){return nt(e,it)}(s).firstElementChild;n.classList.add("hellotext--webchat-message"),n.setAttribute("data-id",e.id),n.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(n,i),this.localizeMessageTimestamps(n),this.clearTypingIndicator(),this.insertMessageElement(n),!1!==t.scroll&&n.scrollIntoView({behavior:"smooth"}),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:n.querySelector("[data-body]")?.innerText||""}),this.updateMessageTeaser(e.teaser),this.openValue?this.messagesAPI.markAsSeen(e.id):this.incrementUnreadCounter()}resizeInput(){this.inputTarget.style.height="auto";const e=this.inputTarget.scrollHeight;this.inputTarget.style.height=`${Math.min(e,96)}px`}async sendQuickReplyMessage({detail:{id:e,product:t,buttonId:s,body:i,cardElement:n}}){this.dismissTeaserForSession?.();const r=new FormData;r.append("message[body]",i),e&&r.append("message[replied_to]",e),t&&r.append("message[product]",t),s&&r.append("message[button]",s),r.append("session",vt.session),r.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(r);const o=this.buildMessageElement(),c=n?.querySelector("img")?.cloneNode(!0);o.querySelector("[data-body]").innerText=i,c&&(c.removeAttribute("width"),c.removeAttribute("height"),this.messageAttachmentsContainer(o)?.appendChild(c)),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(o,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(o),o.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:o.outerHTML});const l=await this.messagesAPI.create(r);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,o);const h=await l.json();this.dispatch("set:id",{target:o,detail:h.id}),this.localizeMessageTimestamp(o.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds();const u={id:h.id,body:i,attachments:c?[c.src]:[],replied_to:e,product:t,button:s,type:"quick_reply"};vt.eventEmitter.dispatch("webchat:message:sent",u)}async sendTeaserQuickReply(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=(t.dataset.value||"").trim(),i=[t.dataset.text,t.textContent].map(e=>(e||"").trim()).find(e=>e.length>0),n=s||i;if(!n)return;this.dismissTeaserForSession?.(),this.show();const r=(t.dataset.type||"").trim()||"quick_reply",o=new FormData;o.append("message[body]",n),o.append("session",vt.session),o.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(o);const c=this.buildMessageElement();c.querySelector("[data-body]").innerText=n,this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(c,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(c),c.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:c.outerHTML}),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const l=await this.messagesAPI.create(o);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,c);const h=await l.json();c.setAttribute("data-id",h.id),this.localizeMessageTimestamp(c.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",{id:h.id,body:n,attachments:[],type:"quick_reply",teaser:{text:i||n,value:s||n,type:r}}),h.conversation&&h.conversation!==this.conversationIdValue&&(this.conversationIdValue=h.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer()}async sendMessage(e){const t={body:this.inputTarget.value,attachments:this.files};if(0===this.inputTarget.value.trim().length&&0===this.files.length)return void(e&&e.target&&e.preventDefault());this.dismissTeaserForSession?.();const s=new FormData;this.inputTarget.value.trim().length>0?s.append("message[body]",this.inputTarget.value):delete t.body,this.files.forEach(e=>{s.append("message[attachments][]",e)}),s.append("session",vt.session),s.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(s);const i=this.buildMessageElement();this.inputTarget.value.trim().length>0?i.querySelector("[data-body]").innerText=this.inputTarget.value:i.querySelector("[data-message-bubble]").remove();const n=this.attachmentContainerTarget.querySelectorAll("img");n.length>0&&n.forEach(e=>{this.messageAttachmentsContainer(i)?.appendChild(e.cloneNode(!0))}),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(i,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(i),i.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:i.outerHTML}),this.inputTarget.value="",this.resizeInput(),this.files=[],this.attachmentInputTarget.value="",this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none",this.errorMessageContainerTarget.style.display="none",this.focusComposeInput(),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const r=await this.messagesAPI.create(s);if(r.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(r,i);const o=await r.json();i.setAttribute("data-id",o.id),t.id=o.id,this.localizeMessageTimestamp(i.querySelector("[data-message-timestamp]"),o.created_at||o.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",t),o.conversation!==this.conversationIdValue&&(this.conversationIdValue=o.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer(),this.attachmentContainerTarget.style.display=""}buildMessageElement(){const e=this.messageTemplateTarget.cloneNode(!0);return e.id=`hellotext--webchat--${this.idValue}--message--${Date.now()}`,e.classList.add("received"),e.style.removeProperty("display"),e.setAttribute("data-controller","hellotext--message"),e.setAttribute("data-hellotext--webchat-target","message"),this.localizeMessageTimestamp(e.querySelector("[data-message-timestamp]"),new Date),e}focusCompose(e){const{target:t}=e,s=["button","a","input","textarea","select","label",'[role="button"]',"em-emoji-picker",'[data-hellotext--webchat--emoji-target~="popover"]','[data-controller~="hellotext--webchat--emoji"]'].join(", ");this.hasInputTarget&&!t.closest(s)&&this.focusComposeInput({moveCursorToEnd:!0})&&e.preventDefault()}closePopoverFromHeader(e){const{target:t}=e;t.closest(".hellotext--webchat-header-channel-button, .hellotext--webchat-close-button")||(e.preventDefault(),this.closePopover())}closePopoverOnEscape(e){"Escape"===e.key&&this.openValue&&(e.preventDefault(),e.stopPropagation(),this.closePopover(),this.triggerTarget?.focus?.())}async markMessageFailedFromResponse(e,t){const s=await this.messageFailureReason(e);this.markMessageFailed(t,s),this.broadcastChannel.postMessage({type:"message:failed",id:t.id,reason:s})}markMessageFailed(e,t){if(!e)return;if(e.classList.add("failed"),!t)return;const s=e.querySelector("[data-message-timestamp]");s&&(s.textContent=t)}localizeMessageTimestamps(e=this.element){e&&(e.matches?.("time[datetime][data-message-timestamp]")?[e]:Array.from(e.querySelectorAll?.("time[datetime][data-message-timestamp]")||[])).forEach(e=>this.localizeMessageTimestamp(e))}localizeMessageTimestamp(e,t=e?.getAttribute("datetime")){if(!e||!t)return;const s=t instanceof Date?t:new Date(t);Number.isNaN(s.getTime())||(e.setAttribute("datetime",s.toISOString()),e.textContent=this.formatMessageTimestamp(s))}formatMessageTimestamp(e){return this.constructor.messageTimestampFormatterFor(a.toString()).format(e)}static messageTimestampFormatterFor(e){const t=e||"default";return this.messageTimestampFormatters[t]||(this.messageTimestampFormatters[t]=this.buildMessageTimestampFormatter(e)),this.messageTimestampFormatters[t]}static buildMessageTimestampFormatter(e){try{return new Intl.DateTimeFormat(e||void 0,ii)}catch(e){return new Intl.DateTimeFormat(void 0,ii)}}async messageFailureReason(e){const t=e?.data||e?.response,s=t?.statusText||"Message failed";try{const e=t?.clone?t.clone():t,s=await(e?.json?.()),i=this.messageFailureReasonFromPayload(s);if(i)return i}catch(e){}try{const e=t?.clone?t.clone():t,i=await(e?.text?.());return this.messageFailureReasonFromText(i)||s}catch(e){return s}}messageFailureReasonFromText(e){if("string"!=typeof e)return null;const t=e.trim();if(!t||t.startsWith("<"))return null;try{return this.messageFailureReasonFromPayload(JSON.parse(t))||t}catch(e){return t}}messageFailureReasonFromPayload(e){return e?[e.error?.message,e.message,e.errors?.message,e.errors?.[0]?.message,e.errors?.[0]?.description].find(e=>"string"==typeof e&&e.trim().length>0):null}messageAttachmentsContainer(e){return e.querySelector("[data-attachments-container], [data-attachment-container]")}incrementUnreadCounter(){this.unreadCounterTarget.style.display="flex";const e=(parseInt(this.unreadCounterTarget.innerText)||0)+1;this.unreadCounterTarget.innerText=Math.min(e,9)}openAttachment(){this.attachmentInputTarget.click()}onFileInputChange(){this.errorMessageContainerTarget.style.display="none";const e=Array.from(this.attachmentInputTarget.files);this.attachmentInputTarget.value="";const t=e.find(e=>{const t=e.type.split("/")[0];return["image","video","audio"].includes(t)?this.mediaValue[t].max_sizethis.createAttachmentElement(e)),this.focusComposeInput()}createAttachmentElement(e){const t=this.attachmentElement();if(this.attachmentContainerTarget.style.display="",t.setAttribute("data-name",e.name),e.type.startsWith("image/")){const s=this.attachmentImageTarget.cloneNode(!0);s.src=URL.createObjectURL(e),s.style.display="block",t.appendChild(s),this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}else{const s=t.querySelector("main");s.style.height="5rem",s.style.borderRadius="0.375rem",s.style.backgroundColor="#e5e7eb",s.style.padding="0.25rem",t.querySelector("p[data-attachment-name]").innerText=e.name,this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}}removeAttachment({currentTarget:e}){const t=e.closest("[data-hellotext--webchat-target='attachment']");this.files=this.files.filter(e=>e.name!==t.dataset.name),this.attachmentInputTarget.value="",t.remove(),this.focusComposeInput()}attachmentTargetDisconnected(){0===this.attachmentTargets.length&&(this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none")}attachmentElement(){const e=this.attachmentTemplateTarget.cloneNode(!0);return e.removeAttribute("hidden"),e.style.display="flex",e.setAttribute("data-hellotext--webchat-target","attachment"),e}onEmojiSelect({detail:e}){const t=this.inputTarget.value,s=this.inputTarget.selectionStart,i=this.inputTarget.selectionEnd;this.inputTarget.value=t.slice(0,s)+e+t.slice(i),this.inputTarget.selectionStart=this.inputTarget.selectionEnd=s+e.length,this.focusComposeInput()}focusComposeInput({moveCursorToEnd:e=!1}={}){if(!this.shouldAutofocusCompose)return!1;if(!1===this.hasInputTarget)return!1;if(void 0===this.hasInputTarget&&!this.inputTarget)return!1;if(this.inputTarget.focus(),e&&"number"==typeof this.inputTarget.selectionStart){const e=this.inputTarget.value.length;this.inputTarget.setSelectionRange(e,e)}return!0}byteToMegabyte(e){return Math.ceil(e/1024/1024)}get middlewares(){return[zs(this.offsetValue),Ws({padding:this.paddingValue}),Ks()]}get shouldOpenOnMount(){return"opened"===localStorage.getItem(`hellotext--webchat--${this.idValue}`)&&!this.onMobile}get shouldAutofocusCompose(){return!this.usesVirtualKeyboard}get usesVirtualKeyboard(){if("undefined"==typeof navigator)return!1;const e=navigator.userAgent||"",t="MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,s=ni.test(e),i=!0===navigator.userAgentData?.mobile;return s||t||i||this.hasTouchOnlyPointer}get hasTouchOnlyPointer(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches&&window.matchMedia("(hover: none)").matches}get onMobile(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(`(max-width: ${this.fullScreenThresholdValue}px)`).matches}},ai=i.lg.start();ai.register("hellotext--alert",Tt),ai.register("hellotext--form",St),ai.register("hellotext--popup",Ot),ai.register("hellotext--webchat",oi),ai.register("hellotext--webchat--emoji",Gs),ai.register("hellotext--message",Ct),window.Hellotext=vt;const ci=vt}};const t={};function s(i){const n=t[i];if(void 0!==n)return n.exports;const r=t[i]={exports:{}};return e[i](r,r.exports,s),r.exports}s.m=e,(()=>{const e=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;let t;s.t=function(i,n){if(1&n&&(i=this(i)),8&n)return i;if("object"==typeof i&&i){if(4&n&&i.__esModule)return i;if(16&n&&"function"==typeof i.then)return i}const r=Object.create(null);s.r(r);const o={};t=t||[null,e({}),e([]),e(e)];for(var a=2&n&&i;("object"==typeof a||"function"==typeof a)&&!~t.indexOf(a);a=e(a))Object.getOwnPropertyNames(a).forEach(e=>o[e]=()=>i[e]);return o.default=()=>i,s.d(r,o),r}})(),s.d=(e,t)=>{if(Array.isArray(t))for(var i=0;iPromise.all(Object.keys(s.f).reduce((t,i)=>(s.f[i](e,t),t),[])),s.u=e=>({160:"webchat-emoji",200:"webchat-emoji-en",437:"webchat-emoji-es"}[e]+".js"),s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{const e={},t="Hellotext:";s.l=(i,n,r,o)=>{if(e[i])return void e[i].push(n);let a,c;if(void 0!==r){const e=document.getElementsByTagName("script");for(var l=0;l{a.onerror=a.onload=null,clearTimeout(u);const n=e[i];if(delete e[i],a.parentNode?.removeChild(a),n?.forEach(e=>e(s)),t)return t(s)},u=setTimeout(h.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=h.bind(null,a.onerror),a.onload=h.bind(null,a.onload),c&&document.head.appendChild(a)}})(),s.r=e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{let e;s.g.importScripts&&(e=s.g.location+"");const t=s.g.document;if(!e&&t&&("SCRIPT"===t.currentScript?.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){const s=t.getElementsByTagName("script");if(s.length){let t=s.length-1;for(;t>-1&&(!e||!/^http(s?):/.test(e));)e=s[t--].src}}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})(),(()=>{const e={792:0};s.f.j=(t,i)=>{let n=s.o(e,t)?e[t]:void 0;if(0!==n)if(n)i.push(n[2]);else{const r=new Promise((s,i)=>n=e[t]=[s,i]);i.push(n[2]=r);const o=s.p+s.u(t),a=new Error,c=i=>{if(s.o(e,t)&&(n=e[t],0!==n&&(e[t]=void 0),n)){const e=i&&("load"===i.type?"missing":i.type),s=i&&i.target&&i.target.src;a.message="Loading chunk "+t+" failed.\n("+e+": "+s+")",a.name="ChunkLoadError",a.type=e,a.request=s,n[1](a)}};s.l(o,c,"chunk-"+t,t)}};const t=(t,i)=>{let[n,r,o]=i;var a,c,l=0;if(n.some(t=>0!==e[t])){for(a in r)s.o(r,a)&&(s.m[a]=r[a]);o&&o(s)}for(t&&t(i);l Date: Thu, 8 Oct 2026 09:09:39 -0400 Subject: [PATCH 3/4] Ignore Escape while the whole popup is hidden --- __tests__/controllers/popup_controller_test.js | 11 +++++++++++ dist/hellotext.js | 2 +- lib/controllers/popup_controller.cjs | 4 ++-- lib/controllers/popup_controller.js | 4 ++-- src/controllers/popup_controller.js | 4 ++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/__tests__/controllers/popup_controller_test.js b/__tests__/controllers/popup_controller_test.js index a0d9788..813fc40 100644 --- a/__tests__/controllers/popup_controller_test.js +++ b/__tests__/controllers/popup_controller_test.js @@ -188,6 +188,17 @@ describe('PopupController', () => { expect(Hellotext.eventEmitter.dispatch).not.toHaveBeenCalledWith('popup:closed') }) + it('ignores Escape while the whole popup is hidden', () => { + const { element } = buildController({ hasBubble: false }) + + controller.connect() + element.hidden = true + Hellotext.eventEmitter.dispatch.mockClear() + controller.closeOnEscape(escape()) + + expect(Hellotext.eventEmitter.dispatch).not.toHaveBeenCalledWith('popup:closed') + }) + it('ignores Escape already handled by another control or an input method', () => { const { element } = buildController({ hasBubble: false }) diff --git a/dist/hellotext.js b/dist/hellotext.js index 9d43bff..b4f012a 100644 --- a/dist/hellotext.js +++ b/dist/hellotext.js @@ -1,2 +1,2 @@ /*! For license information please see hellotext.js.LICENSE.txt */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={891(e,t,s){s.d(t,{lg:()=>G,xI:()=>ne});class i{constructor(e,t,s){this.eventTarget=e,this.eventName=t,this.eventOptions=s,this.unorderedBindings=new Set}connect(){this.eventTarget.addEventListener(this.eventName,this,this.eventOptions)}disconnect(){this.eventTarget.removeEventListener(this.eventName,this,this.eventOptions)}bindingConnected(e){this.unorderedBindings.add(e)}bindingDisconnected(e){this.unorderedBindings.delete(e)}handleEvent(e){const t=function(e){if("immediatePropagationStopped"in e)return e;{const{stopImmediatePropagation:t}=e;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e);for(const e of this.bindings){if(t.immediatePropagationStopped)break;e.handleEvent(t)}}hasBindings(){return this.unorderedBindings.size>0}get bindings(){return Array.from(this.unorderedBindings).sort((e,t)=>{const s=e.index,i=t.index;return si?1:0})}}class n{constructor(e){this.application=e,this.eventListenerMaps=new Map,this.started=!1}start(){this.started||(this.started=!0,this.eventListeners.forEach(e=>e.connect()))}stop(){this.started&&(this.started=!1,this.eventListeners.forEach(e=>e.disconnect()))}get eventListeners(){return Array.from(this.eventListenerMaps.values()).reduce((e,t)=>e.concat(Array.from(t.values())),[])}bindingConnected(e){this.fetchEventListenerForBinding(e).bindingConnected(e)}bindingDisconnected(e,t=!1){this.fetchEventListenerForBinding(e).bindingDisconnected(e),t&&this.clearEventListenersForBinding(e)}handleError(e,t,s={}){this.application.handleError(e,`Error ${t}`,s)}clearEventListenersForBinding(e){const t=this.fetchEventListenerForBinding(e);t.hasBindings()||(t.disconnect(),this.removeMappedEventListenerFor(e))}removeMappedEventListenerFor(e){const{eventTarget:t,eventName:s,eventOptions:i}=e,n=this.fetchEventListenerMapForEventTarget(t),r=this.cacheKey(s,i);n.delete(r),0==n.size&&this.eventListenerMaps.delete(t)}fetchEventListenerForBinding(e){const{eventTarget:t,eventName:s,eventOptions:i}=e;return this.fetchEventListener(t,s,i)}fetchEventListener(e,t,s){const i=this.fetchEventListenerMapForEventTarget(e),n=this.cacheKey(t,s);let r=i.get(n);return r||(r=this.createEventListener(e,t,s),i.set(n,r)),r}createEventListener(e,t,s){const n=new i(e,t,s);return this.started&&n.connect(),n}fetchEventListenerMapForEventTarget(e){let t=this.eventListenerMaps.get(e);return t||(t=new Map,this.eventListenerMaps.set(e,t)),t}cacheKey(e,t){const s=[e];return Object.keys(t).sort().forEach(e=>{s.push(`${t[e]?"":"!"}${e}`)}),s.join(":")}}const r={stop:({event:e,value:t})=>(t&&e.stopPropagation(),!0),prevent:({event:e,value:t})=>(t&&e.preventDefault(),!0),self:({event:e,value:t,element:s})=>!t||s===e.target},o=/^(?:(?:([^.]+?)\+)?(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;function a(e){return e.replace(/(?:[_-])([a-z0-9])/g,(e,t)=>t.toUpperCase())}function c(e){return a(e.replace(/--/g,"-").replace(/__/g,"_"))}function l(e){return e.charAt(0).toUpperCase()+e.slice(1)}function h(e){return e.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`)}function u(e){return null!=e}function d(e,t){return Object.prototype.hasOwnProperty.call(e,t)}const p=["meta","ctrl","alt","shift"];class m{constructor(e,t,s,i){this.element=e,this.index=t,this.eventTarget=s.eventTarget||e,this.eventName=s.eventName||function(e){const t=e.tagName.toLowerCase();if(t in g)return g[t](e)}(e)||f("missing event name"),this.eventOptions=s.eventOptions||{},this.identifier=s.identifier||f("missing identifier"),this.methodName=s.methodName||f("missing method name"),this.keyFilter=s.keyFilter||"",this.schema=i}static forToken(e,t){return new this(e.element,e.index,function(e){const t=e.trim().match(o)||[];let s=t[2],i=t[3];return i&&!["keydown","keyup","keypress"].includes(s)&&(s+=`.${i}`,i=""),{eventTarget:(n=t[4],"window"==n?window:"document"==n?document:void 0),eventName:s,eventOptions:t[7]?(r=t[7],r.split(":").reduce((e,t)=>Object.assign(e,{[t.replace(/^!/,"")]:!/^!/.test(t)}),{})):{},identifier:t[5],methodName:t[6],keyFilter:t[1]||i};var n,r}(e.content),t)}toString(){const e=this.keyFilter?`.${this.keyFilter}`:"",t=this.eventTargetName?`@${this.eventTargetName}`:"";return`${this.eventName}${e}${t}->${this.identifier}#${this.methodName}`}shouldIgnoreKeyboardEvent(e){if(!this.keyFilter)return!1;const t=this.keyFilter.split("+");if(this.keyFilterDissatisfied(e,t))return!0;const s=t.filter(e=>!p.includes(e))[0];return!!s&&(d(this.keyMappings,s)||f(`contains unknown key filter: ${this.keyFilter}`),this.keyMappings[s].toLowerCase()!==e.key.toLowerCase())}shouldIgnoreMouseEvent(e){if(!this.keyFilter)return!1;const t=[this.keyFilter];return!!this.keyFilterDissatisfied(e,t)}get params(){const e={},t=new RegExp(`^data-${this.identifier}-(.+)-param$`,"i");for(const{name:s,value:i}of Array.from(this.element.attributes)){const n=s.match(t),r=n&&n[1];r&&(e[a(r)]=b(i))}return e}get eventTargetName(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e}get keyMappings(){return this.schema.keyMappings}keyFilterDissatisfied(e,t){const[s,i,n,r]=p.map(e=>t.includes(e));return e.metaKey!==s||e.ctrlKey!==i||e.altKey!==n||e.shiftKey!==r}}const g={a:()=>"click",button:()=>"click",form:()=>"submit",details:()=>"toggle",input:e=>"submit"==e.getAttribute("type")?"click":"input",select:()=>"change",textarea:()=>"input"};function f(e){throw new Error(e)}function b(e){try{return JSON.parse(e)}catch(t){return e}}class y{constructor(e,t){this.context=e,this.action=t}get index(){return this.action.index}get eventTarget(){return this.action.eventTarget}get eventOptions(){return this.action.eventOptions}get identifier(){return this.context.identifier}handleEvent(e){const t=this.prepareActionEvent(e);this.willBeInvokedByEvent(e)&&this.applyEventModifiers(t)&&this.invokeWithEvent(t)}get eventName(){return this.action.eventName}get method(){const e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`)}applyEventModifiers(e){const{element:t}=this.action,{actionDescriptorFilters:s}=this.context.application,{controller:i}=this.context;let n=!0;for(const[r,o]of Object.entries(this.eventOptions))if(r in s){const a=s[r];n=n&&a({name:r,value:o,event:e,element:t,controller:i})}return n}prepareActionEvent(e){return Object.assign(e,{params:this.action.params})}invokeWithEvent(e){const{target:t,currentTarget:s}=e;try{this.method.call(this.controller,e),this.context.logDebugActivity(this.methodName,{event:e,target:t,currentTarget:s,action:this.methodName})}catch(t){const{identifier:s,controller:i,element:n,index:r}=this,o={identifier:s,controller:i,element:n,index:r,event:e};this.context.handleError(t,`invoking action "${this.action}"`,o)}}willBeInvokedByEvent(e){const t=e.target;return!(e instanceof KeyboardEvent&&this.action.shouldIgnoreKeyboardEvent(e))&&!(e instanceof MouseEvent&&this.action.shouldIgnoreMouseEvent(e))&&(this.element===t||(t instanceof Element&&this.element.contains(t)?this.scope.containsElement(t):this.scope.containsElement(this.action.element)))}get controller(){return this.context.controller}get methodName(){return this.action.methodName}get element(){return this.scope.element}get scope(){return this.context.scope}}class v{constructor(e,t){this.mutationObserverInit={attributes:!0,childList:!0,subtree:!0},this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,this.mutationObserverInit),this.refresh())}pause(e){this.started&&(this.mutationObserver.disconnect(),this.started=!1),e(),this.started||(this.mutationObserver.observe(this.element,this.mutationObserverInit),this.started=!0)}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started){const e=new Set(this.matchElementsInTree());for(const t of Array.from(this.elements))e.has(t)||this.removeElement(t);for(const t of Array.from(e))this.addElement(t)}}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){"attributes"==e.type?this.processAttributeChange(e.target,e.attributeName):"childList"==e.type&&(this.processRemovedNodes(e.removedNodes),this.processAddedNodes(e.addedNodes))}processAttributeChange(e,t){this.elements.has(e)?this.delegate.elementAttributeChanged&&this.matchElement(e)?this.delegate.elementAttributeChanged(e,t):this.removeElement(e):this.matchElement(e)&&this.addElement(e)}processRemovedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.processTree(e,this.removeElement)}}processAddedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.elementIsActive(e)&&this.processTree(e,this.addElement)}}matchElement(e){return this.delegate.matchElement(e)}matchElementsInTree(e=this.element){return this.delegate.matchElementsInTree(e)}processTree(e,t){for(const s of this.matchElementsInTree(e))t.call(this,s)}elementFromNode(e){if(e.nodeType==Node.ELEMENT_NODE)return e}elementIsActive(e){return e.isConnected==this.element.isConnected&&this.element.contains(e)}addElement(e){this.elements.has(e)||this.elementIsActive(e)&&(this.elements.add(e),this.delegate.elementMatched&&this.delegate.elementMatched(e))}removeElement(e){this.elements.has(e)&&(this.elements.delete(e),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(e))}}class w{constructor(e,t,s){this.attributeName=t,this.delegate=s,this.elementObserver=new v(e,this)}get element(){return this.elementObserver.element}get selector(){return`[${this.attributeName}]`}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get started(){return this.elementObserver.started}matchElement(e){return e.hasAttribute(this.attributeName)}matchElementsInTree(e){const t=this.matchElement(e)?[e]:[],s=Array.from(e.querySelectorAll(this.selector));return t.concat(s)}elementMatched(e){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(e,this.attributeName)}elementUnmatched(e){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(e,this.attributeName)}elementAttributeChanged(e,t){this.delegate.elementAttributeValueChanged&&this.attributeName==t&&this.delegate.elementAttributeValueChanged(e,t)}}function T(e,t){let s=e.get(t);return s||(s=new Set,e.set(t,s)),s}class S{constructor(){this.valuesByKey=new Map}get keys(){return Array.from(this.valuesByKey.keys())}get values(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e.concat(Array.from(t)),[])}get size(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e+t.size,0)}add(e,t){!function(e,t,s){T(e,t).add(s)}(this.valuesByKey,e,t)}delete(e,t){!function(e,t,s){T(e,t).delete(s),function(e,t){const s=e.get(t);null!=s&&0==s.size&&e.delete(t)}(e,t)}(this.valuesByKey,e,t)}has(e,t){const s=this.valuesByKey.get(e);return null!=s&&s.has(t)}hasKey(e){return this.valuesByKey.has(e)}hasValue(e){return Array.from(this.valuesByKey.values()).some(t=>t.has(e))}getValuesForKey(e){const t=this.valuesByKey.get(e);return t?Array.from(t):[]}getKeysForValue(e){return Array.from(this.valuesByKey).filter(([t,s])=>s.has(e)).map(([e,t])=>e)}}class C{constructor(e,t,s,i){this._selector=t,this.details=i,this.elementObserver=new v(e,this),this.delegate=s,this.matchesByElement=new S}get started(){return this.elementObserver.started}get selector(){return this._selector}set selector(e){this._selector=e,this.refresh()}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get element(){return this.elementObserver.element}matchElement(e){const{selector:t}=this;if(t){const s=e.matches(t);return this.delegate.selectorMatchElement?s&&this.delegate.selectorMatchElement(e,this.details):s}return!1}matchElementsInTree(e){const{selector:t}=this;if(t){const s=this.matchElement(e)?[e]:[],i=Array.from(e.querySelectorAll(t)).filter(e=>this.matchElement(e));return s.concat(i)}return[]}elementMatched(e){const{selector:t}=this;t&&this.selectorMatched(e,t)}elementUnmatched(e){const t=this.matchesByElement.getKeysForValue(e);for(const s of t)this.selectorUnmatched(e,s)}elementAttributeChanged(e,t){const{selector:s}=this;if(s){const t=this.matchElement(e),i=this.matchesByElement.has(s,e);t&&!i?this.selectorMatched(e,s):!t&&i&&this.selectorUnmatched(e,s)}}selectorMatched(e,t){this.delegate.selectorMatched(e,t,this.details),this.matchesByElement.add(t,e)}selectorUnmatched(e,t){this.delegate.selectorUnmatched(e,t,this.details),this.matchesByElement.delete(t,e)}}class O{constructor(e,t){this.element=e,this.delegate=t,this.started=!1,this.stringMap=new Map,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,attributeOldValue:!0}),this.refresh())}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started)for(const e of this.knownAttributeNames)this.refreshAttribute(e,null)}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){const t=e.attributeName;t&&this.refreshAttribute(t,e.oldValue)}refreshAttribute(e,t){const s=this.delegate.getStringMapKeyForAttribute(e);if(null!=s){this.stringMap.has(e)||this.stringMapKeyAdded(s,e);const i=this.element.getAttribute(e);if(this.stringMap.get(e)!=i&&this.stringMapValueChanged(i,s,t),null==i){const t=this.stringMap.get(e);this.stringMap.delete(e),t&&this.stringMapKeyRemoved(s,e,t)}else this.stringMap.set(e,i)}}stringMapKeyAdded(e,t){this.delegate.stringMapKeyAdded&&this.delegate.stringMapKeyAdded(e,t)}stringMapValueChanged(e,t,s){this.delegate.stringMapValueChanged&&this.delegate.stringMapValueChanged(e,t,s)}stringMapKeyRemoved(e,t,s){this.delegate.stringMapKeyRemoved&&this.delegate.stringMapKeyRemoved(e,t,s)}get knownAttributeNames(){return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)))}get currentAttributeNames(){return Array.from(this.element.attributes).map(e=>e.name)}get recordedAttributeNames(){return Array.from(this.stringMap.keys())}}class E{constructor(e,t,s){this.attributeObserver=new w(e,t,this),this.delegate=s,this.tokensByElement=new S}get started(){return this.attributeObserver.started}start(){this.attributeObserver.start()}pause(e){this.attributeObserver.pause(e)}stop(){this.attributeObserver.stop()}refresh(){this.attributeObserver.refresh()}get element(){return this.attributeObserver.element}get attributeName(){return this.attributeObserver.attributeName}elementMatchedAttribute(e){this.tokensMatched(this.readTokensForElement(e))}elementAttributeValueChanged(e){const[t,s]=this.refreshTokensForElement(e);this.tokensUnmatched(t),this.tokensMatched(s)}elementUnmatchedAttribute(e){this.tokensUnmatched(this.tokensByElement.getValuesForKey(e))}tokensMatched(e){e.forEach(e=>this.tokenMatched(e))}tokensUnmatched(e){e.forEach(e=>this.tokenUnmatched(e))}tokenMatched(e){this.delegate.tokenMatched(e),this.tokensByElement.add(e.element,e)}tokenUnmatched(e){this.delegate.tokenUnmatched(e),this.tokensByElement.delete(e.element,e)}refreshTokensForElement(e){const t=this.tokensByElement.getValuesForKey(e),s=this.readTokensForElement(e),i=function(e,t){const s=Math.max(e.length,t.length);return Array.from({length:s},(s,i)=>[e[i],t[i]])}(t,s).findIndex(([e,t])=>{return i=t,!((s=e)&&i&&s.index==i.index&&s.content==i.content);var s,i});return-1==i?[[],[]]:[t.slice(i),s.slice(i)]}readTokensForElement(e){const t=this.attributeName;return function(e,t,s){return e.trim().split(/\s+/).filter(e=>e.length).map((e,i)=>({element:t,attributeName:s,content:e,index:i}))}(e.getAttribute(t)||"",e,t)}}class A{constructor(e,t,s){this.tokenListObserver=new E(e,t,this),this.delegate=s,this.parseResultsByToken=new WeakMap,this.valuesByTokenByElement=new WeakMap}get started(){return this.tokenListObserver.started}start(){this.tokenListObserver.start()}stop(){this.tokenListObserver.stop()}refresh(){this.tokenListObserver.refresh()}get element(){return this.tokenListObserver.element}get attributeName(){return this.tokenListObserver.attributeName}tokenMatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).set(e,s),this.delegate.elementMatchedValue(t,s))}tokenUnmatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).delete(e),this.delegate.elementUnmatchedValue(t,s))}fetchParseResultForToken(e){let t=this.parseResultsByToken.get(e);return t||(t=this.parseToken(e),this.parseResultsByToken.set(e,t)),t}fetchValuesByTokenForElement(e){let t=this.valuesByTokenByElement.get(e);return t||(t=new Map,this.valuesByTokenByElement.set(e,t)),t}parseToken(e){try{return{value:this.delegate.parseValueForToken(e)}}catch(e){return{error:e}}}}class x{constructor(e,t){this.context=e,this.delegate=t,this.bindingsByAction=new Map}start(){this.valueListObserver||(this.valueListObserver=new A(this.element,this.actionAttribute,this),this.valueListObserver.start())}stop(){this.valueListObserver&&(this.valueListObserver.stop(),delete this.valueListObserver,this.disconnectAllActions())}get element(){return this.context.element}get identifier(){return this.context.identifier}get actionAttribute(){return this.schema.actionAttribute}get schema(){return this.context.schema}get bindings(){return Array.from(this.bindingsByAction.values())}connectAction(e){const t=new y(this.context,e);this.bindingsByAction.set(e,t),this.delegate.bindingConnected(t)}disconnectAction(e){const t=this.bindingsByAction.get(e);t&&(this.bindingsByAction.delete(e),this.delegate.bindingDisconnected(t))}disconnectAllActions(){this.bindings.forEach(e=>this.delegate.bindingDisconnected(e,!0)),this.bindingsByAction.clear()}parseValueForToken(e){const t=m.forToken(e,this.schema);if(t.identifier==this.identifier)return t}elementMatchedValue(e,t){this.connectAction(t)}elementUnmatchedValue(e,t){this.disconnectAction(t)}}class M{constructor(e,t){this.context=e,this.receiver=t,this.stringMapObserver=new O(this.element,this),this.valueDescriptorMap=this.controller.valueDescriptorMap}start(){this.stringMapObserver.start(),this.invokeChangedCallbacksForDefaultValues()}stop(){this.stringMapObserver.stop()}get element(){return this.context.element}get controller(){return this.context.controller}getStringMapKeyForAttribute(e){if(e in this.valueDescriptorMap)return this.valueDescriptorMap[e].name}stringMapKeyAdded(e,t){const s=this.valueDescriptorMap[t];this.hasValue(e)||this.invokeChangedCallback(e,s.writer(this.receiver[e]),s.writer(s.defaultValue))}stringMapValueChanged(e,t,s){const i=this.valueDescriptorNameMap[t];null!==e&&(null===s&&(s=i.writer(i.defaultValue)),this.invokeChangedCallback(t,e,s))}stringMapKeyRemoved(e,t,s){const i=this.valueDescriptorNameMap[e];this.hasValue(e)?this.invokeChangedCallback(e,i.writer(this.receiver[e]),s):this.invokeChangedCallback(e,i.writer(i.defaultValue),s)}invokeChangedCallbacksForDefaultValues(){for(const{key:e,name:t,defaultValue:s,writer:i}of this.valueDescriptors)null==s||this.controller.data.has(e)||this.invokeChangedCallback(t,i(s),void 0)}invokeChangedCallback(e,t,s){const i=`${e}Changed`,n=this.receiver[i];if("function"==typeof n){const i=this.valueDescriptorNameMap[e];try{const e=i.reader(t);let r=s;s&&(r=i.reader(s)),n.call(this.receiver,e,r)}catch(e){throw e instanceof TypeError&&(e.message=`Stimulus Value "${this.context.identifier}.${i.name}" - ${e.message}`),e}}}get valueDescriptors(){const{valueDescriptorMap:e}=this;return Object.keys(e).map(t=>e[t])}get valueDescriptorNameMap(){const e={};return Object.keys(this.valueDescriptorMap).forEach(t=>{const s=this.valueDescriptorMap[t];e[s.name]=s}),e}hasValue(e){const t=`has${l(this.valueDescriptorNameMap[e].name)}`;return this.receiver[t]}}class k{constructor(e,t){this.context=e,this.delegate=t,this.targetsByName=new S}start(){this.tokenListObserver||(this.tokenListObserver=new E(this.element,this.attributeName,this),this.tokenListObserver.start())}stop(){this.tokenListObserver&&(this.disconnectAllTargets(),this.tokenListObserver.stop(),delete this.tokenListObserver)}tokenMatched({element:e,content:t}){this.scope.containsElement(e)&&this.connectTarget(e,t)}tokenUnmatched({element:e,content:t}){this.disconnectTarget(e,t)}connectTarget(e,t){var s;this.targetsByName.has(t,e)||(this.targetsByName.add(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetConnected(e,t)))}disconnectTarget(e,t){var s;this.targetsByName.has(t,e)&&(this.targetsByName.delete(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetDisconnected(e,t)))}disconnectAllTargets(){for(const e of this.targetsByName.keys)for(const t of this.targetsByName.getValuesForKey(e))this.disconnectTarget(t,e)}get attributeName(){return`data-${this.context.identifier}-target`}get element(){return this.context.element}get scope(){return this.context.scope}}function I(e,t){const s=L(e);return Array.from(s.reduce((e,s)=>(function(e,t){const s=e[t];return Array.isArray(s)?s:[]}(s,t).forEach(t=>e.add(t)),e),new Set))}function L(e){const t=[];for(;e;)t.push(e),e=Object.getPrototypeOf(e);return t.reverse()}class P{constructor(e,t){this.started=!1,this.context=e,this.delegate=t,this.outletsByName=new S,this.outletElementsByName=new S,this.selectorObserverMap=new Map,this.attributeObserverMap=new Map}start(){this.started||(this.outletDefinitions.forEach(e=>{this.setupSelectorObserverForOutlet(e),this.setupAttributeObserverForOutlet(e)}),this.started=!0,this.dependentContexts.forEach(e=>e.refresh()))}refresh(){this.selectorObserverMap.forEach(e=>e.refresh()),this.attributeObserverMap.forEach(e=>e.refresh())}stop(){this.started&&(this.started=!1,this.disconnectAllOutlets(),this.stopSelectorObservers(),this.stopAttributeObservers())}stopSelectorObservers(){this.selectorObserverMap.size>0&&(this.selectorObserverMap.forEach(e=>e.stop()),this.selectorObserverMap.clear())}stopAttributeObservers(){this.attributeObserverMap.size>0&&(this.attributeObserverMap.forEach(e=>e.stop()),this.attributeObserverMap.clear())}selectorMatched(e,t,{outletName:s}){const i=this.getOutlet(e,s);i&&this.connectOutlet(i,e,s)}selectorUnmatched(e,t,{outletName:s}){const i=this.getOutletFromMap(e,s);i&&this.disconnectOutlet(i,e,s)}selectorMatchElement(e,{outletName:t}){const s=this.selector(t),i=this.hasOutlet(e,t),n=e.matches(`[${this.schema.controllerAttribute}~=${t}]`);return!!s&&i&&n&&e.matches(s)}elementMatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementAttributeValueChanged(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementUnmatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}connectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)||(this.outletsByName.add(s,e),this.outletElementsByName.add(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletConnected(e,t,s)))}disconnectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)&&(this.outletsByName.delete(s,e),this.outletElementsByName.delete(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletDisconnected(e,t,s)))}disconnectAllOutlets(){for(const e of this.outletElementsByName.keys)for(const t of this.outletElementsByName.getValuesForKey(e))for(const s of this.outletsByName.getValuesForKey(e))this.disconnectOutlet(s,t,e)}updateSelectorObserverForOutlet(e){const t=this.selectorObserverMap.get(e);t&&(t.selector=this.selector(e))}setupSelectorObserverForOutlet(e){const t=this.selector(e),s=new C(document.body,t,this,{outletName:e});this.selectorObserverMap.set(e,s),s.start()}setupAttributeObserverForOutlet(e){const t=this.attributeNameForOutletName(e),s=new w(this.scope.element,t,this);this.attributeObserverMap.set(e,s),s.start()}selector(e){return this.scope.outlets.getSelectorForOutletName(e)}attributeNameForOutletName(e){return this.scope.schema.outletAttributeForScope(this.identifier,e)}getOutletNameFromOutletAttributeName(e){return this.outletDefinitions.find(t=>this.attributeNameForOutletName(t)===e)}get outletDependencies(){const e=new S;return this.router.modules.forEach(t=>{I(t.definition.controllerConstructor,"outlets").forEach(s=>e.add(s,t.identifier))}),e}get outletDefinitions(){return this.outletDependencies.getKeysForValue(this.identifier)}get dependentControllerIdentifiers(){return this.outletDependencies.getValuesForKey(this.identifier)}get dependentContexts(){const e=this.dependentControllerIdentifiers;return this.router.contexts.filter(t=>e.includes(t.identifier))}hasOutlet(e,t){return!!this.getOutlet(e,t)||!!this.getOutletFromMap(e,t)}getOutlet(e,t){return this.application.getControllerForElementAndIdentifier(e,t)}getOutletFromMap(e,t){return this.outletsByName.getValuesForKey(t).find(t=>t.element===e)}get scope(){return this.context.scope}get schema(){return this.context.schema}get identifier(){return this.context.identifier}get application(){return this.context.application}get router(){return this.application.router}}class _{constructor(e,t){this.logDebugActivity=(e,t={})=>{const{identifier:s,controller:i,element:n}=this;t=Object.assign({identifier:s,controller:i,element:n},t),this.application.logDebugActivity(this.identifier,e,t)},this.module=e,this.scope=t,this.controller=new e.controllerConstructor(this),this.bindingObserver=new x(this,this.dispatcher),this.valueObserver=new M(this,this.controller),this.targetObserver=new k(this,this),this.outletObserver=new P(this,this);try{this.controller.initialize(),this.logDebugActivity("initialize")}catch(e){this.handleError(e,"initializing controller")}}connect(){this.bindingObserver.start(),this.valueObserver.start(),this.targetObserver.start(),this.outletObserver.start();try{this.controller.connect(),this.logDebugActivity("connect")}catch(e){this.handleError(e,"connecting controller")}}refresh(){this.outletObserver.refresh()}disconnect(){try{this.controller.disconnect(),this.logDebugActivity("disconnect")}catch(e){this.handleError(e,"disconnecting controller")}this.outletObserver.stop(),this.targetObserver.stop(),this.valueObserver.stop(),this.bindingObserver.stop()}get application(){return this.module.application}get identifier(){return this.module.identifier}get schema(){return this.application.schema}get dispatcher(){return this.application.dispatcher}get element(){return this.scope.element}get parentElement(){return this.element.parentElement}handleError(e,t,s={}){const{identifier:i,controller:n,element:r}=this;s=Object.assign({identifier:i,controller:n,element:r},s),this.application.handleError(e,`Error ${t}`,s)}targetConnected(e,t){this.invokeControllerMethod(`${t}TargetConnected`,e)}targetDisconnected(e,t){this.invokeControllerMethod(`${t}TargetDisconnected`,e)}outletConnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletConnected`,e,t)}outletDisconnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletDisconnected`,e,t)}invokeControllerMethod(e,...t){const s=this.controller;"function"==typeof s[e]&&s[e](...t)}}const N="function"==typeof Object.getOwnPropertySymbols?e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)]:Object.getOwnPropertyNames,D=(()=>{function e(e){function t(){return Reflect.construct(e,arguments,new.target)}return t.prototype=Object.create(e.prototype,{constructor:{value:t}}),Reflect.setPrototypeOf(t,e),t}try{return function(){const t=e(function(){this.a.call(this)});t.prototype.a=function(){},new t}(),e}catch(e){return e=>class extends e{}}})();class F{constructor(e,t){this.application=e,this.definition=function(e){return{identifier:e.identifier,controllerConstructor:(t=e.controllerConstructor,function(e,t){const s=D(e),i=function(e,t){return N(t).reduce((s,i)=>{const n=function(e,t,s){const i=Object.getOwnPropertyDescriptor(e,s);if(!i||!("value"in i)){const e=Object.getOwnPropertyDescriptor(t,s).value;return i&&(e.get=i.get||e.get,e.set=i.set||e.set),e}}(e,t,i);return n&&Object.assign(s,{[i]:n}),s},{})}(e.prototype,t);return Object.defineProperties(s.prototype,i),s}(t,function(e){return I(e,"blessings").reduce((t,s)=>{const i=s(e);for(const e in i){const s=t[e]||{};t[e]=Object.assign(s,i[e])}return t},{})}(t)))};var t}(t),this.contextsByScope=new WeakMap,this.connectedContexts=new Set}get identifier(){return this.definition.identifier}get controllerConstructor(){return this.definition.controllerConstructor}get contexts(){return Array.from(this.connectedContexts)}connectContextForScope(e){const t=this.fetchContextForScope(e);this.connectedContexts.add(t),t.connect()}disconnectContextForScope(e){const t=this.contextsByScope.get(e);t&&(this.connectedContexts.delete(t),t.disconnect())}fetchContextForScope(e){let t=this.contextsByScope.get(e);return t||(t=new _(this,e),this.contextsByScope.set(e,t)),t}}class R{constructor(e){this.scope=e}has(e){return this.data.has(this.getDataKey(e))}get(e){return this.getAll(e)[0]}getAll(e){return(this.data.get(this.getDataKey(e))||"").match(/[^\s]+/g)||[]}getAttributeName(e){return this.data.getAttributeNameForKey(this.getDataKey(e))}getDataKey(e){return`${e}-class`}get data(){return this.scope.data}}class B{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get(e){const t=this.getAttributeNameForKey(e);return this.element.getAttribute(t)}set(e,t){const s=this.getAttributeNameForKey(e);return this.element.setAttribute(s,t),this.get(e)}has(e){const t=this.getAttributeNameForKey(e);return this.element.hasAttribute(t)}delete(e){if(this.has(e)){const t=this.getAttributeNameForKey(e);return this.element.removeAttribute(t),!0}return!1}getAttributeNameForKey(e){return`data-${this.identifier}-${h(e)}`}}class ${constructor(e){this.warnedKeysByObject=new WeakMap,this.logger=e}warn(e,t,s){let i=this.warnedKeysByObject.get(e);i||(i=new Set,this.warnedKeysByObject.set(e,i)),i.has(t)||(i.add(t),this.logger.warn(s,e))}}function j(e,t){return`[${e}~="${t}"]`}class V{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findTarget(t)||this.findLegacyTarget(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllTargets(t),...this.findAllLegacyTargets(t)],[])}findTarget(e){const t=this.getSelectorForTargetName(e);return this.scope.findElement(t)}findAllTargets(e){const t=this.getSelectorForTargetName(e);return this.scope.findAllElements(t)}getSelectorForTargetName(e){return j(this.schema.targetAttributeForScope(this.identifier),e)}findLegacyTarget(e){const t=this.getLegacySelectorForTargetName(e);return this.deprecate(this.scope.findElement(t),e)}findAllLegacyTargets(e){const t=this.getLegacySelectorForTargetName(e);return this.scope.findAllElements(t).map(t=>this.deprecate(t,e))}getLegacySelectorForTargetName(e){const t=`${this.identifier}.${e}`;return j(this.schema.targetAttribute,t)}deprecate(e,t){if(e){const{identifier:s}=this,i=this.schema.targetAttribute,n=this.schema.targetAttributeForScope(s);this.guide.warn(e,`target:${t}`,`Please replace ${i}="${s}.${t}" with ${n}="${t}". The ${i} attribute is deprecated and will be removed in a future version of Stimulus.`)}return e}get guide(){return this.scope.guide}}class q{constructor(e,t){this.scope=e,this.controllerElement=t}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findOutlet(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllOutlets(t)],[])}getSelectorForOutletName(e){const t=this.schema.outletAttributeForScope(this.identifier,e);return this.controllerElement.getAttribute(t)}findOutlet(e){const t=this.getSelectorForOutletName(e);if(t)return this.findElement(t,e)}findAllOutlets(e){const t=this.getSelectorForOutletName(e);return t?this.findAllElements(t,e):[]}findElement(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))[0]}findAllElements(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))}matchesElement(e,t,s){const i=e.getAttribute(this.scope.schema.controllerAttribute)||"";return e.matches(t)&&i.split(" ").includes(s)}}class U{constructor(e,t,s,i){this.targets=new V(this),this.classes=new R(this),this.data=new B(this),this.containsElement=e=>e.closest(this.controllerSelector)===this.element,this.schema=e,this.element=t,this.identifier=s,this.guide=new $(i),this.outlets=new q(this.documentScope,t)}findElement(e){return this.element.matches(e)?this.element:this.queryElements(e).find(this.containsElement)}findAllElements(e){return[...this.element.matches(e)?[this.element]:[],...this.queryElements(e).filter(this.containsElement)]}queryElements(e){return Array.from(this.element.querySelectorAll(e))}get controllerSelector(){return j(this.schema.controllerAttribute,this.identifier)}get isDocumentScope(){return this.element===document.documentElement}get documentScope(){return this.isDocumentScope?this:new U(this.schema,document.documentElement,this.identifier,this.guide.logger)}}class z{constructor(e,t,s){this.element=e,this.schema=t,this.delegate=s,this.valueListObserver=new A(this.element,this.controllerAttribute,this),this.scopesByIdentifierByElement=new WeakMap,this.scopeReferenceCounts=new WeakMap}start(){this.valueListObserver.start()}stop(){this.valueListObserver.stop()}get controllerAttribute(){return this.schema.controllerAttribute}parseValueForToken(e){const{element:t,content:s}=e;return this.parseValueForElementAndIdentifier(t,s)}parseValueForElementAndIdentifier(e,t){const s=this.fetchScopesByIdentifierForElement(e);let i=s.get(t);return i||(i=this.delegate.createScopeForElementAndIdentifier(e,t),s.set(t,i)),i}elementMatchedValue(e,t){const s=(this.scopeReferenceCounts.get(t)||0)+1;this.scopeReferenceCounts.set(t,s),1==s&&this.delegate.scopeConnected(t)}elementUnmatchedValue(e,t){const s=this.scopeReferenceCounts.get(t);s&&(this.scopeReferenceCounts.set(t,s-1),1==s&&this.delegate.scopeDisconnected(t))}fetchScopesByIdentifierForElement(e){let t=this.scopesByIdentifierByElement.get(e);return t||(t=new Map,this.scopesByIdentifierByElement.set(e,t)),t}}class W{constructor(e){this.application=e,this.scopeObserver=new z(this.element,this.schema,this),this.scopesByIdentifier=new S,this.modulesByIdentifier=new Map}get element(){return this.application.element}get schema(){return this.application.schema}get logger(){return this.application.logger}get controllerAttribute(){return this.schema.controllerAttribute}get modules(){return Array.from(this.modulesByIdentifier.values())}get contexts(){return this.modules.reduce((e,t)=>e.concat(t.contexts),[])}start(){this.scopeObserver.start()}stop(){this.scopeObserver.stop()}loadDefinition(e){this.unloadIdentifier(e.identifier);const t=new F(this.application,e);this.connectModule(t);const s=e.controllerConstructor.afterLoad;s&&s.call(e.controllerConstructor,e.identifier,this.application)}unloadIdentifier(e){const t=this.modulesByIdentifier.get(e);t&&this.disconnectModule(t)}getContextForElementAndIdentifier(e,t){const s=this.modulesByIdentifier.get(t);if(s)return s.contexts.find(t=>t.element==e)}proposeToConnectScopeForElementAndIdentifier(e,t){const s=this.scopeObserver.parseValueForElementAndIdentifier(e,t);s?this.scopeObserver.elementMatchedValue(s.element,s):console.error(`Couldn't find or create scope for identifier: "${t}" and element:`,e)}handleError(e,t,s){this.application.handleError(e,t,s)}createScopeForElementAndIdentifier(e,t){return new U(this.schema,e,t,this.logger)}scopeConnected(e){this.scopesByIdentifier.add(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.connectContextForScope(e)}scopeDisconnected(e){this.scopesByIdentifier.delete(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.disconnectContextForScope(e)}connectModule(e){this.modulesByIdentifier.set(e.identifier,e),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.connectContextForScope(t))}disconnectModule(e){this.modulesByIdentifier.delete(e.identifier),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.disconnectContextForScope(t))}}const K={controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target",targetAttributeForScope:e=>`data-${e}-target`,outletAttributeForScope:(e,t)=>`data-${e}-${t}-outlet`,keyMappings:Object.assign(Object.assign({enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"},H("abcdefghijklmnopqrstuvwxyz".split("").map(e=>[e,e]))),H("0123456789".split("").map(e=>[e,e])))};function H(e){return e.reduce((e,[t,s])=>Object.assign(Object.assign({},e),{[t]:s}),{})}class G{constructor(e=document.documentElement,t=K){this.logger=console,this.debug=!1,this.logDebugActivity=(e,t,s={})=>{this.debug&&this.logFormattedMessage(e,t,s)},this.element=e,this.schema=t,this.dispatcher=new n(this),this.router=new W(this),this.actionDescriptorFilters=Object.assign({},r)}static start(e,t){const s=new this(e,t);return s.start(),s}async start(){await new Promise(e=>{"loading"==document.readyState?document.addEventListener("DOMContentLoaded",()=>e()):e()}),this.logDebugActivity("application","starting"),this.dispatcher.start(),this.router.start(),this.logDebugActivity("application","start")}stop(){this.logDebugActivity("application","stopping"),this.dispatcher.stop(),this.router.stop(),this.logDebugActivity("application","stop")}register(e,t){this.load({identifier:e,controllerConstructor:t})}registerActionOption(e,t){this.actionDescriptorFilters[e]=t}load(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>{e.controllerConstructor.shouldLoad&&this.router.loadDefinition(e)})}unload(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>this.router.unloadIdentifier(e))}get controllers(){return this.router.contexts.map(e=>e.controller)}getControllerForElementAndIdentifier(e,t){const s=this.router.getContextForElementAndIdentifier(e,t);return s?s.controller:null}handleError(e,t,s){var i;this.logger.error("%s\n\n%o\n\n%o",t,e,s),null===(i=window.onerror)||void 0===i||i.call(window,t,"",0,0,e)}logFormattedMessage(e,t,s={}){s=Object.assign({application:this},s),this.logger.groupCollapsed(`${e} #${t}`),this.logger.log("details:",Object.assign({},s)),this.logger.groupEnd()}}function J(e,t,s){return e.application.getControllerForElementAndIdentifier(t,s)}function Y(e,t,s){let i=J(e,t,s);return i||(e.application.router.proposeToConnectScopeForElementAndIdentifier(t,s),i=J(e,t,s),i||void 0)}function Z([e,t],s){return function(e){const{token:t,typeDefinition:s}=e,i=`${h(t)}-value`,n=function(e){const{controller:t,token:s,typeDefinition:i}=e,n=function(e){const{controller:t,token:s,typeObject:i}=e,n=u(i.type),r=u(i.default),o=n&&r,a=n&&!r,c=!n&&r,l=X(i.type),h=Q(e.typeObject.default);if(a)return l;if(c)return h;if(l!==h)throw new Error(`The specified default value for the Stimulus Value "${t?`${t}.${s}`:s}" must match the defined type "${l}". The provided default value of "${i.default}" is of type "${h}".`);return o?l:void 0}({controller:t,token:s,typeObject:i}),r=Q(i),o=X(i),a=n||r||o;if(a)return a;throw new Error(`Unknown value type "${t?`${t}.${i}`:s}" for "${s}" value`)}(e);return{type:n,key:i,name:a(i),get defaultValue(){return function(e){const t=X(e);if(t)return ee[t];const s=d(e,"default"),i=d(e,"type"),n=e;if(s)return n.default;if(i){const{type:e}=n,t=X(e);if(t)return ee[t]}return e}(s)},get hasCustomDefaultValue(){return void 0!==Q(s)},reader:te[n],writer:se[n]||se.default}}({controller:s,token:e,typeDefinition:t})}function X(e){switch(e){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function Q(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}return Array.isArray(e)?"array":"[object Object]"===Object.prototype.toString.call(e)?"object":void 0}const ee={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},te={array(e){const t=JSON.parse(e);if(!Array.isArray(t))throw new TypeError(`expected value of type "array" but instead got value "${e}" of type "${Q(t)}"`);return t},boolean:e=>!("0"==e||"false"==String(e).toLowerCase()),number:e=>Number(e.replace(/_/g,"")),object(e){const t=JSON.parse(e);if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`expected value of type "object" but instead got value "${e}" of type "${Q(t)}"`);return t},string:e=>e},se={default:function(e){return`${e}`},array:ie,object:ie};function ie(e){return JSON.stringify(e)}class ne{constructor(e){this.context=e}static get shouldLoad(){return!0}static afterLoad(e,t){}get application(){return this.context.application}get scope(){return this.context.scope}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get targets(){return this.scope.targets}get outlets(){return this.scope.outlets}get classes(){return this.scope.classes}get data(){return this.scope.data}initialize(){}connect(){}disconnect(){}dispatch(e,{target:t=this.element,detail:s={},prefix:i=this.identifier,bubbles:n=!0,cancelable:r=!0}={}){const o=new CustomEvent(i?`${i}:${e}`:e,{detail:s,bubbles:n,cancelable:r});return t.dispatchEvent(o),o}}ne.blessings=[function(e){return I(e,"classes").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Class`]:{get(){const{classes:e}=this;if(e.has(s))return e.get(s);{const t=e.getAttributeName(s);throw new Error(`Missing attribute "${t}"`)}}},[`${s}Classes`]:{get(){return this.classes.getAll(s)}},[`has${l(s)}Class`]:{get(){return this.classes.has(s)}}}));var s},{})},function(e){return I(e,"targets").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Target`]:{get(){const e=this.targets.find(s);if(e)return e;throw new Error(`Missing target element "${s}" for "${this.identifier}" controller`)}},[`${s}Targets`]:{get(){return this.targets.findAll(s)}},[`has${l(s)}Target`]:{get(){return this.targets.has(s)}}}));var s},{})},function(e){const t=function(e,t){return L(e).reduce((e,s)=>(e.push(...function(e,t){const s=e[t];return s?Object.keys(s).map(e=>[e,s[e]]):[]}(s,t)),e),[])}(e,"values"),s={valueDescriptorMap:{get(){return t.reduce((e,t)=>{const s=Z(t,this.identifier),i=this.data.getAttributeNameForKey(s.key);return Object.assign(e,{[i]:s})},{})}}};return t.reduce((e,t)=>Object.assign(e,function(e){const t=Z(e,void 0),{key:s,name:i,reader:n,writer:r}=t;return{[i]:{get(){const e=this.data.get(s);return null!==e?n(e):t.defaultValue},set(e){void 0===e?this.data.delete(s):this.data.set(s,r(e))}},[`has${l(i)}`]:{get(){return this.data.has(s)||t.hasCustomDefaultValue}}}}(t)),s)},function(e){return I(e,"outlets").reduce((e,t)=>Object.assign(e,function(e){const t=c(e);return{[`${t}Outlet`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t){const s=Y(this,t,e);if(s)return s;throw new Error(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`)}throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}Outlets`]:{get(){const t=this.outlets.findAll(e);return t.length>0?t.map(t=>{const s=Y(this,t,e);if(s)return s;console.warn(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`,t)}).filter(e=>e):[]}},[`${t}OutletElement`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t)return t;throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}OutletElements`]:{get(){return this.outlets.findAll(e)}},[`has${l(t)}Outlet`]:{get(){return this.outlets.has(e)}}}}(t)),{})}],ne.targets=[],ne.outlets=[],ne.values={}},290(e,t,s){s.d(t,{default:()=>ci});var i=s(891);class n extends Error{constructor(e){super(`${e} is not valid. Please provide a valid event name`),this.name="InvalidEvent"}}class r{static events=["session-set","utm-set","forms:collected","form:completed","popup:mounted","popup:opened","popup:closed","alert:shown","alert:dismissed","alert:accepted","webchat:mounted","webchat:opened","webchat:closed","webchat:message:sent","webchat:message:received","cart.added"];static valid(e){return r.exists(e)}static invalid(e){return!this.valid(e)}static exists(e){return void 0!==this.events.find(t=>t===e)}constructor(){this.subscribers={}}addSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers={...this.subscribers,[e]:this.subscribers[e]?[...this.subscribers[e],t]:[t]}}removeSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers[e]&&(this.subscribers[e]=this.subscribers[e].filter(e=>e!==t))}dispatch(e,t){this.subscribers[e]?.forEach(e=>{e(t)})}get listeners(){return 0!==Object.keys(this.subscribers).length}}class o{static autoMount=!0;static successMessage=!0;static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static get shouldShowSuccessMessage(){return this.successMessage}}class a{static _identifier;static set identifier(e){this._identifier=e}static get identifier(){return this._identifier?this._identifier:this.#e||this.#t||this.#s||"en"}static toString(){return this.identifier}static get#e(){return"undefined"!=typeof document?document.documentElement?.lang:void 0}static get#t(){return"undefined"!=typeof document?document.querySelector('meta[name="locale"]')?.content:void 0}static get#s(){return"undefined"!=typeof navigator?navigator.language?.split("-")[0]:void 0}}class c{static _id;static _container="body";static _device="auto";static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set device(e){if(!["auto","mobile","desktop"].includes(e))throw new Error(`Invalid popup device value: ${e}`);this._device=e}static get device(){return this._device}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}}const l={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"},h={ABSOLUTE:"absolute",FIXED:"fixed"},u={MODAL:"modal",POPOVER:"popover"};class d{static _id;static _container="body";static _placement="bottom-right";static _style={};static _appearance={};static _whatsapp={};static _mode=u.POPOVER;static _behaviour=null;static _hasBehaviourOverride=!1;static _strategy=null;static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(l).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static set id(e){this._id=e}static get id(){return this._id}static get isSet(){return!!this._id}static get style(){return this._style}static set style(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(([e,t])=>{if(!["primaryColor","secondaryColor","typography"].includes(e))throw new Error(`Invalid style property: ${e}`);if("typography"!==e&&!this.isHexOrRgba(t))throw new Error(`Invalid color value: ${t} for ${e}. Colors must be hex or rgb/a.`)}),this._style=e}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if(!["header","launcher"].includes(e))throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("header"===e&&"name"!==t)throw new Error(`Invalid appearance header property: ${t}`);if("launcher"===e&&"iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get whatsapp(){return this._whatsapp}static set whatsapp(e){if(!this.isPlainObject(e))throw new Error("WhatsApp must be an object");Object.entries(e).forEach(([e,t])=>{if(!["number","restrictToChannel"].includes(e))throw new Error(`Invalid WhatsApp property: ${e}`);if(null!=t){if("number"===e&&"string"!=typeof t)throw new Error(`Invalid WhatsApp number value: ${t}`);if("restrictToChannel"===e&&"boolean"!=typeof t)throw new Error(`Invalid WhatsApp restrictToChannel value: ${t}`)}}),this._whatsapp=e}static get mode(){return this._mode}static set mode(e){if(!Object.values(u).includes(e))throw new Error(`Invalid mode value: ${e}`);this._mode=e}static get behaviour(){return this._behaviour}static set behaviour(e){if(null!=e){if("object"!=typeof e||Array.isArray(e))throw new Error(`Invalid behaviour value: ${e}`);this._behaviour=e}else this._behaviour=e}static get hasBehaviourOverride(){return this._hasBehaviourOverride}static set behaviourOverride(e){this._hasBehaviourOverride=!!e}static get strategy(){return this._strategy?this._strategy:"body"==this.container?h.FIXED:h.ABSOLUTE}static set strategy(e){if(e&&!Object.values(h).includes(e))throw new Error(`Invalid strategy value: ${e}`);this._strategy=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isHexOrRgba(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}const p={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"};class m{static _id;static _container="body";static _placement="bottom-right";static _appearance={};static _number=null;static _body=null;static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(p).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if("launcher"!==e)throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get number(){return this._number}static set number(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid number value: ${e}`);this._number=e}static get body(){return this._body}static set body(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid body value: ${e}`);this._body=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}class g{static serviceWorkerUrl=null;static channelId=null;static assign(e){return this.serviceWorkerUrl=e?.serviceWorkerUrl||null,this.channelId=e?.channelId||null,this}}class f{static apiRoot="https://api.hellotext.com/v1";static actionCableUrl="wss://www.hellotext.com/cable";static autoGenerateSession=!0;static session=null;static forms=o;static popup=c;static webchat=d;static whatsapp=m;static push=g;static assign(e){if(e){const t=Object.prototype.hasOwnProperty.call(e,"apiRoot")&&!Object.prototype.hasOwnProperty.call(e,"actionCableUrl");Object.entries(e).forEach(([e,t])=>{"forms"===e?this.forms=o.assign(t):"popup"===e?this.popup=c.assign(t):"webchat"===e?this.webchat=d.assign(t):"whatsappWidget"===e?this.whatsapp=m.assign(t):"push"===e?this.push=g.assign(t):this[e]=t}),t&&(this.actionCableUrl=this.actionCableUrlForApiRoot(this.apiRoot))}return this}static set locale(e){a.identifier=e}static get locale(){return a.toString()}static endpoint(e){return`${this.apiRoot}/${e}`}static actionCableUrlForApiRoot(e){try{const t=new URL(e),s="https:"===t.protocol?"wss:":"ws:";return t.protocol=s,t.pathname="/cable",t.search="",t.hash="",t.toString()}catch(e){return this.actionCableUrl}}}const b=class{static get endpoint(){return f.endpoint("public/businesses")}static async get(e){return fetch(`${this.endpoint}/${e}`,{method:"GET",headers:{Authorization:`Bearer ${e}`,Accept:"application/json","Content-Type":"application/json"}})}};class y{static get inPreviewMode(){return(new this).inPreviewMode}constructor(){this.urlSearchParams=new URLSearchParams(window.location.search)}get(e){return this.urlSearchParams.get(this.toHellotextParam(e))}has(e){return this.urlSearchParams.has(this.toHellotextParam(e))}get inPreviewMode(){return this.has("preview")}get session(){return this.get("session")}toHellotextParam(e){return`hello_${e}`}}class v{#i;constructor(e,t){this.response=t,this.#i=e}get data(){return this.response}async json(){return await this.response.json()}get failed(){return!1===this.#i}get succeeded(){return!0===this.#i}}class w{static get endpoint(){return f.endpoint("track/events")}static async create({headers:e,body:t,keepalive:s=!1}){if(y.inPreviewMode)return new v(!0,{received:!0});const i={method:"POST",headers:e,body:JSON.stringify(t)};s&&(i.keepalive=!0);const n=await fetch(this.endpoint,i);return new v(200===n.status,await n.json())}}class T{static get endpoint(){return f.endpoint("public/forms")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);return t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),fetch(t,{method:"GET",headers:vt.headers})}static async submit(e,t){const s=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...t})});return new v(s.ok,s)}}const S=class{static get endpoint(){return f.endpoint("public/identifications")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...e})});return new v(t.ok,t)}},C=class{static get endpoint(){return f.endpoint("public/popups")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),t.searchParams.append("device",this.runtimeDevice);const s=await this.fetchPopup(t);if(!s.ok)return null;const i=await this.parsePopupResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static async submit(e,t,s=this.idempotencyKey()){const i=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:{...vt.headers,"Idempotency-Key":s},body:JSON.stringify({session:vt.session,popup_submission:t})});return new v(i.ok,i)}static async resend(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/resend`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static async cancel(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/cancel`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static idempotencyKey(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}static async fetchPopup(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static get runtimeDevice(){return"auto"!==f.popup.device?f.popup.device:window.innerWidth<=767?"mobile":"desktop"}static async parsePopupResponse(e){try{return await e.json()}catch(e){return null}}},O=class{static get endpoint(){return f.endpoint("public/webchats")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),Object.entries(f.webchat.style).forEach(([e,s])=>{t.searchParams.append(`style[${e}]`,s)}),this.appendWebchatOverrides(t),t.searchParams.append("placement",f.webchat.placement);const s=await fetch(t,{method:"GET",headers:vt.headers}),i=await s.json();return vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")}static appendWebchatOverrides(e){const{appearance:t,whatsapp:s}=f.webchat;this.appendIfSupplied(e,"webchat[appearance][header][name]",t.header?.name),this.appendIfSupplied(e,"webchat[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"webchat[handoff][identifier]",s.number),this.appendIfSupplied(e,"webchat[handoff][restrict_to_channel]",s.restrictToChannel)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}},E=class{static get endpoint(){return f.endpoint("public/widgets/whatsapp")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("locale",a.toString()),t.searchParams.append("placement",f.whatsapp.placement),this.appendWhatsAppOverrides(t);const s=await this.fetchWidget(t);if(!s.ok)return null;const i=await this.parseWidgetResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static appendWhatsAppOverrides(e){const{appearance:t,body:s,number:i}=f.whatsapp;this.appendIfSupplied(e,"whatsapp[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"whatsapp[number]",i),this.appendIfSupplied(e,"whatsapp[body]",s)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}static async fetchWidget(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static async parseWidgetResponse(e){try{return await e.json()}catch(e){return null}}},A=class{static get endpoint(){return f.endpoint("public/acks")}static async send(e={}){const t={...e,session:vt.session,at:(new Date).toISOString()};fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify(t),keepalive:!0})}},x=class{static get endpoint(){return f.endpoint("public/push/identities")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}static async destroy(e={}){const t=await fetch(this.endpoint,{method:"DELETE",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}},M=class{static get endpoint(){return f.endpoint("public/push/alerts")}static async create({section:e,kind:t,page:s}){const i=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({session:vt.session,section:e,kind:t,page:s})});return new v(i.ok,i)}};function k(e){const t=JSON.stringify(e);return"undefined"==typeof Blob?t.length<6e4:new Blob([t]).size<6e4}class I{static get businesses(){return b}static get events(){return w}static get forms(){return T}static get popups(){return C}static get popups(){return C}static get webchats(){return O}static get whatsappWidgets(){return E}static get identifications(){return S}static get acks(){return A}static get pushAlerts(){return M}static get pushIdentities(){return x}}const L="data-hellotext-stylesheet";class P{constructor(e){this.id=e,this.data=null,this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1)}async hydrate(){try{const e=await b.get(this.id);if(!1===e.ok)return null;const t=await e.json();return t?(this.setData(t),this.setLocale(a.toString()),t):null}catch(e){return null}}setData(e){this.data=e,"undefined"!=typeof document&&e.style_url?(this.stylesheet=this.constructor.ensureStylesheet(e.style_url),this.stylesheetLoaded=this.constructor.waitForStylesheet(this.stylesheet)):(this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1))}static get stylesheetSelector(){return`link[rel="stylesheet"][${L}]`}static ensureStylesheet(e){const t=this.normalizedStylesheetUrl(e),s=this.stylesheetLinks.find(e=>e.href===t);if(s)return s.setAttribute(L,"true"),s;const i=document.createElement("link");return i.rel="stylesheet",i.href=e,i.setAttribute(L,"true"),this.waitForStylesheet(i),document.head.append(i),i}static get stylesheetLinks(){return"undefined"==typeof document?[]:Array.from(document.querySelectorAll(this.stylesheetSelector))}static get latestStylesheet(){return this.stylesheetLinks[this.stylesheetLinks.length-1]}static normalizedStylesheetUrl(e){try{return new URL(e,document.baseURI).href}catch(t){return e}}static waitForStylesheet(e){return e?this.stylesheetIsLoaded(e)?Promise.resolve(!0):"false"===e.dataset.hellotextStylesheetLoaded?Promise.resolve(!1):(e._hellotextStylesheetLoaded||(e._hellotextStylesheetLoaded=new Promise(t=>{let s;const i=i=>{clearTimeout(s),e.removeEventListener("load",n),e.removeEventListener("error",r),e.dataset.hellotextStylesheetLoaded=i?"true":"false",t(i)},n=()=>i(this.stylesheetIsLoaded(e)),r=()=>i(!1);e.addEventListener("load",n),e.addEventListener("error",r),s=setTimeout(()=>i(this.stylesheetIsLoaded(e)),1e4),s.unref&&s.unref()})),e._hellotextStylesheetLoaded):Promise.resolve(!1)}static stylesheetIsLoaded(e){return"true"===e.dataset.hellotextStylesheetLoaded||!!e.sheet}get subscription(){return this.data.subscription}get country(){return this.data.country}get enabledWhitelist(){return"disabled"!==this.data.whitelist}setLocale(e){this.data||(this.data={});const t=e?.toLowerCase().split("-")[0];this.data.locale=Object.prototype.hasOwnProperty.call(this.data.locales||{},t)?t:"en"}get locale(){const e=this.data?.locales;return e?.[this.data.locale]||e?.en}get features(){return this.data.features}}class _{static set(e,t){if("undefined"!=typeof document){const s="https:"===window.location.protocol?"; Secure":"",i=D.getRootDomain(),n=31536e4;document.cookie=i?`${e}=${t}; path=/${s}; domain=${i}; max-age=${n}; SameSite=Lax`:`${e}=${t}; path=/${s}; max-age=${n}; SameSite=Lax`}return"hello_session"===e&&vt.eventEmitter.dispatch("session-set",t),"hello_utm"===e&&vt.eventEmitter.dispatch("utm-set",t),t}static get(e){return"undefined"!=typeof document?document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)")?.pop():void 0}static delete(e){if("undefined"!=typeof document){const t=D.getRootDomain(),s="https:"===window.location.protocol?"; Secure":"";document.cookie=t?`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; domain=${t}; SameSite=Lax`:`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; SameSite=Lax`}}}class N{constructor(){const e=new URLSearchParams(window.location.search),t={source:e.get("utm_source"),medium:e.get("utm_medium"),campaign:e.get("utm_campaign"),term:e.get("utm_term"),content:e.get("utm_content")};this.save(t)}save(e){if(!e.source||!e.medium)return;const t=Object.fromEntries(Object.entries(e).filter(([e,t])=>t));t.observed_at=(new Date).toISOString(),_.set("hello_utm",JSON.stringify(t))}get current(){try{return JSON.parse(_.get("hello_utm"))||{}}catch(e){return{}}}}class D{constructor(e=null){this.utm=new N,this._url=e}get url(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}get title(){return document.title}get path(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}get utmParams(){return this.utm.current}get trackingData(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}get domain(){try{const e=this.url;if(!e)return null;const t=new URL(e).hostname;return D.getRootDomain(t)}catch(e){return null}}static getRootDomain(e=null){try{if(!e){if("undefined"==typeof window||!window.location?.hostname)return null;e=window.location.hostname}const t=e.split(".");if(t.length<=1)return e;const s=["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"];for(const e of s){const s=e.split(".");if(t.slice(-s.length).join(".")===e&&t.length>s.length)return`.${t.slice(-(s.length+1)).join(".")}`}const i=t[t.length-1],n=t[t.length-2];return t.length>2&&2===i.length&&n.length<=3?`.${t.slice(-3).join(".")}`:`.${t.slice(-2).join(".")}`}catch(e){return null}}}class F{static#n;static#r;static#o;static get session(){return this.#n}static get ackPayload(){return{utm_params:this.#o?.utmParams||{}}}static set session(e){const t=_.get("hello_session");return this.#n=e,_.set("hello_session",e),t!==e&&_.delete("hello_session_ack_at"),_.get("hello_session_ack_at")||(I.acks.send(this.ackPayload),_.set("hello_session_ack_at",(new Date).toISOString())),this.#n}static initialize(e=new D){this.#o=e,this.#r=new y,this.session=this.#r.session||f.session||_.get("hello_session"),!this.session&&f.autoGenerateSession&&(this.session=crypto.randomUUID())}}class R{static build(e){const t=document.createElement("article"),s=document.createElement("label"),i=document.createElement("input");s.innerText=e.label,i.type=e.type,i.required=e.required,i.placeholder=e.placeholder,["first_name","last_name"].includes(e.kind)?(i.type="text",i.id=i.name=e.kind,s.setAttribute("for",e.kind)):(i.type=e.type,"email"===e.type?(i.id=i.name="email",s.setAttribute("for","email")):"tel"===i.type?(i.id=i.name="phone",s.setAttribute("for","phone"),i.value=`+${vt.business.country.prefix}`,i.setAttribute("data-default-value",`+${vt.business.country.prefix}`)):(i.name=i.id=`property_by_id[${e.property}]`,s.setAttribute("for",`property_by_id[${e.property}]`)));const n=document.createElement("main");n.appendChild(s),n.appendChild(i),t.appendChild(n),t.setAttribute("data-hellotext--form-target","inputContainer"),i.setAttribute("data-hellotext--form-target","input");const r=document.createElement("div");return r.setAttribute("data-error-container",""),t.appendChild(r),t}}class B{static build(){const e=document.createElement("div");return e.innerHTML=this.#a(),e.firstElementChild}static#a(){const e=`https://www.hellotext.com?hello_session=${vt.session}`;return`\n
\n ${vt.business.locale.white_label.powered_by}\n\n \n \n Hellotext\n \n \n \n
\n `}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var s=0,i=Array(t);s2?s-2:0),n=2;n1?t-1:0),i=1;i1?s-1:0),n=1;n2&&void 0!==arguments[2]?arguments[2]:ne;if(q&&q(e,null),!ie(t))return e;let i=t.length;for(;i--;){let n=t[i];if("string"==typeof n){const e=s(n);e!==n&&(U(t)||(t[i]=e),n=e)}e[n]=!0}return e}function Te(e){for(let t=0;t/g),Re=H(/\${[\w\W]*/g),Be=H(/^data-[\-\w.\u00B7-\uFFFF]+$/),$e=H(/^aria-[\-\w]+$/),je=H(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Ve=H(/^(?:\w+script|data):/i),qe=H(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ue=H(/^html$/i),ze=H(/^[a-z][.\w]*(-[.\w]+)+$/i),We=H(/<[/\w!]/g),Ke=H(/<[/\w]/g),He=H(/<\/no(script|embed|frames)/i),Ge=H(/\/>/i),Je=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"],Ye=K(we({},Je)),Ze=function(){const e={};return X(Je,t=>{e[t]=H(new RegExp("])","i"))}),K(e)}(),Xe=function(){return"undefined"==typeof window?null:window},Qe=function(e,t,s,i){return me(e,t)&&ie(e[t])?we(i.base?Se(i.base):{},e[t],i.transform):s},et=function(e,t,s){const i=me(e,t)?e[t]:void 0;return i&&"object"==typeof i?Se(i):s()};var tt=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Xe();const s=t=>e(t);if(s.version="3.4.15",s.removed=[],!t||!t.document||9!==t.document.nodeType||!t.Element)return s.isSupported=!1,s;let i=t.document;const n=i,r=n.currentScript;t.DocumentFragment;const o=t.HTMLTemplateElement,a=t.Node,c=t.Element,l=t.NodeFilter;void 0===t.NamedNodeMap&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;const h=t.DOMParser,u=t.trustedTypes,d=c.prototype,p=Ce(d,"cloneNode"),m=Ce(d,"remove"),g=Ce(d,"removeAttributeNode"),f=Ce(d,"nextSibling"),b=Ce(d,"childNodes"),y=Ce(d,"parentNode"),v=Ce(d,"shadowRoot"),w=Ce(d,"attributes"),T=a&&a.prototype?Ce(a.prototype,"nodeType"):null,S=a&&a.prototype?Ce(a.prototype,"nodeName"):null,C=a&&a.prototype?Ce(a.prototype,"ownerDocument"):null,O=function(e){return T?T(e):e.nodeType},E=function(e){return S?S(e):e.nodeName};if("function"==typeof o){const e=i.createElement("template");e.content&&e.content.ownerDocument&&(i=e.content.ownerDocument)}let A,x,M="",k=!1,I=0;const L=function(){if(I>0)throw be('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},P=function(e){L(),I++;try{return A.createHTML(e)}finally{I--}},_=i,N=_.implementation,D=_.createNodeIterator,F=_.createDocumentFragment,R=_.getElementsByTagName,B=n.importNode;let $={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};s.isSupported="function"==typeof V&&"function"==typeof y&&N&&void 0!==N.createHTMLDocument;const j=De,q=Fe,U=Re,z=Be,W=$e,J=Ve,Y=qe,Z=ze;let ye=je,ve=null;const Te=we({},[...Oe,...Ee,...Ae,...Me,...Ie]);let Je=null;const tt=we({},[...Le,...Pe,..._e,...Ne]);let st=Object.seal(G(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),it=null,nt=null;const rt=Object.seal(G(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let ot=!0,at=!0,ct=!1,lt=!0,ht=!1,ut=!0,dt=!1,pt=!1,mt=null,gt=null,ft=!1,bt=!1,yt=!1,vt=!1,wt=!0,Tt=!1;const St="user-content-";let Ct=!0,Ot=!1,Et={},At=null;const xt=we({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let Mt=null;const kt=we({},["audio","video","img","source","image","track"]);let It=null;const Lt=we({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Pt="http://www.w3.org/1998/Math/MathML",_t="http://www.w3.org/2000/svg",Nt="http://www.w3.org/1999/xhtml";let Dt=Nt,Ft=!1,Rt=null;const Bt=we({},[Pt,_t,Nt],re),$t=K(["mi","mo","mn","ms","mtext"]);let jt=we({},$t);const Vt=K(["annotation-xml"]);let qt=we({},Vt);const Ut=we({},["title","style","font","a","script"]);let zt=null;const Wt=["application/xhtml+xml","text/html"];let Kt=null,Ht=null;const Gt=i.createElement("form"),Jt=function(e){return e instanceof RegExp||e instanceof Function},Yt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(Ht&&Ht===e)return;e&&"object"==typeof e||(e={}),e=Se(e),zt=-1===Wt.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,Kt="application/xhtml+xml"===zt?re:ne,ve=Qe(e,"ALLOWED_TAGS",Te,{transform:Kt}),Je=Qe(e,"ALLOWED_ATTR",tt,{transform:Kt}),Rt=Qe(e,"ALLOWED_NAMESPACES",Bt,{transform:re}),It=Qe(e,"ADD_URI_SAFE_ATTR",Lt,{transform:Kt,base:Lt}),Mt=Qe(e,"ADD_DATA_URI_TAGS",kt,{transform:Kt,base:kt}),At=Qe(e,"FORBID_CONTENTS",xt,{transform:Kt}),it=Qe(e,"FORBID_TAGS",Se({}),{transform:Kt}),nt=Qe(e,"FORBID_ATTR",Se({}),{transform:Kt}),Et=!!me(e,"USE_PROFILES")&&(e.USE_PROFILES&&"object"==typeof e.USE_PROFILES?Se(e.USE_PROFILES):e.USE_PROFILES),ot=!1!==e.ALLOW_ARIA_ATTR,at=!1!==e.ALLOW_DATA_ATTR,ct=e.ALLOW_UNKNOWN_PROTOCOLS||!1,lt=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,ht=e.SAFE_FOR_TEMPLATES||!1,ut=!1!==e.SAFE_FOR_XML,dt=e.WHOLE_DOCUMENT||!1,bt=e.RETURN_DOM||!1,yt=e.RETURN_DOM_FRAGMENT||!1,vt=e.RETURN_TRUSTED_TYPE||!1,ft=e.FORCE_BODY||!1,wt=!1!==e.SANITIZE_DOM,Tt=e.SANITIZE_NAMED_PROPS||!1,Ct=!1!==e.KEEP_CONTENT,Ot=e.IN_PLACE||!1,ye=function(e){try{return fe(e,""),!0}catch(e){return!1}}(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:je,Dt="string"==typeof e.NAMESPACE?e.NAMESPACE:Nt,jt=et(e,"MATHML_TEXT_INTEGRATION_POINTS",()=>we({},$t)),qt=et(e,"HTML_INTEGRATION_POINTS",()=>we({},Vt));const t=et(e,"CUSTOM_ELEMENT_HANDLING",()=>G(null));if(st=G(null),me(t,"tagNameCheck")&&Jt(t.tagNameCheck)&&(st.tagNameCheck=t.tagNameCheck),me(t,"attributeNameCheck")&&Jt(t.attributeNameCheck)&&(st.attributeNameCheck=t.attributeNameCheck),me(t,"allowCustomizedBuiltInElements")&&"boolean"==typeof t.allowCustomizedBuiltInElements&&(st.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),H(st),ht&&(at=!1),yt&&(bt=!0),Et&&(ve=we({},Ie),Je=G(null),!0===Et.html&&(we(ve,Oe),we(Je,Le)),!0===Et.svg&&(we(ve,Ee),we(Je,Pe),we(Je,Ne)),!0===Et.svgFilters&&(we(ve,Ae),we(Je,Pe),we(Je,Ne)),!0===Et.mathMl&&(we(ve,Me),we(Je,_e),we(Je,Ne))),rt.tagCheck=null,rt.attributeCheck=null,me(e,"ADD_TAGS")&&("function"==typeof e.ADD_TAGS?rt.tagCheck=e.ADD_TAGS:ie(e.ADD_TAGS)&&(ve===Te&&(ve=Se(ve)),we(ve,e.ADD_TAGS,Kt))),me(e,"ADD_ATTR")&&("function"==typeof e.ADD_ATTR?rt.attributeCheck=e.ADD_ATTR:ie(e.ADD_ATTR)&&(Je===tt&&(Je=Se(Je)),we(Je,e.ADD_ATTR,Kt))),me(e,"ADD_FORBID_CONTENTS")&&ie(e.ADD_FORBID_CONTENTS)&&(At===xt&&(At=Se(At)),we(At,e.ADD_FORBID_CONTENTS,Kt)),Ct&&(ve["#text"]=!0),dt&&we(ve,["html","head","body"]),ve.table&&(we(ve,["tbody"]),delete it.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const t=A;A=e.TRUSTED_TYPES_POLICY;try{M=P("")}catch(e){throw A=t,e}}else null===e.TRUSTED_TYPES_POLICY?(A=void 0,M=""):(void 0===A&&(k||(x=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let s=null;const i="data-tt-policy-suffix";t&&t.hasAttribute(i)&&(s=t.getAttribute(i));const n="dompurify"+(s?"#"+s:"");try{return e.createPolicy(n,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+n+" could not be created."),null}}(u,r),k=!0),A=x),A&&"string"==typeof M&&(M=P("")));K&&K(e),Ht=e},Zt=we({},[...Ee,...Ae,...xe]),Xt=we({},[...Me,...ke]),Qt=function(e){te(s.removed,{element:e});try{y(e).removeChild(e)}catch(t){if(m(e),!y(e))throw be("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},es=function(e,t,s){try{g(e,t)}catch(t){try{e.removeAttribute(s)}catch(e){}}},ts=function(e){ns(e);const t=b(e);if(t){const e=[];X(t,t=>{te(e,t)}),X(e,e=>{try{m(e)}catch(e){}})}const s=w(e);if(s)for(let t=s.length-1;t>=0;--t){const i=s[t],n=i&&i.name;"string"==typeof n&&es(e,i,n)}},ss=function(e,t,i){if(!i)try{i=t.getAttributeNode(e)}catch(e){i=null}te(s.removed,{attribute:i||null,from:t});try{i?g(t,i):t.removeAttribute(e)}catch(s){try{t.removeAttribute(e)}catch(e){}}if("is"===e)if(bt||yt)try{Qt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},is=function(e){const t=w(e);if(t)for(let s=t.length-1;s>=0;--s){const i=t[s],n=i&&i.name;"string"!=typeof n||Je[Kt(n)]||es(e,i,n)}},ns=function(e){const t=[e];for(;t.length>0;){const e=t.pop();1===O(e)&&is(e);const s=b(e);if(s)for(let e=s.length-1;e>=0;--e)t.push(s[e])}},rs=function(e,t){return!!ut&&("patchsrc"===e||"for"===e&&"label"!==t&&"output"!==t)},os=function(e){let t=null,s=null;if(ft)e=""+e;else{const t=oe(e,/^[\r\n\t ]+/);s=t&&t[0]}"application/xhtml+xml"===zt&&Dt===Nt&&(e=''+e+"");const n=A?P(e):e;if(Dt===Nt)try{t=(new h).parseFromString(n,zt)}catch(e){}if(!t||!t.documentElement){t=N.createDocument(Dt,"template",null);try{t.documentElement.innerHTML=Ft?M:n}catch(e){}}const r=t.body||t.documentElement;return e&&s&&r.insertBefore(i.createTextNode(s),r.childNodes[0]||null),Dt===Nt?R.call(t,dt?"html":"body")[0]:dt?t.documentElement:r},as=function(e){const t=C?C(e):e.ownerDocument;return D.call(t||e,e,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},cs=function(e){return e=ae(e,j," "),e=ae(e,q," "),ae(e,U," ")},ls=function(e){var t;e.normalize();const s=C?C(e):e.ownerDocument,i=D.call(s||e,e,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null);let n=i.nextNode();for(;n;)n.data=cs(n.data),n=i.nextNode();const r=null===(t=e.querySelectorAll)||void 0===t?void 0:t.call(e,"template");r&&X(r,e=>{us(e.content)&&ls(e.content)})},hs=function(e){const t=S?S(e):null;return"string"==typeof t&&"form"===Kt(t)&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||e.attributes!==w(e)||"function"!=typeof e.removeAttribute||"function"!=typeof e.removeAttributeNode||"function"!=typeof e.getAttributeNode||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes||e.nodeType!==T(e)||e.childNodes!==b(e))},us=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return 11===T(e)}catch(e){return!1}},ds=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return"number"==typeof T(e)}catch(e){return!1}};function ps(e,t,i){0!==e.length&&X(e,e=>{e.call(s,t,i,Ht)})}const ms=function(e,t){if(e instanceof RegExp)return fe(e,t);if(e instanceof Function){for(var s=arguments.length,i=new Array(s>2?s-2:0),n=2;n=0;--n){const r=e===s?p(i[n],!0):i[n];t.insertBefore(r,f(e))}}return Qt(e),!0}(e,i,t);return!1===s&&ps($.afterSanitizeElements,e,null),s}if(1===O(e)&&!function(e){let t=y(e);t&&t.tagName||(t={namespaceURI:Dt,tagName:"template"});const s=ne(e.tagName),i=ne(t.tagName);return!!Rt[e.namespaceURI]&&(e.namespaceURI===_t?function(e,t,s){return t.namespaceURI===Nt?"svg"===e:t.namespaceURI===Pt?"svg"===e&&("annotation-xml"===s||jt[s]):Boolean(Zt[e])}(s,t,i):e.namespaceURI===Pt?function(e,t,s){return t.namespaceURI===Nt?"math"===e:t.namespaceURI===_t?"math"===e&&qt[s]:Boolean(Xt[e])}(s,t,i):e.namespaceURI===Nt?function(e,t,s){return!(t.namespaceURI===_t&&!qt[s])&&!(t.namespaceURI===Pt&&!jt[s])&&!Xt[e]&&(Ut[e]||!Zt[e])}(s,t,i):!("application/xhtml+xml"!==zt||!Rt[e.namespaceURI]))}(e))return Qt(e),!0;if(("noscript"===i||"noembed"===i||"noframes"===i)&&fe(He,e.innerHTML))return Qt(e),!0;if(ht&&3===e.nodeType){const t=cs(e.textContent);e.textContent!==t&&(te(s.removed,{element:e.cloneNode()}),e.textContent=t)}return ps($.afterSanitizeElements,e,null),!1},ys=function(e,t,s){if(nt[t])return!1;if(rs(t,e))return!1;if(wt&&("id"===t||"name"===t)&&(s in i||s in Gt))return!1;const n=Je[t]||rt.attributeCheck instanceof Function&&rt.attributeCheck(t,e);return!(!at||!fe(z,t))||!(!ot||!fe(W,t))||(n?!(!It[t]&&!fe(ye,ae(s,Y,""))&&("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==ce(s,"data:")||!Mt[e])&&(!ct||fe(J,ae(s,Y,"")))&&s):ws(e)&&ms(st.tagNameCheck,e)&&ms(st.attributeNameCheck,t,e)||"is"===t&&st.allowCustomizedBuiltInElements&&ms(st.tagNameCheck,s))},vs=we({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),ws=function(e){return!vs[ne(e)]&&fe(Z,e)},Ts=function(e,t,s,i){if(A&&"object"==typeof u&&"function"==typeof u.getAttributeType&&!s)switch(u.getAttributeType(e,t)){case"TrustedHTML":return P(i);case"TrustedScriptURL":return function(e){L(),I++;try{return A.createScriptURL(e)}finally{I--}}(i)}return i},Ss=function(e,t,s,i){try{return s?e.setAttributeNS(s,t,i):e.setAttribute(t,i),!hs(e)||(Qt(e),!1)}catch(s){return ss(t,e),!1}},Cs=function(e){ps($.beforeSanitizeAttributes,e,null);const t=e.attributes;if(!t||hs(e))return;Je=gs($.uponSanitizeAttribute,Je,tt,gt);const i={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Je,forceKeepAttr:void 0};let n=t.length;const r=Kt(e.nodeName);for(;n--;){const o=t[n],a=o.name,c=o.namespaceURI,l=o.value,h=Kt(a),u=l;let d="value"===a?u:le(u),p=!1;i.attrName=h,i.attrValue=d,i.keepAttr=!0,i.forceKeepAttr=void 0,ps($.uponSanitizeAttribute,e,i),d=i.attrValue,!Tt||"id"!==h&&"name"!==h||0===ce(d,St)||(ss(a,e,o),d=St+d,p=!0),ut&&fe(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)||"attributename"===h&&oe(d,"href")?ss(a,e,o):i.forceKeepAttr||(i.keepAttr&&(lt||!fe(Ge,d))?(ht&&(d=cs(d)),ys(r,h,d)?(d=Ts(r,h,c,d),d!==u&&Ss(e,a,c,d)&&p&&ee(s.removed)):ss(a,e,o)):ss(a,e,o))}ps($.afterSanitizeAttributes,e,null)},Os=function(e){let t=null;const s=as(e);for(ps($.beforeSanitizeShadowDOM,e,null);t=s.nextNode();)if(ps($.uponSanitizeShadowNode,t,null),bs(t,e),Cs(t),us(t.content)&&Os(t.content),1===O(t)){const e=v(t);us(e)&&(Es(e),Os(e))}ps($.afterSanitizeShadowDOM,e,null)},Es=function(e){const t=[{node:e,shadow:null}];for(;t.length>0;){const e=t.pop();if(e.shadow){Os(e.shadow);continue}const s=e.node,i=1===O(s),n=b(s);if(n)for(let e=n.length-1;e>=0;--e)t.push({node:n[e],shadow:null});if(i){const e=S?S(s):null;if("string"==typeof e&&"template"===Kt(e)){const e=s.content;us(e)&&t.push({node:e,shadow:null})}}if(i){const e=v(s);us(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return s.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=null,r=null,o=null,a=null;if(Ft=!e,Ft&&(e="\x3c!--\x3e"),"string"!=typeof e&&!ds(e)&&"string"!=typeof(e=function(e){switch(typeof e){case"string":return e;case"number":return he(e);case"boolean":return ue(e);case"bigint":return de?de(e):"0";case"symbol":return pe?pe(e):"Symbol()";case"undefined":default:return ge(e);case"function":case"object":{if(null===e)return ge(e);const t=e,s=Ce(t,"toString");if("function"==typeof s){const e=s(t);return"string"==typeof e?e:ge(e)}return ge(e)}}}(e)))throw be("dirty is not a string, aborting");if(!s.isSupported)return e;pt?(ve=mt,Je=gt):Yt(t),($.uponSanitizeElement.length>0||$.uponSanitizeAttribute.length>0)&&(ve=Se(ve)),$.uponSanitizeAttribute.length>0&&(Je=Se(Je)),s.removed=[];const c=Ot&&"string"!=typeof e&&ds(e);if(c){!function(e){if(!ut)return;const t=[e];for(;t.length>0;){const e=t.pop(),s=O(e);if(7===s||8===s&&fe(Ke,e.data)){try{m(e)}catch(e){}continue}if(1===s){const t=e,s=Kt(E(e));try{t.hasAttribute&&t.hasAttribute("patchsrc")&&t.removeAttribute("patchsrc"),t.hasAttribute&&t.hasAttribute("for")&&rs("for",s)&&t.removeAttribute("for")}catch(e){}}const i=b(e);if(i)for(let e=i.length-1;e>=0;--e)t.push(i[e])}}(e);const t=E(e);if("string"==typeof t){const s=Kt(t);if(!ve[s]||it[s])throw ts(e),be("root node is forbidden and cannot be sanitized in-place")}if(hs(e))throw ts(e),be("root node is clobbered and cannot be sanitized in-place");try{Es(e)}catch(t){throw ts(e),t}}else if(ds(e))i=os("\x3c!----\x3e"),r=i.ownerDocument.importNode(e,!0),1===r.nodeType&&"BODY"===r.nodeName||"HTML"===r.nodeName?i=r:i.appendChild(r),Es(i);else{if(!bt&&!ht&&!dt&&-1===e.indexOf("<"))return A&&vt?P(e):e;if(i=os(e),!i)return bt?null:vt?M:""}i&&ft&&Qt(i.firstChild);const l=c?e:i;try{const e=as(l);for(;o=e.nextNode();)bs(o,l),Cs(o),us(o.content)&&Os(o.content)}catch(t){throw c&&(ts(e),X(s.removed,e=>{e.element&&ns(e.element)})),t}if(c)return X(s.removed,e=>{e.element&&ns(e.element)}),ht&&ls(e),e;if(bt){if(ht&&ls(i),yt)for(a=F.call(i.ownerDocument);i.firstChild;)a.appendChild(i.firstChild);else a=i;return(Je.shadowroot||Je.shadowrootmode)&&(a=B.call(n,a,!0)),a}let h=dt?i.outerHTML:i.innerHTML;return dt&&ve["!doctype"]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&fe(Ue,i.ownerDocument.doctype.name)&&(h="\n"+h),ht&&(h=cs(h)),A&&vt?P(h):h},s.setConfig=function(){Yt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),pt=!0,mt=ve,gt=Je},s.clearConfig=function(){Ht=null,pt=!1,mt=null,gt=null,A=x,M=""},s.isValidAttribute=function(e,t,s){Ht||Yt({});const i=Kt(e),n=Kt(t);return ys(i,n,s)},s.addHook=function(e,t){"function"==typeof t&&me($,e)&&te($[e],t)},s.removeHook=function(e,t){if(me($,e)){if(void 0!==t){const s=Q($[e],t);return-1===s?void 0:se($[e],s,1)[0]}return ee($[e])}},s.removeHooks=function(e){me($,e)&&($[e]=[])},s.removeAllHooks=function(){$={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},s}();const st={ADD_ATTR:["target"],ALLOW_DATA_ATTR:!1,RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0}},it={ADD_ATTR:["target"],ADD_TAGS:["hellotext-icon"],RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0,svg:!0}};function nt(e,t){const s=tt.sanitize(e,t);return s.querySelectorAll('a[target="_blank"]').forEach(e=>{const t=new Set(e.rel.split(/\s+/).filter(Boolean));t.add("noopener"),t.add("noreferrer"),e.rel=Array.from(t).join(" ")}),s}function rt(e,t){e.replaceChildren(function(e){return nt(e,st)}(t))}class ot{constructor(e,t=null){this.data=e,this.element=t||document.querySelector(`[data-hello-form="${this.id}"]`)||document.createElement("form")}async mount({ifCompleted:e=!0}={}){if(e&&this.hasBeenCompleted)return this.element?.remove(),vt.eventEmitter.dispatch("form:completed",{id:this.id,...JSON.parse(localStorage.getItem(`hello-form-${this.id}`))});const t=this.data.steps[0];this.buildHeader(t.header),this.buildInputs(t.inputs),this.buildButton(t.button),this.buildFooter(t.footer),this.elementAttributes.forEach(e=>{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),vt.business.features.white_label||this.element.prepend(B.build())}buildHeader(e){const t=this.#c("[data-form-header]","header");rt(t,e.content),this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}buildInputs(e){const t=this.#c("[data-form-inputs]","main");e.map(e=>R.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}buildButton(e){const t=this.#c("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}buildFooter(e){const t=this.#c("[data-form-footer]","footer");rt(t,e.content),this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}markAsCompleted(e){const t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem(`hello-form-${this.id}`,JSON.stringify(t)),vt.eventEmitter.dispatch("form:completed",t)}get hasBeenCompleted(){return null!==localStorage.getItem(`hello-form-${this.id}`)}get id(){return this.data.id}get localeAuthKey(){const e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}get elementAttributes(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}#c(e,t){const s=this.element.querySelector(e);if(s)return s.cloneNode(!0);const i=document.createElement(t);return i.setAttribute(e.replace("[","").replace("]",""),""),i}}class at extends Error{constructor(){super("You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id"),this.name="NotInitializedError"}}class ct{constructor(){this.forms=[],this.includes=this.includes.bind(this),this.excludes=this.excludes.bind(this),this.add=this.add.bind(this),"undefined"!=typeof MutationObserver&&(this.mutationObserver=new MutationObserver(this.formMutationObserver.bind(this)),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0}))}collectExistingFormsOnPage(){Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}formMutationObserver(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}async collect(){if(vt.notInitialized)throw new at;if(this.fetching)return;if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");const e=this.#l;if(0===e.length)return;const t=e.map(e=>T.get(e).then(e=>e.json()));this.fetching=!0,await Promise.all(t).then(e=>e.forEach(this.add)).then(()=>vt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),f.forms.autoMount&&this.forms.forEach(e=>e.mount())}forEach(e){this.forms.forEach(e)}map(e){return this.forms.map(e)}add(e){this.includes(e.id)||(vt.business.data||(vt.business.setData(e.business),vt.business.setLocale(a.toString())),vt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new ot(e)))}getById(e){return this.forms.find(t=>t.id===e)}getByIndex(e){return this.forms[e]}includes(e){return this.forms.some(t=>t.id===e)}excludes(e){return!this.includes(e)}get length(){return this.forms.length}get#l(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}}class lt{constructor(e){this.publicKey=e.public_key,this.serviceWorkerUrl=f.push.serviceWorkerUrl,this.channelId=f.push.channelId,this.ready=null,this.registrationPromise=null,this.subscribePromise=null,this.unsubscribePromise=null,this.syncPromise=null,this.subscription=null,this.retryTimeout=null,this.retryAttempts=0,this.disposed=!1}initialize(){return this.ready=this.restoreSubscription(),this.ready}async restoreSubscription(){const e=await this.getRegistration(),t=await e.pushManager.getSubscription();!this.disposed&&!this.unsubscribePromise&&t&&this.owns(t)&&(this.subscription=t,await this.sync())}subscribe(){if(this.disposed)return Promise.resolve();if(this.unsubscribePromise)return Promise.reject(new Error("Push unsubscribe is in progress"));if(this.subscribePromise)return this.subscribePromise;const e="default"===Notification.permission?Notification.requestPermission():Promise.resolve(Notification.permission);return this.subscribePromise=this.createSubscription(e).finally(()=>{this.subscribePromise=null}),this.subscribePromise}async createSubscription(e){if("granted"!==await e)throw new Error("Push permission was not granted");const t=await this.getRegistration();if(this.disposed)return;let s=await t.pushManager.getSubscription();if(!this.disposed){if(s&&!this.owns(s))throw new Error("The existing Push subscription belongs to a different application");if(s||=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:this.applicationServerKey}),!this.disposed)return this.subscription=s,this.sync()}}unsubscribe(){return this.disposed?Promise.resolve():(this.unsubscribePromise||(this.clearRetryTimeout(),this.unsubscribePromise=this.removeSubscription().finally(()=>{this.unsubscribePromise=null})),this.unsubscribePromise)}async removeSubscription(){await(this.ready?.catch(()=>{})),await(this.subscribePromise?.catch(()=>{})),await(this.syncPromise?.catch(()=>{}));const e=await this.getRegistration(),t=await e.pushManager.getSubscription()||this.subscription;if(this.disposed)return;if(!t)return null;if(!this.owns(t))throw new Error("The existing Push subscription belongs to a different application");this.subscription=t;const s=await I.pushIdentities.destroy({subscription:t.toJSON()});return s.failed?s:this.disposed?void 0:(await t.unsubscribe(),this.subscription=null,this.clearRetryTimeout(),s)}sync(){return this.disposed?Promise.resolve():(this.syncPromise||(this.clearRetryTimeout(),this.syncPromise=this.registerIdentity().finally(()=>{this.syncPromise=null})),this.syncPromise)}async registerIdentity(){try{const e=await I.pushIdentities.create({subscription:this.subscription.toJSON(),...this.channelId?{channel_id:this.channelId}:{}});return e.succeeded?this.retryAttempts=0:this.scheduleRetry(),e}catch(e){throw this.scheduleRetry(),e}}scheduleRetry(){this.disposed||this.unsubscribePromise||this.retryTimeout||this.retryAttempts>=3||(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.sync().catch(()=>{})},1e3*2**this.retryAttempts),this.retryAttempts+=1)}clearRetryTimeout(){clearTimeout(this.retryTimeout),this.retryTimeout=null}dispose(){this.disposed=!0,this.clearRetryTimeout()}get subscribed(){return!!this.subscription}get applicationServerKey(){const e=this.publicKey.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e.padEnd(4*Math.ceil(e.length/4),"=")),e=>e.charCodeAt(0))}owns(e){const t=e.options?.applicationServerKey;if(!t)return!1;const s=new Uint8Array(t),i=this.applicationServerKey;return s.length===i.length&&s.every((e,t)=>e===i[t])}getRegistration(){return this.registrationPromise||(this.registrationPromise=this.loadRegistration().catch(e=>{throw this.registrationPromise=null,e})),this.registrationPromise}async loadRegistration(){if(this.serviceWorkerUrl){const e=await navigator.serviceWorker.register(this.serviceWorkerUrl);!e.active||e.installing||e.waiting||await e.update();const t=e.installing||e.waiting||e.active;return"activated"===t?.state?e:new Promise((s,i)=>{const n=setTimeout(()=>r(new Error("Push service worker did not become active")),1e4),r=r=>{clearTimeout(n),t?.removeEventListener("statechange",o),r?i(r):s(e)},o=()=>{"activated"===t?.state&&r(),"redundant"===t?.state&&r(new Error("Push service worker installation failed"))};t?.addEventListener("statechange",o),o()})}return new Promise((e,t)=>{const s=setTimeout(()=>t(new Error("Push service worker is not available")),1e4);navigator.serviceWorker.ready.then(t=>{clearTimeout(s),e(t)},e=>{clearTimeout(s),t(e)})})}static get supported(){return"undefined"!=typeof window&&!0===window.isSecureContext&&"undefined"!=typeof navigator&&"serviceWorker"in navigator&&"undefined"!=typeof PushManager&&"undefined"!=typeof Notification}}class ht{constructor(e,t,s){this.business=t,this.push=s,this.disposed=!1,this.showRequest=0,this.controller=null,this.element=(new DOMParser).parseFromString(e.html,"text/html").querySelector('[data-controller~="hellotext--alert"]'),this.connected=new Promise(e=>{this.resolveConnected=e}),this.onConnect=this.onConnect.bind(this),this.ready=this.render()}onConnect(e){this.controller=e.detail.controller,this.controller.alert=this,this.resolveConnected(!0)}async render(){return!!this.element&&(this.element.addEventListener("hellotext--alert:connected",this.onConnect),!(!await this.business.stylesheetLoaded||this.disposed)&&(document.body.appendChild(this.element),this.connected))}async show(e,t={}){const s=++this.showRequest;return!(!await this.ready||this.disposed||s!==this.showRequest)&&this.controller.show(e,t)}hide(){this.showRequest+=1,this.controller?.close()}dispose(){this.disposed=!0,this.hide(),this.resolveConnected(!1),this.element?.removeEventListener("hellotext--alert:connected",this.onConnect),this.element?.remove()}}class ut{static async load(e){const t=new ut({id:e,html:await I.webchats.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){return this.applyBehaviourOverride(),await this.stylesheetLoaded?(this.containerToAppendTo.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext webchat was not mounted because its stylesheet failed to load."),!1)}applyBehaviourOverride(){f.webchat.hasBehaviourOverride&&f.webchat.behaviour&&this.data.html.setAttribute("data-hellotext--webchat-behaviour-value",JSON.stringify(this.serializedBehaviour))}get serializedBehaviour(){const e=f.webchat.behaviour;return{trigger:this.serializeTrigger(e.trigger),delay_seconds:e.delaySeconds,first_visit_only:e.firstVisitOnly,once_per_session:e.oncePerSession}}serializeTrigger(e){return"onLoad"===e?"on_load":"onClick"===e?"on_click":e}get containerToAppendTo(){return document.querySelector(f.webchat.container)}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=this.data.html,t=document.querySelector(".hellotext--whatsapp-widget");e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class dt{static async load(e){const t=new dt({id:e,html:await I.whatsappWidgets.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){if(!this.data.html)return!1;const e=this.containerToAppendTo;return e?await this.stylesheetLoaded?(e.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext WhatsApp widget was not mounted because its stylesheet failed to load."),!1):(console.warn(`Hellotext WhatsApp widget was not mounted because the container ${f.whatsapp.container} was not found.`),!1)}get containerToAppendTo(){try{return document.querySelector(f.whatsapp.container)}catch(e){return null}}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=document.querySelector(".hellotext--webchat:not(.hellotext--whatsapp-widget)"),t=this.data.html;e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class pt{static async load(e,t={}){const s=new pt({id:e,html:await I.popups.get(e)},t);return s.rendered=s.render(),s}constructor(e,{container:t=f.popup.container,shouldMount:s=()=>!0}={}){this.data=e,this.container=t,this.mounted=!1,this.rendered=Promise.resolve(!1),this.shouldMount=s}async render(){if(!this.data.html||!this.shouldMount())return!1;const e=this.containerToAppendTo;return e?!!this.shouldMount()&&(e.appendChild(this.data.html),this.mounted=!0,this.shouldMount()||this.unmount(),this.mounted):(console.warn(`Hellotext popup was not mounted because the container ${this.container} was not found.`),!1)}unmount(){this.data.html?.remove(),this.mounted=!1}get containerToAppendTo(){try{return document.querySelector(this.container)}catch(e){return null}}}class mt{static get id(){return _.get("hello_user_id")}static get source(){return _.get("hello_user_source")}static get fingerprint(){return _.get("hello_user_identification_hash")}static remember(e,t,s){t&&_.set("hello_user_source",t),s&&_.set("hello_user_identification_hash",s),_.set("hello_user_id",e)}static forget(){_.delete("hello_user_id"),_.delete("hello_user_source"),_.delete("hello_user_identification_hash")}static get identificationData(){return this.id?{id:this.id,source:this.source}:{}}}function gt(e){if(null!=e){if("string"==typeof e){const t=e.trim();return""===t?void 0:t}if(Array.isArray(e))return e.map(e=>gt(e)).filter(e=>void 0!==e);if(e instanceof Date)return e.toISOString();if("object"==typeof e){const t=Object.keys(e).sort((e,t)=>e.localeCompare(t)).reduce((t,s)=>{const i=gt(e[s]);return void 0!==i&&(t[s]=i),t},{});return Object.keys(t).length>0?t:void 0}return"number"==typeof e||"boolean"==typeof e?e:void 0}}function ft(e,t,s={}){const i=gt({session:e,user_id:t,...s})||{};return JSON.stringify(i)}class bt{static matches(e,t){return!!e&&e===t}static async generate(e,t,s={}){return await async function(e){if(!globalThis.crypto?.subtle||"undefined"==typeof TextEncoder)return function(e){let t=5381;for(let s=0;s>>0).toString(16)}`}(e);const t=await globalThis.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e));return`v1:${Array.from(new Uint8Array(t)).map(e=>e.toString(16).padStart(2,"0")).join("")}`}(ft(e,t,s))}}class yt{static eventEmitter=new r;static forms;static business;static popup;static webchat;static whatsapp;static push;static alert;static initializationVersion=0;static async initialize(e,t={}){const s=++this.initializationVersion;this.popup?.unmount?.(),this.popup=void 0,this.alert?.dispose(),this.alert=null,this.push?.dispose(),this.push=null;const i=new P(e);this.business=i,this.page=new D,f.assign({push:{},...t}),F.initialize(this.page),this.forms=new ct,this.query=new y;const n=await i.hydrate();if(this.business!==i)return;!1!==t.push&&n?.push?.public_key&<.supported&&(this.push=new lt(n.push),this.push.initialize().catch(e=>{console.warn("Hellotext Push initialization failed:",e)}),n.alert?.html&&(this.alert=new ht(n.alert,i,this.push)));const r=!1!==t.popup&&this.deepMergePlainObjects(n&&n.popup||{},t.popup||{}),o=!1!==t.webchat&&this.mergeWebchatConfig(n&&n.webchat||{},t.webchat||{}),a=!1!==t.whatsappWidget&&this.mergeWhatsAppConfig(n&&n.whatsapp||{},t.whatsappWidget||{}),c=t.webchat&&!1!==t.webchat&&Object.prototype.hasOwnProperty.call(t.webchat,"behaviour");f.webchat.behaviourOverride=c;const l=[];if(o&&o.id&&(f.webchat.assign(o),l.push(ut.load(o.id).then(e=>{this.business===i&&(this.webchat=e)}))),a&&a.id&&(f.whatsapp.assign(a),l.push(dt.load(a.id).then(e=>{this.business===i&&(this.whatsapp=e)}))),r&&r.id){const e={container:"body",device:"auto",...r};f.popup.assign(e),l.push(pt.load(e.id,{container:e.container,shouldMount:()=>this.business===i&&this.initializationVersion===s}).then(e=>{this.business===i&&this.initializationVersion===s&&(this.popup=e)}))}await Promise.all(l),this.business===i&&this.initializationVersion===s&&"undefined"!=typeof MutationObserver&&this.forms.collectExistingFormsOnPage()}static mergeWebchatConfig(e,t){return this.deepMergePlainObjects(e,t)}static mergeWhatsAppConfig(e,t){return this.deepMergePlainObjects(e,t)}static deepMergePlainObjects(e,t){const s={...e};return Object.entries(t).forEach(([e,t])=>{this.isPlainObject(t)&&this.isPlainObject(s[e])?s[e]=this.deepMergePlainObjects(s[e],t):s[e]=t}),s}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}static async track(e,t={}){if(this.notInitialized)throw new at;const s={...t&&t.headers||{},...this.headers},i={...mt.identificationData,...t.user_parameters||{}},n=t&&t.url?new D(t.url):this.page,r={session:this.session,user_parameters:i,action:e,...t,...n.trackingData};return delete r.headers,await I.events.create({headers:s,body:r,keepalive:k(r)})}static async identify(e,t={}){const s=await bt.generate(this.session,e,t);if(bt.matches(mt.fingerprint,s))return new v(!0,{json:async()=>({already_identified:!0})});const i=await I.identifications.create({user_id:e,...t});return i.succeeded&&mt.remember(e,t.source,s),i}static forget(){mt.forget()}static on(e,t){this.eventEmitter.addSubscriber(e,t)}static removeEventListener(e,t){this.eventEmitter.removeSubscriber(e,t)}static get session(){return F.session}static get isInitialized(){return void 0!==F.session}static get notInitialized(){return!this.business||void 0===this.business.id}static get headers(){if(this.notInitialized)throw new at;return{Authorization:`Bearer ${this.business.id}`,Accept:"application/json","Content-Type":"application/json"}}}const vt=yt,wt=new Map,Tt=class extends i.xI{static values={sections:Array};static targets=["title","description","primaryAction","secondaryAction"];initialize(){this.showRequest=0,this.submitting=!1,this.onStorage=this.onStorage.bind(this)}connect(){this.dispatch("connected",{detail:{controller:this}}),window.addEventListener("storage",this.onStorage)}disconnect(){this.close(),window.removeEventListener("storage",this.onStorage)}onStorage(e){e.key===this.storageKey&&this.dismissal.dismissedUntil>Date.now()&&this.close()}async show(e,{force:t=!1,title:s,description:i,primaryAction:n,secondaryAction:r}={}){const o=++this.showRequest,a=this.sectionsValue.find(t=>t.kind===e);return a?(await(this.alert.push.ready?.catch(()=>{})),!(o!==this.showRequest||this.alert.disposed||!this.element.isConnected||(this.unavailable||!t&&this.dismissal.dismissedUntil>Date.now()?(this.close(),1):(this.titleTarget.textContent=s??a.title,this.descriptionTarget.textContent=i??a.description,this.primaryActionTarget.textContent=n??a.primary_action,this.secondaryActionTarget.textContent=r??a.secondary_action,this.kind=e,this.page=vt.page.trackingData.page,this.element.hidden=!1,this.record("shown"),vt.eventEmitter.dispatch("alert:shown",{kind:e}),0)))):(this.close(),!1)}hide(){if(this.element.hidden||this.submitting)return;const e=this.dismissal.dismissals+1,t={dismissals:e,dismissedUntil:Date.now()+864e5*(1===e?7:30)};wt.set(this.storageKey,t);try{localStorage.setItem(this.storageKey,JSON.stringify(t))}catch(e){}this.close(),this.record("dismissed"),vt.eventEmitter.dispatch("alert:dismissed",{kind:this.kind})}close(){this.showRequest+=1,this.element.hidden=!0}async subscribe(){if(!this.submitting&&!this.element.hidden){if(this.unavailable)return this.close();this.submitting=!0,this.primaryActionTarget.disabled=!0,this.secondaryActionTarget.disabled=!0,this.element.setAttribute("aria-busy","true");try{this.record("accepted"),vt.eventEmitter.dispatch("alert:accepted",{kind:this.kind});const e=await this.alert.push.subscribe();return this.unavailable&&this.close(),e?.failed&&this.dispatch("error",{detail:{response:e}}),e}catch(e){this.unavailable&&this.close(),this.dispatch("error",{detail:{error:e}})}finally{this.submitting=!1,this.primaryActionTarget.disabled=!1,this.secondaryActionTarget.disabled=!1,this.element.removeAttribute("aria-busy")}}}async record(e){try{const t=await I.pushAlerts.create({section:this.kind,kind:e,page:this.page});t.failed&&console.warn("Hellotext Smart Alert submission failed:",t)}catch(e){console.warn("Hellotext Smart Alert submission failed:",e)}}get unavailable(){return this.alert.push.disposed||this.alert.push.subscribed||"undefined"==typeof Notification||"denied"===Notification.permission}get storageKey(){return`hellotext:alert:${this.alert.business.id}`}get dismissal(){try{const e=JSON.parse(localStorage.getItem(this.storageKey));Number.isSafeInteger(e?.dismissals)&&e.dismissals>0&&Number.isFinite(e.dismissedUntil)&&e.dismissedUntil>=0&&wt.set(this.storageKey,e)}catch(e){}return wt.get(this.storageKey)||{dismissals:0,dismissedUntil:0}}},St=class extends i.xI{static values={data:Object,step:{type:Number,default:1}};static targets=["inputContainer","input","button","otpContainer"];initialize(){this.form=new ot(this.dataValue,this.element)}connect(){super.connect(),this.element.addEventListener("submit",this.submit.bind(this)),"INPUT"!==document.activeElement.tagName&&this.inputTargets[0].focus()}async submit(e){if(e.preventDefault(),this.invalid)return this.showErrorMessages();this.clearErrorMessages(),this.formData=Object.fromEntries(new FormData(this.element)),this.buttonTarget.disabled=!0;const t=await T.submit(this.form.id,this.formData);this.buttonTarget.disabled=!1;const s=await t.json();if(t.failed)return s.errors.forEach(e=>{const{type:t,parameter:s}=e,i=this.inputTargets.find(e=>e.name===s);i.setCustomValidity(vt.business.locale.errors[t]),i.reportValidity(),i.addEventListener("input",()=>{i.setCustomValidity(""),i.reportValidity()})}),this.showErrorMessages();this.buttonTarget.style.display="none",this.element.querySelectorAll("input").forEach(e=>e.disabled=!0),this.completed()}completed(){if(this.form.markAsCompleted(this.formData),!f.forms.shouldShowSuccessMessage)return this.element.remove();"string"==typeof f.forms.successMessage?this.element.innerHTML=f.forms.successMessage:this.element.innerHTML=vt.business.locale.forms[this.form.localeAuthKey]}showErrorMessages(){this.inputTargets.forEach(e=>{const t=e.closest("article").querySelector("[data-error-container]");e.validity.valid?t.innerText="":t.innerText=e.validationMessage})}clearErrorMessages(){this.inputTargets.forEach(e=>{e.setCustomValidity(""),e.closest("article").querySelector("[data-error-container]").innerText=""})}inputTargetConnected(e){e.getAttribute("data-default-value")&&(e.value=e.getAttribute("data-default-value"))}get requiredInputs(){return this.inputTargets.filter(e=>e.required)}get invalid(){return!this.element.checkValidity()}},Ct=class extends i.xI{static values={fadeDistance:{type:Number,default:64},id:String,kind:String,pageStartOffset:{type:Number,default:0},utm:Object};static targets=["carouselContainer","leftFade","rightFade","carouselCard"];connect(){this.updateFades(),this.observeContainerSize()}disconnect(){this.resizeObserver?.disconnect()}setId({detail:e}){this.idValue=e,this.element.id=e}onScroll(){this.updateFades()}quickReply({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),s=e.closest('[data-controller~="hellotext--message"]'),i=e.dataset.text||e.textContent.trim();this.dispatch("quickReply",{detail:{id:this.idValue,product:t?.dataset.id,buttonId:e.dataset.id,body:i,cardElement:t||s||e}})}addToCart({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),{id:s,reference:i,source:n}=t.dataset,r={product:s,quantity:1};this.hasUtmValue&&vt.page.utm.save(this.utmValue),vt.eventEmitter.dispatch("cart.added",{object_parameters:{items:[{...r,...i&&{reference:i},...n&&{source:n}}]},source:{kind:this.kindValue,message_id:this.idValue,button_id:e.dataset.id}})}moveToLeft(){if(!this.hasCarouselContainerTarget)return;const e=this.getPreviousPageScrollLeft(),t=this.carouselContainerTarget.scrollLeft-e;t<1||this.carouselContainerTarget.scrollBy({left:-t,behavior:"smooth"})}moveToRight(){if(!this.hasCarouselContainerTarget)return;const e=this.getNextPageScrollLeft()-this.carouselContainerTarget.scrollLeft;e<1||this.carouselContainerTarget.scrollBy({left:e,behavior:"smooth"})}getScrollAmount(){return this.getCardScrollAmount()}getCardScrollAmount(){const e=this.carouselContainerTarget.querySelector(".message__carousel_card");return e?e.offsetWidth+this.getGap():280}getPageScrollAmount(){const e=this.carouselContainerTarget.clientWidth-this.getGap();return e>0?e:this.getCardScrollAmount()}getNextPageScrollLeft(){const e=this.getCurrentScrollLeft(),t=e+this.carouselContainerTarget.clientWidth,s=this.getCardMetrics().find(e=>e.end>t+1),i=s?this.getPageAlignedScrollLeft(s.start):e+this.getPageScrollAmount(),n=e+this.getPageScrollAmount();return this.clampScrollLeft(i>e+1?i:n)}getPreviousPageScrollLeft(){const e=this.getCurrentScrollLeft();if(e<=1)return 0;const t=Math.max(e-this.getPageScrollAmount(),0);if(t<=1)return 0;const s=this.getCardMetrics(),i=s.find(s=>s.start>=t-1&&s.startt.start{const t=this.getCardScrollLeft(e);return{start:t,end:t+e.offsetWidth}})}getCardScrollLeft(e){const t=e.getBoundingClientRect(),s=this.carouselContainerTarget.getBoundingClientRect();return t.left||t.width||s.left||s.width?t.left-s.left+this.carouselContainerTarget.scrollLeft:e.offsetLeft||0}getCurrentScrollLeft(){return this.clampScrollLeft(this.carouselContainerTarget.scrollLeft)}clampScrollLeft(e){const t=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);return Math.min(Math.max(e,0),t)}getGap(){const e=window.getComputedStyle(this.carouselContainerTarget),t=Number.parseFloat(e.columnGap||e.gap);return Number.isFinite(t)?t:16}getFadeDistance(){return Number.isFinite(this.fadeDistanceValue)?this.fadeDistanceValue:64}getPageStartOffset(){return Number.isFinite(this.pageStartOffsetValue)?this.pageStartOffsetValue:0}observeContainerSize(){this.hasCarouselContainerTarget&&window.ResizeObserver&&(this.resizeObserver=new ResizeObserver(()=>this.updateFades()),this.resizeObserver.observe(this.carouselContainerTarget))}updateFades(){if(!this.hasCarouselContainerTarget)return;const e=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);if(e<=1)return this.hideFade(this.leftFadeTarget),void this.hideFade(this.rightFadeTarget);const t=Math.min(Math.max(this.carouselContainerTarget.scrollLeft,0),e),s=this.getFadeDistance();this.setFadeOpacity(this.leftFadeTarget,t/s),this.setFadeOpacity(this.rightFadeTarget,(e-t)/s)}setFadeOpacity(e,t){const s=Math.min(Math.max(t,0),1);s<=.05?this.hideFade(e):(e.classList.remove("hidden"),e.removeAttribute("disabled"),e.removeAttribute("tabindex"),e.setAttribute("aria-hidden","false"),e.style.opacity=s.toFixed(3),e.style.pointerEvents="auto")}hideFade(e){e.style.opacity="0",e.style.pointerEvents="none",e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1"),"disabled"in e&&(e.disabled=!0),e.classList.add("hidden")}},Ot=class extends i.xI{static targets=["bubble","dialog","step","completed","input","submitButton","globalError","resendButton","changeDestinationButton","deliveryCopy","noDeliveryCopy"];static values={capture:Object,device:String,hasBubble:Boolean,id:String};initialize(){this.stepIndex=0,this.resendLabel=this.hasResendButtonTarget?this.resendButtonTarget.textContent.trim():""}connect(){vt.eventEmitter.dispatch("popup:mounted"),this.evaluateDisplay()}disconnect(){this.stopResendCooldown()}open(e){e&&e.preventDefault(),this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}close(e){e&&e.preventDefault(),this.dismissed=!0,this.dialogTarget.hidden=!0,this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.element.hidden=!0,vt.eventEmitter.dispatch("popup:closed")}closeOnEscape(e){this.dialogTarget.hidden||e.defaultPrevented||e.isComposing||this.close(e)}async next(e){e&&e.preventDefault(),this.clearCustomValidity(),this.currentStepValid()?(this.clearErrorMessages(this.currentStepInputs),this.stepIndex{e.disabled=!0});try{const e=this.submissionPayload(),t=await C.submit(this.idValue,e,this.idempotencyKeyFor(e));if(t.failed)return void await this.handleSubmissionError(t);const s=await t.json();this.submissionId=s.id,this.submissionVerificationState=s.verification_state,this.submissionActionToken=s.action_token,this.submissionDeliveryStatus=s.delivery_status,this.submissionDeliveryChannel=s.delivery_channel,this.submissionDestination=s.destination,this.resetSubmissionRequest()}catch(e){return void this.showGlobalError()}finally{this.submitButtonTargets.forEach(e=>{e.disabled=!1})}this.showCompleted()}else this.showErrorMessages(this.currentStepInputs)}evaluateDisplay(){!this.dismissed&&this.matchesDevice()?this.showInitialState():this.element.hidden=!0}showInitialState(){if(this.element.hidden=!1,this.hasBubbleValue&&this.hasBubbleTarget)return this.bubbleTarget.hidden=!1,void(this.dialogTarget.hidden=!0);this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}showStep(e){this.stepIndex=e,this.stepTargets.forEach((t,s)=>{t.hidden=s!==e}),this.completedTarget.hidden=!0}showCompleted(){this.stepTargets.forEach(e=>{e.hidden=!0}),this.interpolateCompletionCopy(),this.configureCompletionActions(),this.completedTarget.hidden=!1}interpolateCompletionCopy(){const e=this.completedIdentity;if(!e)return;const t={destination:e.value,channel:this.submissionDeliveryChannel||e.kind};this.completionTextTemplates.forEach(({node:e,template:s})=>{e.nodeValue=s.replace(/\{(destination|channel)\}/g,(e,s)=>t[s]||e)})}identityValue(e){const t=this.inputValue(e).trim();if("phone"!==e.dataset.popupFieldKind||t.startsWith("+"))return t;const s=this.phoneCountryPrefix(e);if(s)return`${s}${this.phoneDigits(t)}`;const i=e.dataset.popupPhonePrefix;return i?`${i}${t.replace(/^0+/,"")}`:t}asciiDigits(e){const t=e=>/\p{Nd}/u.test(e);return e.replace(/\p{Nd}/gu,e=>{let s=e.codePointAt(0);const i=s;for(;t(String.fromCodePoint(s-1));)s-=1;return(i-s)%10})}phoneDigits(e){return this.asciiDigits(e).replace(/\D/g,"")}phoneCountryPrefix(e){const t=e.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country]");return t?.selectedOptions?.[0]?.dataset.prefix}selectPhoneCountry(e){const t=e.target,s=t.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country-label]");s&&(s.textContent=t.selectedOptions[0]?.dataset.label||"")}submissionValue(e){const t=this.inputValue(e),s="phone"===e.dataset.popupFieldKind&&this.phoneCountryPrefix(e),i="string"==typeof t?t.trim():"";return s&&i?i.startsWith("+")?this.asciiDigits(t):`${s}${this.phoneDigits(i)}`:t}configureCompletionActions(){const e="not_required"!==this.submissionDeliveryStatus;if(this.revealCompletionCopy(e),!e)return void this.completedTarget.querySelector("[data-delivery-actions]")?.setAttribute("hidden","");const t=this.completedIdentity;t&&(this.hasChangeDestinationButtonTarget&&(this.changeDestinationButtonTarget.textContent=this.changeDestinationButtonTarget.dataset[`${t.kind}Label`],this.changeDestinationButtonTarget.hidden=!1),this.submissionId&&this.submissionActionToken&&"queued"===this.submissionDeliveryStatus&&"unverified"===this.submissionVerificationState&&this.hasResendButtonTarget&&(this.resendButtonTarget.hidden=!1,this.startResendCooldown(60)))}async resend(e){if(e&&e.preventDefault(),this.submissionId&&this.submissionActionToken&&!this.resendPending&&!this.resendCooldownActive&&this.completedIdentity){this.resendPending=!0,this.resendButtonTarget.disabled=!0;try{const e=await C.resend(this.idValue,this.submissionId,this.submissionActionToken),t=Number(e.data.headers?.get("Retry-After"))||60;e.succeeded||429===e.data.status?this.startResendCooldown(t):this.resendButtonTarget.disabled=!1}catch(e){this.resendButtonTarget.disabled=!1}finally{this.resendPending=!1}}}async changeDestination(e){if(e&&e.preventDefault(),!this.submissionId||!this.submissionActionToken||this.changeDestinationPending)return;const t=this.completedIdentity?.input;if(!t)return;const s=this.stepTargets.findIndex(e=>e.dataset.stepId===t.dataset.popupStepId);if(!(s<0)){this.changeDestinationPending=!0,this.changeDestinationButtonTarget.disabled=!0;try{if((await C.cancel(this.idValue,this.submissionId,this.submissionActionToken)).failed)return;this.stopResendCooldown(),this.submissionId=null,this.submissionActionToken=null,this.submissionVerificationState=null,this.submissionDeliveryStatus=null,this.submissionDeliveryChannel=null,this.submissionDestination=null,this.resetSubmissionRequest(),this.showStep(s),t.focus()}catch(e){}finally{this.changeDestinationPending=!1,this.changeDestinationButtonTarget.disabled=!1}}}startResendCooldown(e){this.stopResendCooldown(),this.resendCooldownEndsAt=Date.now()+1e3*Math.max(e,1),this.updateResendCountdown(),this.resendTimer=window.setInterval(()=>this.updateResendCountdown(),1e3)}stopResendCooldown(){this.resendTimer&&window.clearInterval(this.resendTimer),this.resendTimer=null,this.resendCooldownEndsAt=null}updateResendCountdown(){const e=Math.max(0,Math.ceil((this.resendCooldownEndsAt-Date.now())/1e3));if(0===e)return this.stopResendCooldown(),this.resendButtonTarget.textContent=this.resendLabel,void(this.resendButtonTarget.disabled=!1);const t=`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`,s=this.resendButtonTarget.dataset.countdownLabel||`${this.resendLabel} %{time}`;this.resendButtonTarget.textContent=s.replace("%{time}",t),this.resendButtonTarget.disabled=!0}get resendCooldownActive(){return this.resendCooldownEndsAt>Date.now()}get completionIdentity(){return this.identityInputs.map(e=>({input:e,kind:e.dataset.popupFieldKind,value:this.identityValue(e)})).find(({value:e})=>e)}get completedIdentity(){if(this.submissionDestination&&this.submissionDeliveryChannel){const e="email"===this.submissionDeliveryChannel?"email":"phone";return{input:this.identityInputs.find(t=>t.dataset.popupFieldKind===e),kind:e,value:this.submissionDestination}}return this.completionIdentity}revealCompletionCopy(e){this.hasDeliveryCopyTarget&&this.deliveryCopyTargets.forEach(t=>{t.hidden=!e}),this.hasNoDeliveryCopyTarget&&this.noDeliveryCopyTargets.forEach(t=>{t.hidden=e})}currentStepValid(){return this.currentStepInputs.every(e=>e.checkValidity())}showErrorMessages(e){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent=e.validity.valid?"":e.validationMessage)})}clearErrorMessages(e=this.inputTargets){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent="")})}clearCustomValidity(){this.inputTargets.forEach(e=>e.setCustomValidity(""))}clearGlobalError(){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent="",this.globalErrorTarget.hidden=!0)}showGlobalError(e=null){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent=e||this.globalErrorTarget.dataset.submitError||"Unable to submit. Please try again.",this.globalErrorTarget.hidden=!1)}async handleSubmissionError(e){let t;try{t=await e.json()}catch(e){return void this.showGlobalError()}const s=t.errors||[],i=[];s.forEach(e=>{const t=this.inputForError(e);t?(t.setCustomValidity(e.description||t.validationMessage),t.reportValidity()):e.description&&i.push(e.description)}),this.showErrorMessages(this.inputTargets),i.length?this.showGlobalError(i.join(" ")):s.length||this.showGlobalError()}inputForError(e){const t=e.parameter;return t?this.inputTargets.find(e=>e.dataset.popupFieldKind===t||e.dataset.popupFieldKey===t):null}submissionPayload(){const e={metadata:{capture:this.captureValue||{},fields:{},steps:[]}};return this.stepTargets.forEach(t=>{const s={};this.inputsForStep(t).forEach(t=>{const i=this.submissionValue(t),n=t.dataset.popupFieldKey||t.name;s[n]=i,e.metadata.fields[n]=i,"email"===t.dataset.popupFieldKind&&(e.email=i),"phone"===t.dataset.popupFieldKind&&(e.phone=i)}),e.metadata.steps.push({id:t.dataset.stepId,name:t.dataset.stepName,fields:s})}),e}idempotencyKeyFor(e){const t=JSON.stringify(e);return this.submissionPayloadSnapshot!==t&&(this.submissionPayloadSnapshot=t,this.submissionIdempotencyKey=C.idempotencyKey()),this.submissionIdempotencyKey}resetSubmissionRequest(){this.submissionPayloadSnapshot=null,this.submissionIdempotencyKey=null}inputValue(e){return"checkbox"===e.type?e.checked:e.value}inputsForStep(e){return this.inputTargets.filter(t=>t.dataset.popupStepId===e.dataset.stepId)}get identityInputs(){const e=this.inputTargets.filter(e=>["email","phone"].includes(e.dataset.popupFieldKind));return e.filter(e=>e.required).concat(e.filter(e=>!e.required))}get completionTextTemplates(){if(this._completionTextTemplates)return this._completionTextTemplates;const e=document.createTreeWalker(this.completedTarget,NodeFilter.SHOW_TEXT);for(this._completionTextTemplates=[];e.nextNode();)this._completionTextTemplates.push({node:e.currentNode,template:e.currentNode.nodeValue});return this._completionTextTemplates}matchesDevice(){return"all"===this.deviceValue||("mobile"===this.deviceValue?window.innerWidth<768:"desktop"!==this.deviceValue||window.innerWidth>=768)}get currentStep(){return this.stepTargets[this.stepIndex]}get currentStepInputs(){return this.inputsForStep(this.currentStep)}},Et=["start","end"],At=["top","right","bottom","left"].reduce((e,t)=>e.concat(t,t+"-"+Et[0],t+"-"+Et[1]),[]),xt=Math.min,Mt=Math.max,kt=Math.round,It=Math.floor,Lt=e=>({x:e,y:e}),Pt={left:"right",right:"left",bottom:"top",top:"bottom"},_t={start:"end",end:"start"};function Nt(e,t,s){return Mt(e,xt(t,s))}function Dt(e,t){return"function"==typeof e?e(t):e}function Ft(e){return e.split("-")[0]}function Rt(e){return e.split("-")[1]}function Bt(e){return"x"===e?"y":"x"}function $t(e){return"y"===e?"height":"width"}const jt=new Set(["top","bottom"]);function Vt(e){return jt.has(Ft(e))?"y":"x"}function qt(e){return Bt(Vt(e))}function Ut(e,t,s){void 0===s&&(s=!1);const i=Rt(e),n=qt(e),r=$t(n);let o="x"===n?i===(s?"end":"start")?"right":"left":"start"===i?"bottom":"top";return t.reference[r]>t.floating[r]&&(o=Jt(o)),[o,Jt(o)]}function zt(e){return e.replace(/start|end/g,e=>_t[e])}const Wt=["left","right"],Kt=["right","left"],Ht=["top","bottom"],Gt=["bottom","top"];function Jt(e){return e.replace(/left|right|bottom|top/g,e=>Pt[e])}function Yt(e){const{x:t,y:s,width:i,height:n}=e;return{width:i,height:n,top:s,left:t,right:t+i,bottom:s+n,x:t,y:s}}function Zt(e,t,s){let{reference:i,floating:n}=e;const r=Vt(t),o=qt(t),a=$t(o),c=Ft(t),l="y"===r,h=i.x+i.width/2-n.width/2,u=i.y+i.height/2-n.height/2,d=i[a]/2-n[a]/2;let p;switch(c){case"top":p={x:h,y:i.y-n.height};break;case"bottom":p={x:h,y:i.y+i.height};break;case"right":p={x:i.x+i.width,y:u};break;case"left":p={x:i.x-n.width,y:u};break;default:p={x:i.x,y:i.y}}switch(Rt(t)){case"start":p[o]-=d*(s&&l?-1:1);break;case"end":p[o]+=d*(s&&l?-1:1)}return p}async function Xt(e,t){var s;void 0===t&&(t={});const{x:i,y:n,platform:r,rects:o,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:h="viewport",elementContext:u="floating",altBoundary:d=!1,padding:p=0}=Dt(t,e),m=function(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}(p),g=a[d?"floating"===u?"reference":"floating":u],f=Yt(await r.getClippingRect({element:null==(s=await(null==r.isElement?void 0:r.isElement(g)))||s?g:g.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(a.floating)),boundary:l,rootBoundary:h,strategy:c})),b="floating"===u?{x:i,y:n,width:o.floating.width,height:o.floating.height}:o.reference,y=await(null==r.getOffsetParent?void 0:r.getOffsetParent(a.floating)),v=await(null==r.isElement?void 0:r.isElement(y))&&await(null==r.getScale?void 0:r.getScale(y))||{x:1,y:1},w=Yt(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:y,strategy:c}):b);return{top:(f.top-w.top+m.top)/v.y,bottom:(w.bottom-f.bottom+m.bottom)/v.y,left:(f.left-w.left+m.left)/v.x,right:(w.right-f.right+m.right)/v.x}}const Qt=new Set(["left","top"]);function es(){return"undefined"!=typeof window}function ts(e){return ns(e)?(e.nodeName||"").toLowerCase():"#document"}function ss(e){var t;return(null==e||null==(t=e.ownerDocument)?void 0:t.defaultView)||window}function is(e){var t;return null==(t=(ns(e)?e.ownerDocument:e.document)||window.document)?void 0:t.documentElement}function ns(e){return!!es()&&(e instanceof Node||e instanceof ss(e).Node)}function rs(e){return!!es()&&(e instanceof Element||e instanceof ss(e).Element)}function os(e){return!!es()&&(e instanceof HTMLElement||e instanceof ss(e).HTMLElement)}function as(e){return!(!es()||"undefined"==typeof ShadowRoot)&&(e instanceof ShadowRoot||e instanceof ss(e).ShadowRoot)}const cs=new Set(["inline","contents"]);function ls(e){const{overflow:t,overflowX:s,overflowY:i,display:n}=Ts(e);return/auto|scroll|overlay|hidden|clip/.test(t+i+s)&&!cs.has(n)}const hs=new Set(["table","td","th"]);function us(e){return hs.has(ts(e))}const ds=[":popover-open",":modal"];function ps(e){return ds.some(t=>{try{return e.matches(t)}catch(e){return!1}})}const ms=["transform","translate","scale","rotate","perspective"],gs=["transform","translate","scale","rotate","perspective","filter"],fs=["paint","layout","strict","content"];function bs(e){const t=ys(),s=rs(e)?Ts(e):e;return ms.some(e=>!!s[e]&&"none"!==s[e])||!!s.containerType&&"normal"!==s.containerType||!t&&!!s.backdropFilter&&"none"!==s.backdropFilter||!t&&!!s.filter&&"none"!==s.filter||gs.some(e=>(s.willChange||"").includes(e))||fs.some(e=>(s.contain||"").includes(e))}function ys(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}const vs=new Set(["html","body","#document"]);function ws(e){return vs.has(ts(e))}function Ts(e){return ss(e).getComputedStyle(e)}function Ss(e){return rs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Cs(e){if("html"===ts(e))return e;const t=e.assignedSlot||e.parentNode||as(e)&&e.host||is(e);return as(t)?t.host:t}function Os(e){const t=Cs(e);return ws(t)?e.ownerDocument?e.ownerDocument.body:e.body:os(t)&&ls(t)?t:Os(t)}function Es(e,t,s){var i;void 0===t&&(t=[]),void 0===s&&(s=!0);const n=Os(e),r=n===(null==(i=e.ownerDocument)?void 0:i.body),o=ss(n);if(r){const e=As(o);return t.concat(o,o.visualViewport||[],ls(n)?n:[],e&&s?Es(e):[])}return t.concat(n,Es(n,[],s))}function As(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function xs(e){const t=Ts(e);let s=parseFloat(t.width)||0,i=parseFloat(t.height)||0;const n=os(e),r=n?e.offsetWidth:s,o=n?e.offsetHeight:i,a=kt(s)!==r||kt(i)!==o;return a&&(s=r,i=o),{width:s,height:i,$:a}}function Ms(e){return rs(e)?e:e.contextElement}function ks(e){const t=Ms(e);if(!os(t))return Lt(1);const s=t.getBoundingClientRect(),{width:i,height:n,$:r}=xs(t);let o=(r?kt(s.width):s.width)/i,a=(r?kt(s.height):s.height)/n;return o&&Number.isFinite(o)||(o=1),a&&Number.isFinite(a)||(a=1),{x:o,y:a}}const Is=Lt(0);function Ls(e){const t=ss(e);return ys()&&t.visualViewport?{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}:Is}function Ps(e,t,s,i){void 0===t&&(t=!1),void 0===s&&(s=!1);const n=e.getBoundingClientRect(),r=Ms(e);let o=Lt(1);t&&(i?rs(i)&&(o=ks(i)):o=ks(e));const a=function(e,t,s){return void 0===t&&(t=!1),!(!s||t&&s!==ss(e))&&t}(r,s,i)?Ls(r):Lt(0);let c=(n.left+a.x)/o.x,l=(n.top+a.y)/o.y,h=n.width/o.x,u=n.height/o.y;if(r){const e=ss(r),t=i&&rs(i)?ss(i):i;let s=e,n=As(s);for(;n&&i&&t!==s;){const e=ks(n),t=n.getBoundingClientRect(),i=Ts(n),r=t.left+(n.clientLeft+parseFloat(i.paddingLeft))*e.x,o=t.top+(n.clientTop+parseFloat(i.paddingTop))*e.y;c*=e.x,l*=e.y,h*=e.x,u*=e.y,c+=r,l+=o,s=ss(n),n=As(s)}}return Yt({width:h,height:u,x:c,y:l})}function _s(e,t){const s=Ss(e).scrollLeft;return t?t.left+s:Ps(is(e)).left+s}function Ns(e,t,s){void 0===s&&(s=!1);const i=e.getBoundingClientRect();return{x:i.left+t.scrollLeft-(s?0:_s(e,i)),y:i.top+t.scrollTop}}const Ds=new Set(["absolute","fixed"]);function Fs(e,t,s){let i;if("viewport"===t)i=function(e,t){const s=ss(e),i=is(e),n=s.visualViewport;let r=i.clientWidth,o=i.clientHeight,a=0,c=0;if(n){r=n.width,o=n.height;const e=ys();(!e||e&&"fixed"===t)&&(a=n.offsetLeft,c=n.offsetTop)}return{width:r,height:o,x:a,y:c}}(e,s);else if("document"===t)i=function(e){const t=is(e),s=Ss(e),i=e.ownerDocument.body,n=Mt(t.scrollWidth,t.clientWidth,i.scrollWidth,i.clientWidth),r=Mt(t.scrollHeight,t.clientHeight,i.scrollHeight,i.clientHeight);let o=-s.scrollLeft+_s(e);const a=-s.scrollTop;return"rtl"===Ts(i).direction&&(o+=Mt(t.clientWidth,i.clientWidth)-n),{width:n,height:r,x:o,y:a}}(is(e));else if(rs(t))i=function(e,t){const s=Ps(e,!0,"fixed"===t),i=s.top+e.clientTop,n=s.left+e.clientLeft,r=os(e)?ks(e):Lt(1);return{width:e.clientWidth*r.x,height:e.clientHeight*r.y,x:n*r.x,y:i*r.y}}(t,s);else{const s=Ls(e);i={x:t.x-s.x,y:t.y-s.y,width:t.width,height:t.height}}return Yt(i)}function Rs(e,t){const s=Cs(e);return!(s===t||!rs(s)||ws(s))&&("fixed"===Ts(s).position||Rs(s,t))}function Bs(e,t,s){const i=os(t),n=is(t),r="fixed"===s,o=Ps(e,!0,r,t);let a={scrollLeft:0,scrollTop:0};const c=Lt(0);function l(){c.x=_s(n)}if(i||!i&&!r)if(("body"!==ts(t)||ls(n))&&(a=Ss(t)),i){const e=Ps(t,!0,r,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else n&&l();r&&!i&&n&&l();const h=!n||i||r?Lt(0):Ns(n,a);return{x:o.left+a.scrollLeft-c.x-h.x,y:o.top+a.scrollTop-c.y-h.y,width:o.width,height:o.height}}function $s(e){return"static"===Ts(e).position}function js(e,t){if(!os(e)||"fixed"===Ts(e).position)return null;if(t)return t(e);let s=e.offsetParent;return is(e)===s&&(s=s.ownerDocument.body),s}function Vs(e,t){const s=ss(e);if(ps(e))return s;if(!os(e)){let t=Cs(e);for(;t&&!ws(t);){if(rs(t)&&!$s(t))return t;t=Cs(t)}return s}let i=js(e,t);for(;i&&us(i)&&$s(i);)i=js(i,t);return i&&ws(i)&&$s(i)&&!bs(i)?s:i||function(e){let t=Cs(e);for(;os(t)&&!ws(t);){if(bs(t))return t;if(ps(t))return null;t=Cs(t)}return null}(e)||s}const qs={convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{elements:t,rect:s,offsetParent:i,strategy:n}=e;const r="fixed"===n,o=is(i),a=!!t&&ps(t.floating);if(i===o||a&&r)return s;let c={scrollLeft:0,scrollTop:0},l=Lt(1);const h=Lt(0),u=os(i);if((u||!u&&!r)&&(("body"!==ts(i)||ls(o))&&(c=Ss(i)),os(i))){const e=Ps(i);l=ks(i),h.x=e.x+i.clientLeft,h.y=e.y+i.clientTop}const d=!o||u||r?Lt(0):Ns(o,c,!0);return{width:s.width*l.x,height:s.height*l.y,x:s.x*l.x-c.scrollLeft*l.x+h.x+d.x,y:s.y*l.y-c.scrollTop*l.y+h.y+d.y}},getDocumentElement:is,getClippingRect:function(e){let{element:t,boundary:s,rootBoundary:i,strategy:n}=e;const r=[..."clippingAncestors"===s?ps(t)?[]:function(e,t){const s=t.get(e);if(s)return s;let i=Es(e,[],!1).filter(e=>rs(e)&&"body"!==ts(e)),n=null;const r="fixed"===Ts(e).position;let o=r?Cs(e):e;for(;rs(o)&&!ws(o);){const t=Ts(o),s=bs(o);s||"fixed"!==t.position||(n=null),(r?!s&&!n:!s&&"static"===t.position&&n&&Ds.has(n.position)||ls(o)&&!s&&Rs(e,o))?i=i.filter(e=>e!==o):n=t,o=Cs(o)}return t.set(e,i),i}(t,this._c):[].concat(s),i],o=r[0],a=r.reduce((e,s)=>{const i=Fs(t,s,n);return e.top=Mt(i.top,e.top),e.right=xt(i.right,e.right),e.bottom=xt(i.bottom,e.bottom),e.left=Mt(i.left,e.left),e},Fs(t,o,n));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}},getOffsetParent:Vs,getElementRects:async function(e){const t=this.getOffsetParent||Vs,s=this.getDimensions,i=await s(e.floating);return{reference:Bs(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}},getClientRects:function(e){return Array.from(e.getClientRects())},getDimensions:function(e){const{width:t,height:s}=xs(e);return{width:t,height:s}},getScale:ks,isElement:rs,isRTL:function(e){return"rtl"===Ts(e).direction}};function Us(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}const zs=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){var s,i;const{x:n,y:r,placement:o,middlewareData:a}=t,c=await async function(e,t){const{placement:s,platform:i,elements:n}=e,r=await(null==i.isRTL?void 0:i.isRTL(n.floating)),o=Ft(s),a=Rt(s),c="y"===Vt(s),l=Qt.has(o)?-1:1,h=r&&c?-1:1,u=Dt(t,e);let{mainAxis:d,crossAxis:p,alignmentAxis:m}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return a&&"number"==typeof m&&(p="end"===a?-1*m:m),c?{x:p*h,y:d*l}:{x:d*l,y:p*h}}(t,e);return o===(null==(s=a.offset)?void 0:s.placement)&&null!=(i=a.arrow)&&i.alignmentOffset?{}:{x:n+c.x,y:r+c.y,data:{...c,placement:o}}}}},Ws=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:i,placement:n}=t,{mainAxis:r=!0,crossAxis:o=!1,limiter:a={fn:e=>{let{x:t,y:s}=e;return{x:t,y:s}}},...c}=Dt(e,t),l={x:s,y:i},h=await Xt(t,c),u=Vt(Ft(n)),d=Bt(u);let p=l[d],m=l[u];if(r){const e="y"===d?"bottom":"right";p=Nt(p+h["y"===d?"top":"left"],p,p-h[e])}if(o){const e="y"===u?"bottom":"right";m=Nt(m+h["y"===u?"top":"left"],m,m-h[e])}const g=a.fn({...t,[d]:p,[u]:m});return{...g,data:{x:g.x-s,y:g.y-i,enabled:{[d]:r,[u]:o}}}}}},Ks=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var s,i;const{placement:n,middlewareData:r,rects:o,initialPlacement:a,platform:c,elements:l}=t,{mainAxis:h=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...f}=Dt(e,t);if(null!=(s=r.arrow)&&s.alignmentOffset)return{};const b=Ft(n),y=Vt(a),v=Ft(a)===a,w=await(null==c.isRTL?void 0:c.isRTL(l.floating)),T=d||(v||!g?[Jt(a)]:function(e){const t=Jt(e);return[zt(e),t,zt(t)]}(a)),S="none"!==m;!d&&S&&T.push(...function(e,t,s,i){const n=Rt(e);let r=function(e,t,s){switch(e){case"top":case"bottom":return s?t?Kt:Wt:t?Wt:Kt;case"left":case"right":return t?Ht:Gt;default:return[]}}(Ft(e),"start"===s,i);return n&&(r=r.map(e=>e+"-"+n),t&&(r=r.concat(r.map(zt)))),r}(a,g,m,w));const C=[a,...T],O=await Xt(t,f),E=[];let A=(null==(i=r.flip)?void 0:i.overflows)||[];if(h&&E.push(O[b]),u){const e=Ut(n,o,w);E.push(O[e[0]],O[e[1]])}if(A=[...A,{placement:n,overflows:E}],!E.every(e=>e<=0)){var x,M;const e=((null==(x=r.flip)?void 0:x.index)||0)+1,t=C[e];if(t&&("alignment"!==u||y===Vt(t)||A.every(e=>Vt(e.placement)!==y||e.overflows[0]>0)))return{data:{index:e,overflows:A},reset:{placement:t}};let s=null==(M=A.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0])?void 0:M.placement;if(!s)switch(p){case"bestFit":{var k;const e=null==(k=A.filter(e=>{if(S){const t=Vt(e.placement);return t===y||"y"===t}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0])?void 0:k[0];e&&(s=e);break}case"initialPlacement":s=a}if(n!==s)return{reset:{placement:s}}}return{}}}},Hs=e=>{Object.assign(e,{show(){this.cancelBehaviourOpen?.(),this.openValue=!0},hide(){this.openValue=!1},toggle(){this.cancelBehaviourOpen?.(),this.openValue=!this.openValue},setupFloatingUI({trigger:e,popover:t,strategy:s}){this.floatingUICleanup=function(e,t,s,i){void 0===i&&(i={});const{ancestorScroll:n=!0,ancestorResize:r=!0,elementResize:o="function"==typeof ResizeObserver,layoutShift:a="function"==typeof IntersectionObserver,animationFrame:c=!1}=i,l=Ms(e),h=n||r?[...l?Es(l):[],...Es(t)]:[];h.forEach(e=>{n&&e.addEventListener("scroll",s,{passive:!0}),r&&e.addEventListener("resize",s)});const u=l&&a?function(e,t){let s,i=null;const n=is(e);function r(){var e;clearTimeout(s),null==(e=i)||e.disconnect(),i=null}return function o(a,c){void 0===a&&(a=!1),void 0===c&&(c=1),r();const l=e.getBoundingClientRect(),{left:h,top:u,width:d,height:p}=l;if(a||t(),!d||!p)return;const m={rootMargin:-It(u)+"px "+-It(n.clientWidth-(h+d))+"px "+-It(n.clientHeight-(u+p))+"px "+-It(h)+"px",threshold:Mt(0,xt(1,c))||1};let g=!0;function f(t){const i=t[0].intersectionRatio;if(i!==c){if(!g)return o();i?o(!1,i):s=setTimeout(()=>{o(!1,1e-7)},1e3)}1!==i||Us(l,e.getBoundingClientRect())||o(),g=!1}try{i=new IntersectionObserver(f,{...m,root:n.ownerDocument})}catch(e){i=new IntersectionObserver(f,m)}i.observe(e)}(!0),r}(l,s):null;let d,p=-1,m=null;o&&(m=new ResizeObserver(e=>{let[i]=e;i&&i.target===l&&m&&(m.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var e;null==(e=m)||e.observe(t)})),s()}),l&&!c&&m.observe(l),m.observe(t));let g=c?Ps(e):null;return c&&function t(){const i=Ps(e);g&&!Us(g,i)&&s(),g=i,d=requestAnimationFrame(t)}(),s(),()=>{var e;h.forEach(e=>{n&&e.removeEventListener("scroll",s),r&&e.removeEventListener("resize",s)}),null==u||u(),null==(e=m)||e.disconnect(),m=null,c&&cancelAnimationFrame(d)}}(e,t,()=>{((e,t,s)=>{const i=new Map,n={platform:qs,...s},r={...n.platform,_c:i};return(async(e,t,s)=>{const{placement:i="bottom",strategy:n="absolute",middleware:r=[],platform:o}=s,a=r.filter(Boolean),c=await(null==o.isRTL?void 0:o.isRTL(t));let l=await o.getElementRects({reference:e,floating:t,strategy:n}),{x:h,y:u}=Zt(l,i,c),d=i,p={},m=0;for(let s=0;s{const n={left:`${e}px`,top:`${s}px`,position:i};Object.assign(t.style,n)})})},openValueChanged(){this.disabledValue||(this.openValue?(this.preparePopoverOpenAnimation?.(),this.popoverTarget.showPopover(),this.popoverTarget.setAttribute("aria-expanded","true"),this.onPopoverOpened&&this.onPopoverOpened()):(this.popoverTarget.hidePopover(),this.popoverTarget.removeAttribute("aria-expanded"),this.onPopoverClosed&&this.onPopoverClosed()))}})},Gs=class extends i.xI{static targets=["button","popover"];static values={placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},size:{type:Number,default:24},perLine:{type:Number,default:9}};initialize(){this.onEmojiSelect=this.onEmojiSelect.bind(this),this.pickerLoaded=!1,this.pickerLoadPromise=null,this.connected=!1,super.initialize()}connect(){this.connected=!0,Hs(this),this.setupFloatingUI({trigger:this.buttonTarget,popover:this.popoverTarget,strategy:"absolute"}),super.connect()}disconnect(){this.connected=!1,this.pickerLoadPromise=null,this.floatingUICleanup(),super.disconnect()}onEmojiSelect(e){this.dispatch("selected",{detail:e.native}),this.hide()}onClickOutside(e){this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}async onPopoverOpened(){await this.loadPicker()}async loadPicker(){if(this.pickerLoaded)return;this.pickerLoadPromise||=this.loadPickerDependencies();const{Picker:e,i18n:t}=await this.pickerLoadPromise;this.connected&&!this.pickerLoaded&&(this.popoverTarget.appendChild(this.buildPicker(e,t)),this.pickerLoaded=!0)}async loadPickerDependencies(){const[e,t]=await Promise.all([s.e(160).then(s.bind(s,405)),this.loadI18n()]);return{Picker:e.Picker,i18n:t.default||t}}loadI18n(){return"es"===Hellotext.business.locale?s.e(437).then(s.t.bind(s,9,19)):s.e(200).then(s.t.bind(s,714,19))}buildPicker(e,t){return new e({onEmojiSelect:this.onEmojiSelect,theme:"light",dynamicWidth:!0,previewPosition:"none",skinTonePosition:"none",emojiSize:this.sizeValue,perLine:this.perLineValue,i18n:t})}get middlewares(){return[zs(5),Ws({padding:24}),(e={allowedPlacements:["top","bottom"]},void 0===e&&(e={}),{name:"autoPlacement",options:e,async fn(t){var s,i,n;const{rects:r,middlewareData:o,placement:a,platform:c,elements:l}=t,{crossAxis:h=!1,alignment:u,allowedPlacements:d=At,autoAlignment:p=!0,...m}=Dt(e,t),g=void 0!==u||d===At?function(e,t,s){return(e?[...s.filter(t=>Rt(t)===e),...s.filter(t=>Rt(t)!==e)]:s.filter(e=>Ft(e)===e)).filter(s=>!e||Rt(s)===e||!!t&&zt(s)!==s)}(u||null,p,d):d,f=await Xt(t,m),b=(null==(s=o.autoPlacement)?void 0:s.index)||0,y=g[b];if(null==y)return{};const v=Ut(y,r,await(null==c.isRTL?void 0:c.isRTL(l.floating)));if(a!==y)return{reset:{placement:g[0]}};const w=[f[Ft(y)],f[v[0]],f[v[1]]],T=[...(null==(i=o.autoPlacement)?void 0:i.overflows)||[],{placement:y,overflows:w}],S=g[b+1];if(S)return{data:{index:b+1,overflows:T},reset:{placement:S}};const C=T.map(e=>{const t=Rt(e.placement);return[e.placement,t&&h?e.overflows.slice(0,2).reduce((e,t)=>e+t,0):e.overflows[0],e.overflows]}).sort((e,t)=>e[1]-t[1]),O=(null==(n=C.filter(e=>e[2].slice(0,Rt(e[0])?2:3).every(e=>e<=0))[0])?void 0:n[0])||C[0][0];return O!==a?{data:{index:b+1,overflows:T},reset:{placement:O}}:{}}})];var e}};class Js{static get endpoint(){return f.endpoint("public/webchats/:id/messages")}constructor(e){this.webchatId=e}async index(e){const t=new URL(this.url);return Object.entries(e).forEach(([e,s])=>{t.searchParams.append(e,s)}),await fetch(t,{method:"GET",headers:vt.headers})}catchUp(e){return this.index({after_id:e,session:vt.session})}async create(e){const t=await fetch(this.url,{method:"POST",headers:{Authorization:`Bearer ${vt.business.id}`},body:e});return new v(t.ok,t)}markAsSeen(e=null){const t=e?this.url+`/${e}`:this.url+"/seen";fetch(t,{method:"PATCH",headers:vt.headers,body:JSON.stringify({session:vt.session})})}get url(){return Js.endpoint.replace(":id",this.webchatId)}}const Ys=Js;class Zs{static webSocket;static channels=new Set;static messageHandlers=new Set;static disconnectHandlers=new Set;static subscriptionConfirmHandlers=new Set;static reconnectTimeout=null;static reconnectAttempts=0;static reconnectBaseDelay=500;static reconnectMaxDelay=1e4;static reconnectJitter=.3;static needsResubscribe=!1;constructor(){Zs.channels.add(this)}send({command:e,identifier:t,data:s}){const i={command:e,identifier:JSON.stringify(t),data:JSON.stringify(s||{})},n=Zs.ensureWebSocket(),r=JSON.stringify(i);n.readyState===WebSocket.OPEN?n.send(r):n.addEventListener("open",()=>{n.send(r)})}onMessage(e){const t=t=>{const s=JSON.parse(t.data),{type:i,message:n}=s;this.ignoredEvents.includes(i)||e(n)};Zs.messageHandlers.add(t),Zs.ensureWebSocket().addEventListener("message",t)}onDisconnect(e){Zs.disconnectHandlers.add(e)}onSubscriptionConfirmed(e){Zs.subscriptionConfirmHandlers.add(e)}get webSocket(){return Zs.ensureWebSocket()}static ensureWebSocket(){return this.webSocket&&!this.closedWebSocket(this.webSocket)?this.webSocket:(this.webSocket&&(this.needsResubscribe=!0),this.openWebSocket())}static openWebSocket(){this.clearReconnectTimeout();const e=new WebSocket(f.actionCableUrl);return this.webSocket=e,this.installWebSocketHandlers(e),e}static installWebSocketHandlers(e){e.addEventListener("open",()=>this.handleOpen(e)),e.addEventListener("close",()=>this.handleDisconnect(e)),e.addEventListener("error",()=>this.handleDisconnect(e)),e.addEventListener("message",e=>this.handleControlMessage(e)),this.messageHandlers.forEach(t=>{e.addEventListener("message",t)})}static handleOpen(e){e===this.webSocket&&(this.reconnectAttempts=0,this.needsResubscribe&&(this.needsResubscribe=!1,this.resubscribeChannels()))}static handleControlMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}"confirm_subscription"===t.type&&this.subscriptionConfirmHandlers.forEach(e=>e(t.identifier))}static handleDisconnect(e){e===this.webSocket&&(this.disconnectHandlers.forEach(e=>e()),this.webSocket=null,this.needsResubscribe=!0,this.scheduleReconnect())}static scheduleReconnect(){this.reconnectTimeout||(this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts+=1,this.openWebSocket()},this.reconnectDelay))}static clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}static resubscribeChannels(){this.channels.forEach(e=>{const t=e.resubscribe||e.subscribe;"function"==typeof t&&t.call(e)})}static closedWebSocket(e){return e.readyState===WebSocket.CLOSED||e.readyState===WebSocket.CLOSING}static get reconnectDelay(){const e=Math.min(this.reconnectMaxDelay,this.reconnectBaseDelay*2**this.reconnectAttempts);return e+Math.round(e*this.reconnectJitter*Math.random())}get ignoredEvents(){return["ping","confirm_subscription","welcome"]}}const Xs=Zs,Qs=class extends Xs{constructor(e,t,s){super(),this.id=e,this.session=t,this.conversation=s,this.subscribed=!1,this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks=new Set,this.onSubscriptionConfirmed(e=>this.handleSubscriptionConfirmed(e)),this.subscribe()}subscribe(){this.subscribed=!0;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"subscribe",identifier:e})}unsubscribe(){this.subscribed=!1;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"unsubscribe",identifier:e})}resubscribe(){!1!==this.subscribed&&(this.awaitingReconnectConfirmation=!0,this.subscribe())}onReconnect(e){this.reconnectCallbacks.add(e)}handleSubscriptionConfirmed(e){this.awaitingReconnectConfirmation&&this.matchesIdentifier(e)&&(this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks.forEach(e=>e()))}matchesIdentifier(e){let t;try{t="string"==typeof e?JSON.parse(e):e}catch{return!1}return"WebchatChannel"===t.channel&&t.id===this.id&&t.session===this.session&&t.conversation===this.conversation}startTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"message",identifier:e,data:{action:"started_typing"}})}stopTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"typing:stop",identifier:e,data:{action:"stopped_typing"}})}onMessage(e){super.onMessage(t=>{"message"===t.type&&e(t)})}onReaction(e){super.onMessage(t=>{"reaction.create"!==t.type&&"reaction.destroy"!==t.type||e(t)})}onTypingStart(e){super.onMessage(t=>{"started_typing"===t.type&&e(t)})}updateSubscriptionWith(e){this.unsubscribe(),setTimeout(()=>{this.conversation=e,this.subscribe()},1e3)}},ei=e=>{Object.assign(e,{scheduleBehaviourOpen(){if(!this.shouldAutoOpenFromBehaviour())return;const e=1e3*Number(this.behaviourValue.delay_seconds||0);this.behaviourOpenTimeout=window.setTimeout(()=>{this.behaviourOpenTimeout=null,this.openValue||(this.openValue=!0,this.markBehaviourAutoOpened())},e)},cancelBehaviourOpen(){window.clearTimeout(this.behaviourOpenTimeout),this.behaviourOpenTimeout=null},shouldAutoOpenFromBehaviour(){const e=this.behaviourValue;return!(!e||"on_load"!==e.trigger||e.first_visit_only&&localStorage.getItem(this.firstVisitKey())||e.once_per_session&&sessionStorage.getItem(this.sessionKey()))},markBehaviourAutoOpened(){this.behaviourValue.first_visit_only&&localStorage.setItem(this.firstVisitKey(),"1"),this.behaviourValue.once_per_session&&sessionStorage.setItem(this.sessionKey(),"1")},firstVisitKey(){return`hellotext--webchat--${this.idValue}--auto-opened`},sessionKey(){return`hellotext--webchat--${this.idValue}--auto-opened-session`}})},ti=e=>{Object.assign(e,{setupOpeningSequence(){this.openingSequenceStarted=!1,this.openingSequenceCancelled=!1,this.openingSequenceTimeout=null,this.openingSequenceMessages=[],this.revealedOpeningSequenceMessageIds=[]},teardownOpeningSequence(){this.cancelOpeningSequence()},startOpeningSequence(){this.openingSequenceMessages=Array.from(this.openingSequenceMessageTargets||[]),this.openingSequenceCanStart()&&(this.openingSequenceStarted=!0,this.openingSequenceCancelled=!1,this.revealedOpeningSequenceMessageIds=[],this.playOpeningSequenceMessageAt(0))},openingSequenceCanStart(){return!this.conversationIdValue&&this.hasOpeningSequenceTarget&&this.openingSequenceMessages.length>0&&!this.openingSequenceStarted},playOpeningSequenceMessageAt(e){const t=this.openingSequenceMessages[e];if(!t)return;const s=1e3*this.openingSequenceMessageDelay(t);this.openingSequenceTimeout=window.setTimeout(()=>{this.openingSequenceTimeout=null,this.openingSequenceCancelled||(this.revealOpeningSequenceMessage(t),this.playOpeningSequenceMessageAt(e+1))},s)},revealOpeningSequenceMessage(e){this.messagesContainerTarget.insertBefore(e,this.messageTemplateTarget),e.hidden=!1,this.recordOpeningSequenceMessage(e),this.scrollOpeningSequenceToBottom()},recordOpeningSequenceMessage(e){const t=e.dataset.openingSequenceMessageId;t&&!this.revealedOpeningSequenceMessageIds.includes(t)&&this.revealedOpeningSequenceMessageIds.push(t)},openingSequenceMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},scrollOpeningSequenceToBottom(){this.messagesContainerTarget.scroll&&this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"smooth"})},cancelOpeningSequence(){this.openingSequenceCancelled=!0,null!==this.openingSequenceTimeout&&void 0!==this.openingSequenceTimeout&&(window.clearTimeout(this.openingSequenceTimeout),this.openingSequenceTimeout=null)},appendOpeningSequenceMessageIds(e){this.cancelOpeningSequence(),(this.revealedOpeningSequenceMessageIds||[]).forEach(t=>{e.append("message[opening_sequence_message_ids][]",t)})},clearRevealedOpeningSequenceMessageIds(){this.revealedOpeningSequenceMessageIds=[]}})},si=e=>{Object.assign(e,{setupTeaser(){this.teaserCycleTimeout=null,this.teaserMessages=[],this.boundOnTeaserClick=this.boundOnTeaserClick||this.onTeaserClick.bind(this),this.hasTeaserTarget&&(this.teaserTarget.addEventListener("click",this.boundOnTeaserClick),this.startTeaserPresentation())},teardownTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.boundOnTeaserClick&&this.teaserTarget.removeEventListener("click",this.boundOnTeaserClick)},collectTeaserMessages(){return this.hasTeaserTarget?Array.from(this.teaserTarget.querySelectorAll("[data-teaser-message]")):[]},startTeaserPresentation(){this.stopTeaserCycle(),this.teaserMessages=this.collectTeaserMessages(),this.hasTeaserTarget&&(0!==this.teaserMessages.length?this.openValue||this.conversationIdValue||this.hasRenderedConversationMessages()?this.dismissTeaserForSession():this.teaserSeenForSession()?this.hideTeaser():this.teaserMessageDelay(this.teaserMessages[0])>0?this.scheduleTeaserMessage(0):(this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(0),this.scheduleTeaserMessage(1)):this.hideTeaser())},scheduleTeaserMessage(e){const t=this.teaserMessages[e];if(!t)return;const s=this.teaserPresentationDelay(t);this.teaserCycleTimeout=window.setTimeout(()=>{this.teaserCycleTimeout=null,this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(e),this.scheduleTeaserMessage(e+1)},s)},showTeaserMessage(e){this.teaserMessages.forEach((t,s)=>{t.classList.toggle("hidden",s!==e)})},stopTeaserCycle(){null!==this.teaserCycleTimeout&&void 0!==this.teaserCycleTimeout&&(window.clearTimeout(this.teaserCycleTimeout),this.teaserCycleTimeout=null)},teaserMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},teaserPresentationDelay(e){return Math.max(1e3*this.teaserMessageDelay(e),250)},hasRenderedConversationMessages(){let e=[];try{e=Array.from(this.messageTargets||[])}catch(t){e=[]}return e.some(e=>e!==this.messageTemplateTarget)},teaserSeenKey(){const e=this.hasTeaserTarget?this.teaserTarget.dataset.teaserVersion:"",t=e?`:${e}`:"";return`hellotext:webchat:${this.idValue||this.element.id}:teaser-seen${t}`},teaserSeenForSession(){try{return"true"===window.sessionStorage.getItem(this.teaserSeenKey())}catch(e){return!1}},markTeaserSeenForSession(){try{window.sessionStorage.setItem(this.teaserSeenKey(),"true")}catch(e){}},dismissTeaserForSession(){this.markTeaserSeenForSession(),this.hideTeaser()},hideTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.teaserTarget.classList.add("invisible")},onTeaserClick(e){e.target.closest("a")||(this.dismissTeaserForSession(),this.show())}})},ii={hour:"numeric",minute:"2-digit"},ni=/Android|iPhone|iPad|iPod/i,ri={capture:!0,passive:!0},oi=class extends i.xI{static messageTimestampFormatters={};static values={id:String,conversationId:String,media:Object,fileSizeErrorMessage:String,placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},nextPage:{type:Number,default:void 0},fullScreenThreshold:{type:Number,default:1024},typingIndicatorKeepAlive:{type:Number,default:3e4},offset:{type:Number,default:24},padding:{type:Number,default:24},optimisticTypingIndicatorWait:{type:Number,default:1e3},teaser:Object,messageTeaser:String,behaviour:Object};static classes=["fadeOut"];static targets=["trigger","popover","input","attachmentInput","attachmentButton","errorMessageContainer","attachmentTemplate","attachmentContainer","attachment","messageTemplate","messagesContainer","title","attachmentImage","footer","toolbar","message","unreadCounter","typingIndicator","typingIndicatorTemplate","teaser","teaserMessage","inboundMessageTeaser","inboundMessageTeaserBody","openingSequence","openingSequenceMessage"];initialize(){this.messagesAPI=new Ys(this.idValue),this.webChatChannel=new Qs(this.idValue,vt.session,this.conversationIdValue),this.files=[],this.messageIds=new Set,this.catchUpAfterMessageId=null,this.fetchingCatchUpMessages=!1,this.onMessageReceived=this.onMessageReceived.bind(this),this.onMessageReaction=this.onMessageReaction.bind(this),this.onTypingStart=this.onTypingStart.bind(this),this.captureCatchUpCursor=this.captureCatchUpCursor.bind(this),this.catchUpMessages=this.catchUpMessages.bind(this),this.onScroll=this.onScroll.bind(this),this.onOutboundMessageSent=this.onOutboundMessageSent.bind(this),this.closePopoverOnEscape=this.closePopoverOnEscape.bind(this),this.broadcastChannel=new BroadcastChannel(`hellotext--webchat--${this.idValue}`),this.webChatChannel.onDisconnect(this.captureCatchUpCursor),this.webChatChannel.onReconnect(this.catchUpMessages),super.initialize()}connect(){ei(this),Hs(this),ti(this),si(this),this.setupFloatingUI({trigger:this.triggerTarget,popover:this.popoverTarget}),this.hasTeaserTarget&&this.setupFloatingUI({trigger:this.triggerTarget,popover:this.teaserTarget,strategy:"absolute"}),this.setupTeaser(),this.setupOpeningSequence(),this.localizeMessageTimestamps(),this.webChatChannel.onMessage(this.onMessageReceived),this.webChatChannel.onTypingStart(this.onTypingStart),this.webChatChannel.onReaction(this.onMessageReaction),this.setupMessagesContainerScrollIsolation(),this.messagesContainerTarget.addEventListener("scroll",this.onScroll),this.messagesContainerTarget.addEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.addEventListener("touchmove",this.stopHostScrollPropagation,ri),this.shouldOpenOnMount&&(this.openValue=!0),vt.eventEmitter.dispatch("webchat:mounted"),this.broadcastChannel.addEventListener("message",this.onOutboundMessageSent),window.addEventListener("keydown",this.closePopoverOnEscape,!0),this.scheduleBehaviourOpen(),super.connect()}disconnect(){this.cancelBehaviourOpen(),this.clearPopoverOpenAnimation(),this.teardownTeaser(),this.teardownOpeningSequence(),this.broadcastChannel.removeEventListener("message",this.onOutboundMessageSent),this.messagesContainerTarget.removeEventListener("scroll",this.onScroll),this.messagesContainerTarget.removeEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.removeEventListener("touchmove",this.stopHostScrollPropagation,ri),window.removeEventListener("keydown",this.closePopoverOnEscape,!0),this.clearTypingIndicator(),this.broadcastChannel.close(),this.floatingUICleanup(),super.disconnect()}setupMessagesContainerScrollIsolation(){this.messagesContainerTarget.style.overscrollBehavior="contain",this.messagesContainerTarget.style.webkitOverflowScrolling="touch",this.messagesContainerTarget.style.touchAction="pan-y",this.messagesContainerTarget.setAttribute("data-lenis-prevent",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-wheel",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-touch","")}stopHostScrollPropagation(e){e.stopPropagation()}onTypingStart(){if(this.typingIndicatorVisible)return this.resetTypingIndicatorTimer();this.showTypingIndicator()}showOptimisticTypingIndicator(){this.typingIndicatorVisible||this.showTypingIndicator()}showTypingIndicator(){this.clearTypingIndicator(),this.typingIndicatorVisible=!0;const e=this.typingIndicatorTemplateTarget.cloneNode(!0);e.setAttribute("data-hellotext--webchat-target","typingIndicator"),e.style.display="flex",this.messagesContainerTarget.appendChild(e),requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})});const t=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},t)}resetTypingIndicatorTimer(){if(!this.typingIndicatorVisible)return;clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout);const e=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},e)}clearTypingIndicator(){this.hasTypingIndicatorTarget&&this.typingIndicatorTarget.remove(),this.typingIndicatorVisible=!1,clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout)}onMessageInputChange(){this.resizeInput(),clearTimeout(this.typingIndicatorTimeout),this.hasSentTypingIndicator||(this.webChatChannel.startTypingIndicator(),this.hasSentTypingIndicator=!0),this.typingIndicatorTimeout=setTimeout(()=>{this.hasSentTypingIndicator=!1},3e3)}onOutboundMessageSent(e){const{data:t}=e,s={"message:sent":e=>{const t=(new DOMParser).parseFromString(e.element,"text/html").body.firstElementChild;this.localizeMessageTimestamps(t),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(t,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(t),t.scrollIntoView({behavior:"instant"})},"message:failed":e=>{const t=this.messagesContainerTarget.querySelector(`#${e.id}`);this.markMessageFailed(t,e.reason)}};s[t.type]?s[t.type](t):console.log(`Unhandled message event: ${t.type}`)}async onScroll(){if(this.messagesContainerTarget.scrollTop>300||!this.nextPageValue||this.fetchingNextPage)return;this.fetchingNextPage=!0;const e=await this.messagesAPI.index({page:this.nextPageValue,session:vt.session}),{next:t,messages:s}=await e.json();this.nextPageValue=t,this.oldScrollHeight=this.messagesContainerTarget.scrollHeight,s.forEach(e=>{const{body:t,attachments:s}=e,i=e.created_at||e.createdAt,n=this.messageTemplateTarget.cloneNode(!0);n.classList.add("hellotext--webchat-message"),n.setAttribute("data-hellotext--webchat-target","message"),n.setAttribute("data-id",e.id),i&&n.setAttribute("data-created-at",i),n.style.removeProperty("display"),rt(n.querySelector("[data-body]"),t),"received"===e.state?n.classList.add("received"):n.classList.remove("received"),s&&s.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.removeAttribute("data-hellotext--webchat-target"),t.src=e,t.style.display="block",this.messageAttachmentsContainer(n)?.appendChild(t)}),n.setAttribute("data-body",t),this.localizeMessageTimestamp(n.querySelector("[data-message-timestamp]"),i),this.messagesContainerTarget.prepend(n)}),this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight-this.oldScrollHeight,behavior:"instant"}),this.fetchingNextPage=!1}onClickOutside(e){d.mode===u.POPOVER&&this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}closePopover(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.openValue=!1}preparePopoverOpenAnimation(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.popoverTarget.classList.add("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=setTimeout(()=>{this.popoverTarget.classList.remove("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=null},120)}clearPopoverOpenAnimation(){this.popoverOpenAnimationTimeout&&(clearTimeout(this.popoverOpenAnimationTimeout),this.popoverOpenAnimationTimeout=null),this.popoverTarget?.classList.remove("hellotext--webchat-popover-opening")}onPopoverOpened(){this.popoverTarget.classList.remove(...this.fadeOutClasses),this.dismissTeaserForSession?.(),this.onMobile||this.focusComposeInput(),this.scrolled||(requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})}),this.scrolled=!0),vt.eventEmitter.dispatch("webchat:opened"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"opened"),this.messageTeaserValue&&(this.messageTeaserValue=null),this.startOpeningSequence(),"none"!==this.unreadCounterTarget.style.display&&(this.unreadCounterTarget.style.display="none",this.unreadCounterTarget.innerText="0",this.messagesAPI.markAsSeen())}onPopoverClosed(){this.clearPopoverOpenAnimation(),vt.eventEmitter.dispatch("webchat:closed"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"closed")}onMessageReaction(e){const{message:t,reaction:s,type:i}=e,n=this.messageTargets.find(e=>e.dataset.id===t).querySelector("[data-reactions]");if("reaction.destroy"===i)return n.querySelector(`[data-id="${s.id}"]`).remove();if(n.querySelector(`[data-id="${s.id}"]`))n.querySelector(`[data-id="${s.id}"]`).innerText=s.emoji;else{const e=document.createElement("span");e.innerText=s.emoji,e.setAttribute("data-id",s.id),n.appendChild(e)}}onMessageReceived(e,t={}){const{id:s,body:i,attachments:n,teaser:r}=e,o=e.created_at||e.createdAt;if(!this.claimMessageId(s))return;if(this.hideTeaser?.(),e.carousel)return this.insertCarouselMessage(e,t);const a=this.messageTemplateTarget.cloneNode(!0);a.classList.add("hellotext--webchat-message"),a.style.display="flex",rt(a.querySelector("[data-body]"),i),a.setAttribute("data-id",s),a.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(a,o),this.localizeMessageTimestamp(a.querySelector("[data-message-timestamp]"),o),n&&n.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.src=e,t.style.display="block",this.messageAttachmentsContainer(a)?.appendChild(t)}),this.clearTypingIndicator(),this.insertMessageElement(a),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:a.querySelector("[data-body]").innerText}),!1!==t.scroll&&a.scrollIntoView({behavior:"smooth"}),this.updateMessageTeaser(r),this.openValue?this.messagesAPI.markAsSeen(s):this.incrementUnreadCounter()}claimMessageId(e){const t=this.messageTargets||[];return!this.messageIds.has(e)&&(this.messageIds.add(e),!t.some(t=>t.dataset.id===e))}captureCatchUpCursor(){this.catchUpAfterMessageId=this.lastRenderedMessageId}async catchUpMessages(){const e=this.catchUpAfterMessageId;if(e&&!this.fetchingCatchUpMessages){this.fetchingCatchUpMessages=!0;try{const t=await this.messagesAPI.catchUp(e),{messages:s=[]}=await t.json();s.forEach(e=>this.onMessageReceived(e,{scroll:!1})),this.catchUpAfterMessageId=this.lastRenderedMessageId}finally{this.fetchingCatchUpMessages=!1}}}get lastRenderedMessageId(){const e=this.persistedMessageElements;return e[e.length-1]?.dataset.id||null}get persistedMessageElements(){return Array.from(this.messagesContainerTarget.querySelectorAll(".hellotext--webchat-message[data-id]"))}setMessageCreatedAt(e,t){t&&e.setAttribute("data-created-at",t)}insertMessageElement(e){const t=this.nextMessageElementFor(e);t?this.messagesContainerTarget.insertBefore(e,t):this.messagesContainerTarget.appendChild(e)}nextMessageElementFor(e){const t=Date.parse(e.dataset.createdAt);return Number.isNaN(t)?null:this.persistedMessageElements.find(s=>{if(s===e)return!1;const i=Date.parse(s.dataset.createdAt);return!Number.isNaN(i)&&i>t})}updateMessageTeaser(e){this.messageTeaserValue=e,this.messageTeaserValue&&this.hasTeaserTarget&&this.hasInboundMessageTeaserTarget&&this.hasInboundMessageTeaserBodyTarget&&(this.teaserMessageTargets.forEach(e=>e.classList.add("hidden")),this.inboundMessageTeaserBodyTarget.textContent=this.messageTeaserValue,this.inboundMessageTeaserTarget.classList.remove("hidden"),this.teaserTarget.classList.toggle("invisible",this.openValue))}insertCarouselMessage(e,t={}){const s=e.html,i=e.created_at||e.createdAt,n=function(e){return nt(e,it)}(s).firstElementChild;n.classList.add("hellotext--webchat-message"),n.setAttribute("data-id",e.id),n.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(n,i),this.localizeMessageTimestamps(n),this.clearTypingIndicator(),this.insertMessageElement(n),!1!==t.scroll&&n.scrollIntoView({behavior:"smooth"}),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:n.querySelector("[data-body]")?.innerText||""}),this.updateMessageTeaser(e.teaser),this.openValue?this.messagesAPI.markAsSeen(e.id):this.incrementUnreadCounter()}resizeInput(){this.inputTarget.style.height="auto";const e=this.inputTarget.scrollHeight;this.inputTarget.style.height=`${Math.min(e,96)}px`}async sendQuickReplyMessage({detail:{id:e,product:t,buttonId:s,body:i,cardElement:n}}){this.dismissTeaserForSession?.();const r=new FormData;r.append("message[body]",i),e&&r.append("message[replied_to]",e),t&&r.append("message[product]",t),s&&r.append("message[button]",s),r.append("session",vt.session),r.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(r);const o=this.buildMessageElement(),c=n?.querySelector("img")?.cloneNode(!0);o.querySelector("[data-body]").innerText=i,c&&(c.removeAttribute("width"),c.removeAttribute("height"),this.messageAttachmentsContainer(o)?.appendChild(c)),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(o,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(o),o.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:o.outerHTML});const l=await this.messagesAPI.create(r);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,o);const h=await l.json();this.dispatch("set:id",{target:o,detail:h.id}),this.localizeMessageTimestamp(o.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds();const u={id:h.id,body:i,attachments:c?[c.src]:[],replied_to:e,product:t,button:s,type:"quick_reply"};vt.eventEmitter.dispatch("webchat:message:sent",u)}async sendTeaserQuickReply(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=(t.dataset.value||"").trim(),i=[t.dataset.text,t.textContent].map(e=>(e||"").trim()).find(e=>e.length>0),n=s||i;if(!n)return;this.dismissTeaserForSession?.(),this.show();const r=(t.dataset.type||"").trim()||"quick_reply",o=new FormData;o.append("message[body]",n),o.append("session",vt.session),o.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(o);const c=this.buildMessageElement();c.querySelector("[data-body]").innerText=n,this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(c,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(c),c.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:c.outerHTML}),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const l=await this.messagesAPI.create(o);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,c);const h=await l.json();c.setAttribute("data-id",h.id),this.localizeMessageTimestamp(c.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",{id:h.id,body:n,attachments:[],type:"quick_reply",teaser:{text:i||n,value:s||n,type:r}}),h.conversation&&h.conversation!==this.conversationIdValue&&(this.conversationIdValue=h.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer()}async sendMessage(e){const t={body:this.inputTarget.value,attachments:this.files};if(0===this.inputTarget.value.trim().length&&0===this.files.length)return void(e&&e.target&&e.preventDefault());this.dismissTeaserForSession?.();const s=new FormData;this.inputTarget.value.trim().length>0?s.append("message[body]",this.inputTarget.value):delete t.body,this.files.forEach(e=>{s.append("message[attachments][]",e)}),s.append("session",vt.session),s.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(s);const i=this.buildMessageElement();this.inputTarget.value.trim().length>0?i.querySelector("[data-body]").innerText=this.inputTarget.value:i.querySelector("[data-message-bubble]").remove();const n=this.attachmentContainerTarget.querySelectorAll("img");n.length>0&&n.forEach(e=>{this.messageAttachmentsContainer(i)?.appendChild(e.cloneNode(!0))}),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(i,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(i),i.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:i.outerHTML}),this.inputTarget.value="",this.resizeInput(),this.files=[],this.attachmentInputTarget.value="",this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none",this.errorMessageContainerTarget.style.display="none",this.focusComposeInput(),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const r=await this.messagesAPI.create(s);if(r.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(r,i);const o=await r.json();i.setAttribute("data-id",o.id),t.id=o.id,this.localizeMessageTimestamp(i.querySelector("[data-message-timestamp]"),o.created_at||o.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",t),o.conversation!==this.conversationIdValue&&(this.conversationIdValue=o.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer(),this.attachmentContainerTarget.style.display=""}buildMessageElement(){const e=this.messageTemplateTarget.cloneNode(!0);return e.id=`hellotext--webchat--${this.idValue}--message--${Date.now()}`,e.classList.add("received"),e.style.removeProperty("display"),e.setAttribute("data-controller","hellotext--message"),e.setAttribute("data-hellotext--webchat-target","message"),this.localizeMessageTimestamp(e.querySelector("[data-message-timestamp]"),new Date),e}focusCompose(e){const{target:t}=e,s=["button","a","input","textarea","select","label",'[role="button"]',"em-emoji-picker",'[data-hellotext--webchat--emoji-target~="popover"]','[data-controller~="hellotext--webchat--emoji"]'].join(", ");this.hasInputTarget&&!t.closest(s)&&this.focusComposeInput({moveCursorToEnd:!0})&&e.preventDefault()}closePopoverFromHeader(e){const{target:t}=e;t.closest(".hellotext--webchat-header-channel-button, .hellotext--webchat-close-button")||(e.preventDefault(),this.closePopover())}closePopoverOnEscape(e){"Escape"===e.key&&this.openValue&&(e.preventDefault(),e.stopPropagation(),this.closePopover(),this.triggerTarget?.focus?.())}async markMessageFailedFromResponse(e,t){const s=await this.messageFailureReason(e);this.markMessageFailed(t,s),this.broadcastChannel.postMessage({type:"message:failed",id:t.id,reason:s})}markMessageFailed(e,t){if(!e)return;if(e.classList.add("failed"),!t)return;const s=e.querySelector("[data-message-timestamp]");s&&(s.textContent=t)}localizeMessageTimestamps(e=this.element){e&&(e.matches?.("time[datetime][data-message-timestamp]")?[e]:Array.from(e.querySelectorAll?.("time[datetime][data-message-timestamp]")||[])).forEach(e=>this.localizeMessageTimestamp(e))}localizeMessageTimestamp(e,t=e?.getAttribute("datetime")){if(!e||!t)return;const s=t instanceof Date?t:new Date(t);Number.isNaN(s.getTime())||(e.setAttribute("datetime",s.toISOString()),e.textContent=this.formatMessageTimestamp(s))}formatMessageTimestamp(e){return this.constructor.messageTimestampFormatterFor(a.toString()).format(e)}static messageTimestampFormatterFor(e){const t=e||"default";return this.messageTimestampFormatters[t]||(this.messageTimestampFormatters[t]=this.buildMessageTimestampFormatter(e)),this.messageTimestampFormatters[t]}static buildMessageTimestampFormatter(e){try{return new Intl.DateTimeFormat(e||void 0,ii)}catch(e){return new Intl.DateTimeFormat(void 0,ii)}}async messageFailureReason(e){const t=e?.data||e?.response,s=t?.statusText||"Message failed";try{const e=t?.clone?t.clone():t,s=await(e?.json?.()),i=this.messageFailureReasonFromPayload(s);if(i)return i}catch(e){}try{const e=t?.clone?t.clone():t,i=await(e?.text?.());return this.messageFailureReasonFromText(i)||s}catch(e){return s}}messageFailureReasonFromText(e){if("string"!=typeof e)return null;const t=e.trim();if(!t||t.startsWith("<"))return null;try{return this.messageFailureReasonFromPayload(JSON.parse(t))||t}catch(e){return t}}messageFailureReasonFromPayload(e){return e?[e.error?.message,e.message,e.errors?.message,e.errors?.[0]?.message,e.errors?.[0]?.description].find(e=>"string"==typeof e&&e.trim().length>0):null}messageAttachmentsContainer(e){return e.querySelector("[data-attachments-container], [data-attachment-container]")}incrementUnreadCounter(){this.unreadCounterTarget.style.display="flex";const e=(parseInt(this.unreadCounterTarget.innerText)||0)+1;this.unreadCounterTarget.innerText=Math.min(e,9)}openAttachment(){this.attachmentInputTarget.click()}onFileInputChange(){this.errorMessageContainerTarget.style.display="none";const e=Array.from(this.attachmentInputTarget.files);this.attachmentInputTarget.value="";const t=e.find(e=>{const t=e.type.split("/")[0];return["image","video","audio"].includes(t)?this.mediaValue[t].max_sizethis.createAttachmentElement(e)),this.focusComposeInput()}createAttachmentElement(e){const t=this.attachmentElement();if(this.attachmentContainerTarget.style.display="",t.setAttribute("data-name",e.name),e.type.startsWith("image/")){const s=this.attachmentImageTarget.cloneNode(!0);s.src=URL.createObjectURL(e),s.style.display="block",t.appendChild(s),this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}else{const s=t.querySelector("main");s.style.height="5rem",s.style.borderRadius="0.375rem",s.style.backgroundColor="#e5e7eb",s.style.padding="0.25rem",t.querySelector("p[data-attachment-name]").innerText=e.name,this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}}removeAttachment({currentTarget:e}){const t=e.closest("[data-hellotext--webchat-target='attachment']");this.files=this.files.filter(e=>e.name!==t.dataset.name),this.attachmentInputTarget.value="",t.remove(),this.focusComposeInput()}attachmentTargetDisconnected(){0===this.attachmentTargets.length&&(this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none")}attachmentElement(){const e=this.attachmentTemplateTarget.cloneNode(!0);return e.removeAttribute("hidden"),e.style.display="flex",e.setAttribute("data-hellotext--webchat-target","attachment"),e}onEmojiSelect({detail:e}){const t=this.inputTarget.value,s=this.inputTarget.selectionStart,i=this.inputTarget.selectionEnd;this.inputTarget.value=t.slice(0,s)+e+t.slice(i),this.inputTarget.selectionStart=this.inputTarget.selectionEnd=s+e.length,this.focusComposeInput()}focusComposeInput({moveCursorToEnd:e=!1}={}){if(!this.shouldAutofocusCompose)return!1;if(!1===this.hasInputTarget)return!1;if(void 0===this.hasInputTarget&&!this.inputTarget)return!1;if(this.inputTarget.focus(),e&&"number"==typeof this.inputTarget.selectionStart){const e=this.inputTarget.value.length;this.inputTarget.setSelectionRange(e,e)}return!0}byteToMegabyte(e){return Math.ceil(e/1024/1024)}get middlewares(){return[zs(this.offsetValue),Ws({padding:this.paddingValue}),Ks()]}get shouldOpenOnMount(){return"opened"===localStorage.getItem(`hellotext--webchat--${this.idValue}`)&&!this.onMobile}get shouldAutofocusCompose(){return!this.usesVirtualKeyboard}get usesVirtualKeyboard(){if("undefined"==typeof navigator)return!1;const e=navigator.userAgent||"",t="MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,s=ni.test(e),i=!0===navigator.userAgentData?.mobile;return s||t||i||this.hasTouchOnlyPointer}get hasTouchOnlyPointer(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches&&window.matchMedia("(hover: none)").matches}get onMobile(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(`(max-width: ${this.fullScreenThresholdValue}px)`).matches}},ai=i.lg.start();ai.register("hellotext--alert",Tt),ai.register("hellotext--form",St),ai.register("hellotext--popup",Ot),ai.register("hellotext--webchat",oi),ai.register("hellotext--webchat--emoji",Gs),ai.register("hellotext--message",Ct),window.Hellotext=vt;const ci=vt}};const t={};function s(i){const n=t[i];if(void 0!==n)return n.exports;const r=t[i]={exports:{}};return e[i](r,r.exports,s),r.exports}s.m=e,(()=>{const e=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;let t;s.t=function(i,n){if(1&n&&(i=this(i)),8&n)return i;if("object"==typeof i&&i){if(4&n&&i.__esModule)return i;if(16&n&&"function"==typeof i.then)return i}const r=Object.create(null);s.r(r);const o={};t=t||[null,e({}),e([]),e(e)];for(var a=2&n&&i;("object"==typeof a||"function"==typeof a)&&!~t.indexOf(a);a=e(a))Object.getOwnPropertyNames(a).forEach(e=>o[e]=()=>i[e]);return o.default=()=>i,s.d(r,o),r}})(),s.d=(e,t)=>{if(Array.isArray(t))for(var i=0;iPromise.all(Object.keys(s.f).reduce((t,i)=>(s.f[i](e,t),t),[])),s.u=e=>({160:"webchat-emoji",200:"webchat-emoji-en",437:"webchat-emoji-es"}[e]+".js"),s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{const e={},t="Hellotext:";s.l=(i,n,r,o)=>{if(e[i])return void e[i].push(n);let a,c;if(void 0!==r){const e=document.getElementsByTagName("script");for(var l=0;l{a.onerror=a.onload=null,clearTimeout(u);const n=e[i];if(delete e[i],a.parentNode?.removeChild(a),n?.forEach(e=>e(s)),t)return t(s)},u=setTimeout(h.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=h.bind(null,a.onerror),a.onload=h.bind(null,a.onload),c&&document.head.appendChild(a)}})(),s.r=e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{let e;s.g.importScripts&&(e=s.g.location+"");const t=s.g.document;if(!e&&t&&("SCRIPT"===t.currentScript?.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){const s=t.getElementsByTagName("script");if(s.length){let t=s.length-1;for(;t>-1&&(!e||!/^http(s?):/.test(e));)e=s[t--].src}}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})(),(()=>{const e={792:0};s.f.j=(t,i)=>{let n=s.o(e,t)?e[t]:void 0;if(0!==n)if(n)i.push(n[2]);else{const r=new Promise((s,i)=>n=e[t]=[s,i]);i.push(n[2]=r);const o=s.p+s.u(t),a=new Error,c=i=>{if(s.o(e,t)&&(n=e[t],0!==n&&(e[t]=void 0),n)){const e=i&&("load"===i.type?"missing":i.type),s=i&&i.target&&i.target.src;a.message="Loading chunk "+t+" failed.\n("+e+": "+s+")",a.name="ChunkLoadError",a.type=e,a.request=s,n[1](a)}};s.l(o,c,"chunk-"+t,t)}};const t=(t,i)=>{let[n,r,o]=i;var a,c,l=0;if(n.some(t=>0!==e[t])){for(a in r)s.o(r,a)&&(s.m[a]=r[a]);o&&o(s)}for(t&&t(i);l(()=>{"use strict";var e={891(e,t,s){s.d(t,{lg:()=>G,xI:()=>ne});class i{constructor(e,t,s){this.eventTarget=e,this.eventName=t,this.eventOptions=s,this.unorderedBindings=new Set}connect(){this.eventTarget.addEventListener(this.eventName,this,this.eventOptions)}disconnect(){this.eventTarget.removeEventListener(this.eventName,this,this.eventOptions)}bindingConnected(e){this.unorderedBindings.add(e)}bindingDisconnected(e){this.unorderedBindings.delete(e)}handleEvent(e){const t=function(e){if("immediatePropagationStopped"in e)return e;{const{stopImmediatePropagation:t}=e;return Object.assign(e,{immediatePropagationStopped:!1,stopImmediatePropagation(){this.immediatePropagationStopped=!0,t.call(this)}})}}(e);for(const e of this.bindings){if(t.immediatePropagationStopped)break;e.handleEvent(t)}}hasBindings(){return this.unorderedBindings.size>0}get bindings(){return Array.from(this.unorderedBindings).sort((e,t)=>{const s=e.index,i=t.index;return si?1:0})}}class n{constructor(e){this.application=e,this.eventListenerMaps=new Map,this.started=!1}start(){this.started||(this.started=!0,this.eventListeners.forEach(e=>e.connect()))}stop(){this.started&&(this.started=!1,this.eventListeners.forEach(e=>e.disconnect()))}get eventListeners(){return Array.from(this.eventListenerMaps.values()).reduce((e,t)=>e.concat(Array.from(t.values())),[])}bindingConnected(e){this.fetchEventListenerForBinding(e).bindingConnected(e)}bindingDisconnected(e,t=!1){this.fetchEventListenerForBinding(e).bindingDisconnected(e),t&&this.clearEventListenersForBinding(e)}handleError(e,t,s={}){this.application.handleError(e,`Error ${t}`,s)}clearEventListenersForBinding(e){const t=this.fetchEventListenerForBinding(e);t.hasBindings()||(t.disconnect(),this.removeMappedEventListenerFor(e))}removeMappedEventListenerFor(e){const{eventTarget:t,eventName:s,eventOptions:i}=e,n=this.fetchEventListenerMapForEventTarget(t),r=this.cacheKey(s,i);n.delete(r),0==n.size&&this.eventListenerMaps.delete(t)}fetchEventListenerForBinding(e){const{eventTarget:t,eventName:s,eventOptions:i}=e;return this.fetchEventListener(t,s,i)}fetchEventListener(e,t,s){const i=this.fetchEventListenerMapForEventTarget(e),n=this.cacheKey(t,s);let r=i.get(n);return r||(r=this.createEventListener(e,t,s),i.set(n,r)),r}createEventListener(e,t,s){const n=new i(e,t,s);return this.started&&n.connect(),n}fetchEventListenerMapForEventTarget(e){let t=this.eventListenerMaps.get(e);return t||(t=new Map,this.eventListenerMaps.set(e,t)),t}cacheKey(e,t){const s=[e];return Object.keys(t).sort().forEach(e=>{s.push(`${t[e]?"":"!"}${e}`)}),s.join(":")}}const r={stop:({event:e,value:t})=>(t&&e.stopPropagation(),!0),prevent:({event:e,value:t})=>(t&&e.preventDefault(),!0),self:({event:e,value:t,element:s})=>!t||s===e.target},o=/^(?:(?:([^.]+?)\+)?(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;function a(e){return e.replace(/(?:[_-])([a-z0-9])/g,(e,t)=>t.toUpperCase())}function c(e){return a(e.replace(/--/g,"-").replace(/__/g,"_"))}function l(e){return e.charAt(0).toUpperCase()+e.slice(1)}function h(e){return e.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`)}function u(e){return null!=e}function d(e,t){return Object.prototype.hasOwnProperty.call(e,t)}const p=["meta","ctrl","alt","shift"];class m{constructor(e,t,s,i){this.element=e,this.index=t,this.eventTarget=s.eventTarget||e,this.eventName=s.eventName||function(e){const t=e.tagName.toLowerCase();if(t in g)return g[t](e)}(e)||f("missing event name"),this.eventOptions=s.eventOptions||{},this.identifier=s.identifier||f("missing identifier"),this.methodName=s.methodName||f("missing method name"),this.keyFilter=s.keyFilter||"",this.schema=i}static forToken(e,t){return new this(e.element,e.index,function(e){const t=e.trim().match(o)||[];let s=t[2],i=t[3];return i&&!["keydown","keyup","keypress"].includes(s)&&(s+=`.${i}`,i=""),{eventTarget:(n=t[4],"window"==n?window:"document"==n?document:void 0),eventName:s,eventOptions:t[7]?(r=t[7],r.split(":").reduce((e,t)=>Object.assign(e,{[t.replace(/^!/,"")]:!/^!/.test(t)}),{})):{},identifier:t[5],methodName:t[6],keyFilter:t[1]||i};var n,r}(e.content),t)}toString(){const e=this.keyFilter?`.${this.keyFilter}`:"",t=this.eventTargetName?`@${this.eventTargetName}`:"";return`${this.eventName}${e}${t}->${this.identifier}#${this.methodName}`}shouldIgnoreKeyboardEvent(e){if(!this.keyFilter)return!1;const t=this.keyFilter.split("+");if(this.keyFilterDissatisfied(e,t))return!0;const s=t.filter(e=>!p.includes(e))[0];return!!s&&(d(this.keyMappings,s)||f(`contains unknown key filter: ${this.keyFilter}`),this.keyMappings[s].toLowerCase()!==e.key.toLowerCase())}shouldIgnoreMouseEvent(e){if(!this.keyFilter)return!1;const t=[this.keyFilter];return!!this.keyFilterDissatisfied(e,t)}get params(){const e={},t=new RegExp(`^data-${this.identifier}-(.+)-param$`,"i");for(const{name:s,value:i}of Array.from(this.element.attributes)){const n=s.match(t),r=n&&n[1];r&&(e[a(r)]=b(i))}return e}get eventTargetName(){return(e=this.eventTarget)==window?"window":e==document?"document":void 0;var e}get keyMappings(){return this.schema.keyMappings}keyFilterDissatisfied(e,t){const[s,i,n,r]=p.map(e=>t.includes(e));return e.metaKey!==s||e.ctrlKey!==i||e.altKey!==n||e.shiftKey!==r}}const g={a:()=>"click",button:()=>"click",form:()=>"submit",details:()=>"toggle",input:e=>"submit"==e.getAttribute("type")?"click":"input",select:()=>"change",textarea:()=>"input"};function f(e){throw new Error(e)}function b(e){try{return JSON.parse(e)}catch(t){return e}}class y{constructor(e,t){this.context=e,this.action=t}get index(){return this.action.index}get eventTarget(){return this.action.eventTarget}get eventOptions(){return this.action.eventOptions}get identifier(){return this.context.identifier}handleEvent(e){const t=this.prepareActionEvent(e);this.willBeInvokedByEvent(e)&&this.applyEventModifiers(t)&&this.invokeWithEvent(t)}get eventName(){return this.action.eventName}get method(){const e=this.controller[this.methodName];if("function"==typeof e)return e;throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`)}applyEventModifiers(e){const{element:t}=this.action,{actionDescriptorFilters:s}=this.context.application,{controller:i}=this.context;let n=!0;for(const[r,o]of Object.entries(this.eventOptions))if(r in s){const a=s[r];n=n&&a({name:r,value:o,event:e,element:t,controller:i})}return n}prepareActionEvent(e){return Object.assign(e,{params:this.action.params})}invokeWithEvent(e){const{target:t,currentTarget:s}=e;try{this.method.call(this.controller,e),this.context.logDebugActivity(this.methodName,{event:e,target:t,currentTarget:s,action:this.methodName})}catch(t){const{identifier:s,controller:i,element:n,index:r}=this,o={identifier:s,controller:i,element:n,index:r,event:e};this.context.handleError(t,`invoking action "${this.action}"`,o)}}willBeInvokedByEvent(e){const t=e.target;return!(e instanceof KeyboardEvent&&this.action.shouldIgnoreKeyboardEvent(e))&&!(e instanceof MouseEvent&&this.action.shouldIgnoreMouseEvent(e))&&(this.element===t||(t instanceof Element&&this.element.contains(t)?this.scope.containsElement(t):this.scope.containsElement(this.action.element)))}get controller(){return this.context.controller}get methodName(){return this.action.methodName}get element(){return this.scope.element}get scope(){return this.context.scope}}class v{constructor(e,t){this.mutationObserverInit={attributes:!0,childList:!0,subtree:!0},this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,this.mutationObserverInit),this.refresh())}pause(e){this.started&&(this.mutationObserver.disconnect(),this.started=!1),e(),this.started||(this.mutationObserver.observe(this.element,this.mutationObserverInit),this.started=!0)}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started){const e=new Set(this.matchElementsInTree());for(const t of Array.from(this.elements))e.has(t)||this.removeElement(t);for(const t of Array.from(e))this.addElement(t)}}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){"attributes"==e.type?this.processAttributeChange(e.target,e.attributeName):"childList"==e.type&&(this.processRemovedNodes(e.removedNodes),this.processAddedNodes(e.addedNodes))}processAttributeChange(e,t){this.elements.has(e)?this.delegate.elementAttributeChanged&&this.matchElement(e)?this.delegate.elementAttributeChanged(e,t):this.removeElement(e):this.matchElement(e)&&this.addElement(e)}processRemovedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.processTree(e,this.removeElement)}}processAddedNodes(e){for(const t of Array.from(e)){const e=this.elementFromNode(t);e&&this.elementIsActive(e)&&this.processTree(e,this.addElement)}}matchElement(e){return this.delegate.matchElement(e)}matchElementsInTree(e=this.element){return this.delegate.matchElementsInTree(e)}processTree(e,t){for(const s of this.matchElementsInTree(e))t.call(this,s)}elementFromNode(e){if(e.nodeType==Node.ELEMENT_NODE)return e}elementIsActive(e){return e.isConnected==this.element.isConnected&&this.element.contains(e)}addElement(e){this.elements.has(e)||this.elementIsActive(e)&&(this.elements.add(e),this.delegate.elementMatched&&this.delegate.elementMatched(e))}removeElement(e){this.elements.has(e)&&(this.elements.delete(e),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(e))}}class w{constructor(e,t,s){this.attributeName=t,this.delegate=s,this.elementObserver=new v(e,this)}get element(){return this.elementObserver.element}get selector(){return`[${this.attributeName}]`}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get started(){return this.elementObserver.started}matchElement(e){return e.hasAttribute(this.attributeName)}matchElementsInTree(e){const t=this.matchElement(e)?[e]:[],s=Array.from(e.querySelectorAll(this.selector));return t.concat(s)}elementMatched(e){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(e,this.attributeName)}elementUnmatched(e){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(e,this.attributeName)}elementAttributeChanged(e,t){this.delegate.elementAttributeValueChanged&&this.attributeName==t&&this.delegate.elementAttributeValueChanged(e,t)}}function T(e,t){let s=e.get(t);return s||(s=new Set,e.set(t,s)),s}class S{constructor(){this.valuesByKey=new Map}get keys(){return Array.from(this.valuesByKey.keys())}get values(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e.concat(Array.from(t)),[])}get size(){return Array.from(this.valuesByKey.values()).reduce((e,t)=>e+t.size,0)}add(e,t){!function(e,t,s){T(e,t).add(s)}(this.valuesByKey,e,t)}delete(e,t){!function(e,t,s){T(e,t).delete(s),function(e,t){const s=e.get(t);null!=s&&0==s.size&&e.delete(t)}(e,t)}(this.valuesByKey,e,t)}has(e,t){const s=this.valuesByKey.get(e);return null!=s&&s.has(t)}hasKey(e){return this.valuesByKey.has(e)}hasValue(e){return Array.from(this.valuesByKey.values()).some(t=>t.has(e))}getValuesForKey(e){const t=this.valuesByKey.get(e);return t?Array.from(t):[]}getKeysForValue(e){return Array.from(this.valuesByKey).filter(([t,s])=>s.has(e)).map(([e,t])=>e)}}class C{constructor(e,t,s,i){this._selector=t,this.details=i,this.elementObserver=new v(e,this),this.delegate=s,this.matchesByElement=new S}get started(){return this.elementObserver.started}get selector(){return this._selector}set selector(e){this._selector=e,this.refresh()}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get element(){return this.elementObserver.element}matchElement(e){const{selector:t}=this;if(t){const s=e.matches(t);return this.delegate.selectorMatchElement?s&&this.delegate.selectorMatchElement(e,this.details):s}return!1}matchElementsInTree(e){const{selector:t}=this;if(t){const s=this.matchElement(e)?[e]:[],i=Array.from(e.querySelectorAll(t)).filter(e=>this.matchElement(e));return s.concat(i)}return[]}elementMatched(e){const{selector:t}=this;t&&this.selectorMatched(e,t)}elementUnmatched(e){const t=this.matchesByElement.getKeysForValue(e);for(const s of t)this.selectorUnmatched(e,s)}elementAttributeChanged(e,t){const{selector:s}=this;if(s){const t=this.matchElement(e),i=this.matchesByElement.has(s,e);t&&!i?this.selectorMatched(e,s):!t&&i&&this.selectorUnmatched(e,s)}}selectorMatched(e,t){this.delegate.selectorMatched(e,t,this.details),this.matchesByElement.add(t,e)}selectorUnmatched(e,t){this.delegate.selectorUnmatched(e,t,this.details),this.matchesByElement.delete(t,e)}}class O{constructor(e,t){this.element=e,this.delegate=t,this.started=!1,this.stringMap=new Map,this.mutationObserver=new MutationObserver(e=>this.processMutations(e))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,attributeOldValue:!0}),this.refresh())}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started)for(const e of this.knownAttributeNames)this.refreshAttribute(e,null)}processMutations(e){if(this.started)for(const t of e)this.processMutation(t)}processMutation(e){const t=e.attributeName;t&&this.refreshAttribute(t,e.oldValue)}refreshAttribute(e,t){const s=this.delegate.getStringMapKeyForAttribute(e);if(null!=s){this.stringMap.has(e)||this.stringMapKeyAdded(s,e);const i=this.element.getAttribute(e);if(this.stringMap.get(e)!=i&&this.stringMapValueChanged(i,s,t),null==i){const t=this.stringMap.get(e);this.stringMap.delete(e),t&&this.stringMapKeyRemoved(s,e,t)}else this.stringMap.set(e,i)}}stringMapKeyAdded(e,t){this.delegate.stringMapKeyAdded&&this.delegate.stringMapKeyAdded(e,t)}stringMapValueChanged(e,t,s){this.delegate.stringMapValueChanged&&this.delegate.stringMapValueChanged(e,t,s)}stringMapKeyRemoved(e,t,s){this.delegate.stringMapKeyRemoved&&this.delegate.stringMapKeyRemoved(e,t,s)}get knownAttributeNames(){return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)))}get currentAttributeNames(){return Array.from(this.element.attributes).map(e=>e.name)}get recordedAttributeNames(){return Array.from(this.stringMap.keys())}}class E{constructor(e,t,s){this.attributeObserver=new w(e,t,this),this.delegate=s,this.tokensByElement=new S}get started(){return this.attributeObserver.started}start(){this.attributeObserver.start()}pause(e){this.attributeObserver.pause(e)}stop(){this.attributeObserver.stop()}refresh(){this.attributeObserver.refresh()}get element(){return this.attributeObserver.element}get attributeName(){return this.attributeObserver.attributeName}elementMatchedAttribute(e){this.tokensMatched(this.readTokensForElement(e))}elementAttributeValueChanged(e){const[t,s]=this.refreshTokensForElement(e);this.tokensUnmatched(t),this.tokensMatched(s)}elementUnmatchedAttribute(e){this.tokensUnmatched(this.tokensByElement.getValuesForKey(e))}tokensMatched(e){e.forEach(e=>this.tokenMatched(e))}tokensUnmatched(e){e.forEach(e=>this.tokenUnmatched(e))}tokenMatched(e){this.delegate.tokenMatched(e),this.tokensByElement.add(e.element,e)}tokenUnmatched(e){this.delegate.tokenUnmatched(e),this.tokensByElement.delete(e.element,e)}refreshTokensForElement(e){const t=this.tokensByElement.getValuesForKey(e),s=this.readTokensForElement(e),i=function(e,t){const s=Math.max(e.length,t.length);return Array.from({length:s},(s,i)=>[e[i],t[i]])}(t,s).findIndex(([e,t])=>{return i=t,!((s=e)&&i&&s.index==i.index&&s.content==i.content);var s,i});return-1==i?[[],[]]:[t.slice(i),s.slice(i)]}readTokensForElement(e){const t=this.attributeName;return function(e,t,s){return e.trim().split(/\s+/).filter(e=>e.length).map((e,i)=>({element:t,attributeName:s,content:e,index:i}))}(e.getAttribute(t)||"",e,t)}}class A{constructor(e,t,s){this.tokenListObserver=new E(e,t,this),this.delegate=s,this.parseResultsByToken=new WeakMap,this.valuesByTokenByElement=new WeakMap}get started(){return this.tokenListObserver.started}start(){this.tokenListObserver.start()}stop(){this.tokenListObserver.stop()}refresh(){this.tokenListObserver.refresh()}get element(){return this.tokenListObserver.element}get attributeName(){return this.tokenListObserver.attributeName}tokenMatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).set(e,s),this.delegate.elementMatchedValue(t,s))}tokenUnmatched(e){const{element:t}=e,{value:s}=this.fetchParseResultForToken(e);s&&(this.fetchValuesByTokenForElement(t).delete(e),this.delegate.elementUnmatchedValue(t,s))}fetchParseResultForToken(e){let t=this.parseResultsByToken.get(e);return t||(t=this.parseToken(e),this.parseResultsByToken.set(e,t)),t}fetchValuesByTokenForElement(e){let t=this.valuesByTokenByElement.get(e);return t||(t=new Map,this.valuesByTokenByElement.set(e,t)),t}parseToken(e){try{return{value:this.delegate.parseValueForToken(e)}}catch(e){return{error:e}}}}class x{constructor(e,t){this.context=e,this.delegate=t,this.bindingsByAction=new Map}start(){this.valueListObserver||(this.valueListObserver=new A(this.element,this.actionAttribute,this),this.valueListObserver.start())}stop(){this.valueListObserver&&(this.valueListObserver.stop(),delete this.valueListObserver,this.disconnectAllActions())}get element(){return this.context.element}get identifier(){return this.context.identifier}get actionAttribute(){return this.schema.actionAttribute}get schema(){return this.context.schema}get bindings(){return Array.from(this.bindingsByAction.values())}connectAction(e){const t=new y(this.context,e);this.bindingsByAction.set(e,t),this.delegate.bindingConnected(t)}disconnectAction(e){const t=this.bindingsByAction.get(e);t&&(this.bindingsByAction.delete(e),this.delegate.bindingDisconnected(t))}disconnectAllActions(){this.bindings.forEach(e=>this.delegate.bindingDisconnected(e,!0)),this.bindingsByAction.clear()}parseValueForToken(e){const t=m.forToken(e,this.schema);if(t.identifier==this.identifier)return t}elementMatchedValue(e,t){this.connectAction(t)}elementUnmatchedValue(e,t){this.disconnectAction(t)}}class M{constructor(e,t){this.context=e,this.receiver=t,this.stringMapObserver=new O(this.element,this),this.valueDescriptorMap=this.controller.valueDescriptorMap}start(){this.stringMapObserver.start(),this.invokeChangedCallbacksForDefaultValues()}stop(){this.stringMapObserver.stop()}get element(){return this.context.element}get controller(){return this.context.controller}getStringMapKeyForAttribute(e){if(e in this.valueDescriptorMap)return this.valueDescriptorMap[e].name}stringMapKeyAdded(e,t){const s=this.valueDescriptorMap[t];this.hasValue(e)||this.invokeChangedCallback(e,s.writer(this.receiver[e]),s.writer(s.defaultValue))}stringMapValueChanged(e,t,s){const i=this.valueDescriptorNameMap[t];null!==e&&(null===s&&(s=i.writer(i.defaultValue)),this.invokeChangedCallback(t,e,s))}stringMapKeyRemoved(e,t,s){const i=this.valueDescriptorNameMap[e];this.hasValue(e)?this.invokeChangedCallback(e,i.writer(this.receiver[e]),s):this.invokeChangedCallback(e,i.writer(i.defaultValue),s)}invokeChangedCallbacksForDefaultValues(){for(const{key:e,name:t,defaultValue:s,writer:i}of this.valueDescriptors)null==s||this.controller.data.has(e)||this.invokeChangedCallback(t,i(s),void 0)}invokeChangedCallback(e,t,s){const i=`${e}Changed`,n=this.receiver[i];if("function"==typeof n){const i=this.valueDescriptorNameMap[e];try{const e=i.reader(t);let r=s;s&&(r=i.reader(s)),n.call(this.receiver,e,r)}catch(e){throw e instanceof TypeError&&(e.message=`Stimulus Value "${this.context.identifier}.${i.name}" - ${e.message}`),e}}}get valueDescriptors(){const{valueDescriptorMap:e}=this;return Object.keys(e).map(t=>e[t])}get valueDescriptorNameMap(){const e={};return Object.keys(this.valueDescriptorMap).forEach(t=>{const s=this.valueDescriptorMap[t];e[s.name]=s}),e}hasValue(e){const t=`has${l(this.valueDescriptorNameMap[e].name)}`;return this.receiver[t]}}class k{constructor(e,t){this.context=e,this.delegate=t,this.targetsByName=new S}start(){this.tokenListObserver||(this.tokenListObserver=new E(this.element,this.attributeName,this),this.tokenListObserver.start())}stop(){this.tokenListObserver&&(this.disconnectAllTargets(),this.tokenListObserver.stop(),delete this.tokenListObserver)}tokenMatched({element:e,content:t}){this.scope.containsElement(e)&&this.connectTarget(e,t)}tokenUnmatched({element:e,content:t}){this.disconnectTarget(e,t)}connectTarget(e,t){var s;this.targetsByName.has(t,e)||(this.targetsByName.add(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetConnected(e,t)))}disconnectTarget(e,t){var s;this.targetsByName.has(t,e)&&(this.targetsByName.delete(t,e),null===(s=this.tokenListObserver)||void 0===s||s.pause(()=>this.delegate.targetDisconnected(e,t)))}disconnectAllTargets(){for(const e of this.targetsByName.keys)for(const t of this.targetsByName.getValuesForKey(e))this.disconnectTarget(t,e)}get attributeName(){return`data-${this.context.identifier}-target`}get element(){return this.context.element}get scope(){return this.context.scope}}function I(e,t){const s=L(e);return Array.from(s.reduce((e,s)=>(function(e,t){const s=e[t];return Array.isArray(s)?s:[]}(s,t).forEach(t=>e.add(t)),e),new Set))}function L(e){const t=[];for(;e;)t.push(e),e=Object.getPrototypeOf(e);return t.reverse()}class P{constructor(e,t){this.started=!1,this.context=e,this.delegate=t,this.outletsByName=new S,this.outletElementsByName=new S,this.selectorObserverMap=new Map,this.attributeObserverMap=new Map}start(){this.started||(this.outletDefinitions.forEach(e=>{this.setupSelectorObserverForOutlet(e),this.setupAttributeObserverForOutlet(e)}),this.started=!0,this.dependentContexts.forEach(e=>e.refresh()))}refresh(){this.selectorObserverMap.forEach(e=>e.refresh()),this.attributeObserverMap.forEach(e=>e.refresh())}stop(){this.started&&(this.started=!1,this.disconnectAllOutlets(),this.stopSelectorObservers(),this.stopAttributeObservers())}stopSelectorObservers(){this.selectorObserverMap.size>0&&(this.selectorObserverMap.forEach(e=>e.stop()),this.selectorObserverMap.clear())}stopAttributeObservers(){this.attributeObserverMap.size>0&&(this.attributeObserverMap.forEach(e=>e.stop()),this.attributeObserverMap.clear())}selectorMatched(e,t,{outletName:s}){const i=this.getOutlet(e,s);i&&this.connectOutlet(i,e,s)}selectorUnmatched(e,t,{outletName:s}){const i=this.getOutletFromMap(e,s);i&&this.disconnectOutlet(i,e,s)}selectorMatchElement(e,{outletName:t}){const s=this.selector(t),i=this.hasOutlet(e,t),n=e.matches(`[${this.schema.controllerAttribute}~=${t}]`);return!!s&&i&&n&&e.matches(s)}elementMatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementAttributeValueChanged(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}elementUnmatchedAttribute(e,t){const s=this.getOutletNameFromOutletAttributeName(t);s&&this.updateSelectorObserverForOutlet(s)}connectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)||(this.outletsByName.add(s,e),this.outletElementsByName.add(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletConnected(e,t,s)))}disconnectOutlet(e,t,s){var i;this.outletElementsByName.has(s,t)&&(this.outletsByName.delete(s,e),this.outletElementsByName.delete(s,t),null===(i=this.selectorObserverMap.get(s))||void 0===i||i.pause(()=>this.delegate.outletDisconnected(e,t,s)))}disconnectAllOutlets(){for(const e of this.outletElementsByName.keys)for(const t of this.outletElementsByName.getValuesForKey(e))for(const s of this.outletsByName.getValuesForKey(e))this.disconnectOutlet(s,t,e)}updateSelectorObserverForOutlet(e){const t=this.selectorObserverMap.get(e);t&&(t.selector=this.selector(e))}setupSelectorObserverForOutlet(e){const t=this.selector(e),s=new C(document.body,t,this,{outletName:e});this.selectorObserverMap.set(e,s),s.start()}setupAttributeObserverForOutlet(e){const t=this.attributeNameForOutletName(e),s=new w(this.scope.element,t,this);this.attributeObserverMap.set(e,s),s.start()}selector(e){return this.scope.outlets.getSelectorForOutletName(e)}attributeNameForOutletName(e){return this.scope.schema.outletAttributeForScope(this.identifier,e)}getOutletNameFromOutletAttributeName(e){return this.outletDefinitions.find(t=>this.attributeNameForOutletName(t)===e)}get outletDependencies(){const e=new S;return this.router.modules.forEach(t=>{I(t.definition.controllerConstructor,"outlets").forEach(s=>e.add(s,t.identifier))}),e}get outletDefinitions(){return this.outletDependencies.getKeysForValue(this.identifier)}get dependentControllerIdentifiers(){return this.outletDependencies.getValuesForKey(this.identifier)}get dependentContexts(){const e=this.dependentControllerIdentifiers;return this.router.contexts.filter(t=>e.includes(t.identifier))}hasOutlet(e,t){return!!this.getOutlet(e,t)||!!this.getOutletFromMap(e,t)}getOutlet(e,t){return this.application.getControllerForElementAndIdentifier(e,t)}getOutletFromMap(e,t){return this.outletsByName.getValuesForKey(t).find(t=>t.element===e)}get scope(){return this.context.scope}get schema(){return this.context.schema}get identifier(){return this.context.identifier}get application(){return this.context.application}get router(){return this.application.router}}class _{constructor(e,t){this.logDebugActivity=(e,t={})=>{const{identifier:s,controller:i,element:n}=this;t=Object.assign({identifier:s,controller:i,element:n},t),this.application.logDebugActivity(this.identifier,e,t)},this.module=e,this.scope=t,this.controller=new e.controllerConstructor(this),this.bindingObserver=new x(this,this.dispatcher),this.valueObserver=new M(this,this.controller),this.targetObserver=new k(this,this),this.outletObserver=new P(this,this);try{this.controller.initialize(),this.logDebugActivity("initialize")}catch(e){this.handleError(e,"initializing controller")}}connect(){this.bindingObserver.start(),this.valueObserver.start(),this.targetObserver.start(),this.outletObserver.start();try{this.controller.connect(),this.logDebugActivity("connect")}catch(e){this.handleError(e,"connecting controller")}}refresh(){this.outletObserver.refresh()}disconnect(){try{this.controller.disconnect(),this.logDebugActivity("disconnect")}catch(e){this.handleError(e,"disconnecting controller")}this.outletObserver.stop(),this.targetObserver.stop(),this.valueObserver.stop(),this.bindingObserver.stop()}get application(){return this.module.application}get identifier(){return this.module.identifier}get schema(){return this.application.schema}get dispatcher(){return this.application.dispatcher}get element(){return this.scope.element}get parentElement(){return this.element.parentElement}handleError(e,t,s={}){const{identifier:i,controller:n,element:r}=this;s=Object.assign({identifier:i,controller:n,element:r},s),this.application.handleError(e,`Error ${t}`,s)}targetConnected(e,t){this.invokeControllerMethod(`${t}TargetConnected`,e)}targetDisconnected(e,t){this.invokeControllerMethod(`${t}TargetDisconnected`,e)}outletConnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletConnected`,e,t)}outletDisconnected(e,t,s){this.invokeControllerMethod(`${c(s)}OutletDisconnected`,e,t)}invokeControllerMethod(e,...t){const s=this.controller;"function"==typeof s[e]&&s[e](...t)}}const N="function"==typeof Object.getOwnPropertySymbols?e=>[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)]:Object.getOwnPropertyNames,D=(()=>{function e(e){function t(){return Reflect.construct(e,arguments,new.target)}return t.prototype=Object.create(e.prototype,{constructor:{value:t}}),Reflect.setPrototypeOf(t,e),t}try{return function(){const t=e(function(){this.a.call(this)});t.prototype.a=function(){},new t}(),e}catch(e){return e=>class extends e{}}})();class F{constructor(e,t){this.application=e,this.definition=function(e){return{identifier:e.identifier,controllerConstructor:(t=e.controllerConstructor,function(e,t){const s=D(e),i=function(e,t){return N(t).reduce((s,i)=>{const n=function(e,t,s){const i=Object.getOwnPropertyDescriptor(e,s);if(!i||!("value"in i)){const e=Object.getOwnPropertyDescriptor(t,s).value;return i&&(e.get=i.get||e.get,e.set=i.set||e.set),e}}(e,t,i);return n&&Object.assign(s,{[i]:n}),s},{})}(e.prototype,t);return Object.defineProperties(s.prototype,i),s}(t,function(e){return I(e,"blessings").reduce((t,s)=>{const i=s(e);for(const e in i){const s=t[e]||{};t[e]=Object.assign(s,i[e])}return t},{})}(t)))};var t}(t),this.contextsByScope=new WeakMap,this.connectedContexts=new Set}get identifier(){return this.definition.identifier}get controllerConstructor(){return this.definition.controllerConstructor}get contexts(){return Array.from(this.connectedContexts)}connectContextForScope(e){const t=this.fetchContextForScope(e);this.connectedContexts.add(t),t.connect()}disconnectContextForScope(e){const t=this.contextsByScope.get(e);t&&(this.connectedContexts.delete(t),t.disconnect())}fetchContextForScope(e){let t=this.contextsByScope.get(e);return t||(t=new _(this,e),this.contextsByScope.set(e,t)),t}}class R{constructor(e){this.scope=e}has(e){return this.data.has(this.getDataKey(e))}get(e){return this.getAll(e)[0]}getAll(e){return(this.data.get(this.getDataKey(e))||"").match(/[^\s]+/g)||[]}getAttributeName(e){return this.data.getAttributeNameForKey(this.getDataKey(e))}getDataKey(e){return`${e}-class`}get data(){return this.scope.data}}class B{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get(e){const t=this.getAttributeNameForKey(e);return this.element.getAttribute(t)}set(e,t){const s=this.getAttributeNameForKey(e);return this.element.setAttribute(s,t),this.get(e)}has(e){const t=this.getAttributeNameForKey(e);return this.element.hasAttribute(t)}delete(e){if(this.has(e)){const t=this.getAttributeNameForKey(e);return this.element.removeAttribute(t),!0}return!1}getAttributeNameForKey(e){return`data-${this.identifier}-${h(e)}`}}class ${constructor(e){this.warnedKeysByObject=new WeakMap,this.logger=e}warn(e,t,s){let i=this.warnedKeysByObject.get(e);i||(i=new Set,this.warnedKeysByObject.set(e,i)),i.has(t)||(i.add(t),this.logger.warn(s,e))}}function j(e,t){return`[${e}~="${t}"]`}class V{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findTarget(t)||this.findLegacyTarget(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllTargets(t),...this.findAllLegacyTargets(t)],[])}findTarget(e){const t=this.getSelectorForTargetName(e);return this.scope.findElement(t)}findAllTargets(e){const t=this.getSelectorForTargetName(e);return this.scope.findAllElements(t)}getSelectorForTargetName(e){return j(this.schema.targetAttributeForScope(this.identifier),e)}findLegacyTarget(e){const t=this.getLegacySelectorForTargetName(e);return this.deprecate(this.scope.findElement(t),e)}findAllLegacyTargets(e){const t=this.getLegacySelectorForTargetName(e);return this.scope.findAllElements(t).map(t=>this.deprecate(t,e))}getLegacySelectorForTargetName(e){const t=`${this.identifier}.${e}`;return j(this.schema.targetAttribute,t)}deprecate(e,t){if(e){const{identifier:s}=this,i=this.schema.targetAttribute,n=this.schema.targetAttributeForScope(s);this.guide.warn(e,`target:${t}`,`Please replace ${i}="${s}.${t}" with ${n}="${t}". The ${i} attribute is deprecated and will be removed in a future version of Stimulus.`)}return e}get guide(){return this.scope.guide}}class q{constructor(e,t){this.scope=e,this.controllerElement=t}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return null!=this.find(e)}find(...e){return e.reduce((e,t)=>e||this.findOutlet(t),void 0)}findAll(...e){return e.reduce((e,t)=>[...e,...this.findAllOutlets(t)],[])}getSelectorForOutletName(e){const t=this.schema.outletAttributeForScope(this.identifier,e);return this.controllerElement.getAttribute(t)}findOutlet(e){const t=this.getSelectorForOutletName(e);if(t)return this.findElement(t,e)}findAllOutlets(e){const t=this.getSelectorForOutletName(e);return t?this.findAllElements(t,e):[]}findElement(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))[0]}findAllElements(e,t){return this.scope.queryElements(e).filter(s=>this.matchesElement(s,e,t))}matchesElement(e,t,s){const i=e.getAttribute(this.scope.schema.controllerAttribute)||"";return e.matches(t)&&i.split(" ").includes(s)}}class U{constructor(e,t,s,i){this.targets=new V(this),this.classes=new R(this),this.data=new B(this),this.containsElement=e=>e.closest(this.controllerSelector)===this.element,this.schema=e,this.element=t,this.identifier=s,this.guide=new $(i),this.outlets=new q(this.documentScope,t)}findElement(e){return this.element.matches(e)?this.element:this.queryElements(e).find(this.containsElement)}findAllElements(e){return[...this.element.matches(e)?[this.element]:[],...this.queryElements(e).filter(this.containsElement)]}queryElements(e){return Array.from(this.element.querySelectorAll(e))}get controllerSelector(){return j(this.schema.controllerAttribute,this.identifier)}get isDocumentScope(){return this.element===document.documentElement}get documentScope(){return this.isDocumentScope?this:new U(this.schema,document.documentElement,this.identifier,this.guide.logger)}}class z{constructor(e,t,s){this.element=e,this.schema=t,this.delegate=s,this.valueListObserver=new A(this.element,this.controllerAttribute,this),this.scopesByIdentifierByElement=new WeakMap,this.scopeReferenceCounts=new WeakMap}start(){this.valueListObserver.start()}stop(){this.valueListObserver.stop()}get controllerAttribute(){return this.schema.controllerAttribute}parseValueForToken(e){const{element:t,content:s}=e;return this.parseValueForElementAndIdentifier(t,s)}parseValueForElementAndIdentifier(e,t){const s=this.fetchScopesByIdentifierForElement(e);let i=s.get(t);return i||(i=this.delegate.createScopeForElementAndIdentifier(e,t),s.set(t,i)),i}elementMatchedValue(e,t){const s=(this.scopeReferenceCounts.get(t)||0)+1;this.scopeReferenceCounts.set(t,s),1==s&&this.delegate.scopeConnected(t)}elementUnmatchedValue(e,t){const s=this.scopeReferenceCounts.get(t);s&&(this.scopeReferenceCounts.set(t,s-1),1==s&&this.delegate.scopeDisconnected(t))}fetchScopesByIdentifierForElement(e){let t=this.scopesByIdentifierByElement.get(e);return t||(t=new Map,this.scopesByIdentifierByElement.set(e,t)),t}}class W{constructor(e){this.application=e,this.scopeObserver=new z(this.element,this.schema,this),this.scopesByIdentifier=new S,this.modulesByIdentifier=new Map}get element(){return this.application.element}get schema(){return this.application.schema}get logger(){return this.application.logger}get controllerAttribute(){return this.schema.controllerAttribute}get modules(){return Array.from(this.modulesByIdentifier.values())}get contexts(){return this.modules.reduce((e,t)=>e.concat(t.contexts),[])}start(){this.scopeObserver.start()}stop(){this.scopeObserver.stop()}loadDefinition(e){this.unloadIdentifier(e.identifier);const t=new F(this.application,e);this.connectModule(t);const s=e.controllerConstructor.afterLoad;s&&s.call(e.controllerConstructor,e.identifier,this.application)}unloadIdentifier(e){const t=this.modulesByIdentifier.get(e);t&&this.disconnectModule(t)}getContextForElementAndIdentifier(e,t){const s=this.modulesByIdentifier.get(t);if(s)return s.contexts.find(t=>t.element==e)}proposeToConnectScopeForElementAndIdentifier(e,t){const s=this.scopeObserver.parseValueForElementAndIdentifier(e,t);s?this.scopeObserver.elementMatchedValue(s.element,s):console.error(`Couldn't find or create scope for identifier: "${t}" and element:`,e)}handleError(e,t,s){this.application.handleError(e,t,s)}createScopeForElementAndIdentifier(e,t){return new U(this.schema,e,t,this.logger)}scopeConnected(e){this.scopesByIdentifier.add(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.connectContextForScope(e)}scopeDisconnected(e){this.scopesByIdentifier.delete(e.identifier,e);const t=this.modulesByIdentifier.get(e.identifier);t&&t.disconnectContextForScope(e)}connectModule(e){this.modulesByIdentifier.set(e.identifier,e),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.connectContextForScope(t))}disconnectModule(e){this.modulesByIdentifier.delete(e.identifier),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(t=>e.disconnectContextForScope(t))}}const K={controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target",targetAttributeForScope:e=>`data-${e}-target`,outletAttributeForScope:(e,t)=>`data-${e}-${t}-outlet`,keyMappings:Object.assign(Object.assign({enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"},H("abcdefghijklmnopqrstuvwxyz".split("").map(e=>[e,e]))),H("0123456789".split("").map(e=>[e,e])))};function H(e){return e.reduce((e,[t,s])=>Object.assign(Object.assign({},e),{[t]:s}),{})}class G{constructor(e=document.documentElement,t=K){this.logger=console,this.debug=!1,this.logDebugActivity=(e,t,s={})=>{this.debug&&this.logFormattedMessage(e,t,s)},this.element=e,this.schema=t,this.dispatcher=new n(this),this.router=new W(this),this.actionDescriptorFilters=Object.assign({},r)}static start(e,t){const s=new this(e,t);return s.start(),s}async start(){await new Promise(e=>{"loading"==document.readyState?document.addEventListener("DOMContentLoaded",()=>e()):e()}),this.logDebugActivity("application","starting"),this.dispatcher.start(),this.router.start(),this.logDebugActivity("application","start")}stop(){this.logDebugActivity("application","stopping"),this.dispatcher.stop(),this.router.stop(),this.logDebugActivity("application","stop")}register(e,t){this.load({identifier:e,controllerConstructor:t})}registerActionOption(e,t){this.actionDescriptorFilters[e]=t}load(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>{e.controllerConstructor.shouldLoad&&this.router.loadDefinition(e)})}unload(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(e=>this.router.unloadIdentifier(e))}get controllers(){return this.router.contexts.map(e=>e.controller)}getControllerForElementAndIdentifier(e,t){const s=this.router.getContextForElementAndIdentifier(e,t);return s?s.controller:null}handleError(e,t,s){var i;this.logger.error("%s\n\n%o\n\n%o",t,e,s),null===(i=window.onerror)||void 0===i||i.call(window,t,"",0,0,e)}logFormattedMessage(e,t,s={}){s=Object.assign({application:this},s),this.logger.groupCollapsed(`${e} #${t}`),this.logger.log("details:",Object.assign({},s)),this.logger.groupEnd()}}function J(e,t,s){return e.application.getControllerForElementAndIdentifier(t,s)}function Y(e,t,s){let i=J(e,t,s);return i||(e.application.router.proposeToConnectScopeForElementAndIdentifier(t,s),i=J(e,t,s),i||void 0)}function Z([e,t],s){return function(e){const{token:t,typeDefinition:s}=e,i=`${h(t)}-value`,n=function(e){const{controller:t,token:s,typeDefinition:i}=e,n=function(e){const{controller:t,token:s,typeObject:i}=e,n=u(i.type),r=u(i.default),o=n&&r,a=n&&!r,c=!n&&r,l=X(i.type),h=Q(e.typeObject.default);if(a)return l;if(c)return h;if(l!==h)throw new Error(`The specified default value for the Stimulus Value "${t?`${t}.${s}`:s}" must match the defined type "${l}". The provided default value of "${i.default}" is of type "${h}".`);return o?l:void 0}({controller:t,token:s,typeObject:i}),r=Q(i),o=X(i),a=n||r||o;if(a)return a;throw new Error(`Unknown value type "${t?`${t}.${i}`:s}" for "${s}" value`)}(e);return{type:n,key:i,name:a(i),get defaultValue(){return function(e){const t=X(e);if(t)return ee[t];const s=d(e,"default"),i=d(e,"type"),n=e;if(s)return n.default;if(i){const{type:e}=n,t=X(e);if(t)return ee[t]}return e}(s)},get hasCustomDefaultValue(){return void 0!==Q(s)},reader:te[n],writer:se[n]||se.default}}({controller:s,token:e,typeDefinition:t})}function X(e){switch(e){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function Q(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}return Array.isArray(e)?"array":"[object Object]"===Object.prototype.toString.call(e)?"object":void 0}const ee={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},te={array(e){const t=JSON.parse(e);if(!Array.isArray(t))throw new TypeError(`expected value of type "array" but instead got value "${e}" of type "${Q(t)}"`);return t},boolean:e=>!("0"==e||"false"==String(e).toLowerCase()),number:e=>Number(e.replace(/_/g,"")),object(e){const t=JSON.parse(e);if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`expected value of type "object" but instead got value "${e}" of type "${Q(t)}"`);return t},string:e=>e},se={default:function(e){return`${e}`},array:ie,object:ie};function ie(e){return JSON.stringify(e)}class ne{constructor(e){this.context=e}static get shouldLoad(){return!0}static afterLoad(e,t){}get application(){return this.context.application}get scope(){return this.context.scope}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get targets(){return this.scope.targets}get outlets(){return this.scope.outlets}get classes(){return this.scope.classes}get data(){return this.scope.data}initialize(){}connect(){}disconnect(){}dispatch(e,{target:t=this.element,detail:s={},prefix:i=this.identifier,bubbles:n=!0,cancelable:r=!0}={}){const o=new CustomEvent(i?`${i}:${e}`:e,{detail:s,bubbles:n,cancelable:r});return t.dispatchEvent(o),o}}ne.blessings=[function(e){return I(e,"classes").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Class`]:{get(){const{classes:e}=this;if(e.has(s))return e.get(s);{const t=e.getAttributeName(s);throw new Error(`Missing attribute "${t}"`)}}},[`${s}Classes`]:{get(){return this.classes.getAll(s)}},[`has${l(s)}Class`]:{get(){return this.classes.has(s)}}}));var s},{})},function(e){return I(e,"targets").reduce((e,t)=>{return Object.assign(e,(s=t,{[`${s}Target`]:{get(){const e=this.targets.find(s);if(e)return e;throw new Error(`Missing target element "${s}" for "${this.identifier}" controller`)}},[`${s}Targets`]:{get(){return this.targets.findAll(s)}},[`has${l(s)}Target`]:{get(){return this.targets.has(s)}}}));var s},{})},function(e){const t=function(e,t){return L(e).reduce((e,s)=>(e.push(...function(e,t){const s=e[t];return s?Object.keys(s).map(e=>[e,s[e]]):[]}(s,t)),e),[])}(e,"values"),s={valueDescriptorMap:{get(){return t.reduce((e,t)=>{const s=Z(t,this.identifier),i=this.data.getAttributeNameForKey(s.key);return Object.assign(e,{[i]:s})},{})}}};return t.reduce((e,t)=>Object.assign(e,function(e){const t=Z(e,void 0),{key:s,name:i,reader:n,writer:r}=t;return{[i]:{get(){const e=this.data.get(s);return null!==e?n(e):t.defaultValue},set(e){void 0===e?this.data.delete(s):this.data.set(s,r(e))}},[`has${l(i)}`]:{get(){return this.data.has(s)||t.hasCustomDefaultValue}}}}(t)),s)},function(e){return I(e,"outlets").reduce((e,t)=>Object.assign(e,function(e){const t=c(e);return{[`${t}Outlet`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t){const s=Y(this,t,e);if(s)return s;throw new Error(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`)}throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}Outlets`]:{get(){const t=this.outlets.findAll(e);return t.length>0?t.map(t=>{const s=Y(this,t,e);if(s)return s;console.warn(`The provided outlet element is missing an outlet controller "${e}" instance for host controller "${this.identifier}"`,t)}).filter(e=>e):[]}},[`${t}OutletElement`]:{get(){const t=this.outlets.find(e),s=this.outlets.getSelectorForOutletName(e);if(t)return t;throw new Error(`Missing outlet element "${e}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${s}".`)}},[`${t}OutletElements`]:{get(){return this.outlets.findAll(e)}},[`has${l(t)}Outlet`]:{get(){return this.outlets.has(e)}}}}(t)),{})}],ne.targets=[],ne.outlets=[],ne.values={}},290(e,t,s){s.d(t,{default:()=>ci});var i=s(891);class n extends Error{constructor(e){super(`${e} is not valid. Please provide a valid event name`),this.name="InvalidEvent"}}class r{static events=["session-set","utm-set","forms:collected","form:completed","popup:mounted","popup:opened","popup:closed","alert:shown","alert:dismissed","alert:accepted","webchat:mounted","webchat:opened","webchat:closed","webchat:message:sent","webchat:message:received","cart.added"];static valid(e){return r.exists(e)}static invalid(e){return!this.valid(e)}static exists(e){return void 0!==this.events.find(t=>t===e)}constructor(){this.subscribers={}}addSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers={...this.subscribers,[e]:this.subscribers[e]?[...this.subscribers[e],t]:[t]}}removeSubscriber(e,t){if(r.invalid(e))throw new n(e);this.subscribers[e]&&(this.subscribers[e]=this.subscribers[e].filter(e=>e!==t))}dispatch(e,t){this.subscribers[e]?.forEach(e=>{e(t)})}get listeners(){return 0!==Object.keys(this.subscribers).length}}class o{static autoMount=!0;static successMessage=!0;static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static get shouldShowSuccessMessage(){return this.successMessage}}class a{static _identifier;static set identifier(e){this._identifier=e}static get identifier(){return this._identifier?this._identifier:this.#e||this.#t||this.#s||"en"}static toString(){return this.identifier}static get#e(){return"undefined"!=typeof document?document.documentElement?.lang:void 0}static get#t(){return"undefined"!=typeof document?document.querySelector('meta[name="locale"]')?.content:void 0}static get#s(){return"undefined"!=typeof navigator?navigator.language?.split("-")[0]:void 0}}class c{static _id;static _container="body";static _device="auto";static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set device(e){if(!["auto","mobile","desktop"].includes(e))throw new Error(`Invalid popup device value: ${e}`);this._device=e}static get device(){return this._device}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}}const l={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"},h={ABSOLUTE:"absolute",FIXED:"fixed"},u={MODAL:"modal",POPOVER:"popover"};class d{static _id;static _container="body";static _placement="bottom-right";static _style={};static _appearance={};static _whatsapp={};static _mode=u.POPOVER;static _behaviour=null;static _hasBehaviourOverride=!1;static _strategy=null;static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(l).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static set id(e){this._id=e}static get id(){return this._id}static get isSet(){return!!this._id}static get style(){return this._style}static set style(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(([e,t])=>{if(!["primaryColor","secondaryColor","typography"].includes(e))throw new Error(`Invalid style property: ${e}`);if("typography"!==e&&!this.isHexOrRgba(t))throw new Error(`Invalid color value: ${t} for ${e}. Colors must be hex or rgb/a.`)}),this._style=e}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if(!["header","launcher"].includes(e))throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("header"===e&&"name"!==t)throw new Error(`Invalid appearance header property: ${t}`);if("launcher"===e&&"iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get whatsapp(){return this._whatsapp}static set whatsapp(e){if(!this.isPlainObject(e))throw new Error("WhatsApp must be an object");Object.entries(e).forEach(([e,t])=>{if(!["number","restrictToChannel"].includes(e))throw new Error(`Invalid WhatsApp property: ${e}`);if(null!=t){if("number"===e&&"string"!=typeof t)throw new Error(`Invalid WhatsApp number value: ${t}`);if("restrictToChannel"===e&&"boolean"!=typeof t)throw new Error(`Invalid WhatsApp restrictToChannel value: ${t}`)}}),this._whatsapp=e}static get mode(){return this._mode}static set mode(e){if(!Object.values(u).includes(e))throw new Error(`Invalid mode value: ${e}`);this._mode=e}static get behaviour(){return this._behaviour}static set behaviour(e){if(null!=e){if("object"!=typeof e||Array.isArray(e))throw new Error(`Invalid behaviour value: ${e}`);this._behaviour=e}else this._behaviour=e}static get hasBehaviourOverride(){return this._hasBehaviourOverride}static set behaviourOverride(e){this._hasBehaviourOverride=!!e}static get strategy(){return this._strategy?this._strategy:"body"==this.container?h.FIXED:h.ABSOLUTE}static set strategy(e){if(e&&!Object.values(h).includes(e))throw new Error(`Invalid strategy value: ${e}`);this._strategy=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isHexOrRgba(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}const p={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right"};class m{static _id;static _container="body";static _placement="bottom-right";static _appearance={};static _number=null;static _body=null;static set id(e){this._id=e}static get id(){return this._id}static set container(e){this._container=e}static get container(){return this._container}static set placement(e){if(!Object.values(p).includes(e))throw new Error(`Invalid placement value: ${e}`);this._placement=e}static get placement(){return this._placement}static get appearance(){return this._appearance}static set appearance(e){if(!this.isPlainObject(e))throw new Error("Appearance must be an object");Object.entries(e).forEach(([e,t])=>{if("launcher"!==e)throw new Error(`Invalid appearance property: ${e}`);if(!this.isPlainObject(t))throw new Error(`Appearance ${e} must be an object`);Object.entries(t).forEach(([t,s])=>{if("iconUrl"!==t)throw new Error(`Invalid appearance launcher property: ${t}`);if(null!=s&&"string"!=typeof s)throw new Error(`Invalid appearance ${e}.${t} value: ${s}`)})}),this._appearance=e}static get number(){return this._number}static set number(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid number value: ${e}`);this._number=e}static get body(){return this._body}static set body(e){if(null!=e&&"string"!=typeof e)throw new Error(`Invalid body value: ${e}`);this._body=e}static assign(e){return e&&Object.entries(e).forEach(([e,t])=>{this[e]=t}),this}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}}class g{static serviceWorkerUrl=null;static channelId=null;static assign(e){return this.serviceWorkerUrl=e?.serviceWorkerUrl||null,this.channelId=e?.channelId||null,this}}class f{static apiRoot="https://api.hellotext.com/v1";static actionCableUrl="wss://www.hellotext.com/cable";static autoGenerateSession=!0;static session=null;static forms=o;static popup=c;static webchat=d;static whatsapp=m;static push=g;static assign(e){if(e){const t=Object.prototype.hasOwnProperty.call(e,"apiRoot")&&!Object.prototype.hasOwnProperty.call(e,"actionCableUrl");Object.entries(e).forEach(([e,t])=>{"forms"===e?this.forms=o.assign(t):"popup"===e?this.popup=c.assign(t):"webchat"===e?this.webchat=d.assign(t):"whatsappWidget"===e?this.whatsapp=m.assign(t):"push"===e?this.push=g.assign(t):this[e]=t}),t&&(this.actionCableUrl=this.actionCableUrlForApiRoot(this.apiRoot))}return this}static set locale(e){a.identifier=e}static get locale(){return a.toString()}static endpoint(e){return`${this.apiRoot}/${e}`}static actionCableUrlForApiRoot(e){try{const t=new URL(e),s="https:"===t.protocol?"wss:":"ws:";return t.protocol=s,t.pathname="/cable",t.search="",t.hash="",t.toString()}catch(e){return this.actionCableUrl}}}const b=class{static get endpoint(){return f.endpoint("public/businesses")}static async get(e){return fetch(`${this.endpoint}/${e}`,{method:"GET",headers:{Authorization:`Bearer ${e}`,Accept:"application/json","Content-Type":"application/json"}})}};class y{static get inPreviewMode(){return(new this).inPreviewMode}constructor(){this.urlSearchParams=new URLSearchParams(window.location.search)}get(e){return this.urlSearchParams.get(this.toHellotextParam(e))}has(e){return this.urlSearchParams.has(this.toHellotextParam(e))}get inPreviewMode(){return this.has("preview")}get session(){return this.get("session")}toHellotextParam(e){return`hello_${e}`}}class v{#i;constructor(e,t){this.response=t,this.#i=e}get data(){return this.response}async json(){return await this.response.json()}get failed(){return!1===this.#i}get succeeded(){return!0===this.#i}}class w{static get endpoint(){return f.endpoint("track/events")}static async create({headers:e,body:t,keepalive:s=!1}){if(y.inPreviewMode)return new v(!0,{received:!0});const i={method:"POST",headers:e,body:JSON.stringify(t)};s&&(i.keepalive=!0);const n=await fetch(this.endpoint,i);return new v(200===n.status,await n.json())}}class T{static get endpoint(){return f.endpoint("public/forms")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);return t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),fetch(t,{method:"GET",headers:vt.headers})}static async submit(e,t){const s=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...t})});return new v(s.ok,s)}}const S=class{static get endpoint(){return f.endpoint("public/identifications")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify({session:vt.session,...e})});return new v(t.ok,t)}},C=class{static get endpoint(){return f.endpoint("public/popups")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),t.searchParams.append("device",this.runtimeDevice);const s=await this.fetchPopup(t);if(!s.ok)return null;const i=await this.parsePopupResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static async submit(e,t,s=this.idempotencyKey()){const i=await fetch(`${this.endpoint}/${e}/submissions`,{method:"POST",headers:{...vt.headers,"Idempotency-Key":s},body:JSON.stringify({session:vt.session,popup_submission:t})});return new v(i.ok,i)}static async resend(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/resend`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static async cancel(e,t,s){const i=await fetch(`${this.endpoint}/${e}/submissions/${t}/cancel`,{method:"POST",headers:vt.headers,body:JSON.stringify({token:s})});return new v(i.ok,i)}static idempotencyKey(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}static async fetchPopup(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static get runtimeDevice(){return"auto"!==f.popup.device?f.popup.device:window.innerWidth<=767?"mobile":"desktop"}static async parsePopupResponse(e){try{return await e.json()}catch(e){return null}}},O=class{static get endpoint(){return f.endpoint("public/webchats")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("session",vt.session),t.searchParams.append("locale",a.toString()),Object.entries(f.webchat.style).forEach(([e,s])=>{t.searchParams.append(`style[${e}]`,s)}),this.appendWebchatOverrides(t),t.searchParams.append("placement",f.webchat.placement);const s=await fetch(t,{method:"GET",headers:vt.headers}),i=await s.json();return vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")}static appendWebchatOverrides(e){const{appearance:t,whatsapp:s}=f.webchat;this.appendIfSupplied(e,"webchat[appearance][header][name]",t.header?.name),this.appendIfSupplied(e,"webchat[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"webchat[handoff][identifier]",s.number),this.appendIfSupplied(e,"webchat[handoff][restrict_to_channel]",s.restrictToChannel)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}},E=class{static get endpoint(){return f.endpoint("public/widgets/whatsapp")}static async get(e){const t=new URL(`${this.endpoint}/${e}`);t.searchParams.append("locale",a.toString()),t.searchParams.append("placement",f.whatsapp.placement),this.appendWhatsAppOverrides(t);const s=await this.fetchWidget(t);if(!s.ok)return null;const i=await this.parseWidgetResponse(s);return i?(vt.business.data||(vt.business.setData(i.business),vt.business.setLocale(i.locale)),(new DOMParser).parseFromString(i.html,"text/html").querySelector("article")):null}static appendWhatsAppOverrides(e){const{appearance:t,body:s,number:i}=f.whatsapp;this.appendIfSupplied(e,"whatsapp[appearance][launcher][icon_url]",t.launcher?.iconUrl),this.appendIfSupplied(e,"whatsapp[number]",i),this.appendIfSupplied(e,"whatsapp[body]",s)}static appendIfSupplied(e,t,s){null!=s&&e.searchParams.append(t,String(s))}static async fetchWidget(e){try{return await fetch(e,{method:"GET",headers:vt.headers})}catch(e){return{ok:!1}}}static async parseWidgetResponse(e){try{return await e.json()}catch(e){return null}}},A=class{static get endpoint(){return f.endpoint("public/acks")}static async send(e={}){const t={...e,session:vt.session,at:(new Date).toISOString()};fetch(this.endpoint,{method:"POST",headers:vt.headers,body:JSON.stringify(t),keepalive:!0})}},x=class{static get endpoint(){return f.endpoint("public/push/identities")}static async create(e={}){const t=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}static async destroy(e={}){const t=await fetch(this.endpoint,{method:"DELETE",keepalive:!0,headers:vt.headers,body:JSON.stringify({...e,session:vt.session,origin:window.location.origin})});return new v(t.ok,t)}},M=class{static get endpoint(){return f.endpoint("public/push/alerts")}static async create({section:e,kind:t,page:s}){const i=await fetch(this.endpoint,{method:"POST",keepalive:!0,headers:vt.headers,body:JSON.stringify({session:vt.session,section:e,kind:t,page:s})});return new v(i.ok,i)}};function k(e){const t=JSON.stringify(e);return"undefined"==typeof Blob?t.length<6e4:new Blob([t]).size<6e4}class I{static get businesses(){return b}static get events(){return w}static get forms(){return T}static get popups(){return C}static get popups(){return C}static get webchats(){return O}static get whatsappWidgets(){return E}static get identifications(){return S}static get acks(){return A}static get pushAlerts(){return M}static get pushIdentities(){return x}}const L="data-hellotext-stylesheet";class P{constructor(e){this.id=e,this.data=null,this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1)}async hydrate(){try{const e=await b.get(this.id);if(!1===e.ok)return null;const t=await e.json();return t?(this.setData(t),this.setLocale(a.toString()),t):null}catch(e){return null}}setData(e){this.data=e,"undefined"!=typeof document&&e.style_url?(this.stylesheet=this.constructor.ensureStylesheet(e.style_url),this.stylesheetLoaded=this.constructor.waitForStylesheet(this.stylesheet)):(this.stylesheet=null,this.stylesheetLoaded=Promise.resolve(!1))}static get stylesheetSelector(){return`link[rel="stylesheet"][${L}]`}static ensureStylesheet(e){const t=this.normalizedStylesheetUrl(e),s=this.stylesheetLinks.find(e=>e.href===t);if(s)return s.setAttribute(L,"true"),s;const i=document.createElement("link");return i.rel="stylesheet",i.href=e,i.setAttribute(L,"true"),this.waitForStylesheet(i),document.head.append(i),i}static get stylesheetLinks(){return"undefined"==typeof document?[]:Array.from(document.querySelectorAll(this.stylesheetSelector))}static get latestStylesheet(){return this.stylesheetLinks[this.stylesheetLinks.length-1]}static normalizedStylesheetUrl(e){try{return new URL(e,document.baseURI).href}catch(t){return e}}static waitForStylesheet(e){return e?this.stylesheetIsLoaded(e)?Promise.resolve(!0):"false"===e.dataset.hellotextStylesheetLoaded?Promise.resolve(!1):(e._hellotextStylesheetLoaded||(e._hellotextStylesheetLoaded=new Promise(t=>{let s;const i=i=>{clearTimeout(s),e.removeEventListener("load",n),e.removeEventListener("error",r),e.dataset.hellotextStylesheetLoaded=i?"true":"false",t(i)},n=()=>i(this.stylesheetIsLoaded(e)),r=()=>i(!1);e.addEventListener("load",n),e.addEventListener("error",r),s=setTimeout(()=>i(this.stylesheetIsLoaded(e)),1e4),s.unref&&s.unref()})),e._hellotextStylesheetLoaded):Promise.resolve(!1)}static stylesheetIsLoaded(e){return"true"===e.dataset.hellotextStylesheetLoaded||!!e.sheet}get subscription(){return this.data.subscription}get country(){return this.data.country}get enabledWhitelist(){return"disabled"!==this.data.whitelist}setLocale(e){this.data||(this.data={});const t=e?.toLowerCase().split("-")[0];this.data.locale=Object.prototype.hasOwnProperty.call(this.data.locales||{},t)?t:"en"}get locale(){const e=this.data?.locales;return e?.[this.data.locale]||e?.en}get features(){return this.data.features}}class _{static set(e,t){if("undefined"!=typeof document){const s="https:"===window.location.protocol?"; Secure":"",i=D.getRootDomain(),n=31536e4;document.cookie=i?`${e}=${t}; path=/${s}; domain=${i}; max-age=${n}; SameSite=Lax`:`${e}=${t}; path=/${s}; max-age=${n}; SameSite=Lax`}return"hello_session"===e&&vt.eventEmitter.dispatch("session-set",t),"hello_utm"===e&&vt.eventEmitter.dispatch("utm-set",t),t}static get(e){return"undefined"!=typeof document?document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)")?.pop():void 0}static delete(e){if("undefined"!=typeof document){const t=D.getRootDomain(),s="https:"===window.location.protocol?"; Secure":"";document.cookie=t?`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; domain=${t}; SameSite=Lax`:`${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${s}; SameSite=Lax`}}}class N{constructor(){const e=new URLSearchParams(window.location.search),t={source:e.get("utm_source"),medium:e.get("utm_medium"),campaign:e.get("utm_campaign"),term:e.get("utm_term"),content:e.get("utm_content")};this.save(t)}save(e){if(!e.source||!e.medium)return;const t=Object.fromEntries(Object.entries(e).filter(([e,t])=>t));t.observed_at=(new Date).toISOString(),_.set("hello_utm",JSON.stringify(t))}get current(){try{return JSON.parse(_.get("hello_utm"))||{}}catch(e){return{}}}}class D{constructor(e=null){this.utm=new N,this._url=e}get url(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}get title(){return document.title}get path(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}get utmParams(){return this.utm.current}get trackingData(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}get domain(){try{const e=this.url;if(!e)return null;const t=new URL(e).hostname;return D.getRootDomain(t)}catch(e){return null}}static getRootDomain(e=null){try{if(!e){if("undefined"==typeof window||!window.location?.hostname)return null;e=window.location.hostname}const t=e.split(".");if(t.length<=1)return e;const s=["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"];for(const e of s){const s=e.split(".");if(t.slice(-s.length).join(".")===e&&t.length>s.length)return`.${t.slice(-(s.length+1)).join(".")}`}const i=t[t.length-1],n=t[t.length-2];return t.length>2&&2===i.length&&n.length<=3?`.${t.slice(-3).join(".")}`:`.${t.slice(-2).join(".")}`}catch(e){return null}}}class F{static#n;static#r;static#o;static get session(){return this.#n}static get ackPayload(){return{utm_params:this.#o?.utmParams||{}}}static set session(e){const t=_.get("hello_session");return this.#n=e,_.set("hello_session",e),t!==e&&_.delete("hello_session_ack_at"),_.get("hello_session_ack_at")||(I.acks.send(this.ackPayload),_.set("hello_session_ack_at",(new Date).toISOString())),this.#n}static initialize(e=new D){this.#o=e,this.#r=new y,this.session=this.#r.session||f.session||_.get("hello_session"),!this.session&&f.autoGenerateSession&&(this.session=crypto.randomUUID())}}class R{static build(e){const t=document.createElement("article"),s=document.createElement("label"),i=document.createElement("input");s.innerText=e.label,i.type=e.type,i.required=e.required,i.placeholder=e.placeholder,["first_name","last_name"].includes(e.kind)?(i.type="text",i.id=i.name=e.kind,s.setAttribute("for",e.kind)):(i.type=e.type,"email"===e.type?(i.id=i.name="email",s.setAttribute("for","email")):"tel"===i.type?(i.id=i.name="phone",s.setAttribute("for","phone"),i.value=`+${vt.business.country.prefix}`,i.setAttribute("data-default-value",`+${vt.business.country.prefix}`)):(i.name=i.id=`property_by_id[${e.property}]`,s.setAttribute("for",`property_by_id[${e.property}]`)));const n=document.createElement("main");n.appendChild(s),n.appendChild(i),t.appendChild(n),t.setAttribute("data-hellotext--form-target","inputContainer"),i.setAttribute("data-hellotext--form-target","input");const r=document.createElement("div");return r.setAttribute("data-error-container",""),t.appendChild(r),t}}class B{static build(){const e=document.createElement("div");return e.innerHTML=this.#a(),e.firstElementChild}static#a(){const e=`https://www.hellotext.com?hello_session=${vt.session}`;return`\n
\n ${vt.business.locale.white_label.powered_by}\n\n \n \n Hellotext\n \n \n \n
\n `}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var s=0,i=Array(t);s2?s-2:0),n=2;n1?t-1:0),i=1;i1?s-1:0),n=1;n2&&void 0!==arguments[2]?arguments[2]:ne;if(q&&q(e,null),!ie(t))return e;let i=t.length;for(;i--;){let n=t[i];if("string"==typeof n){const e=s(n);e!==n&&(U(t)||(t[i]=e),n=e)}e[n]=!0}return e}function Te(e){for(let t=0;t/g),Re=H(/\${[\w\W]*/g),Be=H(/^data-[\-\w.\u00B7-\uFFFF]+$/),$e=H(/^aria-[\-\w]+$/),je=H(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Ve=H(/^(?:\w+script|data):/i),qe=H(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ue=H(/^html$/i),ze=H(/^[a-z][.\w]*(-[.\w]+)+$/i),We=H(/<[/\w!]/g),Ke=H(/<[/\w]/g),He=H(/<\/no(script|embed|frames)/i),Ge=H(/\/>/i),Je=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"],Ye=K(we({},Je)),Ze=function(){const e={};return X(Je,t=>{e[t]=H(new RegExp("])","i"))}),K(e)}(),Xe=function(){return"undefined"==typeof window?null:window},Qe=function(e,t,s,i){return me(e,t)&&ie(e[t])?we(i.base?Se(i.base):{},e[t],i.transform):s},et=function(e,t,s){const i=me(e,t)?e[t]:void 0;return i&&"object"==typeof i?Se(i):s()};var tt=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Xe();const s=t=>e(t);if(s.version="3.4.15",s.removed=[],!t||!t.document||9!==t.document.nodeType||!t.Element)return s.isSupported=!1,s;let i=t.document;const n=i,r=n.currentScript;t.DocumentFragment;const o=t.HTMLTemplateElement,a=t.Node,c=t.Element,l=t.NodeFilter;void 0===t.NamedNodeMap&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;const h=t.DOMParser,u=t.trustedTypes,d=c.prototype,p=Ce(d,"cloneNode"),m=Ce(d,"remove"),g=Ce(d,"removeAttributeNode"),f=Ce(d,"nextSibling"),b=Ce(d,"childNodes"),y=Ce(d,"parentNode"),v=Ce(d,"shadowRoot"),w=Ce(d,"attributes"),T=a&&a.prototype?Ce(a.prototype,"nodeType"):null,S=a&&a.prototype?Ce(a.prototype,"nodeName"):null,C=a&&a.prototype?Ce(a.prototype,"ownerDocument"):null,O=function(e){return T?T(e):e.nodeType},E=function(e){return S?S(e):e.nodeName};if("function"==typeof o){const e=i.createElement("template");e.content&&e.content.ownerDocument&&(i=e.content.ownerDocument)}let A,x,M="",k=!1,I=0;const L=function(){if(I>0)throw be('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},P=function(e){L(),I++;try{return A.createHTML(e)}finally{I--}},_=i,N=_.implementation,D=_.createNodeIterator,F=_.createDocumentFragment,R=_.getElementsByTagName,B=n.importNode;let $={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};s.isSupported="function"==typeof V&&"function"==typeof y&&N&&void 0!==N.createHTMLDocument;const j=De,q=Fe,U=Re,z=Be,W=$e,J=Ve,Y=qe,Z=ze;let ye=je,ve=null;const Te=we({},[...Oe,...Ee,...Ae,...Me,...Ie]);let Je=null;const tt=we({},[...Le,...Pe,..._e,...Ne]);let st=Object.seal(G(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),it=null,nt=null;const rt=Object.seal(G(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let ot=!0,at=!0,ct=!1,lt=!0,ht=!1,ut=!0,dt=!1,pt=!1,mt=null,gt=null,ft=!1,bt=!1,yt=!1,vt=!1,wt=!0,Tt=!1;const St="user-content-";let Ct=!0,Ot=!1,Et={},At=null;const xt=we({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let Mt=null;const kt=we({},["audio","video","img","source","image","track"]);let It=null;const Lt=we({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Pt="http://www.w3.org/1998/Math/MathML",_t="http://www.w3.org/2000/svg",Nt="http://www.w3.org/1999/xhtml";let Dt=Nt,Ft=!1,Rt=null;const Bt=we({},[Pt,_t,Nt],re),$t=K(["mi","mo","mn","ms","mtext"]);let jt=we({},$t);const Vt=K(["annotation-xml"]);let qt=we({},Vt);const Ut=we({},["title","style","font","a","script"]);let zt=null;const Wt=["application/xhtml+xml","text/html"];let Kt=null,Ht=null;const Gt=i.createElement("form"),Jt=function(e){return e instanceof RegExp||e instanceof Function},Yt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(Ht&&Ht===e)return;e&&"object"==typeof e||(e={}),e=Se(e),zt=-1===Wt.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,Kt="application/xhtml+xml"===zt?re:ne,ve=Qe(e,"ALLOWED_TAGS",Te,{transform:Kt}),Je=Qe(e,"ALLOWED_ATTR",tt,{transform:Kt}),Rt=Qe(e,"ALLOWED_NAMESPACES",Bt,{transform:re}),It=Qe(e,"ADD_URI_SAFE_ATTR",Lt,{transform:Kt,base:Lt}),Mt=Qe(e,"ADD_DATA_URI_TAGS",kt,{transform:Kt,base:kt}),At=Qe(e,"FORBID_CONTENTS",xt,{transform:Kt}),it=Qe(e,"FORBID_TAGS",Se({}),{transform:Kt}),nt=Qe(e,"FORBID_ATTR",Se({}),{transform:Kt}),Et=!!me(e,"USE_PROFILES")&&(e.USE_PROFILES&&"object"==typeof e.USE_PROFILES?Se(e.USE_PROFILES):e.USE_PROFILES),ot=!1!==e.ALLOW_ARIA_ATTR,at=!1!==e.ALLOW_DATA_ATTR,ct=e.ALLOW_UNKNOWN_PROTOCOLS||!1,lt=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,ht=e.SAFE_FOR_TEMPLATES||!1,ut=!1!==e.SAFE_FOR_XML,dt=e.WHOLE_DOCUMENT||!1,bt=e.RETURN_DOM||!1,yt=e.RETURN_DOM_FRAGMENT||!1,vt=e.RETURN_TRUSTED_TYPE||!1,ft=e.FORCE_BODY||!1,wt=!1!==e.SANITIZE_DOM,Tt=e.SANITIZE_NAMED_PROPS||!1,Ct=!1!==e.KEEP_CONTENT,Ot=e.IN_PLACE||!1,ye=function(e){try{return fe(e,""),!0}catch(e){return!1}}(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:je,Dt="string"==typeof e.NAMESPACE?e.NAMESPACE:Nt,jt=et(e,"MATHML_TEXT_INTEGRATION_POINTS",()=>we({},$t)),qt=et(e,"HTML_INTEGRATION_POINTS",()=>we({},Vt));const t=et(e,"CUSTOM_ELEMENT_HANDLING",()=>G(null));if(st=G(null),me(t,"tagNameCheck")&&Jt(t.tagNameCheck)&&(st.tagNameCheck=t.tagNameCheck),me(t,"attributeNameCheck")&&Jt(t.attributeNameCheck)&&(st.attributeNameCheck=t.attributeNameCheck),me(t,"allowCustomizedBuiltInElements")&&"boolean"==typeof t.allowCustomizedBuiltInElements&&(st.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),H(st),ht&&(at=!1),yt&&(bt=!0),Et&&(ve=we({},Ie),Je=G(null),!0===Et.html&&(we(ve,Oe),we(Je,Le)),!0===Et.svg&&(we(ve,Ee),we(Je,Pe),we(Je,Ne)),!0===Et.svgFilters&&(we(ve,Ae),we(Je,Pe),we(Je,Ne)),!0===Et.mathMl&&(we(ve,Me),we(Je,_e),we(Je,Ne))),rt.tagCheck=null,rt.attributeCheck=null,me(e,"ADD_TAGS")&&("function"==typeof e.ADD_TAGS?rt.tagCheck=e.ADD_TAGS:ie(e.ADD_TAGS)&&(ve===Te&&(ve=Se(ve)),we(ve,e.ADD_TAGS,Kt))),me(e,"ADD_ATTR")&&("function"==typeof e.ADD_ATTR?rt.attributeCheck=e.ADD_ATTR:ie(e.ADD_ATTR)&&(Je===tt&&(Je=Se(Je)),we(Je,e.ADD_ATTR,Kt))),me(e,"ADD_FORBID_CONTENTS")&&ie(e.ADD_FORBID_CONTENTS)&&(At===xt&&(At=Se(At)),we(At,e.ADD_FORBID_CONTENTS,Kt)),Ct&&(ve["#text"]=!0),dt&&we(ve,["html","head","body"]),ve.table&&(we(ve,["tbody"]),delete it.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw be('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const t=A;A=e.TRUSTED_TYPES_POLICY;try{M=P("")}catch(e){throw A=t,e}}else null===e.TRUSTED_TYPES_POLICY?(A=void 0,M=""):(void 0===A&&(k||(x=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let s=null;const i="data-tt-policy-suffix";t&&t.hasAttribute(i)&&(s=t.getAttribute(i));const n="dompurify"+(s?"#"+s:"");try{return e.createPolicy(n,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+n+" could not be created."),null}}(u,r),k=!0),A=x),A&&"string"==typeof M&&(M=P("")));K&&K(e),Ht=e},Zt=we({},[...Ee,...Ae,...xe]),Xt=we({},[...Me,...ke]),Qt=function(e){te(s.removed,{element:e});try{y(e).removeChild(e)}catch(t){if(m(e),!y(e))throw be("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},es=function(e,t,s){try{g(e,t)}catch(t){try{e.removeAttribute(s)}catch(e){}}},ts=function(e){ns(e);const t=b(e);if(t){const e=[];X(t,t=>{te(e,t)}),X(e,e=>{try{m(e)}catch(e){}})}const s=w(e);if(s)for(let t=s.length-1;t>=0;--t){const i=s[t],n=i&&i.name;"string"==typeof n&&es(e,i,n)}},ss=function(e,t,i){if(!i)try{i=t.getAttributeNode(e)}catch(e){i=null}te(s.removed,{attribute:i||null,from:t});try{i?g(t,i):t.removeAttribute(e)}catch(s){try{t.removeAttribute(e)}catch(e){}}if("is"===e)if(bt||yt)try{Qt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},is=function(e){const t=w(e);if(t)for(let s=t.length-1;s>=0;--s){const i=t[s],n=i&&i.name;"string"!=typeof n||Je[Kt(n)]||es(e,i,n)}},ns=function(e){const t=[e];for(;t.length>0;){const e=t.pop();1===O(e)&&is(e);const s=b(e);if(s)for(let e=s.length-1;e>=0;--e)t.push(s[e])}},rs=function(e,t){return!!ut&&("patchsrc"===e||"for"===e&&"label"!==t&&"output"!==t)},os=function(e){let t=null,s=null;if(ft)e=""+e;else{const t=oe(e,/^[\r\n\t ]+/);s=t&&t[0]}"application/xhtml+xml"===zt&&Dt===Nt&&(e=''+e+"");const n=A?P(e):e;if(Dt===Nt)try{t=(new h).parseFromString(n,zt)}catch(e){}if(!t||!t.documentElement){t=N.createDocument(Dt,"template",null);try{t.documentElement.innerHTML=Ft?M:n}catch(e){}}const r=t.body||t.documentElement;return e&&s&&r.insertBefore(i.createTextNode(s),r.childNodes[0]||null),Dt===Nt?R.call(t,dt?"html":"body")[0]:dt?t.documentElement:r},as=function(e){const t=C?C(e):e.ownerDocument;return D.call(t||e,e,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},cs=function(e){return e=ae(e,j," "),e=ae(e,q," "),ae(e,U," ")},ls=function(e){var t;e.normalize();const s=C?C(e):e.ownerDocument,i=D.call(s||e,e,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null);let n=i.nextNode();for(;n;)n.data=cs(n.data),n=i.nextNode();const r=null===(t=e.querySelectorAll)||void 0===t?void 0:t.call(e,"template");r&&X(r,e=>{us(e.content)&&ls(e.content)})},hs=function(e){const t=S?S(e):null;return"string"==typeof t&&"form"===Kt(t)&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||e.attributes!==w(e)||"function"!=typeof e.removeAttribute||"function"!=typeof e.removeAttributeNode||"function"!=typeof e.getAttributeNode||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes||e.nodeType!==T(e)||e.childNodes!==b(e))},us=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return 11===T(e)}catch(e){return!1}},ds=function(e){if(!T||"object"!=typeof e||null===e)return!1;try{return"number"==typeof T(e)}catch(e){return!1}};function ps(e,t,i){0!==e.length&&X(e,e=>{e.call(s,t,i,Ht)})}const ms=function(e,t){if(e instanceof RegExp)return fe(e,t);if(e instanceof Function){for(var s=arguments.length,i=new Array(s>2?s-2:0),n=2;n=0;--n){const r=e===s?p(i[n],!0):i[n];t.insertBefore(r,f(e))}}return Qt(e),!0}(e,i,t);return!1===s&&ps($.afterSanitizeElements,e,null),s}if(1===O(e)&&!function(e){let t=y(e);t&&t.tagName||(t={namespaceURI:Dt,tagName:"template"});const s=ne(e.tagName),i=ne(t.tagName);return!!Rt[e.namespaceURI]&&(e.namespaceURI===_t?function(e,t,s){return t.namespaceURI===Nt?"svg"===e:t.namespaceURI===Pt?"svg"===e&&("annotation-xml"===s||jt[s]):Boolean(Zt[e])}(s,t,i):e.namespaceURI===Pt?function(e,t,s){return t.namespaceURI===Nt?"math"===e:t.namespaceURI===_t?"math"===e&&qt[s]:Boolean(Xt[e])}(s,t,i):e.namespaceURI===Nt?function(e,t,s){return!(t.namespaceURI===_t&&!qt[s])&&!(t.namespaceURI===Pt&&!jt[s])&&!Xt[e]&&(Ut[e]||!Zt[e])}(s,t,i):!("application/xhtml+xml"!==zt||!Rt[e.namespaceURI]))}(e))return Qt(e),!0;if(("noscript"===i||"noembed"===i||"noframes"===i)&&fe(He,e.innerHTML))return Qt(e),!0;if(ht&&3===e.nodeType){const t=cs(e.textContent);e.textContent!==t&&(te(s.removed,{element:e.cloneNode()}),e.textContent=t)}return ps($.afterSanitizeElements,e,null),!1},ys=function(e,t,s){if(nt[t])return!1;if(rs(t,e))return!1;if(wt&&("id"===t||"name"===t)&&(s in i||s in Gt))return!1;const n=Je[t]||rt.attributeCheck instanceof Function&&rt.attributeCheck(t,e);return!(!at||!fe(z,t))||!(!ot||!fe(W,t))||(n?!(!It[t]&&!fe(ye,ae(s,Y,""))&&("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==ce(s,"data:")||!Mt[e])&&(!ct||fe(J,ae(s,Y,"")))&&s):ws(e)&&ms(st.tagNameCheck,e)&&ms(st.attributeNameCheck,t,e)||"is"===t&&st.allowCustomizedBuiltInElements&&ms(st.tagNameCheck,s))},vs=we({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),ws=function(e){return!vs[ne(e)]&&fe(Z,e)},Ts=function(e,t,s,i){if(A&&"object"==typeof u&&"function"==typeof u.getAttributeType&&!s)switch(u.getAttributeType(e,t)){case"TrustedHTML":return P(i);case"TrustedScriptURL":return function(e){L(),I++;try{return A.createScriptURL(e)}finally{I--}}(i)}return i},Ss=function(e,t,s,i){try{return s?e.setAttributeNS(s,t,i):e.setAttribute(t,i),!hs(e)||(Qt(e),!1)}catch(s){return ss(t,e),!1}},Cs=function(e){ps($.beforeSanitizeAttributes,e,null);const t=e.attributes;if(!t||hs(e))return;Je=gs($.uponSanitizeAttribute,Je,tt,gt);const i={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Je,forceKeepAttr:void 0};let n=t.length;const r=Kt(e.nodeName);for(;n--;){const o=t[n],a=o.name,c=o.namespaceURI,l=o.value,h=Kt(a),u=l;let d="value"===a?u:le(u),p=!1;i.attrName=h,i.attrValue=d,i.keepAttr=!0,i.forceKeepAttr=void 0,ps($.uponSanitizeAttribute,e,i),d=i.attrValue,!Tt||"id"!==h&&"name"!==h||0===ce(d,St)||(ss(a,e,o),d=St+d,p=!0),ut&&fe(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)||"attributename"===h&&oe(d,"href")?ss(a,e,o):i.forceKeepAttr||(i.keepAttr&&(lt||!fe(Ge,d))?(ht&&(d=cs(d)),ys(r,h,d)?(d=Ts(r,h,c,d),d!==u&&Ss(e,a,c,d)&&p&&ee(s.removed)):ss(a,e,o)):ss(a,e,o))}ps($.afterSanitizeAttributes,e,null)},Os=function(e){let t=null;const s=as(e);for(ps($.beforeSanitizeShadowDOM,e,null);t=s.nextNode();)if(ps($.uponSanitizeShadowNode,t,null),bs(t,e),Cs(t),us(t.content)&&Os(t.content),1===O(t)){const e=v(t);us(e)&&(Es(e),Os(e))}ps($.afterSanitizeShadowDOM,e,null)},Es=function(e){const t=[{node:e,shadow:null}];for(;t.length>0;){const e=t.pop();if(e.shadow){Os(e.shadow);continue}const s=e.node,i=1===O(s),n=b(s);if(n)for(let e=n.length-1;e>=0;--e)t.push({node:n[e],shadow:null});if(i){const e=S?S(s):null;if("string"==typeof e&&"template"===Kt(e)){const e=s.content;us(e)&&t.push({node:e,shadow:null})}}if(i){const e=v(s);us(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return s.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=null,r=null,o=null,a=null;if(Ft=!e,Ft&&(e="\x3c!--\x3e"),"string"!=typeof e&&!ds(e)&&"string"!=typeof(e=function(e){switch(typeof e){case"string":return e;case"number":return he(e);case"boolean":return ue(e);case"bigint":return de?de(e):"0";case"symbol":return pe?pe(e):"Symbol()";case"undefined":default:return ge(e);case"function":case"object":{if(null===e)return ge(e);const t=e,s=Ce(t,"toString");if("function"==typeof s){const e=s(t);return"string"==typeof e?e:ge(e)}return ge(e)}}}(e)))throw be("dirty is not a string, aborting");if(!s.isSupported)return e;pt?(ve=mt,Je=gt):Yt(t),($.uponSanitizeElement.length>0||$.uponSanitizeAttribute.length>0)&&(ve=Se(ve)),$.uponSanitizeAttribute.length>0&&(Je=Se(Je)),s.removed=[];const c=Ot&&"string"!=typeof e&&ds(e);if(c){!function(e){if(!ut)return;const t=[e];for(;t.length>0;){const e=t.pop(),s=O(e);if(7===s||8===s&&fe(Ke,e.data)){try{m(e)}catch(e){}continue}if(1===s){const t=e,s=Kt(E(e));try{t.hasAttribute&&t.hasAttribute("patchsrc")&&t.removeAttribute("patchsrc"),t.hasAttribute&&t.hasAttribute("for")&&rs("for",s)&&t.removeAttribute("for")}catch(e){}}const i=b(e);if(i)for(let e=i.length-1;e>=0;--e)t.push(i[e])}}(e);const t=E(e);if("string"==typeof t){const s=Kt(t);if(!ve[s]||it[s])throw ts(e),be("root node is forbidden and cannot be sanitized in-place")}if(hs(e))throw ts(e),be("root node is clobbered and cannot be sanitized in-place");try{Es(e)}catch(t){throw ts(e),t}}else if(ds(e))i=os("\x3c!----\x3e"),r=i.ownerDocument.importNode(e,!0),1===r.nodeType&&"BODY"===r.nodeName||"HTML"===r.nodeName?i=r:i.appendChild(r),Es(i);else{if(!bt&&!ht&&!dt&&-1===e.indexOf("<"))return A&&vt?P(e):e;if(i=os(e),!i)return bt?null:vt?M:""}i&&ft&&Qt(i.firstChild);const l=c?e:i;try{const e=as(l);for(;o=e.nextNode();)bs(o,l),Cs(o),us(o.content)&&Os(o.content)}catch(t){throw c&&(ts(e),X(s.removed,e=>{e.element&&ns(e.element)})),t}if(c)return X(s.removed,e=>{e.element&&ns(e.element)}),ht&&ls(e),e;if(bt){if(ht&&ls(i),yt)for(a=F.call(i.ownerDocument);i.firstChild;)a.appendChild(i.firstChild);else a=i;return(Je.shadowroot||Je.shadowrootmode)&&(a=B.call(n,a,!0)),a}let h=dt?i.outerHTML:i.innerHTML;return dt&&ve["!doctype"]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&fe(Ue,i.ownerDocument.doctype.name)&&(h="\n"+h),ht&&(h=cs(h)),A&&vt?P(h):h},s.setConfig=function(){Yt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),pt=!0,mt=ve,gt=Je},s.clearConfig=function(){Ht=null,pt=!1,mt=null,gt=null,A=x,M=""},s.isValidAttribute=function(e,t,s){Ht||Yt({});const i=Kt(e),n=Kt(t);return ys(i,n,s)},s.addHook=function(e,t){"function"==typeof t&&me($,e)&&te($[e],t)},s.removeHook=function(e,t){if(me($,e)){if(void 0!==t){const s=Q($[e],t);return-1===s?void 0:se($[e],s,1)[0]}return ee($[e])}},s.removeHooks=function(e){me($,e)&&($[e]=[])},s.removeAllHooks=function(){$={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},s}();const st={ADD_ATTR:["target"],ALLOW_DATA_ATTR:!1,RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0}},it={ADD_ATTR:["target"],ADD_TAGS:["hellotext-icon"],RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0,svg:!0}};function nt(e,t){const s=tt.sanitize(e,t);return s.querySelectorAll('a[target="_blank"]').forEach(e=>{const t=new Set(e.rel.split(/\s+/).filter(Boolean));t.add("noopener"),t.add("noreferrer"),e.rel=Array.from(t).join(" ")}),s}function rt(e,t){e.replaceChildren(function(e){return nt(e,st)}(t))}class ot{constructor(e,t=null){this.data=e,this.element=t||document.querySelector(`[data-hello-form="${this.id}"]`)||document.createElement("form")}async mount({ifCompleted:e=!0}={}){if(e&&this.hasBeenCompleted)return this.element?.remove(),vt.eventEmitter.dispatch("form:completed",{id:this.id,...JSON.parse(localStorage.getItem(`hello-form-${this.id}`))});const t=this.data.steps[0];this.buildHeader(t.header),this.buildInputs(t.inputs),this.buildButton(t.button),this.buildFooter(t.footer),this.elementAttributes.forEach(e=>{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),vt.business.features.white_label||this.element.prepend(B.build())}buildHeader(e){const t=this.#c("[data-form-header]","header");rt(t,e.content),this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}buildInputs(e){const t=this.#c("[data-form-inputs]","main");e.map(e=>R.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}buildButton(e){const t=this.#c("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}buildFooter(e){const t=this.#c("[data-form-footer]","footer");rt(t,e.content),this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}markAsCompleted(e){const t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem(`hello-form-${this.id}`,JSON.stringify(t)),vt.eventEmitter.dispatch("form:completed",t)}get hasBeenCompleted(){return null!==localStorage.getItem(`hello-form-${this.id}`)}get id(){return this.data.id}get localeAuthKey(){const e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}get elementAttributes(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}#c(e,t){const s=this.element.querySelector(e);if(s)return s.cloneNode(!0);const i=document.createElement(t);return i.setAttribute(e.replace("[","").replace("]",""),""),i}}class at extends Error{constructor(){super("You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id"),this.name="NotInitializedError"}}class ct{constructor(){this.forms=[],this.includes=this.includes.bind(this),this.excludes=this.excludes.bind(this),this.add=this.add.bind(this),"undefined"!=typeof MutationObserver&&(this.mutationObserver=new MutationObserver(this.formMutationObserver.bind(this)),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0}))}collectExistingFormsOnPage(){Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}formMutationObserver(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}async collect(){if(vt.notInitialized)throw new at;if(this.fetching)return;if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");const e=this.#l;if(0===e.length)return;const t=e.map(e=>T.get(e).then(e=>e.json()));this.fetching=!0,await Promise.all(t).then(e=>e.forEach(this.add)).then(()=>vt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),f.forms.autoMount&&this.forms.forEach(e=>e.mount())}forEach(e){this.forms.forEach(e)}map(e){return this.forms.map(e)}add(e){this.includes(e.id)||(vt.business.data||(vt.business.setData(e.business),vt.business.setLocale(a.toString())),vt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new ot(e)))}getById(e){return this.forms.find(t=>t.id===e)}getByIndex(e){return this.forms[e]}includes(e){return this.forms.some(t=>t.id===e)}excludes(e){return!this.includes(e)}get length(){return this.forms.length}get#l(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}}class lt{constructor(e){this.publicKey=e.public_key,this.serviceWorkerUrl=f.push.serviceWorkerUrl,this.channelId=f.push.channelId,this.ready=null,this.registrationPromise=null,this.subscribePromise=null,this.unsubscribePromise=null,this.syncPromise=null,this.subscription=null,this.retryTimeout=null,this.retryAttempts=0,this.disposed=!1}initialize(){return this.ready=this.restoreSubscription(),this.ready}async restoreSubscription(){const e=await this.getRegistration(),t=await e.pushManager.getSubscription();!this.disposed&&!this.unsubscribePromise&&t&&this.owns(t)&&(this.subscription=t,await this.sync())}subscribe(){if(this.disposed)return Promise.resolve();if(this.unsubscribePromise)return Promise.reject(new Error("Push unsubscribe is in progress"));if(this.subscribePromise)return this.subscribePromise;const e="default"===Notification.permission?Notification.requestPermission():Promise.resolve(Notification.permission);return this.subscribePromise=this.createSubscription(e).finally(()=>{this.subscribePromise=null}),this.subscribePromise}async createSubscription(e){if("granted"!==await e)throw new Error("Push permission was not granted");const t=await this.getRegistration();if(this.disposed)return;let s=await t.pushManager.getSubscription();if(!this.disposed){if(s&&!this.owns(s))throw new Error("The existing Push subscription belongs to a different application");if(s||=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:this.applicationServerKey}),!this.disposed)return this.subscription=s,this.sync()}}unsubscribe(){return this.disposed?Promise.resolve():(this.unsubscribePromise||(this.clearRetryTimeout(),this.unsubscribePromise=this.removeSubscription().finally(()=>{this.unsubscribePromise=null})),this.unsubscribePromise)}async removeSubscription(){await(this.ready?.catch(()=>{})),await(this.subscribePromise?.catch(()=>{})),await(this.syncPromise?.catch(()=>{}));const e=await this.getRegistration(),t=await e.pushManager.getSubscription()||this.subscription;if(this.disposed)return;if(!t)return null;if(!this.owns(t))throw new Error("The existing Push subscription belongs to a different application");this.subscription=t;const s=await I.pushIdentities.destroy({subscription:t.toJSON()});return s.failed?s:this.disposed?void 0:(await t.unsubscribe(),this.subscription=null,this.clearRetryTimeout(),s)}sync(){return this.disposed?Promise.resolve():(this.syncPromise||(this.clearRetryTimeout(),this.syncPromise=this.registerIdentity().finally(()=>{this.syncPromise=null})),this.syncPromise)}async registerIdentity(){try{const e=await I.pushIdentities.create({subscription:this.subscription.toJSON(),...this.channelId?{channel_id:this.channelId}:{}});return e.succeeded?this.retryAttempts=0:this.scheduleRetry(),e}catch(e){throw this.scheduleRetry(),e}}scheduleRetry(){this.disposed||this.unsubscribePromise||this.retryTimeout||this.retryAttempts>=3||(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.sync().catch(()=>{})},1e3*2**this.retryAttempts),this.retryAttempts+=1)}clearRetryTimeout(){clearTimeout(this.retryTimeout),this.retryTimeout=null}dispose(){this.disposed=!0,this.clearRetryTimeout()}get subscribed(){return!!this.subscription}get applicationServerKey(){const e=this.publicKey.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e.padEnd(4*Math.ceil(e.length/4),"=")),e=>e.charCodeAt(0))}owns(e){const t=e.options?.applicationServerKey;if(!t)return!1;const s=new Uint8Array(t),i=this.applicationServerKey;return s.length===i.length&&s.every((e,t)=>e===i[t])}getRegistration(){return this.registrationPromise||(this.registrationPromise=this.loadRegistration().catch(e=>{throw this.registrationPromise=null,e})),this.registrationPromise}async loadRegistration(){if(this.serviceWorkerUrl){const e=await navigator.serviceWorker.register(this.serviceWorkerUrl);!e.active||e.installing||e.waiting||await e.update();const t=e.installing||e.waiting||e.active;return"activated"===t?.state?e:new Promise((s,i)=>{const n=setTimeout(()=>r(new Error("Push service worker did not become active")),1e4),r=r=>{clearTimeout(n),t?.removeEventListener("statechange",o),r?i(r):s(e)},o=()=>{"activated"===t?.state&&r(),"redundant"===t?.state&&r(new Error("Push service worker installation failed"))};t?.addEventListener("statechange",o),o()})}return new Promise((e,t)=>{const s=setTimeout(()=>t(new Error("Push service worker is not available")),1e4);navigator.serviceWorker.ready.then(t=>{clearTimeout(s),e(t)},e=>{clearTimeout(s),t(e)})})}static get supported(){return"undefined"!=typeof window&&!0===window.isSecureContext&&"undefined"!=typeof navigator&&"serviceWorker"in navigator&&"undefined"!=typeof PushManager&&"undefined"!=typeof Notification}}class ht{constructor(e,t,s){this.business=t,this.push=s,this.disposed=!1,this.showRequest=0,this.controller=null,this.element=(new DOMParser).parseFromString(e.html,"text/html").querySelector('[data-controller~="hellotext--alert"]'),this.connected=new Promise(e=>{this.resolveConnected=e}),this.onConnect=this.onConnect.bind(this),this.ready=this.render()}onConnect(e){this.controller=e.detail.controller,this.controller.alert=this,this.resolveConnected(!0)}async render(){return!!this.element&&(this.element.addEventListener("hellotext--alert:connected",this.onConnect),!(!await this.business.stylesheetLoaded||this.disposed)&&(document.body.appendChild(this.element),this.connected))}async show(e,t={}){const s=++this.showRequest;return!(!await this.ready||this.disposed||s!==this.showRequest)&&this.controller.show(e,t)}hide(){this.showRequest+=1,this.controller?.close()}dispose(){this.disposed=!0,this.hide(),this.resolveConnected(!1),this.element?.removeEventListener("hellotext--alert:connected",this.onConnect),this.element?.remove()}}class ut{static async load(e){const t=new ut({id:e,html:await I.webchats.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){return this.applyBehaviourOverride(),await this.stylesheetLoaded?(this.containerToAppendTo.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext webchat was not mounted because its stylesheet failed to load."),!1)}applyBehaviourOverride(){f.webchat.hasBehaviourOverride&&f.webchat.behaviour&&this.data.html.setAttribute("data-hellotext--webchat-behaviour-value",JSON.stringify(this.serializedBehaviour))}get serializedBehaviour(){const e=f.webchat.behaviour;return{trigger:this.serializeTrigger(e.trigger),delay_seconds:e.delaySeconds,first_visit_only:e.firstVisitOnly,once_per_session:e.oncePerSession}}serializeTrigger(e){return"onLoad"===e?"on_load":"onClick"===e?"on_click":e}get containerToAppendTo(){return document.querySelector(f.webchat.container)}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=this.data.html,t=document.querySelector(".hellotext--whatsapp-widget");e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class dt{static async load(e){const t=new dt({id:e,html:await I.whatsappWidgets.get(e)});return t.rendered=t.render(),t}constructor(e){this.data=e,this.mounted=!1,this.rendered=Promise.resolve(!1)}async render(){if(!this.data.html)return!1;const e=this.containerToAppendTo;return e?await this.stylesheetLoaded?(e.appendChild(this.data.html),this.markCoexistingWidgets(),this.mounted=!0,!0):(console.warn("Hellotext WhatsApp widget was not mounted because its stylesheet failed to load."),!1):(console.warn(`Hellotext WhatsApp widget was not mounted because the container ${f.whatsapp.container} was not found.`),!1)}get containerToAppendTo(){try{return document.querySelector(f.whatsapp.container)}catch(e){return null}}get stylesheetLoaded(){return P.waitForStylesheet(P.latestStylesheet)}markCoexistingWidgets(){const e=document.querySelector(".hellotext--webchat:not(.hellotext--whatsapp-widget)"),t=this.data.html;e&&t&&(e.classList.add("hellotext--with-whatsapp-widget"),t.classList.add("hellotext--with-webchat"))}}class pt{static async load(e,t={}){const s=new pt({id:e,html:await I.popups.get(e)},t);return s.rendered=s.render(),s}constructor(e,{container:t=f.popup.container,shouldMount:s=()=>!0}={}){this.data=e,this.container=t,this.mounted=!1,this.rendered=Promise.resolve(!1),this.shouldMount=s}async render(){if(!this.data.html||!this.shouldMount())return!1;const e=this.containerToAppendTo;return e?!!this.shouldMount()&&(e.appendChild(this.data.html),this.mounted=!0,this.shouldMount()||this.unmount(),this.mounted):(console.warn(`Hellotext popup was not mounted because the container ${this.container} was not found.`),!1)}unmount(){this.data.html?.remove(),this.mounted=!1}get containerToAppendTo(){try{return document.querySelector(this.container)}catch(e){return null}}}class mt{static get id(){return _.get("hello_user_id")}static get source(){return _.get("hello_user_source")}static get fingerprint(){return _.get("hello_user_identification_hash")}static remember(e,t,s){t&&_.set("hello_user_source",t),s&&_.set("hello_user_identification_hash",s),_.set("hello_user_id",e)}static forget(){_.delete("hello_user_id"),_.delete("hello_user_source"),_.delete("hello_user_identification_hash")}static get identificationData(){return this.id?{id:this.id,source:this.source}:{}}}function gt(e){if(null!=e){if("string"==typeof e){const t=e.trim();return""===t?void 0:t}if(Array.isArray(e))return e.map(e=>gt(e)).filter(e=>void 0!==e);if(e instanceof Date)return e.toISOString();if("object"==typeof e){const t=Object.keys(e).sort((e,t)=>e.localeCompare(t)).reduce((t,s)=>{const i=gt(e[s]);return void 0!==i&&(t[s]=i),t},{});return Object.keys(t).length>0?t:void 0}return"number"==typeof e||"boolean"==typeof e?e:void 0}}function ft(e,t,s={}){const i=gt({session:e,user_id:t,...s})||{};return JSON.stringify(i)}class bt{static matches(e,t){return!!e&&e===t}static async generate(e,t,s={}){return await async function(e){if(!globalThis.crypto?.subtle||"undefined"==typeof TextEncoder)return function(e){let t=5381;for(let s=0;s>>0).toString(16)}`}(e);const t=await globalThis.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e));return`v1:${Array.from(new Uint8Array(t)).map(e=>e.toString(16).padStart(2,"0")).join("")}`}(ft(e,t,s))}}class yt{static eventEmitter=new r;static forms;static business;static popup;static webchat;static whatsapp;static push;static alert;static initializationVersion=0;static async initialize(e,t={}){const s=++this.initializationVersion;this.popup?.unmount?.(),this.popup=void 0,this.alert?.dispose(),this.alert=null,this.push?.dispose(),this.push=null;const i=new P(e);this.business=i,this.page=new D,f.assign({push:{},...t}),F.initialize(this.page),this.forms=new ct,this.query=new y;const n=await i.hydrate();if(this.business!==i)return;!1!==t.push&&n?.push?.public_key&<.supported&&(this.push=new lt(n.push),this.push.initialize().catch(e=>{console.warn("Hellotext Push initialization failed:",e)}),n.alert?.html&&(this.alert=new ht(n.alert,i,this.push)));const r=!1!==t.popup&&this.deepMergePlainObjects(n&&n.popup||{},t.popup||{}),o=!1!==t.webchat&&this.mergeWebchatConfig(n&&n.webchat||{},t.webchat||{}),a=!1!==t.whatsappWidget&&this.mergeWhatsAppConfig(n&&n.whatsapp||{},t.whatsappWidget||{}),c=t.webchat&&!1!==t.webchat&&Object.prototype.hasOwnProperty.call(t.webchat,"behaviour");f.webchat.behaviourOverride=c;const l=[];if(o&&o.id&&(f.webchat.assign(o),l.push(ut.load(o.id).then(e=>{this.business===i&&(this.webchat=e)}))),a&&a.id&&(f.whatsapp.assign(a),l.push(dt.load(a.id).then(e=>{this.business===i&&(this.whatsapp=e)}))),r&&r.id){const e={container:"body",device:"auto",...r};f.popup.assign(e),l.push(pt.load(e.id,{container:e.container,shouldMount:()=>this.business===i&&this.initializationVersion===s}).then(e=>{this.business===i&&this.initializationVersion===s&&(this.popup=e)}))}await Promise.all(l),this.business===i&&this.initializationVersion===s&&"undefined"!=typeof MutationObserver&&this.forms.collectExistingFormsOnPage()}static mergeWebchatConfig(e,t){return this.deepMergePlainObjects(e,t)}static mergeWhatsAppConfig(e,t){return this.deepMergePlainObjects(e,t)}static deepMergePlainObjects(e,t){const s={...e};return Object.entries(t).forEach(([e,t])=>{this.isPlainObject(t)&&this.isPlainObject(s[e])?s[e]=this.deepMergePlainObjects(s[e],t):s[e]=t}),s}static isPlainObject(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}static async track(e,t={}){if(this.notInitialized)throw new at;const s={...t&&t.headers||{},...this.headers},i={...mt.identificationData,...t.user_parameters||{}},n=t&&t.url?new D(t.url):this.page,r={session:this.session,user_parameters:i,action:e,...t,...n.trackingData};return delete r.headers,await I.events.create({headers:s,body:r,keepalive:k(r)})}static async identify(e,t={}){const s=await bt.generate(this.session,e,t);if(bt.matches(mt.fingerprint,s))return new v(!0,{json:async()=>({already_identified:!0})});const i=await I.identifications.create({user_id:e,...t});return i.succeeded&&mt.remember(e,t.source,s),i}static forget(){mt.forget()}static on(e,t){this.eventEmitter.addSubscriber(e,t)}static removeEventListener(e,t){this.eventEmitter.removeSubscriber(e,t)}static get session(){return F.session}static get isInitialized(){return void 0!==F.session}static get notInitialized(){return!this.business||void 0===this.business.id}static get headers(){if(this.notInitialized)throw new at;return{Authorization:`Bearer ${this.business.id}`,Accept:"application/json","Content-Type":"application/json"}}}const vt=yt,wt=new Map,Tt=class extends i.xI{static values={sections:Array};static targets=["title","description","primaryAction","secondaryAction"];initialize(){this.showRequest=0,this.submitting=!1,this.onStorage=this.onStorage.bind(this)}connect(){this.dispatch("connected",{detail:{controller:this}}),window.addEventListener("storage",this.onStorage)}disconnect(){this.close(),window.removeEventListener("storage",this.onStorage)}onStorage(e){e.key===this.storageKey&&this.dismissal.dismissedUntil>Date.now()&&this.close()}async show(e,{force:t=!1,title:s,description:i,primaryAction:n,secondaryAction:r}={}){const o=++this.showRequest,a=this.sectionsValue.find(t=>t.kind===e);return a?(await(this.alert.push.ready?.catch(()=>{})),!(o!==this.showRequest||this.alert.disposed||!this.element.isConnected||(this.unavailable||!t&&this.dismissal.dismissedUntil>Date.now()?(this.close(),1):(this.titleTarget.textContent=s??a.title,this.descriptionTarget.textContent=i??a.description,this.primaryActionTarget.textContent=n??a.primary_action,this.secondaryActionTarget.textContent=r??a.secondary_action,this.kind=e,this.page=vt.page.trackingData.page,this.element.hidden=!1,this.record("shown"),vt.eventEmitter.dispatch("alert:shown",{kind:e}),0)))):(this.close(),!1)}hide(){if(this.element.hidden||this.submitting)return;const e=this.dismissal.dismissals+1,t={dismissals:e,dismissedUntil:Date.now()+864e5*(1===e?7:30)};wt.set(this.storageKey,t);try{localStorage.setItem(this.storageKey,JSON.stringify(t))}catch(e){}this.close(),this.record("dismissed"),vt.eventEmitter.dispatch("alert:dismissed",{kind:this.kind})}close(){this.showRequest+=1,this.element.hidden=!0}async subscribe(){if(!this.submitting&&!this.element.hidden){if(this.unavailable)return this.close();this.submitting=!0,this.primaryActionTarget.disabled=!0,this.secondaryActionTarget.disabled=!0,this.element.setAttribute("aria-busy","true");try{this.record("accepted"),vt.eventEmitter.dispatch("alert:accepted",{kind:this.kind});const e=await this.alert.push.subscribe();return this.unavailable&&this.close(),e?.failed&&this.dispatch("error",{detail:{response:e}}),e}catch(e){this.unavailable&&this.close(),this.dispatch("error",{detail:{error:e}})}finally{this.submitting=!1,this.primaryActionTarget.disabled=!1,this.secondaryActionTarget.disabled=!1,this.element.removeAttribute("aria-busy")}}}async record(e){try{const t=await I.pushAlerts.create({section:this.kind,kind:e,page:this.page});t.failed&&console.warn("Hellotext Smart Alert submission failed:",t)}catch(e){console.warn("Hellotext Smart Alert submission failed:",e)}}get unavailable(){return this.alert.push.disposed||this.alert.push.subscribed||"undefined"==typeof Notification||"denied"===Notification.permission}get storageKey(){return`hellotext:alert:${this.alert.business.id}`}get dismissal(){try{const e=JSON.parse(localStorage.getItem(this.storageKey));Number.isSafeInteger(e?.dismissals)&&e.dismissals>0&&Number.isFinite(e.dismissedUntil)&&e.dismissedUntil>=0&&wt.set(this.storageKey,e)}catch(e){}return wt.get(this.storageKey)||{dismissals:0,dismissedUntil:0}}},St=class extends i.xI{static values={data:Object,step:{type:Number,default:1}};static targets=["inputContainer","input","button","otpContainer"];initialize(){this.form=new ot(this.dataValue,this.element)}connect(){super.connect(),this.element.addEventListener("submit",this.submit.bind(this)),"INPUT"!==document.activeElement.tagName&&this.inputTargets[0].focus()}async submit(e){if(e.preventDefault(),this.invalid)return this.showErrorMessages();this.clearErrorMessages(),this.formData=Object.fromEntries(new FormData(this.element)),this.buttonTarget.disabled=!0;const t=await T.submit(this.form.id,this.formData);this.buttonTarget.disabled=!1;const s=await t.json();if(t.failed)return s.errors.forEach(e=>{const{type:t,parameter:s}=e,i=this.inputTargets.find(e=>e.name===s);i.setCustomValidity(vt.business.locale.errors[t]),i.reportValidity(),i.addEventListener("input",()=>{i.setCustomValidity(""),i.reportValidity()})}),this.showErrorMessages();this.buttonTarget.style.display="none",this.element.querySelectorAll("input").forEach(e=>e.disabled=!0),this.completed()}completed(){if(this.form.markAsCompleted(this.formData),!f.forms.shouldShowSuccessMessage)return this.element.remove();"string"==typeof f.forms.successMessage?this.element.innerHTML=f.forms.successMessage:this.element.innerHTML=vt.business.locale.forms[this.form.localeAuthKey]}showErrorMessages(){this.inputTargets.forEach(e=>{const t=e.closest("article").querySelector("[data-error-container]");e.validity.valid?t.innerText="":t.innerText=e.validationMessage})}clearErrorMessages(){this.inputTargets.forEach(e=>{e.setCustomValidity(""),e.closest("article").querySelector("[data-error-container]").innerText=""})}inputTargetConnected(e){e.getAttribute("data-default-value")&&(e.value=e.getAttribute("data-default-value"))}get requiredInputs(){return this.inputTargets.filter(e=>e.required)}get invalid(){return!this.element.checkValidity()}},Ct=class extends i.xI{static values={fadeDistance:{type:Number,default:64},id:String,kind:String,pageStartOffset:{type:Number,default:0},utm:Object};static targets=["carouselContainer","leftFade","rightFade","carouselCard"];connect(){this.updateFades(),this.observeContainerSize()}disconnect(){this.resizeObserver?.disconnect()}setId({detail:e}){this.idValue=e,this.element.id=e}onScroll(){this.updateFades()}quickReply({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),s=e.closest('[data-controller~="hellotext--message"]'),i=e.dataset.text||e.textContent.trim();this.dispatch("quickReply",{detail:{id:this.idValue,product:t?.dataset.id,buttonId:e.dataset.id,body:i,cardElement:t||s||e}})}addToCart({currentTarget:e}){const t=e.closest('[data-hellotext--message-target="carouselCard"]'),{id:s,reference:i,source:n}=t.dataset,r={product:s,quantity:1};this.hasUtmValue&&vt.page.utm.save(this.utmValue),vt.eventEmitter.dispatch("cart.added",{object_parameters:{items:[{...r,...i&&{reference:i},...n&&{source:n}}]},source:{kind:this.kindValue,message_id:this.idValue,button_id:e.dataset.id}})}moveToLeft(){if(!this.hasCarouselContainerTarget)return;const e=this.getPreviousPageScrollLeft(),t=this.carouselContainerTarget.scrollLeft-e;t<1||this.carouselContainerTarget.scrollBy({left:-t,behavior:"smooth"})}moveToRight(){if(!this.hasCarouselContainerTarget)return;const e=this.getNextPageScrollLeft()-this.carouselContainerTarget.scrollLeft;e<1||this.carouselContainerTarget.scrollBy({left:e,behavior:"smooth"})}getScrollAmount(){return this.getCardScrollAmount()}getCardScrollAmount(){const e=this.carouselContainerTarget.querySelector(".message__carousel_card");return e?e.offsetWidth+this.getGap():280}getPageScrollAmount(){const e=this.carouselContainerTarget.clientWidth-this.getGap();return e>0?e:this.getCardScrollAmount()}getNextPageScrollLeft(){const e=this.getCurrentScrollLeft(),t=e+this.carouselContainerTarget.clientWidth,s=this.getCardMetrics().find(e=>e.end>t+1),i=s?this.getPageAlignedScrollLeft(s.start):e+this.getPageScrollAmount(),n=e+this.getPageScrollAmount();return this.clampScrollLeft(i>e+1?i:n)}getPreviousPageScrollLeft(){const e=this.getCurrentScrollLeft();if(e<=1)return 0;const t=Math.max(e-this.getPageScrollAmount(),0);if(t<=1)return 0;const s=this.getCardMetrics(),i=s.find(s=>s.start>=t-1&&s.startt.start{const t=this.getCardScrollLeft(e);return{start:t,end:t+e.offsetWidth}})}getCardScrollLeft(e){const t=e.getBoundingClientRect(),s=this.carouselContainerTarget.getBoundingClientRect();return t.left||t.width||s.left||s.width?t.left-s.left+this.carouselContainerTarget.scrollLeft:e.offsetLeft||0}getCurrentScrollLeft(){return this.clampScrollLeft(this.carouselContainerTarget.scrollLeft)}clampScrollLeft(e){const t=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);return Math.min(Math.max(e,0),t)}getGap(){const e=window.getComputedStyle(this.carouselContainerTarget),t=Number.parseFloat(e.columnGap||e.gap);return Number.isFinite(t)?t:16}getFadeDistance(){return Number.isFinite(this.fadeDistanceValue)?this.fadeDistanceValue:64}getPageStartOffset(){return Number.isFinite(this.pageStartOffsetValue)?this.pageStartOffsetValue:0}observeContainerSize(){this.hasCarouselContainerTarget&&window.ResizeObserver&&(this.resizeObserver=new ResizeObserver(()=>this.updateFades()),this.resizeObserver.observe(this.carouselContainerTarget))}updateFades(){if(!this.hasCarouselContainerTarget)return;const e=Math.max(this.carouselContainerTarget.scrollWidth-this.carouselContainerTarget.clientWidth,0);if(e<=1)return this.hideFade(this.leftFadeTarget),void this.hideFade(this.rightFadeTarget);const t=Math.min(Math.max(this.carouselContainerTarget.scrollLeft,0),e),s=this.getFadeDistance();this.setFadeOpacity(this.leftFadeTarget,t/s),this.setFadeOpacity(this.rightFadeTarget,(e-t)/s)}setFadeOpacity(e,t){const s=Math.min(Math.max(t,0),1);s<=.05?this.hideFade(e):(e.classList.remove("hidden"),e.removeAttribute("disabled"),e.removeAttribute("tabindex"),e.setAttribute("aria-hidden","false"),e.style.opacity=s.toFixed(3),e.style.pointerEvents="auto")}hideFade(e){e.style.opacity="0",e.style.pointerEvents="none",e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1"),"disabled"in e&&(e.disabled=!0),e.classList.add("hidden")}},Ot=class extends i.xI{static targets=["bubble","dialog","step","completed","input","submitButton","globalError","resendButton","changeDestinationButton","deliveryCopy","noDeliveryCopy"];static values={capture:Object,device:String,hasBubble:Boolean,id:String};initialize(){this.stepIndex=0,this.resendLabel=this.hasResendButtonTarget?this.resendButtonTarget.textContent.trim():""}connect(){vt.eventEmitter.dispatch("popup:mounted"),this.evaluateDisplay()}disconnect(){this.stopResendCooldown()}open(e){e&&e.preventDefault(),this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}close(e){e&&e.preventDefault(),this.dismissed=!0,this.dialogTarget.hidden=!0,this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.element.hidden=!0,vt.eventEmitter.dispatch("popup:closed")}closeOnEscape(e){this.element.hidden||this.dialogTarget.hidden||e.defaultPrevented||e.isComposing||this.close(e)}async next(e){e&&e.preventDefault(),this.clearCustomValidity(),this.currentStepValid()?(this.clearErrorMessages(this.currentStepInputs),this.stepIndex{e.disabled=!0});try{const e=this.submissionPayload(),t=await C.submit(this.idValue,e,this.idempotencyKeyFor(e));if(t.failed)return void await this.handleSubmissionError(t);const s=await t.json();this.submissionId=s.id,this.submissionVerificationState=s.verification_state,this.submissionActionToken=s.action_token,this.submissionDeliveryStatus=s.delivery_status,this.submissionDeliveryChannel=s.delivery_channel,this.submissionDestination=s.destination,this.resetSubmissionRequest()}catch(e){return void this.showGlobalError()}finally{this.submitButtonTargets.forEach(e=>{e.disabled=!1})}this.showCompleted()}else this.showErrorMessages(this.currentStepInputs)}evaluateDisplay(){!this.dismissed&&this.matchesDevice()?this.showInitialState():this.element.hidden=!0}showInitialState(){if(this.element.hidden=!1,this.hasBubbleValue&&this.hasBubbleTarget)return this.bubbleTarget.hidden=!1,void(this.dialogTarget.hidden=!0);this.hasBubbleTarget&&(this.bubbleTarget.hidden=!0),this.dialogTarget.hidden=!1,vt.eventEmitter.dispatch("popup:opened")}showStep(e){this.stepIndex=e,this.stepTargets.forEach((t,s)=>{t.hidden=s!==e}),this.completedTarget.hidden=!0}showCompleted(){this.stepTargets.forEach(e=>{e.hidden=!0}),this.interpolateCompletionCopy(),this.configureCompletionActions(),this.completedTarget.hidden=!1}interpolateCompletionCopy(){const e=this.completedIdentity;if(!e)return;const t={destination:e.value,channel:this.submissionDeliveryChannel||e.kind};this.completionTextTemplates.forEach(({node:e,template:s})=>{e.nodeValue=s.replace(/\{(destination|channel)\}/g,(e,s)=>t[s]||e)})}identityValue(e){const t=this.inputValue(e).trim();if("phone"!==e.dataset.popupFieldKind||t.startsWith("+"))return t;const s=this.phoneCountryPrefix(e);if(s)return`${s}${this.phoneDigits(t)}`;const i=e.dataset.popupPhonePrefix;return i?`${i}${t.replace(/^0+/,"")}`:t}asciiDigits(e){const t=e=>/\p{Nd}/u.test(e);return e.replace(/\p{Nd}/gu,e=>{let s=e.codePointAt(0);const i=s;for(;t(String.fromCodePoint(s-1));)s-=1;return(i-s)%10})}phoneDigits(e){return this.asciiDigits(e).replace(/\D/g,"")}phoneCountryPrefix(e){const t=e.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country]");return t?.selectedOptions?.[0]?.dataset.prefix}selectPhoneCountry(e){const t=e.target,s=t.closest("[data-popup-phone]")?.querySelector("[data-popup-phone-country-label]");s&&(s.textContent=t.selectedOptions[0]?.dataset.label||"")}submissionValue(e){const t=this.inputValue(e),s="phone"===e.dataset.popupFieldKind&&this.phoneCountryPrefix(e),i="string"==typeof t?t.trim():"";return s&&i?i.startsWith("+")?this.asciiDigits(t):`${s}${this.phoneDigits(i)}`:t}configureCompletionActions(){const e="not_required"!==this.submissionDeliveryStatus;if(this.revealCompletionCopy(e),!e)return void this.completedTarget.querySelector("[data-delivery-actions]")?.setAttribute("hidden","");const t=this.completedIdentity;t&&(this.hasChangeDestinationButtonTarget&&(this.changeDestinationButtonTarget.textContent=this.changeDestinationButtonTarget.dataset[`${t.kind}Label`],this.changeDestinationButtonTarget.hidden=!1),this.submissionId&&this.submissionActionToken&&"queued"===this.submissionDeliveryStatus&&"unverified"===this.submissionVerificationState&&this.hasResendButtonTarget&&(this.resendButtonTarget.hidden=!1,this.startResendCooldown(60)))}async resend(e){if(e&&e.preventDefault(),this.submissionId&&this.submissionActionToken&&!this.resendPending&&!this.resendCooldownActive&&this.completedIdentity){this.resendPending=!0,this.resendButtonTarget.disabled=!0;try{const e=await C.resend(this.idValue,this.submissionId,this.submissionActionToken),t=Number(e.data.headers?.get("Retry-After"))||60;e.succeeded||429===e.data.status?this.startResendCooldown(t):this.resendButtonTarget.disabled=!1}catch(e){this.resendButtonTarget.disabled=!1}finally{this.resendPending=!1}}}async changeDestination(e){if(e&&e.preventDefault(),!this.submissionId||!this.submissionActionToken||this.changeDestinationPending)return;const t=this.completedIdentity?.input;if(!t)return;const s=this.stepTargets.findIndex(e=>e.dataset.stepId===t.dataset.popupStepId);if(!(s<0)){this.changeDestinationPending=!0,this.changeDestinationButtonTarget.disabled=!0;try{if((await C.cancel(this.idValue,this.submissionId,this.submissionActionToken)).failed)return;this.stopResendCooldown(),this.submissionId=null,this.submissionActionToken=null,this.submissionVerificationState=null,this.submissionDeliveryStatus=null,this.submissionDeliveryChannel=null,this.submissionDestination=null,this.resetSubmissionRequest(),this.showStep(s),t.focus()}catch(e){}finally{this.changeDestinationPending=!1,this.changeDestinationButtonTarget.disabled=!1}}}startResendCooldown(e){this.stopResendCooldown(),this.resendCooldownEndsAt=Date.now()+1e3*Math.max(e,1),this.updateResendCountdown(),this.resendTimer=window.setInterval(()=>this.updateResendCountdown(),1e3)}stopResendCooldown(){this.resendTimer&&window.clearInterval(this.resendTimer),this.resendTimer=null,this.resendCooldownEndsAt=null}updateResendCountdown(){const e=Math.max(0,Math.ceil((this.resendCooldownEndsAt-Date.now())/1e3));if(0===e)return this.stopResendCooldown(),this.resendButtonTarget.textContent=this.resendLabel,void(this.resendButtonTarget.disabled=!1);const t=`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`,s=this.resendButtonTarget.dataset.countdownLabel||`${this.resendLabel} %{time}`;this.resendButtonTarget.textContent=s.replace("%{time}",t),this.resendButtonTarget.disabled=!0}get resendCooldownActive(){return this.resendCooldownEndsAt>Date.now()}get completionIdentity(){return this.identityInputs.map(e=>({input:e,kind:e.dataset.popupFieldKind,value:this.identityValue(e)})).find(({value:e})=>e)}get completedIdentity(){if(this.submissionDestination&&this.submissionDeliveryChannel){const e="email"===this.submissionDeliveryChannel?"email":"phone";return{input:this.identityInputs.find(t=>t.dataset.popupFieldKind===e),kind:e,value:this.submissionDestination}}return this.completionIdentity}revealCompletionCopy(e){this.hasDeliveryCopyTarget&&this.deliveryCopyTargets.forEach(t=>{t.hidden=!e}),this.hasNoDeliveryCopyTarget&&this.noDeliveryCopyTargets.forEach(t=>{t.hidden=e})}currentStepValid(){return this.currentStepInputs.every(e=>e.checkValidity())}showErrorMessages(e){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent=e.validity.valid?"":e.validationMessage)})}clearErrorMessages(e=this.inputTargets){e.forEach(e=>{const t=e.closest(".hellotext--popup-field")?.querySelector("[data-error-container]");t&&(t.textContent="")})}clearCustomValidity(){this.inputTargets.forEach(e=>e.setCustomValidity(""))}clearGlobalError(){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent="",this.globalErrorTarget.hidden=!0)}showGlobalError(e=null){this.hasGlobalErrorTarget&&(this.globalErrorTarget.textContent=e||this.globalErrorTarget.dataset.submitError||"Unable to submit. Please try again.",this.globalErrorTarget.hidden=!1)}async handleSubmissionError(e){let t;try{t=await e.json()}catch(e){return void this.showGlobalError()}const s=t.errors||[],i=[];s.forEach(e=>{const t=this.inputForError(e);t?(t.setCustomValidity(e.description||t.validationMessage),t.reportValidity()):e.description&&i.push(e.description)}),this.showErrorMessages(this.inputTargets),i.length?this.showGlobalError(i.join(" ")):s.length||this.showGlobalError()}inputForError(e){const t=e.parameter;return t?this.inputTargets.find(e=>e.dataset.popupFieldKind===t||e.dataset.popupFieldKey===t):null}submissionPayload(){const e={metadata:{capture:this.captureValue||{},fields:{},steps:[]}};return this.stepTargets.forEach(t=>{const s={};this.inputsForStep(t).forEach(t=>{const i=this.submissionValue(t),n=t.dataset.popupFieldKey||t.name;s[n]=i,e.metadata.fields[n]=i,"email"===t.dataset.popupFieldKind&&(e.email=i),"phone"===t.dataset.popupFieldKind&&(e.phone=i)}),e.metadata.steps.push({id:t.dataset.stepId,name:t.dataset.stepName,fields:s})}),e}idempotencyKeyFor(e){const t=JSON.stringify(e);return this.submissionPayloadSnapshot!==t&&(this.submissionPayloadSnapshot=t,this.submissionIdempotencyKey=C.idempotencyKey()),this.submissionIdempotencyKey}resetSubmissionRequest(){this.submissionPayloadSnapshot=null,this.submissionIdempotencyKey=null}inputValue(e){return"checkbox"===e.type?e.checked:e.value}inputsForStep(e){return this.inputTargets.filter(t=>t.dataset.popupStepId===e.dataset.stepId)}get identityInputs(){const e=this.inputTargets.filter(e=>["email","phone"].includes(e.dataset.popupFieldKind));return e.filter(e=>e.required).concat(e.filter(e=>!e.required))}get completionTextTemplates(){if(this._completionTextTemplates)return this._completionTextTemplates;const e=document.createTreeWalker(this.completedTarget,NodeFilter.SHOW_TEXT);for(this._completionTextTemplates=[];e.nextNode();)this._completionTextTemplates.push({node:e.currentNode,template:e.currentNode.nodeValue});return this._completionTextTemplates}matchesDevice(){return"all"===this.deviceValue||("mobile"===this.deviceValue?window.innerWidth<768:"desktop"!==this.deviceValue||window.innerWidth>=768)}get currentStep(){return this.stepTargets[this.stepIndex]}get currentStepInputs(){return this.inputsForStep(this.currentStep)}},Et=["start","end"],At=["top","right","bottom","left"].reduce((e,t)=>e.concat(t,t+"-"+Et[0],t+"-"+Et[1]),[]),xt=Math.min,Mt=Math.max,kt=Math.round,It=Math.floor,Lt=e=>({x:e,y:e}),Pt={left:"right",right:"left",bottom:"top",top:"bottom"},_t={start:"end",end:"start"};function Nt(e,t,s){return Mt(e,xt(t,s))}function Dt(e,t){return"function"==typeof e?e(t):e}function Ft(e){return e.split("-")[0]}function Rt(e){return e.split("-")[1]}function Bt(e){return"x"===e?"y":"x"}function $t(e){return"y"===e?"height":"width"}const jt=new Set(["top","bottom"]);function Vt(e){return jt.has(Ft(e))?"y":"x"}function qt(e){return Bt(Vt(e))}function Ut(e,t,s){void 0===s&&(s=!1);const i=Rt(e),n=qt(e),r=$t(n);let o="x"===n?i===(s?"end":"start")?"right":"left":"start"===i?"bottom":"top";return t.reference[r]>t.floating[r]&&(o=Jt(o)),[o,Jt(o)]}function zt(e){return e.replace(/start|end/g,e=>_t[e])}const Wt=["left","right"],Kt=["right","left"],Ht=["top","bottom"],Gt=["bottom","top"];function Jt(e){return e.replace(/left|right|bottom|top/g,e=>Pt[e])}function Yt(e){const{x:t,y:s,width:i,height:n}=e;return{width:i,height:n,top:s,left:t,right:t+i,bottom:s+n,x:t,y:s}}function Zt(e,t,s){let{reference:i,floating:n}=e;const r=Vt(t),o=qt(t),a=$t(o),c=Ft(t),l="y"===r,h=i.x+i.width/2-n.width/2,u=i.y+i.height/2-n.height/2,d=i[a]/2-n[a]/2;let p;switch(c){case"top":p={x:h,y:i.y-n.height};break;case"bottom":p={x:h,y:i.y+i.height};break;case"right":p={x:i.x+i.width,y:u};break;case"left":p={x:i.x-n.width,y:u};break;default:p={x:i.x,y:i.y}}switch(Rt(t)){case"start":p[o]-=d*(s&&l?-1:1);break;case"end":p[o]+=d*(s&&l?-1:1)}return p}async function Xt(e,t){var s;void 0===t&&(t={});const{x:i,y:n,platform:r,rects:o,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:h="viewport",elementContext:u="floating",altBoundary:d=!1,padding:p=0}=Dt(t,e),m=function(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}(p),g=a[d?"floating"===u?"reference":"floating":u],f=Yt(await r.getClippingRect({element:null==(s=await(null==r.isElement?void 0:r.isElement(g)))||s?g:g.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(a.floating)),boundary:l,rootBoundary:h,strategy:c})),b="floating"===u?{x:i,y:n,width:o.floating.width,height:o.floating.height}:o.reference,y=await(null==r.getOffsetParent?void 0:r.getOffsetParent(a.floating)),v=await(null==r.isElement?void 0:r.isElement(y))&&await(null==r.getScale?void 0:r.getScale(y))||{x:1,y:1},w=Yt(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:y,strategy:c}):b);return{top:(f.top-w.top+m.top)/v.y,bottom:(w.bottom-f.bottom+m.bottom)/v.y,left:(f.left-w.left+m.left)/v.x,right:(w.right-f.right+m.right)/v.x}}const Qt=new Set(["left","top"]);function es(){return"undefined"!=typeof window}function ts(e){return ns(e)?(e.nodeName||"").toLowerCase():"#document"}function ss(e){var t;return(null==e||null==(t=e.ownerDocument)?void 0:t.defaultView)||window}function is(e){var t;return null==(t=(ns(e)?e.ownerDocument:e.document)||window.document)?void 0:t.documentElement}function ns(e){return!!es()&&(e instanceof Node||e instanceof ss(e).Node)}function rs(e){return!!es()&&(e instanceof Element||e instanceof ss(e).Element)}function os(e){return!!es()&&(e instanceof HTMLElement||e instanceof ss(e).HTMLElement)}function as(e){return!(!es()||"undefined"==typeof ShadowRoot)&&(e instanceof ShadowRoot||e instanceof ss(e).ShadowRoot)}const cs=new Set(["inline","contents"]);function ls(e){const{overflow:t,overflowX:s,overflowY:i,display:n}=Ts(e);return/auto|scroll|overlay|hidden|clip/.test(t+i+s)&&!cs.has(n)}const hs=new Set(["table","td","th"]);function us(e){return hs.has(ts(e))}const ds=[":popover-open",":modal"];function ps(e){return ds.some(t=>{try{return e.matches(t)}catch(e){return!1}})}const ms=["transform","translate","scale","rotate","perspective"],gs=["transform","translate","scale","rotate","perspective","filter"],fs=["paint","layout","strict","content"];function bs(e){const t=ys(),s=rs(e)?Ts(e):e;return ms.some(e=>!!s[e]&&"none"!==s[e])||!!s.containerType&&"normal"!==s.containerType||!t&&!!s.backdropFilter&&"none"!==s.backdropFilter||!t&&!!s.filter&&"none"!==s.filter||gs.some(e=>(s.willChange||"").includes(e))||fs.some(e=>(s.contain||"").includes(e))}function ys(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}const vs=new Set(["html","body","#document"]);function ws(e){return vs.has(ts(e))}function Ts(e){return ss(e).getComputedStyle(e)}function Ss(e){return rs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Cs(e){if("html"===ts(e))return e;const t=e.assignedSlot||e.parentNode||as(e)&&e.host||is(e);return as(t)?t.host:t}function Os(e){const t=Cs(e);return ws(t)?e.ownerDocument?e.ownerDocument.body:e.body:os(t)&&ls(t)?t:Os(t)}function Es(e,t,s){var i;void 0===t&&(t=[]),void 0===s&&(s=!0);const n=Os(e),r=n===(null==(i=e.ownerDocument)?void 0:i.body),o=ss(n);if(r){const e=As(o);return t.concat(o,o.visualViewport||[],ls(n)?n:[],e&&s?Es(e):[])}return t.concat(n,Es(n,[],s))}function As(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function xs(e){const t=Ts(e);let s=parseFloat(t.width)||0,i=parseFloat(t.height)||0;const n=os(e),r=n?e.offsetWidth:s,o=n?e.offsetHeight:i,a=kt(s)!==r||kt(i)!==o;return a&&(s=r,i=o),{width:s,height:i,$:a}}function Ms(e){return rs(e)?e:e.contextElement}function ks(e){const t=Ms(e);if(!os(t))return Lt(1);const s=t.getBoundingClientRect(),{width:i,height:n,$:r}=xs(t);let o=(r?kt(s.width):s.width)/i,a=(r?kt(s.height):s.height)/n;return o&&Number.isFinite(o)||(o=1),a&&Number.isFinite(a)||(a=1),{x:o,y:a}}const Is=Lt(0);function Ls(e){const t=ss(e);return ys()&&t.visualViewport?{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}:Is}function Ps(e,t,s,i){void 0===t&&(t=!1),void 0===s&&(s=!1);const n=e.getBoundingClientRect(),r=Ms(e);let o=Lt(1);t&&(i?rs(i)&&(o=ks(i)):o=ks(e));const a=function(e,t,s){return void 0===t&&(t=!1),!(!s||t&&s!==ss(e))&&t}(r,s,i)?Ls(r):Lt(0);let c=(n.left+a.x)/o.x,l=(n.top+a.y)/o.y,h=n.width/o.x,u=n.height/o.y;if(r){const e=ss(r),t=i&&rs(i)?ss(i):i;let s=e,n=As(s);for(;n&&i&&t!==s;){const e=ks(n),t=n.getBoundingClientRect(),i=Ts(n),r=t.left+(n.clientLeft+parseFloat(i.paddingLeft))*e.x,o=t.top+(n.clientTop+parseFloat(i.paddingTop))*e.y;c*=e.x,l*=e.y,h*=e.x,u*=e.y,c+=r,l+=o,s=ss(n),n=As(s)}}return Yt({width:h,height:u,x:c,y:l})}function _s(e,t){const s=Ss(e).scrollLeft;return t?t.left+s:Ps(is(e)).left+s}function Ns(e,t,s){void 0===s&&(s=!1);const i=e.getBoundingClientRect();return{x:i.left+t.scrollLeft-(s?0:_s(e,i)),y:i.top+t.scrollTop}}const Ds=new Set(["absolute","fixed"]);function Fs(e,t,s){let i;if("viewport"===t)i=function(e,t){const s=ss(e),i=is(e),n=s.visualViewport;let r=i.clientWidth,o=i.clientHeight,a=0,c=0;if(n){r=n.width,o=n.height;const e=ys();(!e||e&&"fixed"===t)&&(a=n.offsetLeft,c=n.offsetTop)}return{width:r,height:o,x:a,y:c}}(e,s);else if("document"===t)i=function(e){const t=is(e),s=Ss(e),i=e.ownerDocument.body,n=Mt(t.scrollWidth,t.clientWidth,i.scrollWidth,i.clientWidth),r=Mt(t.scrollHeight,t.clientHeight,i.scrollHeight,i.clientHeight);let o=-s.scrollLeft+_s(e);const a=-s.scrollTop;return"rtl"===Ts(i).direction&&(o+=Mt(t.clientWidth,i.clientWidth)-n),{width:n,height:r,x:o,y:a}}(is(e));else if(rs(t))i=function(e,t){const s=Ps(e,!0,"fixed"===t),i=s.top+e.clientTop,n=s.left+e.clientLeft,r=os(e)?ks(e):Lt(1);return{width:e.clientWidth*r.x,height:e.clientHeight*r.y,x:n*r.x,y:i*r.y}}(t,s);else{const s=Ls(e);i={x:t.x-s.x,y:t.y-s.y,width:t.width,height:t.height}}return Yt(i)}function Rs(e,t){const s=Cs(e);return!(s===t||!rs(s)||ws(s))&&("fixed"===Ts(s).position||Rs(s,t))}function Bs(e,t,s){const i=os(t),n=is(t),r="fixed"===s,o=Ps(e,!0,r,t);let a={scrollLeft:0,scrollTop:0};const c=Lt(0);function l(){c.x=_s(n)}if(i||!i&&!r)if(("body"!==ts(t)||ls(n))&&(a=Ss(t)),i){const e=Ps(t,!0,r,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else n&&l();r&&!i&&n&&l();const h=!n||i||r?Lt(0):Ns(n,a);return{x:o.left+a.scrollLeft-c.x-h.x,y:o.top+a.scrollTop-c.y-h.y,width:o.width,height:o.height}}function $s(e){return"static"===Ts(e).position}function js(e,t){if(!os(e)||"fixed"===Ts(e).position)return null;if(t)return t(e);let s=e.offsetParent;return is(e)===s&&(s=s.ownerDocument.body),s}function Vs(e,t){const s=ss(e);if(ps(e))return s;if(!os(e)){let t=Cs(e);for(;t&&!ws(t);){if(rs(t)&&!$s(t))return t;t=Cs(t)}return s}let i=js(e,t);for(;i&&us(i)&&$s(i);)i=js(i,t);return i&&ws(i)&&$s(i)&&!bs(i)?s:i||function(e){let t=Cs(e);for(;os(t)&&!ws(t);){if(bs(t))return t;if(ps(t))return null;t=Cs(t)}return null}(e)||s}const qs={convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{elements:t,rect:s,offsetParent:i,strategy:n}=e;const r="fixed"===n,o=is(i),a=!!t&&ps(t.floating);if(i===o||a&&r)return s;let c={scrollLeft:0,scrollTop:0},l=Lt(1);const h=Lt(0),u=os(i);if((u||!u&&!r)&&(("body"!==ts(i)||ls(o))&&(c=Ss(i)),os(i))){const e=Ps(i);l=ks(i),h.x=e.x+i.clientLeft,h.y=e.y+i.clientTop}const d=!o||u||r?Lt(0):Ns(o,c,!0);return{width:s.width*l.x,height:s.height*l.y,x:s.x*l.x-c.scrollLeft*l.x+h.x+d.x,y:s.y*l.y-c.scrollTop*l.y+h.y+d.y}},getDocumentElement:is,getClippingRect:function(e){let{element:t,boundary:s,rootBoundary:i,strategy:n}=e;const r=[..."clippingAncestors"===s?ps(t)?[]:function(e,t){const s=t.get(e);if(s)return s;let i=Es(e,[],!1).filter(e=>rs(e)&&"body"!==ts(e)),n=null;const r="fixed"===Ts(e).position;let o=r?Cs(e):e;for(;rs(o)&&!ws(o);){const t=Ts(o),s=bs(o);s||"fixed"!==t.position||(n=null),(r?!s&&!n:!s&&"static"===t.position&&n&&Ds.has(n.position)||ls(o)&&!s&&Rs(e,o))?i=i.filter(e=>e!==o):n=t,o=Cs(o)}return t.set(e,i),i}(t,this._c):[].concat(s),i],o=r[0],a=r.reduce((e,s)=>{const i=Fs(t,s,n);return e.top=Mt(i.top,e.top),e.right=xt(i.right,e.right),e.bottom=xt(i.bottom,e.bottom),e.left=Mt(i.left,e.left),e},Fs(t,o,n));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}},getOffsetParent:Vs,getElementRects:async function(e){const t=this.getOffsetParent||Vs,s=this.getDimensions,i=await s(e.floating);return{reference:Bs(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}},getClientRects:function(e){return Array.from(e.getClientRects())},getDimensions:function(e){const{width:t,height:s}=xs(e);return{width:t,height:s}},getScale:ks,isElement:rs,isRTL:function(e){return"rtl"===Ts(e).direction}};function Us(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}const zs=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){var s,i;const{x:n,y:r,placement:o,middlewareData:a}=t,c=await async function(e,t){const{placement:s,platform:i,elements:n}=e,r=await(null==i.isRTL?void 0:i.isRTL(n.floating)),o=Ft(s),a=Rt(s),c="y"===Vt(s),l=Qt.has(o)?-1:1,h=r&&c?-1:1,u=Dt(t,e);let{mainAxis:d,crossAxis:p,alignmentAxis:m}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return a&&"number"==typeof m&&(p="end"===a?-1*m:m),c?{x:p*h,y:d*l}:{x:d*l,y:p*h}}(t,e);return o===(null==(s=a.offset)?void 0:s.placement)&&null!=(i=a.arrow)&&i.alignmentOffset?{}:{x:n+c.x,y:r+c.y,data:{...c,placement:o}}}}},Ws=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:i,placement:n}=t,{mainAxis:r=!0,crossAxis:o=!1,limiter:a={fn:e=>{let{x:t,y:s}=e;return{x:t,y:s}}},...c}=Dt(e,t),l={x:s,y:i},h=await Xt(t,c),u=Vt(Ft(n)),d=Bt(u);let p=l[d],m=l[u];if(r){const e="y"===d?"bottom":"right";p=Nt(p+h["y"===d?"top":"left"],p,p-h[e])}if(o){const e="y"===u?"bottom":"right";m=Nt(m+h["y"===u?"top":"left"],m,m-h[e])}const g=a.fn({...t,[d]:p,[u]:m});return{...g,data:{x:g.x-s,y:g.y-i,enabled:{[d]:r,[u]:o}}}}}},Ks=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var s,i;const{placement:n,middlewareData:r,rects:o,initialPlacement:a,platform:c,elements:l}=t,{mainAxis:h=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...f}=Dt(e,t);if(null!=(s=r.arrow)&&s.alignmentOffset)return{};const b=Ft(n),y=Vt(a),v=Ft(a)===a,w=await(null==c.isRTL?void 0:c.isRTL(l.floating)),T=d||(v||!g?[Jt(a)]:function(e){const t=Jt(e);return[zt(e),t,zt(t)]}(a)),S="none"!==m;!d&&S&&T.push(...function(e,t,s,i){const n=Rt(e);let r=function(e,t,s){switch(e){case"top":case"bottom":return s?t?Kt:Wt:t?Wt:Kt;case"left":case"right":return t?Ht:Gt;default:return[]}}(Ft(e),"start"===s,i);return n&&(r=r.map(e=>e+"-"+n),t&&(r=r.concat(r.map(zt)))),r}(a,g,m,w));const C=[a,...T],O=await Xt(t,f),E=[];let A=(null==(i=r.flip)?void 0:i.overflows)||[];if(h&&E.push(O[b]),u){const e=Ut(n,o,w);E.push(O[e[0]],O[e[1]])}if(A=[...A,{placement:n,overflows:E}],!E.every(e=>e<=0)){var x,M;const e=((null==(x=r.flip)?void 0:x.index)||0)+1,t=C[e];if(t&&("alignment"!==u||y===Vt(t)||A.every(e=>Vt(e.placement)!==y||e.overflows[0]>0)))return{data:{index:e,overflows:A},reset:{placement:t}};let s=null==(M=A.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0])?void 0:M.placement;if(!s)switch(p){case"bestFit":{var k;const e=null==(k=A.filter(e=>{if(S){const t=Vt(e.placement);return t===y||"y"===t}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0])?void 0:k[0];e&&(s=e);break}case"initialPlacement":s=a}if(n!==s)return{reset:{placement:s}}}return{}}}},Hs=e=>{Object.assign(e,{show(){this.cancelBehaviourOpen?.(),this.openValue=!0},hide(){this.openValue=!1},toggle(){this.cancelBehaviourOpen?.(),this.openValue=!this.openValue},setupFloatingUI({trigger:e,popover:t,strategy:s}){this.floatingUICleanup=function(e,t,s,i){void 0===i&&(i={});const{ancestorScroll:n=!0,ancestorResize:r=!0,elementResize:o="function"==typeof ResizeObserver,layoutShift:a="function"==typeof IntersectionObserver,animationFrame:c=!1}=i,l=Ms(e),h=n||r?[...l?Es(l):[],...Es(t)]:[];h.forEach(e=>{n&&e.addEventListener("scroll",s,{passive:!0}),r&&e.addEventListener("resize",s)});const u=l&&a?function(e,t){let s,i=null;const n=is(e);function r(){var e;clearTimeout(s),null==(e=i)||e.disconnect(),i=null}return function o(a,c){void 0===a&&(a=!1),void 0===c&&(c=1),r();const l=e.getBoundingClientRect(),{left:h,top:u,width:d,height:p}=l;if(a||t(),!d||!p)return;const m={rootMargin:-It(u)+"px "+-It(n.clientWidth-(h+d))+"px "+-It(n.clientHeight-(u+p))+"px "+-It(h)+"px",threshold:Mt(0,xt(1,c))||1};let g=!0;function f(t){const i=t[0].intersectionRatio;if(i!==c){if(!g)return o();i?o(!1,i):s=setTimeout(()=>{o(!1,1e-7)},1e3)}1!==i||Us(l,e.getBoundingClientRect())||o(),g=!1}try{i=new IntersectionObserver(f,{...m,root:n.ownerDocument})}catch(e){i=new IntersectionObserver(f,m)}i.observe(e)}(!0),r}(l,s):null;let d,p=-1,m=null;o&&(m=new ResizeObserver(e=>{let[i]=e;i&&i.target===l&&m&&(m.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var e;null==(e=m)||e.observe(t)})),s()}),l&&!c&&m.observe(l),m.observe(t));let g=c?Ps(e):null;return c&&function t(){const i=Ps(e);g&&!Us(g,i)&&s(),g=i,d=requestAnimationFrame(t)}(),s(),()=>{var e;h.forEach(e=>{n&&e.removeEventListener("scroll",s),r&&e.removeEventListener("resize",s)}),null==u||u(),null==(e=m)||e.disconnect(),m=null,c&&cancelAnimationFrame(d)}}(e,t,()=>{((e,t,s)=>{const i=new Map,n={platform:qs,...s},r={...n.platform,_c:i};return(async(e,t,s)=>{const{placement:i="bottom",strategy:n="absolute",middleware:r=[],platform:o}=s,a=r.filter(Boolean),c=await(null==o.isRTL?void 0:o.isRTL(t));let l=await o.getElementRects({reference:e,floating:t,strategy:n}),{x:h,y:u}=Zt(l,i,c),d=i,p={},m=0;for(let s=0;s{const n={left:`${e}px`,top:`${s}px`,position:i};Object.assign(t.style,n)})})},openValueChanged(){this.disabledValue||(this.openValue?(this.preparePopoverOpenAnimation?.(),this.popoverTarget.showPopover(),this.popoverTarget.setAttribute("aria-expanded","true"),this.onPopoverOpened&&this.onPopoverOpened()):(this.popoverTarget.hidePopover(),this.popoverTarget.removeAttribute("aria-expanded"),this.onPopoverClosed&&this.onPopoverClosed()))}})},Gs=class extends i.xI{static targets=["button","popover"];static values={placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},size:{type:Number,default:24},perLine:{type:Number,default:9}};initialize(){this.onEmojiSelect=this.onEmojiSelect.bind(this),this.pickerLoaded=!1,this.pickerLoadPromise=null,this.connected=!1,super.initialize()}connect(){this.connected=!0,Hs(this),this.setupFloatingUI({trigger:this.buttonTarget,popover:this.popoverTarget,strategy:"absolute"}),super.connect()}disconnect(){this.connected=!1,this.pickerLoadPromise=null,this.floatingUICleanup(),super.disconnect()}onEmojiSelect(e){this.dispatch("selected",{detail:e.native}),this.hide()}onClickOutside(e){this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}async onPopoverOpened(){await this.loadPicker()}async loadPicker(){if(this.pickerLoaded)return;this.pickerLoadPromise||=this.loadPickerDependencies();const{Picker:e,i18n:t}=await this.pickerLoadPromise;this.connected&&!this.pickerLoaded&&(this.popoverTarget.appendChild(this.buildPicker(e,t)),this.pickerLoaded=!0)}async loadPickerDependencies(){const[e,t]=await Promise.all([s.e(160).then(s.bind(s,405)),this.loadI18n()]);return{Picker:e.Picker,i18n:t.default||t}}loadI18n(){return"es"===Hellotext.business.locale?s.e(437).then(s.t.bind(s,9,19)):s.e(200).then(s.t.bind(s,714,19))}buildPicker(e,t){return new e({onEmojiSelect:this.onEmojiSelect,theme:"light",dynamicWidth:!0,previewPosition:"none",skinTonePosition:"none",emojiSize:this.sizeValue,perLine:this.perLineValue,i18n:t})}get middlewares(){return[zs(5),Ws({padding:24}),(e={allowedPlacements:["top","bottom"]},void 0===e&&(e={}),{name:"autoPlacement",options:e,async fn(t){var s,i,n;const{rects:r,middlewareData:o,placement:a,platform:c,elements:l}=t,{crossAxis:h=!1,alignment:u,allowedPlacements:d=At,autoAlignment:p=!0,...m}=Dt(e,t),g=void 0!==u||d===At?function(e,t,s){return(e?[...s.filter(t=>Rt(t)===e),...s.filter(t=>Rt(t)!==e)]:s.filter(e=>Ft(e)===e)).filter(s=>!e||Rt(s)===e||!!t&&zt(s)!==s)}(u||null,p,d):d,f=await Xt(t,m),b=(null==(s=o.autoPlacement)?void 0:s.index)||0,y=g[b];if(null==y)return{};const v=Ut(y,r,await(null==c.isRTL?void 0:c.isRTL(l.floating)));if(a!==y)return{reset:{placement:g[0]}};const w=[f[Ft(y)],f[v[0]],f[v[1]]],T=[...(null==(i=o.autoPlacement)?void 0:i.overflows)||[],{placement:y,overflows:w}],S=g[b+1];if(S)return{data:{index:b+1,overflows:T},reset:{placement:S}};const C=T.map(e=>{const t=Rt(e.placement);return[e.placement,t&&h?e.overflows.slice(0,2).reduce((e,t)=>e+t,0):e.overflows[0],e.overflows]}).sort((e,t)=>e[1]-t[1]),O=(null==(n=C.filter(e=>e[2].slice(0,Rt(e[0])?2:3).every(e=>e<=0))[0])?void 0:n[0])||C[0][0];return O!==a?{data:{index:b+1,overflows:T},reset:{placement:O}}:{}}})];var e}};class Js{static get endpoint(){return f.endpoint("public/webchats/:id/messages")}constructor(e){this.webchatId=e}async index(e){const t=new URL(this.url);return Object.entries(e).forEach(([e,s])=>{t.searchParams.append(e,s)}),await fetch(t,{method:"GET",headers:vt.headers})}catchUp(e){return this.index({after_id:e,session:vt.session})}async create(e){const t=await fetch(this.url,{method:"POST",headers:{Authorization:`Bearer ${vt.business.id}`},body:e});return new v(t.ok,t)}markAsSeen(e=null){const t=e?this.url+`/${e}`:this.url+"/seen";fetch(t,{method:"PATCH",headers:vt.headers,body:JSON.stringify({session:vt.session})})}get url(){return Js.endpoint.replace(":id",this.webchatId)}}const Ys=Js;class Zs{static webSocket;static channels=new Set;static messageHandlers=new Set;static disconnectHandlers=new Set;static subscriptionConfirmHandlers=new Set;static reconnectTimeout=null;static reconnectAttempts=0;static reconnectBaseDelay=500;static reconnectMaxDelay=1e4;static reconnectJitter=.3;static needsResubscribe=!1;constructor(){Zs.channels.add(this)}send({command:e,identifier:t,data:s}){const i={command:e,identifier:JSON.stringify(t),data:JSON.stringify(s||{})},n=Zs.ensureWebSocket(),r=JSON.stringify(i);n.readyState===WebSocket.OPEN?n.send(r):n.addEventListener("open",()=>{n.send(r)})}onMessage(e){const t=t=>{const s=JSON.parse(t.data),{type:i,message:n}=s;this.ignoredEvents.includes(i)||e(n)};Zs.messageHandlers.add(t),Zs.ensureWebSocket().addEventListener("message",t)}onDisconnect(e){Zs.disconnectHandlers.add(e)}onSubscriptionConfirmed(e){Zs.subscriptionConfirmHandlers.add(e)}get webSocket(){return Zs.ensureWebSocket()}static ensureWebSocket(){return this.webSocket&&!this.closedWebSocket(this.webSocket)?this.webSocket:(this.webSocket&&(this.needsResubscribe=!0),this.openWebSocket())}static openWebSocket(){this.clearReconnectTimeout();const e=new WebSocket(f.actionCableUrl);return this.webSocket=e,this.installWebSocketHandlers(e),e}static installWebSocketHandlers(e){e.addEventListener("open",()=>this.handleOpen(e)),e.addEventListener("close",()=>this.handleDisconnect(e)),e.addEventListener("error",()=>this.handleDisconnect(e)),e.addEventListener("message",e=>this.handleControlMessage(e)),this.messageHandlers.forEach(t=>{e.addEventListener("message",t)})}static handleOpen(e){e===this.webSocket&&(this.reconnectAttempts=0,this.needsResubscribe&&(this.needsResubscribe=!1,this.resubscribeChannels()))}static handleControlMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}"confirm_subscription"===t.type&&this.subscriptionConfirmHandlers.forEach(e=>e(t.identifier))}static handleDisconnect(e){e===this.webSocket&&(this.disconnectHandlers.forEach(e=>e()),this.webSocket=null,this.needsResubscribe=!0,this.scheduleReconnect())}static scheduleReconnect(){this.reconnectTimeout||(this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts+=1,this.openWebSocket()},this.reconnectDelay))}static clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}static resubscribeChannels(){this.channels.forEach(e=>{const t=e.resubscribe||e.subscribe;"function"==typeof t&&t.call(e)})}static closedWebSocket(e){return e.readyState===WebSocket.CLOSED||e.readyState===WebSocket.CLOSING}static get reconnectDelay(){const e=Math.min(this.reconnectMaxDelay,this.reconnectBaseDelay*2**this.reconnectAttempts);return e+Math.round(e*this.reconnectJitter*Math.random())}get ignoredEvents(){return["ping","confirm_subscription","welcome"]}}const Xs=Zs,Qs=class extends Xs{constructor(e,t,s){super(),this.id=e,this.session=t,this.conversation=s,this.subscribed=!1,this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks=new Set,this.onSubscriptionConfirmed(e=>this.handleSubscriptionConfirmed(e)),this.subscribe()}subscribe(){this.subscribed=!0;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"subscribe",identifier:e})}unsubscribe(){this.subscribed=!1;const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"unsubscribe",identifier:e})}resubscribe(){!1!==this.subscribed&&(this.awaitingReconnectConfirmation=!0,this.subscribe())}onReconnect(e){this.reconnectCallbacks.add(e)}handleSubscriptionConfirmed(e){this.awaitingReconnectConfirmation&&this.matchesIdentifier(e)&&(this.awaitingReconnectConfirmation=!1,this.reconnectCallbacks.forEach(e=>e()))}matchesIdentifier(e){let t;try{t="string"==typeof e?JSON.parse(e):e}catch{return!1}return"WebchatChannel"===t.channel&&t.id===this.id&&t.session===this.session&&t.conversation===this.conversation}startTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"message",identifier:e,data:{action:"started_typing"}})}stopTypingIndicator(){const e={channel:"WebchatChannel",id:this.id,session:this.session,conversation:this.conversation};this.send({command:"typing:stop",identifier:e,data:{action:"stopped_typing"}})}onMessage(e){super.onMessage(t=>{"message"===t.type&&e(t)})}onReaction(e){super.onMessage(t=>{"reaction.create"!==t.type&&"reaction.destroy"!==t.type||e(t)})}onTypingStart(e){super.onMessage(t=>{"started_typing"===t.type&&e(t)})}updateSubscriptionWith(e){this.unsubscribe(),setTimeout(()=>{this.conversation=e,this.subscribe()},1e3)}},ei=e=>{Object.assign(e,{scheduleBehaviourOpen(){if(!this.shouldAutoOpenFromBehaviour())return;const e=1e3*Number(this.behaviourValue.delay_seconds||0);this.behaviourOpenTimeout=window.setTimeout(()=>{this.behaviourOpenTimeout=null,this.openValue||(this.openValue=!0,this.markBehaviourAutoOpened())},e)},cancelBehaviourOpen(){window.clearTimeout(this.behaviourOpenTimeout),this.behaviourOpenTimeout=null},shouldAutoOpenFromBehaviour(){const e=this.behaviourValue;return!(!e||"on_load"!==e.trigger||e.first_visit_only&&localStorage.getItem(this.firstVisitKey())||e.once_per_session&&sessionStorage.getItem(this.sessionKey()))},markBehaviourAutoOpened(){this.behaviourValue.first_visit_only&&localStorage.setItem(this.firstVisitKey(),"1"),this.behaviourValue.once_per_session&&sessionStorage.setItem(this.sessionKey(),"1")},firstVisitKey(){return`hellotext--webchat--${this.idValue}--auto-opened`},sessionKey(){return`hellotext--webchat--${this.idValue}--auto-opened-session`}})},ti=e=>{Object.assign(e,{setupOpeningSequence(){this.openingSequenceStarted=!1,this.openingSequenceCancelled=!1,this.openingSequenceTimeout=null,this.openingSequenceMessages=[],this.revealedOpeningSequenceMessageIds=[]},teardownOpeningSequence(){this.cancelOpeningSequence()},startOpeningSequence(){this.openingSequenceMessages=Array.from(this.openingSequenceMessageTargets||[]),this.openingSequenceCanStart()&&(this.openingSequenceStarted=!0,this.openingSequenceCancelled=!1,this.revealedOpeningSequenceMessageIds=[],this.playOpeningSequenceMessageAt(0))},openingSequenceCanStart(){return!this.conversationIdValue&&this.hasOpeningSequenceTarget&&this.openingSequenceMessages.length>0&&!this.openingSequenceStarted},playOpeningSequenceMessageAt(e){const t=this.openingSequenceMessages[e];if(!t)return;const s=1e3*this.openingSequenceMessageDelay(t);this.openingSequenceTimeout=window.setTimeout(()=>{this.openingSequenceTimeout=null,this.openingSequenceCancelled||(this.revealOpeningSequenceMessage(t),this.playOpeningSequenceMessageAt(e+1))},s)},revealOpeningSequenceMessage(e){this.messagesContainerTarget.insertBefore(e,this.messageTemplateTarget),e.hidden=!1,this.recordOpeningSequenceMessage(e),this.scrollOpeningSequenceToBottom()},recordOpeningSequenceMessage(e){const t=e.dataset.openingSequenceMessageId;t&&!this.revealedOpeningSequenceMessageIds.includes(t)&&this.revealedOpeningSequenceMessageIds.push(t)},openingSequenceMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},scrollOpeningSequenceToBottom(){this.messagesContainerTarget.scroll&&this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"smooth"})},cancelOpeningSequence(){this.openingSequenceCancelled=!0,null!==this.openingSequenceTimeout&&void 0!==this.openingSequenceTimeout&&(window.clearTimeout(this.openingSequenceTimeout),this.openingSequenceTimeout=null)},appendOpeningSequenceMessageIds(e){this.cancelOpeningSequence(),(this.revealedOpeningSequenceMessageIds||[]).forEach(t=>{e.append("message[opening_sequence_message_ids][]",t)})},clearRevealedOpeningSequenceMessageIds(){this.revealedOpeningSequenceMessageIds=[]}})},si=e=>{Object.assign(e,{setupTeaser(){this.teaserCycleTimeout=null,this.teaserMessages=[],this.boundOnTeaserClick=this.boundOnTeaserClick||this.onTeaserClick.bind(this),this.hasTeaserTarget&&(this.teaserTarget.addEventListener("click",this.boundOnTeaserClick),this.startTeaserPresentation())},teardownTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.boundOnTeaserClick&&this.teaserTarget.removeEventListener("click",this.boundOnTeaserClick)},collectTeaserMessages(){return this.hasTeaserTarget?Array.from(this.teaserTarget.querySelectorAll("[data-teaser-message]")):[]},startTeaserPresentation(){this.stopTeaserCycle(),this.teaserMessages=this.collectTeaserMessages(),this.hasTeaserTarget&&(0!==this.teaserMessages.length?this.openValue||this.conversationIdValue||this.hasRenderedConversationMessages()?this.dismissTeaserForSession():this.teaserSeenForSession()?this.hideTeaser():this.teaserMessageDelay(this.teaserMessages[0])>0?this.scheduleTeaserMessage(0):(this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(0),this.scheduleTeaserMessage(1)):this.hideTeaser())},scheduleTeaserMessage(e){const t=this.teaserMessages[e];if(!t)return;const s=this.teaserPresentationDelay(t);this.teaserCycleTimeout=window.setTimeout(()=>{this.teaserCycleTimeout=null,this.teaserTarget.classList.remove("invisible"),this.showTeaserMessage(e),this.scheduleTeaserMessage(e+1)},s)},showTeaserMessage(e){this.teaserMessages.forEach((t,s)=>{t.classList.toggle("hidden",s!==e)})},stopTeaserCycle(){null!==this.teaserCycleTimeout&&void 0!==this.teaserCycleTimeout&&(window.clearTimeout(this.teaserCycleTimeout),this.teaserCycleTimeout=null)},teaserMessageDelay(e){const t=Number(e.dataset.delaySeconds||0);return Number.isFinite(t)?t:0},teaserPresentationDelay(e){return Math.max(1e3*this.teaserMessageDelay(e),250)},hasRenderedConversationMessages(){let e=[];try{e=Array.from(this.messageTargets||[])}catch(t){e=[]}return e.some(e=>e!==this.messageTemplateTarget)},teaserSeenKey(){const e=this.hasTeaserTarget?this.teaserTarget.dataset.teaserVersion:"",t=e?`:${e}`:"";return`hellotext:webchat:${this.idValue||this.element.id}:teaser-seen${t}`},teaserSeenForSession(){try{return"true"===window.sessionStorage.getItem(this.teaserSeenKey())}catch(e){return!1}},markTeaserSeenForSession(){try{window.sessionStorage.setItem(this.teaserSeenKey(),"true")}catch(e){}},dismissTeaserForSession(){this.markTeaserSeenForSession(),this.hideTeaser()},hideTeaser(){this.stopTeaserCycle(),this.hasTeaserTarget&&this.teaserTarget.classList.add("invisible")},onTeaserClick(e){e.target.closest("a")||(this.dismissTeaserForSession(),this.show())}})},ii={hour:"numeric",minute:"2-digit"},ni=/Android|iPhone|iPad|iPod/i,ri={capture:!0,passive:!0},oi=class extends i.xI{static messageTimestampFormatters={};static values={id:String,conversationId:String,media:Object,fileSizeErrorMessage:String,placement:{type:String,default:"bottom-end"},open:{type:Boolean,default:!1},autoPlacement:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},nextPage:{type:Number,default:void 0},fullScreenThreshold:{type:Number,default:1024},typingIndicatorKeepAlive:{type:Number,default:3e4},offset:{type:Number,default:24},padding:{type:Number,default:24},optimisticTypingIndicatorWait:{type:Number,default:1e3},teaser:Object,messageTeaser:String,behaviour:Object};static classes=["fadeOut"];static targets=["trigger","popover","input","attachmentInput","attachmentButton","errorMessageContainer","attachmentTemplate","attachmentContainer","attachment","messageTemplate","messagesContainer","title","attachmentImage","footer","toolbar","message","unreadCounter","typingIndicator","typingIndicatorTemplate","teaser","teaserMessage","inboundMessageTeaser","inboundMessageTeaserBody","openingSequence","openingSequenceMessage"];initialize(){this.messagesAPI=new Ys(this.idValue),this.webChatChannel=new Qs(this.idValue,vt.session,this.conversationIdValue),this.files=[],this.messageIds=new Set,this.catchUpAfterMessageId=null,this.fetchingCatchUpMessages=!1,this.onMessageReceived=this.onMessageReceived.bind(this),this.onMessageReaction=this.onMessageReaction.bind(this),this.onTypingStart=this.onTypingStart.bind(this),this.captureCatchUpCursor=this.captureCatchUpCursor.bind(this),this.catchUpMessages=this.catchUpMessages.bind(this),this.onScroll=this.onScroll.bind(this),this.onOutboundMessageSent=this.onOutboundMessageSent.bind(this),this.closePopoverOnEscape=this.closePopoverOnEscape.bind(this),this.broadcastChannel=new BroadcastChannel(`hellotext--webchat--${this.idValue}`),this.webChatChannel.onDisconnect(this.captureCatchUpCursor),this.webChatChannel.onReconnect(this.catchUpMessages),super.initialize()}connect(){ei(this),Hs(this),ti(this),si(this),this.setupFloatingUI({trigger:this.triggerTarget,popover:this.popoverTarget}),this.hasTeaserTarget&&this.setupFloatingUI({trigger:this.triggerTarget,popover:this.teaserTarget,strategy:"absolute"}),this.setupTeaser(),this.setupOpeningSequence(),this.localizeMessageTimestamps(),this.webChatChannel.onMessage(this.onMessageReceived),this.webChatChannel.onTypingStart(this.onTypingStart),this.webChatChannel.onReaction(this.onMessageReaction),this.setupMessagesContainerScrollIsolation(),this.messagesContainerTarget.addEventListener("scroll",this.onScroll),this.messagesContainerTarget.addEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.addEventListener("touchmove",this.stopHostScrollPropagation,ri),this.shouldOpenOnMount&&(this.openValue=!0),vt.eventEmitter.dispatch("webchat:mounted"),this.broadcastChannel.addEventListener("message",this.onOutboundMessageSent),window.addEventListener("keydown",this.closePopoverOnEscape,!0),this.scheduleBehaviourOpen(),super.connect()}disconnect(){this.cancelBehaviourOpen(),this.clearPopoverOpenAnimation(),this.teardownTeaser(),this.teardownOpeningSequence(),this.broadcastChannel.removeEventListener("message",this.onOutboundMessageSent),this.messagesContainerTarget.removeEventListener("scroll",this.onScroll),this.messagesContainerTarget.removeEventListener("wheel",this.stopHostScrollPropagation,ri),this.messagesContainerTarget.removeEventListener("touchmove",this.stopHostScrollPropagation,ri),window.removeEventListener("keydown",this.closePopoverOnEscape,!0),this.clearTypingIndicator(),this.broadcastChannel.close(),this.floatingUICleanup(),super.disconnect()}setupMessagesContainerScrollIsolation(){this.messagesContainerTarget.style.overscrollBehavior="contain",this.messagesContainerTarget.style.webkitOverflowScrolling="touch",this.messagesContainerTarget.style.touchAction="pan-y",this.messagesContainerTarget.setAttribute("data-lenis-prevent",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-wheel",""),this.messagesContainerTarget.setAttribute("data-lenis-prevent-touch","")}stopHostScrollPropagation(e){e.stopPropagation()}onTypingStart(){if(this.typingIndicatorVisible)return this.resetTypingIndicatorTimer();this.showTypingIndicator()}showOptimisticTypingIndicator(){this.typingIndicatorVisible||this.showTypingIndicator()}showTypingIndicator(){this.clearTypingIndicator(),this.typingIndicatorVisible=!0;const e=this.typingIndicatorTemplateTarget.cloneNode(!0);e.setAttribute("data-hellotext--webchat-target","typingIndicator"),e.style.display="flex",this.messagesContainerTarget.appendChild(e),requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})});const t=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},t)}resetTypingIndicatorTimer(){if(!this.typingIndicatorVisible)return;clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout);const e=this.typingIndicatorKeepAliveValue;this.incomingTypingIndicatorTimeout=setTimeout(()=>{this.clearTypingIndicator()},e)}clearTypingIndicator(){this.hasTypingIndicatorTarget&&this.typingIndicatorTarget.remove(),this.typingIndicatorVisible=!1,clearTimeout(this.incomingTypingIndicatorTimeout),clearTimeout(this.optimisticTypingTimeout)}onMessageInputChange(){this.resizeInput(),clearTimeout(this.typingIndicatorTimeout),this.hasSentTypingIndicator||(this.webChatChannel.startTypingIndicator(),this.hasSentTypingIndicator=!0),this.typingIndicatorTimeout=setTimeout(()=>{this.hasSentTypingIndicator=!1},3e3)}onOutboundMessageSent(e){const{data:t}=e,s={"message:sent":e=>{const t=(new DOMParser).parseFromString(e.element,"text/html").body.firstElementChild;this.localizeMessageTimestamps(t),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(t,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(t),t.scrollIntoView({behavior:"instant"})},"message:failed":e=>{const t=this.messagesContainerTarget.querySelector(`#${e.id}`);this.markMessageFailed(t,e.reason)}};s[t.type]?s[t.type](t):console.log(`Unhandled message event: ${t.type}`)}async onScroll(){if(this.messagesContainerTarget.scrollTop>300||!this.nextPageValue||this.fetchingNextPage)return;this.fetchingNextPage=!0;const e=await this.messagesAPI.index({page:this.nextPageValue,session:vt.session}),{next:t,messages:s}=await e.json();this.nextPageValue=t,this.oldScrollHeight=this.messagesContainerTarget.scrollHeight,s.forEach(e=>{const{body:t,attachments:s}=e,i=e.created_at||e.createdAt,n=this.messageTemplateTarget.cloneNode(!0);n.classList.add("hellotext--webchat-message"),n.setAttribute("data-hellotext--webchat-target","message"),n.setAttribute("data-id",e.id),i&&n.setAttribute("data-created-at",i),n.style.removeProperty("display"),rt(n.querySelector("[data-body]"),t),"received"===e.state?n.classList.add("received"):n.classList.remove("received"),s&&s.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.removeAttribute("data-hellotext--webchat-target"),t.src=e,t.style.display="block",this.messageAttachmentsContainer(n)?.appendChild(t)}),n.setAttribute("data-body",t),this.localizeMessageTimestamp(n.querySelector("[data-message-timestamp]"),i),this.messagesContainerTarget.prepend(n)}),this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight-this.oldScrollHeight,behavior:"instant"}),this.fetchingNextPage=!1}onClickOutside(e){d.mode===u.POPOVER&&this.openValue&&e.target.nodeType&&!1===this.element.contains(e.target)&&(this.openValue=!1)}closePopover(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.openValue=!1}preparePopoverOpenAnimation(){this.clearPopoverOpenAnimation(),this.popoverTarget.classList.remove(...this.fadeOutClasses),this.popoverTarget.classList.add("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=setTimeout(()=>{this.popoverTarget.classList.remove("hellotext--webchat-popover-opening"),this.popoverOpenAnimationTimeout=null},120)}clearPopoverOpenAnimation(){this.popoverOpenAnimationTimeout&&(clearTimeout(this.popoverOpenAnimationTimeout),this.popoverOpenAnimationTimeout=null),this.popoverTarget?.classList.remove("hellotext--webchat-popover-opening")}onPopoverOpened(){this.popoverTarget.classList.remove(...this.fadeOutClasses),this.dismissTeaserForSession?.(),this.onMobile||this.focusComposeInput(),this.scrolled||(requestAnimationFrame(()=>{this.messagesContainerTarget.scroll({top:this.messagesContainerTarget.scrollHeight,behavior:"instant"})}),this.scrolled=!0),vt.eventEmitter.dispatch("webchat:opened"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"opened"),this.messageTeaserValue&&(this.messageTeaserValue=null),this.startOpeningSequence(),"none"!==this.unreadCounterTarget.style.display&&(this.unreadCounterTarget.style.display="none",this.unreadCounterTarget.innerText="0",this.messagesAPI.markAsSeen())}onPopoverClosed(){this.clearPopoverOpenAnimation(),vt.eventEmitter.dispatch("webchat:closed"),localStorage.setItem(`hellotext--webchat--${this.idValue}`,"closed")}onMessageReaction(e){const{message:t,reaction:s,type:i}=e,n=this.messageTargets.find(e=>e.dataset.id===t).querySelector("[data-reactions]");if("reaction.destroy"===i)return n.querySelector(`[data-id="${s.id}"]`).remove();if(n.querySelector(`[data-id="${s.id}"]`))n.querySelector(`[data-id="${s.id}"]`).innerText=s.emoji;else{const e=document.createElement("span");e.innerText=s.emoji,e.setAttribute("data-id",s.id),n.appendChild(e)}}onMessageReceived(e,t={}){const{id:s,body:i,attachments:n,teaser:r}=e,o=e.created_at||e.createdAt;if(!this.claimMessageId(s))return;if(this.hideTeaser?.(),e.carousel)return this.insertCarouselMessage(e,t);const a=this.messageTemplateTarget.cloneNode(!0);a.classList.add("hellotext--webchat-message"),a.style.display="flex",rt(a.querySelector("[data-body]"),i),a.setAttribute("data-id",s),a.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(a,o),this.localizeMessageTimestamp(a.querySelector("[data-message-timestamp]"),o),n&&n.forEach(e=>{const t=this.attachmentImageTarget.cloneNode(!0);t.src=e,t.style.display="block",this.messageAttachmentsContainer(a)?.appendChild(t)}),this.clearTypingIndicator(),this.insertMessageElement(a),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:a.querySelector("[data-body]").innerText}),!1!==t.scroll&&a.scrollIntoView({behavior:"smooth"}),this.updateMessageTeaser(r),this.openValue?this.messagesAPI.markAsSeen(s):this.incrementUnreadCounter()}claimMessageId(e){const t=this.messageTargets||[];return!this.messageIds.has(e)&&(this.messageIds.add(e),!t.some(t=>t.dataset.id===e))}captureCatchUpCursor(){this.catchUpAfterMessageId=this.lastRenderedMessageId}async catchUpMessages(){const e=this.catchUpAfterMessageId;if(e&&!this.fetchingCatchUpMessages){this.fetchingCatchUpMessages=!0;try{const t=await this.messagesAPI.catchUp(e),{messages:s=[]}=await t.json();s.forEach(e=>this.onMessageReceived(e,{scroll:!1})),this.catchUpAfterMessageId=this.lastRenderedMessageId}finally{this.fetchingCatchUpMessages=!1}}}get lastRenderedMessageId(){const e=this.persistedMessageElements;return e[e.length-1]?.dataset.id||null}get persistedMessageElements(){return Array.from(this.messagesContainerTarget.querySelectorAll(".hellotext--webchat-message[data-id]"))}setMessageCreatedAt(e,t){t&&e.setAttribute("data-created-at",t)}insertMessageElement(e){const t=this.nextMessageElementFor(e);t?this.messagesContainerTarget.insertBefore(e,t):this.messagesContainerTarget.appendChild(e)}nextMessageElementFor(e){const t=Date.parse(e.dataset.createdAt);return Number.isNaN(t)?null:this.persistedMessageElements.find(s=>{if(s===e)return!1;const i=Date.parse(s.dataset.createdAt);return!Number.isNaN(i)&&i>t})}updateMessageTeaser(e){this.messageTeaserValue=e,this.messageTeaserValue&&this.hasTeaserTarget&&this.hasInboundMessageTeaserTarget&&this.hasInboundMessageTeaserBodyTarget&&(this.teaserMessageTargets.forEach(e=>e.classList.add("hidden")),this.inboundMessageTeaserBodyTarget.textContent=this.messageTeaserValue,this.inboundMessageTeaserTarget.classList.remove("hidden"),this.teaserTarget.classList.toggle("invisible",this.openValue))}insertCarouselMessage(e,t={}){const s=e.html,i=e.created_at||e.createdAt,n=function(e){return nt(e,it)}(s).firstElementChild;n.classList.add("hellotext--webchat-message"),n.setAttribute("data-id",e.id),n.setAttribute("data-hellotext--webchat-target","message"),this.setMessageCreatedAt(n,i),this.localizeMessageTimestamps(n),this.clearTypingIndicator(),this.insertMessageElement(n),!1!==t.scroll&&n.scrollIntoView({behavior:"smooth"}),vt.eventEmitter.dispatch("webchat:message:received",{...e,body:n.querySelector("[data-body]")?.innerText||""}),this.updateMessageTeaser(e.teaser),this.openValue?this.messagesAPI.markAsSeen(e.id):this.incrementUnreadCounter()}resizeInput(){this.inputTarget.style.height="auto";const e=this.inputTarget.scrollHeight;this.inputTarget.style.height=`${Math.min(e,96)}px`}async sendQuickReplyMessage({detail:{id:e,product:t,buttonId:s,body:i,cardElement:n}}){this.dismissTeaserForSession?.();const r=new FormData;r.append("message[body]",i),e&&r.append("message[replied_to]",e),t&&r.append("message[product]",t),s&&r.append("message[button]",s),r.append("session",vt.session),r.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(r);const o=this.buildMessageElement(),c=n?.querySelector("img")?.cloneNode(!0);o.querySelector("[data-body]").innerText=i,c&&(c.removeAttribute("width"),c.removeAttribute("height"),this.messageAttachmentsContainer(o)?.appendChild(c)),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(o,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(o),o.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:o.outerHTML});const l=await this.messagesAPI.create(r);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,o);const h=await l.json();this.dispatch("set:id",{target:o,detail:h.id}),this.localizeMessageTimestamp(o.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds();const u={id:h.id,body:i,attachments:c?[c.src]:[],replied_to:e,product:t,button:s,type:"quick_reply"};vt.eventEmitter.dispatch("webchat:message:sent",u)}async sendTeaserQuickReply(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=(t.dataset.value||"").trim(),i=[t.dataset.text,t.textContent].map(e=>(e||"").trim()).find(e=>e.length>0),n=s||i;if(!n)return;this.dismissTeaserForSession?.(),this.show();const r=(t.dataset.type||"").trim()||"quick_reply",o=new FormData;o.append("message[body]",n),o.append("session",vt.session),o.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(o);const c=this.buildMessageElement();c.querySelector("[data-body]").innerText=n,this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(c,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(c),c.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:c.outerHTML}),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const l=await this.messagesAPI.create(o);if(l.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(l,c);const h=await l.json();c.setAttribute("data-id",h.id),this.localizeMessageTimestamp(c.querySelector("[data-message-timestamp]"),h.created_at||h.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",{id:h.id,body:n,attachments:[],type:"quick_reply",teaser:{text:i||n,value:s||n,type:r}}),h.conversation&&h.conversation!==this.conversationIdValue&&(this.conversationIdValue=h.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer()}async sendMessage(e){const t={body:this.inputTarget.value,attachments:this.files};if(0===this.inputTarget.value.trim().length&&0===this.files.length)return void(e&&e.target&&e.preventDefault());this.dismissTeaserForSession?.();const s=new FormData;this.inputTarget.value.trim().length>0?s.append("message[body]",this.inputTarget.value):delete t.body,this.files.forEach(e=>{s.append("message[attachments][]",e)}),s.append("session",vt.session),s.append("locale",a.toString()),this.appendOpeningSequenceMessageIds(s);const i=this.buildMessageElement();this.inputTarget.value.trim().length>0?i.querySelector("[data-body]").innerText=this.inputTarget.value:i.querySelector("[data-message-bubble]").remove();const n=this.attachmentContainerTarget.querySelectorAll("img");n.length>0&&n.forEach(e=>{this.messageAttachmentsContainer(i)?.appendChild(e.cloneNode(!0))}),this.typingIndicatorVisible&&this.hasTypingIndicatorTarget?this.messagesContainerTarget.insertBefore(i,this.typingIndicatorTarget):this.messagesContainerTarget.appendChild(i),i.scrollIntoView({behavior:"smooth"}),this.broadcastChannel.postMessage({type:"message:sent",element:i.outerHTML}),this.inputTarget.value="",this.resizeInput(),this.files=[],this.attachmentInputTarget.value="",this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none",this.errorMessageContainerTarget.style.display="none",this.focusComposeInput(),this.typingIndicatorVisible||(clearTimeout(this.optimisticTypingTimeout),this.optimisticTypingTimeout=setTimeout(()=>{this.showOptimisticTypingIndicator()},this.optimisticTypingIndicatorWaitValue));const r=await this.messagesAPI.create(s);if(r.failed)return clearTimeout(this.optimisticTypingTimeout),this.markMessageFailedFromResponse(r,i);const o=await r.json();i.setAttribute("data-id",o.id),t.id=o.id,this.localizeMessageTimestamp(i.querySelector("[data-message-timestamp]"),o.created_at||o.createdAt),this.clearRevealedOpeningSequenceMessageIds(),vt.eventEmitter.dispatch("webchat:message:sent",t),o.conversation!==this.conversationIdValue&&(this.conversationIdValue=o.conversation,this.webChatChannel.updateSubscriptionWith(this.conversationIdValue)),this.typingIndicatorVisible&&this.resetTypingIndicatorTimer(),this.attachmentContainerTarget.style.display=""}buildMessageElement(){const e=this.messageTemplateTarget.cloneNode(!0);return e.id=`hellotext--webchat--${this.idValue}--message--${Date.now()}`,e.classList.add("received"),e.style.removeProperty("display"),e.setAttribute("data-controller","hellotext--message"),e.setAttribute("data-hellotext--webchat-target","message"),this.localizeMessageTimestamp(e.querySelector("[data-message-timestamp]"),new Date),e}focusCompose(e){const{target:t}=e,s=["button","a","input","textarea","select","label",'[role="button"]',"em-emoji-picker",'[data-hellotext--webchat--emoji-target~="popover"]','[data-controller~="hellotext--webchat--emoji"]'].join(", ");this.hasInputTarget&&!t.closest(s)&&this.focusComposeInput({moveCursorToEnd:!0})&&e.preventDefault()}closePopoverFromHeader(e){const{target:t}=e;t.closest(".hellotext--webchat-header-channel-button, .hellotext--webchat-close-button")||(e.preventDefault(),this.closePopover())}closePopoverOnEscape(e){"Escape"===e.key&&this.openValue&&(e.preventDefault(),e.stopPropagation(),this.closePopover(),this.triggerTarget?.focus?.())}async markMessageFailedFromResponse(e,t){const s=await this.messageFailureReason(e);this.markMessageFailed(t,s),this.broadcastChannel.postMessage({type:"message:failed",id:t.id,reason:s})}markMessageFailed(e,t){if(!e)return;if(e.classList.add("failed"),!t)return;const s=e.querySelector("[data-message-timestamp]");s&&(s.textContent=t)}localizeMessageTimestamps(e=this.element){e&&(e.matches?.("time[datetime][data-message-timestamp]")?[e]:Array.from(e.querySelectorAll?.("time[datetime][data-message-timestamp]")||[])).forEach(e=>this.localizeMessageTimestamp(e))}localizeMessageTimestamp(e,t=e?.getAttribute("datetime")){if(!e||!t)return;const s=t instanceof Date?t:new Date(t);Number.isNaN(s.getTime())||(e.setAttribute("datetime",s.toISOString()),e.textContent=this.formatMessageTimestamp(s))}formatMessageTimestamp(e){return this.constructor.messageTimestampFormatterFor(a.toString()).format(e)}static messageTimestampFormatterFor(e){const t=e||"default";return this.messageTimestampFormatters[t]||(this.messageTimestampFormatters[t]=this.buildMessageTimestampFormatter(e)),this.messageTimestampFormatters[t]}static buildMessageTimestampFormatter(e){try{return new Intl.DateTimeFormat(e||void 0,ii)}catch(e){return new Intl.DateTimeFormat(void 0,ii)}}async messageFailureReason(e){const t=e?.data||e?.response,s=t?.statusText||"Message failed";try{const e=t?.clone?t.clone():t,s=await(e?.json?.()),i=this.messageFailureReasonFromPayload(s);if(i)return i}catch(e){}try{const e=t?.clone?t.clone():t,i=await(e?.text?.());return this.messageFailureReasonFromText(i)||s}catch(e){return s}}messageFailureReasonFromText(e){if("string"!=typeof e)return null;const t=e.trim();if(!t||t.startsWith("<"))return null;try{return this.messageFailureReasonFromPayload(JSON.parse(t))||t}catch(e){return t}}messageFailureReasonFromPayload(e){return e?[e.error?.message,e.message,e.errors?.message,e.errors?.[0]?.message,e.errors?.[0]?.description].find(e=>"string"==typeof e&&e.trim().length>0):null}messageAttachmentsContainer(e){return e.querySelector("[data-attachments-container], [data-attachment-container]")}incrementUnreadCounter(){this.unreadCounterTarget.style.display="flex";const e=(parseInt(this.unreadCounterTarget.innerText)||0)+1;this.unreadCounterTarget.innerText=Math.min(e,9)}openAttachment(){this.attachmentInputTarget.click()}onFileInputChange(){this.errorMessageContainerTarget.style.display="none";const e=Array.from(this.attachmentInputTarget.files);this.attachmentInputTarget.value="";const t=e.find(e=>{const t=e.type.split("/")[0];return["image","video","audio"].includes(t)?this.mediaValue[t].max_sizethis.createAttachmentElement(e)),this.focusComposeInput()}createAttachmentElement(e){const t=this.attachmentElement();if(this.attachmentContainerTarget.style.display="",t.setAttribute("data-name",e.name),e.type.startsWith("image/")){const s=this.attachmentImageTarget.cloneNode(!0);s.src=URL.createObjectURL(e),s.style.display="block",t.appendChild(s),this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}else{const s=t.querySelector("main");s.style.height="5rem",s.style.borderRadius="0.375rem",s.style.backgroundColor="#e5e7eb",s.style.padding="0.25rem",t.querySelector("p[data-attachment-name]").innerText=e.name,this.attachmentContainerTarget.appendChild(t),this.attachmentContainerTarget.style.display="flex"}}removeAttachment({currentTarget:e}){const t=e.closest("[data-hellotext--webchat-target='attachment']");this.files=this.files.filter(e=>e.name!==t.dataset.name),this.attachmentInputTarget.value="",t.remove(),this.focusComposeInput()}attachmentTargetDisconnected(){0===this.attachmentTargets.length&&(this.attachmentContainerTarget.innerHTML="",this.attachmentContainerTarget.style.display="none")}attachmentElement(){const e=this.attachmentTemplateTarget.cloneNode(!0);return e.removeAttribute("hidden"),e.style.display="flex",e.setAttribute("data-hellotext--webchat-target","attachment"),e}onEmojiSelect({detail:e}){const t=this.inputTarget.value,s=this.inputTarget.selectionStart,i=this.inputTarget.selectionEnd;this.inputTarget.value=t.slice(0,s)+e+t.slice(i),this.inputTarget.selectionStart=this.inputTarget.selectionEnd=s+e.length,this.focusComposeInput()}focusComposeInput({moveCursorToEnd:e=!1}={}){if(!this.shouldAutofocusCompose)return!1;if(!1===this.hasInputTarget)return!1;if(void 0===this.hasInputTarget&&!this.inputTarget)return!1;if(this.inputTarget.focus(),e&&"number"==typeof this.inputTarget.selectionStart){const e=this.inputTarget.value.length;this.inputTarget.setSelectionRange(e,e)}return!0}byteToMegabyte(e){return Math.ceil(e/1024/1024)}get middlewares(){return[zs(this.offsetValue),Ws({padding:this.paddingValue}),Ks()]}get shouldOpenOnMount(){return"opened"===localStorage.getItem(`hellotext--webchat--${this.idValue}`)&&!this.onMobile}get shouldAutofocusCompose(){return!this.usesVirtualKeyboard}get usesVirtualKeyboard(){if("undefined"==typeof navigator)return!1;const e=navigator.userAgent||"",t="MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,s=ni.test(e),i=!0===navigator.userAgentData?.mobile;return s||t||i||this.hasTouchOnlyPointer}get hasTouchOnlyPointer(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches&&window.matchMedia("(hover: none)").matches}get onMobile(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia(`(max-width: ${this.fullScreenThresholdValue}px)`).matches}},ai=i.lg.start();ai.register("hellotext--alert",Tt),ai.register("hellotext--form",St),ai.register("hellotext--popup",Ot),ai.register("hellotext--webchat",oi),ai.register("hellotext--webchat--emoji",Gs),ai.register("hellotext--message",Ct),window.Hellotext=vt;const ci=vt}};const t={};function s(i){const n=t[i];if(void 0!==n)return n.exports;const r=t[i]={exports:{}};return e[i](r,r.exports,s),r.exports}s.m=e,(()=>{const e=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;let t;s.t=function(i,n){if(1&n&&(i=this(i)),8&n)return i;if("object"==typeof i&&i){if(4&n&&i.__esModule)return i;if(16&n&&"function"==typeof i.then)return i}const r=Object.create(null);s.r(r);const o={};t=t||[null,e({}),e([]),e(e)];for(var a=2&n&&i;("object"==typeof a||"function"==typeof a)&&!~t.indexOf(a);a=e(a))Object.getOwnPropertyNames(a).forEach(e=>o[e]=()=>i[e]);return o.default=()=>i,s.d(r,o),r}})(),s.d=(e,t)=>{if(Array.isArray(t))for(var i=0;iPromise.all(Object.keys(s.f).reduce((t,i)=>(s.f[i](e,t),t),[])),s.u=e=>({160:"webchat-emoji",200:"webchat-emoji-en",437:"webchat-emoji-es"}[e]+".js"),s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{const e={},t="Hellotext:";s.l=(i,n,r,o)=>{if(e[i])return void e[i].push(n);let a,c;if(void 0!==r){const e=document.getElementsByTagName("script");for(var l=0;l{a.onerror=a.onload=null,clearTimeout(u);const n=e[i];if(delete e[i],a.parentNode?.removeChild(a),n?.forEach(e=>e(s)),t)return t(s)},u=setTimeout(h.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=h.bind(null,a.onerror),a.onload=h.bind(null,a.onload),c&&document.head.appendChild(a)}})(),s.r=e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{let e;s.g.importScripts&&(e=s.g.location+"");const t=s.g.document;if(!e&&t&&("SCRIPT"===t.currentScript?.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){const s=t.getElementsByTagName("script");if(s.length){let t=s.length-1;for(;t>-1&&(!e||!/^http(s?):/.test(e));)e=s[t--].src}}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})(),(()=>{const e={792:0};s.f.j=(t,i)=>{let n=s.o(e,t)?e[t]:void 0;if(0!==n)if(n)i.push(n[2]);else{const r=new Promise((s,i)=>n=e[t]=[s,i]);i.push(n[2]=r);const o=s.p+s.u(t),a=new Error,c=i=>{if(s.o(e,t)&&(n=e[t],0!==n&&(e[t]=void 0),n)){const e=i&&("load"===i.type?"missing":i.type),s=i&&i.target&&i.target.src;a.message="Loading chunk "+t+" failed.\n("+e+": "+s+")",a.name="ChunkLoadError",a.type=e,a.request=s,n[1](a)}};s.l(o,c,"chunk-"+t,t)}};const t=(t,i)=>{let[n,r,o]=i;var a,c,l=0;if(n.some(t=>0!==e[t])){for(a in r)s.o(r,a)&&(s.m[a]=r[a]);o&&o(s)}for(t&&t(i);l Date: Thu, 8 Oct 2026 09:09:56 -0400 Subject: [PATCH 4/4] Format the Escape guard --- src/controllers/popup_controller.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/controllers/popup_controller.js b/src/controllers/popup_controller.js index fd18eb6..e79335b 100644 --- a/src/controllers/popup_controller.js +++ b/src/controllers/popup_controller.js @@ -168,7 +168,13 @@ export default class extends Controller { * @returns {void} */ closeOnEscape(event) { - if (this.element.hidden || this.dialogTarget.hidden || event.defaultPrevented || event.isComposing) return + if ( + this.element.hidden || + this.dialogTarget.hidden || + event.defaultPrevented || + event.isComposing + ) + return this.close(event) }