ui.shipaid.com 0.3.96 → 0.3.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.es.js CHANGED
@@ -3083,13 +3083,6 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3083
3083
  }
3084
3084
  return null;
3085
3085
  }
3086
- getCheckoutURL() {
3087
- var _a, _b;
3088
- if (this._sellingPlanId) {
3089
- return `/cart/add?id=${(_a = this._protectionVariant) == null ? void 0 : _a.id}&quantity=1&selling_plan=${this._sellingPlanId}&return_to=/checkout`;
3090
- }
3091
- return `/checkout?attributes[_shipaid-internal]=1&updates[${(_b = this._protectionVariant) == null ? void 0 : _b.id}]=1`;
3092
- }
3093
3086
  checkoutButtonTemplate() {
3094
3087
  var _a, _b, _c, _d, _e, _f, _g;
3095
3088
  if (!document.getElementById("shipaid-styles")) {
@@ -3598,7 +3591,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3598
3591
  );
3599
3592
  }
3600
3593
  }, 500);
3601
- if (this.disablePolling || this.useShipAidCheckout) return;
3594
+ if (this.disablePolling) return;
3602
3595
  setInterval(async () => {
3603
3596
  const lastUpdated = this._cartLastUpdated;
3604
3597
  if (lastUpdated) {
@@ -24,7 +24,7 @@ const s=window,d=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"
24
24
  * @license
25
25
  * Copyright 2017 Google LLC
26
26
  * SPDX-License-Identifier: BSD-3-Clause
27
- */;var m;const g=window,f=g.trustedTypes,v=f?f.emptyScript:"",b=g.reactiveElementPolyfillSupport,y={toAttribute(t,e){switch(e){case Boolean:t=t?v:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(o){i=null}}return i}},_=(t,e)=>e!==t&&(e==e||t==t),w={attribute:!0,type:String,converter:y,reflect:!1,hasChanged:_},C="finalized";let x=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const o=this._$Ep(i,e);void 0!==o&&(this._$Ev.set(o,i),t.push(o))})),t}static createProperty(t,e=w){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,o=this.getPropertyDescriptor(t,i,e);void 0!==o&&Object.defineProperty(this.prototype,t,o)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(o){const r=this[t];this[e]=o,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||w}static finalize(){if(this.hasOwnProperty(C))return!1;this[C]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(u(t))}else void 0!==t&&e.push(u(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{d?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),o=s.litNonce;void 0!==o&&i.setAttribute("nonce",o),i.textContent=e.cssText,t.appendChild(i)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=w){var o;const r=this.constructor._$Ep(t,i);if(void 0!==r&&!0===i.reflect){const n=(void 0!==(null===(o=i.converter)||void 0===o?void 0:o.toAttribute)?i.converter:y).toAttribute(e,i.type);this._$El=t,null==n?this.removeAttribute(r):this.setAttribute(r,n),this._$El=null}}_$AK(t,e){var i;const o=this.constructor,r=o._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=o.getPropertyOptions(r),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:y;this._$El=r,this[r]=n.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let o=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||_)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):o=!1),!this.isUpdatePending&&o&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(o){throw e=!1,this._$Ek(),o}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}};
27
+ */;var m;const g=window,f=g.trustedTypes,v=f?f.emptyScript:"",b=g.reactiveElementPolyfillSupport,y={toAttribute(t,e){switch(e){case Boolean:t=t?v:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(o){i=null}}return i}},w=(t,e)=>e!==t&&(e==e||t==t),_={attribute:!0,type:String,converter:y,reflect:!1,hasChanged:w},C="finalized";let x=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const o=this._$Ep(i,e);void 0!==o&&(this._$Ev.set(o,i),t.push(o))})),t}static createProperty(t,e=_){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,o=this.getPropertyDescriptor(t,i,e);void 0!==o&&Object.defineProperty(this.prototype,t,o)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(o){const r=this[t];this[e]=o,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||_}static finalize(){if(this.hasOwnProperty(C))return!1;this[C]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(u(t))}else void 0!==t&&e.push(u(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{d?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),o=s.litNonce;void 0!==o&&i.setAttribute("nonce",o),i.textContent=e.cssText,t.appendChild(i)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=_){var o;const r=this.constructor._$Ep(t,i);if(void 0!==r&&!0===i.reflect){const n=(void 0!==(null===(o=i.converter)||void 0===o?void 0:o.toAttribute)?i.converter:y).toAttribute(e,i.type);this._$El=t,null==n?this.removeAttribute(r):this.setAttribute(r,n),this._$El=null}}_$AK(t,e){var i;const o=this.constructor,r=o._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=o.getPropertyOptions(r),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:y;this._$El=r,this[r]=n.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let o=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||w)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):o=!1),!this.isUpdatePending&&o&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(o){throw e=!1,this._$Ek(),o}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}};
28
28
  /**
29
29
  * @license
30
30
  * Copyright 2017 Google LLC
@@ -41,22 +41,22 @@ var k;x[C]=!0,x.elementProperties=new Map,x.elementStyles=[],x.shadowRootOptions
41
41
  * Copyright 2017 Google LLC
42
42
  * SPDX-License-Identifier: BSD-3-Clause
43
43
  */
44
- const yt=2;class _t{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
44
+ const yt=2;class wt{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
45
45
  /**
46
46
  * @license
47
47
  * Copyright 2020 Google LLC
48
48
  * SPDX-License-Identifier: BSD-3-Clause
49
- */const wt=(t,e)=>{var i,o;const r=t._$AN;if(void 0===r)return!1;for(const n of r)null===(o=(i=n)._$AO)||void 0===o||o.call(i,e,!1),wt(n,e);return!0},Ct=t=>{let e,i;do{if(void 0===(e=t._$AM))break;i=e._$AN,i.delete(t),t=e}while(0===(null==i?void 0:i.size))},xt=t=>{for(let e;e=t._$AM;t=e){let i=e._$AN;if(void 0===i)e._$AN=i=new Set;else if(i.has(t))break;i.add(t),St(e)}};
49
+ */const _t=(t,e)=>{var i,o;const r=t._$AN;if(void 0===r)return!1;for(const n of r)null===(o=(i=n)._$AO)||void 0===o||o.call(i,e,!1),_t(n,e);return!0},Ct=t=>{let e,i;do{if(void 0===(e=t._$AM))break;i=e._$AN,i.delete(t),t=e}while(0===(null==i?void 0:i.size))},xt=t=>{for(let e;e=t._$AM;t=e){let i=e._$AN;if(void 0===i)e._$AN=i=new Set;else if(i.has(t))break;i.add(t),St(e)}};
50
50
  /**
51
51
  * @license
52
52
  * Copyright 2017 Google LLC
53
53
  * SPDX-License-Identifier: BSD-3-Clause
54
- */function kt(t){void 0!==this._$AN?(Ct(this),this._$AM=t,xt(this)):this._$AM=t}function $t(t,e=!1,i=0){const o=this._$AH,r=this._$AN;if(void 0!==r&&0!==r.size)if(e)if(Array.isArray(o))for(let n=i;n<o.length;n++)wt(o[n],!1),Ct(o[n]);else null!=o&&(wt(o,!1),Ct(o));else wt(this,t)}const St=t=>{var e,i,o,r;t.type==yt&&(null!==(e=(o=t)._$AP)&&void 0!==e||(o._$AP=$t),null!==(i=(r=t)._$AQ)&&void 0!==i||(r._$AQ=kt))};class At extends _t{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,i){super._$AT(t,e,i),xt(this),this.isConnected=t._$AU}_$AO(t,e=!0){var i,o;t!==this.isConnected&&(this.isConnected=t,t?null===(i=this.reconnected)||void 0===i||i.call(this):null===(o=this.disconnected)||void 0===o||o.call(this)),e&&(wt(this,t),Ct(this))}setValue(t){if(void 0===this._$Ct.strings)this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}class Pt extends At{constructor(){super(...arguments),this.langChangedSubscription=null,this.getValue=()=>""}renderValue(t){return this.getValue=t,this.subscribe(),this.getValue()}langChanged(t){this.setValue(this.getValue(t))}subscribe(){null==this.langChangedSubscription&&(this.langChangedSubscription=function(t,e){const i=e=>t(e.detail);return window.addEventListener(ut,i,e),()=>window.removeEventListener(ut,i)}(this.langChanged.bind(this)))}unsubscribe(){null!=this.langChangedSubscription&&this.langChangedSubscription()}disconnected(){this.unsubscribe()}reconnected(){this.subscribe()}}const Lt=(t=>(...e)=>({_$litDirective$:t,values:e}))(class extends Pt{render(t,e,i){return this.renderValue((()=>function(t,e,i=vt){let o=i.translationCache[t]||(i.translationCache[t]=i.lookup(t,i)||i.empty(t,i));return null!=(e=null!=e?ft(e):null)?i.interpolate(o,e,i):o}(t,e,i)))}});
54
+ */function kt(t){void 0!==this._$AN?(Ct(this),this._$AM=t,xt(this)):this._$AM=t}function $t(t,e=!1,i=0){const o=this._$AH,r=this._$AN;if(void 0!==r&&0!==r.size)if(e)if(Array.isArray(o))for(let n=i;n<o.length;n++)_t(o[n],!1),Ct(o[n]);else null!=o&&(_t(o,!1),Ct(o));else _t(this,t)}const St=t=>{var e,i,o,r;t.type==yt&&(null!==(e=(o=t)._$AP)&&void 0!==e||(o._$AP=$t),null!==(i=(r=t)._$AQ)&&void 0!==i||(r._$AQ=kt))};class At extends wt{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,i){super._$AT(t,e,i),xt(this),this.isConnected=t._$AU}_$AO(t,e=!0){var i,o;t!==this.isConnected&&(this.isConnected=t,t?null===(i=this.reconnected)||void 0===i||i.call(this):null===(o=this.disconnected)||void 0===o||o.call(this)),e&&(_t(this,t),Ct(this))}setValue(t){if(void 0===this._$Ct.strings)this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}class Pt extends At{constructor(){super(...arguments),this.langChangedSubscription=null,this.getValue=()=>""}renderValue(t){return this.getValue=t,this.subscribe(),this.getValue()}langChanged(t){this.setValue(this.getValue(t))}subscribe(){null==this.langChangedSubscription&&(this.langChangedSubscription=function(t,e){const i=e=>t(e.detail);return window.addEventListener(ut,i,e),()=>window.removeEventListener(ut,i)}(this.langChanged.bind(this)))}unsubscribe(){null!=this.langChangedSubscription&&this.langChangedSubscription()}disconnected(){this.unsubscribe()}reconnected(){this.subscribe()}}const Lt=(t=>(...e)=>({_$litDirective$:t,values:e}))(class extends Pt{render(t,e,i){return this.renderValue((()=>function(t,e,i=vt){let o=i.translationCache[t]||(i.translationCache[t]=i.lookup(t,i)||i.empty(t,i));return null!=(e=null!=e?ft(e):null)?i.interpolate(o,e,i):o}(t,e,i)))}});
55
55
  /**
56
56
  * @license
57
57
  * Copyright 2017 Google LLC
58
58
  * SPDX-License-Identifier: BSD-3-Clause
59
- */class zt extends _t{constructor(t){if(super(t),this.et=W,t.type!==yt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===W||null==t)return this.ft=void 0,this.et=t;if(t===H)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.et)return this.ft;this.et=t;const e=[t];return e.raw=e,this.ft={_$litType$:this.constructor.resultType,strings:e,values:[]}}}zt.directiveName="unsafeHTML",zt.resultType=1;const Et="__registered_effects";function It(t){const e=t;if(e[Et])return e;const i=function(t){if(!t.dispatchEvent||!t.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return t}(t),o=i.updated;return e[Et]={index:0,count:0,effects:[]},i.updated=t=>(e[Et].index=0,o(t)),e}function Mt(t,e,i){const o=function(t,e){const i=It(t),{index:o,count:r}=i[Et];return o===r?(i[Et].index++,i[Et].count++,i[Et].effects.push(e),e):(i[Et].index++,i[Et].effects[o])}(t,{on:e,observe:["__initial__dirty"]});o.observe.some(((t,e)=>i[e]!==t))&&o.on(),o.observe=i}
59
+ */class zt extends wt{constructor(t){if(super(t),this.et=W,t.type!==yt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===W||null==t)return this.ft=void 0,this.et=t;if(t===H)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.et)return this.ft;this.et=t;const e=[t];return e.raw=e,this.ft={_$litType$:this.constructor.resultType,strings:e,values:[]}}}zt.directiveName="unsafeHTML",zt.resultType=1;const Et="__registered_effects";function It(t){const e=t;if(e[Et])return e;const i=function(t){if(!t.dispatchEvent||!t.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return t}(t),o=i.updated;return e[Et]={index:0,count:0,effects:[]},i.updated=t=>(e[Et].index=0,o(t)),e}function Mt(t,e,i){const o=function(t,e){const i=It(t),{index:o,count:r}=i[Et];return o===r?(i[Et].index++,i[Et].count++,i[Et].effects.push(e),e):(i[Et].index++,i[Et].effects[o])}(t,{on:e,observe:["__initial__dirty"]});o.observe.some(((t,e)=>i[e]!==t))&&o.on(),o.observe=i}
60
60
  /**
61
61
  * @license
62
62
  * Copyright 2021 Google LLC
@@ -1168,16 +1168,16 @@ function Tt(t,e,i){return t?e():null==i?void 0:i()}const qt=h`
1168
1168
  .shipaid-prompt .prompt-footer .prompt-footer-badge svg {
1169
1169
  height:var(--shipaid-footer-badge-logo-height, 9px);
1170
1170
  }
1171
- `;var ue=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ue||{});var me=Object.defineProperty,ge=(t,e,i,o)=>{for(var r,n=void 0,a=t.length-1;a>=0;a--)(r=t[a])&&(n=r(e,i,n)||n);return n&&me(e,i,n),n};const fe=t=>({items:t.lines.edges.map((({node:t})=>({id:t.id,key:t.id,variant_id:t.merchandise.id,sku:t.merchandise.sku,final_line_price:parseFloat(t.cost.totalAmount.amount),quantity:t.quantity}))),total_price:parseFloat(t.cost.totalAmount.amount),item_count:t.lines.edges.length}),ve=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},be=t=>console.warn(`[ShipAid] ${t}`),ye=t=>console.error(`[ShipAid] ${t}`),_e="shipaid-protection",we="shipaid-protection-popup-show",Ce="shipaid-protection",xe="query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetPollProtection\n widgetShowCart\n excludedProductSkus\n excludedCustomersIdsAutoOptIn\n protectionSettings\n widgetConfigurations\n useCustomApp\n }\n}",ke=Object.assign({"./lang/de.json":()=>Promise.resolve().then((()=>Te)).then((t=>t.default)),"./lang/en.json":()=>Promise.resolve().then((()=>ce)).then((t=>t.default)),"./lang/es.json":()=>Promise.resolve().then((()=>Be)).then((t=>t.default)),"./lang/fr.json":()=>Promise.resolve().then((()=>Ge)).then((t=>t.default)),"./lang/it.json":()=>Promise.resolve().then((()=>ei)).then((t=>t.default)),"./lang/nl.json":()=>Promise.resolve().then((()=>di)).then((t=>t.default)),"./lang/pt.json":()=>Promise.resolve().then((()=>gi)).then((t=>t.default))});var $e;$e={loader:async t=>{if("en"===t)return le;const e=Reflect.get(ke,`./lang/${t}.json`);return e?await e():le}},vt=Object.assign(Object.assign({},vt),$e);const Se=class extends ct{constructor(){var t,e,i;super(...arguments),this.env="prod",this.useCustomStoreFront=!1,this.storeDomain="",this.storeAccessToken="",this.cartId="",this.disablePolling=!1,this.disableActions=!1,this.pollingInterval=2500,this.disableRefresh=!1,this.refreshCart=!1,this.persistPopup=!1,this.defaultToggleButton=!1,this.lang="en",this.currency=void 0,this.customerId=void 0,this.supportSubscriptions=!1,this.dataSelector="",this.shadowRootSelector="",this.useShipAidCheckout=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),this._hasFinishedSetup=!1,this._shouldShowWidget=!1,this._hasProtectionInCart=!1,this.hasLoadedStrings=!1,this.fetchInterceptorCleanup=()=>{},this.intervalId=null,this._sellingPlanId=null,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>ve(t),post:(t,e)=>ve(t,{method:"POST",headers:{"Content-Type":"application/json","X-ShipAid":"1"},body:JSON.stringify(e)})},this.getElementsBySelector=t=>t?document.querySelectorAll(`${t}:not(#shipaid-checkout-button)`):[],this.addStylesIfNeeded=()=>{var t,e,i,o,r;const n=null==(o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.theme_checkout)?void 0:o.styles,a=n?`\n checkout-package-protection {\n ${n.checkoutWidget||""}\n width: var(--widget-width, 100%);\n }\n .shipaid-checkout-container {\n display: flex;\n ${n.checkoutContainer||""}\n justify-content: var(--container-x-position, center);\n }\n ${n.storeTheme||""}\n `.trim():"",s="[shipaid-hidden] { display: none !important; }"+(a?"\n"+a:""),d=document.getElementById("shipaid-styles");if(d)n&&!(null==(r=d.textContent)?void 0:r.includes(n.checkoutWidget||""))&&(d.textContent+="\n"+a);else{const t=document.createElement("style");t.id="shipaid-styles",t.textContent=s,document.head.appendChild(t)}}}shouldUpdate(t){return this.hasLoadedStrings&&super.shouldUpdate(t)}shouldPersistPopup(){return"true"===localStorage.getItem(`${we}`)?"learn-more":null}setPopupKey(){this.persistPopup&&localStorage.setItem(`${we}`,"true")}get nhost(){const t=`https://${"prod"===this.env?"gjiyysyzjwuculcymsvb":"staging"===this.env?"xfnjpunvafvudwuzwjlm":"local"}.graphql.us-east-1.nhost.run/v1`;return{request:async(e,i)=>{try{const o=await fetch(t,{method:"post",body:JSON.stringify({query:e,variables:i})});return await o.json()}catch(o){console.log(`Nhost Error: ${o}`)}}}}async runStoreFrontQuery(t,e){try{const i=new Headers;i.append("Content-Type","application/json"),i.append("X-Shopify-Storefront-Access-Token",this.storeAccessToken);const o={method:"POST",headers:i,body:JSON.stringify({query:t,variables:e})},r=await fetch(`https://${this.storeDomain}/api/2021-07/graphql.json`,o);if(!r.ok)throw new Error(`GraphQL request failed: ${r.statusText}`);const n=await r.json();if(n.errors)throw new Error(n.errors[0].message);return n.data}catch(i){throw console.error("GraphQL query error:",i),new Error("Failed to execute GraphQL query")}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(be("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,n,a;const s=this.currency||(null==(i=null==(e=window.Shopify)?void 0:e.currency)?void 0:i.active)||(null==(o=this._store)?void 0:o.currency)||"USD";if(null==(a=null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.widget)?void 0:a.currencyFormat){return this._store.widgetConfigurations.widget.currencyFormat.replace("_value_",Number(t)).replace("_currency_",s)}return new Intl.NumberFormat(void 0,{currency:s,style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}_handleRefreshCart(){if(this.refreshCart)return window.location.reload()}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(ue.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.calculateProtectionTotal(this._store,this._protectionProduct,t)}_findProtectionVariant(t){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.findProtectionVariant(this._store,this._protectionProduct,t)}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}_handleConfirmationPopup(){"confirmation"!==this._popup&&(this._popup="confirmation")}_updateProtection(){var t,e,i;const o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.removeWithConfirmation;if(this._hasProtectionInCart)return o?this._handleConfirmationPopup():this.removeProtection();this.addProtection()}async _fetchShipAidData(){var t,e,i,o,r;let n;if(n=this.storeDomain?this.storeDomain:(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),!n)throw new Error("No shop found in Shopify object.");try{let t,e;if(this.useCustomStoreFront)e=await this.nhost.request(xe,{store:n});else{t=new URL(window.location.href),t.pathname=this._apiEndpoint;const i={query:xe,variables:{store:n}};e=await this._fetch.post(t.toString(),i)}if(!e)throw new Error("Missing response for store query.");if(null==(o=e.errors)?void 0:o.length)throw new Error(e.errors[0].message);if(!(null==(r=e.data)?void 0:r.store))throw new Error("Missing store from store query response.");return e.data.store}catch(a){throw console.error(a),new Error(`Could not find a store for ${this._storeDomain}`)}}_findSellingPlanByName(t,e){for(const i of t){const t=i.node;for(const i of t.sellingPlans.edges){const t=i.node;if(e===t.name)return t}}return null}async _fetchSellingPlanFromVariant(t){var e,i,o,r,n,a,s,d,p,l,c,h,u;const m=(null==(e=window.Shopify)?void 0:e.shop)??(null==(o=null==(i=window.Shopify)?void 0:i.Checkout)?void 0:o.apiHost);if(!m)throw new Error("No shop found in Shopify object.");try{const e=new URL(window.location.href);e.pathname=this._apiEndpoint;const i={query:"query SellingPlanFromVariant($store: String!, $variantId: String!){\n sellingPlanFromVariant(input: {store: $store, variantId: $variantId })\n}",variables:{store:m,variantId:`gid://shopify/ProductVariant/${null==(r=this._protectionVariant)?void 0:r.id}`}},o=await this._fetch.post(e.toString(),i);if(!o)throw new Error("Missing response for selling plan query.");if(null==(n=o.errors)?void 0:n.length)throw new Error(o.errors[0].message);if(!(null==(a=o.data)?void 0:a.sellingPlanFromVariant))throw new Error("Missing variant from selling plan query response.");const g=(null==(d=null==(s=o.data.sellingPlanFromVariant)?void 0:s.sellingPlanGroups)?void 0:d.edges)||[],f=(null==(u=null==(h=null==(c=null==(l=null==(p=g[0])?void 0:p.node)?void 0:l.sellingPlans)?void 0:c.edges)?void 0:h[0])?void 0:u.node)||null;return this._findSellingPlanByName(g,t.name)||f}catch(g){console.error("Error during the query ====>",g)}}async _fetchCart(){try{if(this.useCustomStoreFront&&this.cartId){const t=await this.runStoreFrontQuery("query getCart($cartId: ID!){ cart( id: $cartId ) { id createdAt updatedAt lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } }",{cartId:this.cartId});return fe(t.cart)}return await this._fetch.get("/cart.js")}catch(t){throw ye(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){var t,e,i,o,r,n,a,s;try{let d;if(this.useCustomStoreFront){const p=await this.runStoreFrontQuery("query product($handle: String!) { product(handle: $handle) { id title images(first: 1) {edges { node { id url altText } } } handle variants(first: 100) { edges { node { id title price { amount } } } } } }",{handle:Ce});if(null==p?void 0:p.product){const l=p.product;d={id:l.id,title:l.title,image:{id:null==(o=null==(i=null==(e=null==(t=null==l?void 0:l.images)?void 0:t.edges)?void 0:e[0])?void 0:i.node)?void 0:o.id,src:null==(s=null==(a=null==(n=null==(r=null==l?void 0:l.images)?void 0:r.edges)?void 0:n[0])?void 0:a.node)?void 0:s.url},variants:l.variants.edges.map((t=>({id:t.node.id,price:t.node.price.amount})))}}}else d=(await this._fetch.get(`/products/${Ce}.json`)).product;return d}catch(d){throw ye(d.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addCartProtectionVariant(){var t,e;let i;if(this.useCustomStoreFront){const e=await this.runStoreFrontQuery("mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{merchandiseId:String(null==(t=this._protectionVariant)?void 0:t.id),quantity:1,sellingPlanId:this._sellingPlanId}]});i=fe(e.cartLinesAdd.cart)}else{const t={quantity:1,id:String(null==(e=this._protectionVariant)?void 0:e.id),selling_plan:this._sellingPlanId};i=await this._fetch.post("/cart/add.js",t)}return i}async updateCartProtectionVariant(t,e=null){var i,o;let r;if(this.useCustomStoreFront){const o=await this.runStoreFrontQuery("mutation RemoveItemToCart($cartId: ID!, $lines: [CartLineUpdateInput!]!) { cartLinesUpdate(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{id:String(e?e.key:null==(i=this._protectionCartItem)?void 0:i.key),quantity:t,sellingPlanId:this._sellingPlanId}]});r=fe(o.cartLinesUpdate.cart)}else{const i={quantity:t,id:String(e?e.key:null==(o=this._protectionCartItem)?void 0:o.key),selling_plan:this._sellingPlanId};r=await this._fetch.post("/cart/change.js",i)}return r}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i=await this.addCartProtectionVariant();await this._handleRefresh(i),this._setState("success")}catch(i){ye(i.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t=await this.updateCartProtectionVariant(0,this._protectionCartItem);await this._handleRefresh(t),this._cart=t,this._setState("success")}catch(t){ye(t.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async attemptAddProtection(){var t,e,i,o,r,n;if(!(null==(t=this._store)?void 0:t.widgetAutoOptIn))return;if(!(null==(e=this._cart)?void 0:e.items)||!(null==(i=this._cart)?void 0:i.item_count))return;const a=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),s=null==(r=this._cart)?void 0:r.items[a];if(this._hasProtectionInCart=!!s,1===this._cart.item_count&&s)return;!!sessionStorage.getItem(_e)||!this._hasProtectionInCart&&(null==(n=this._cart)?void 0:n.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(_e,JSON.stringify({loaded:!0})))}async handleMultipleProtectionVariants(){var t,e,i,o,r;if(!(null==(t=this._cart)?void 0:t.items)||!(null==(e=this._cart)?void 0:e.item_count))return;let n=0;if(null==(i=this._cart.items)||i.forEach((t=>{var e,i;(null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id)))&&n++})),n>1){const t=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),e=null==(r=this._cart)?void 0:r.items[t],i=await this.updateCartProtectionVariant(0,e);return await this._handleRefresh(i)}}learnMorePopupTemplate(){return F`
1171
+ `;var ue=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ue||{});var me=Object.defineProperty,ge=(t,e,i,o)=>{for(var r,n=void 0,a=t.length-1;a>=0;a--)(r=t[a])&&(n=r(e,i,n)||n);return n&&me(e,i,n),n};const fe=t=>({items:t.lines.edges.map((({node:t})=>({id:t.id,key:t.id,variant_id:t.merchandise.id,sku:t.merchandise.sku,final_line_price:parseFloat(t.cost.totalAmount.amount),quantity:t.quantity}))),total_price:parseFloat(t.cost.totalAmount.amount),item_count:t.lines.edges.length}),ve=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},be=t=>console.warn(`[ShipAid] ${t}`),ye=t=>console.error(`[ShipAid] ${t}`),we="shipaid-protection",_e="shipaid-protection-popup-show",Ce="shipaid-protection",xe="query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetPollProtection\n widgetShowCart\n excludedProductSkus\n excludedCustomersIdsAutoOptIn\n protectionSettings\n widgetConfigurations\n useCustomApp\n }\n}",ke=Object.assign({"./lang/de.json":()=>Promise.resolve().then((()=>Te)).then((t=>t.default)),"./lang/en.json":()=>Promise.resolve().then((()=>ce)).then((t=>t.default)),"./lang/es.json":()=>Promise.resolve().then((()=>Be)).then((t=>t.default)),"./lang/fr.json":()=>Promise.resolve().then((()=>Ge)).then((t=>t.default)),"./lang/it.json":()=>Promise.resolve().then((()=>ei)).then((t=>t.default)),"./lang/nl.json":()=>Promise.resolve().then((()=>di)).then((t=>t.default)),"./lang/pt.json":()=>Promise.resolve().then((()=>gi)).then((t=>t.default))});var $e;$e={loader:async t=>{if("en"===t)return le;const e=Reflect.get(ke,`./lang/${t}.json`);return e?await e():le}},vt=Object.assign(Object.assign({},vt),$e);const Se=class extends ct{constructor(){var t,e,i;super(...arguments),this.env="prod",this.useCustomStoreFront=!1,this.storeDomain="",this.storeAccessToken="",this.cartId="",this.disablePolling=!1,this.disableActions=!1,this.pollingInterval=2500,this.disableRefresh=!1,this.refreshCart=!1,this.persistPopup=!1,this.defaultToggleButton=!1,this.lang="en",this.currency=void 0,this.customerId=void 0,this.supportSubscriptions=!1,this.dataSelector="",this.shadowRootSelector="",this.useShipAidCheckout=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),this._hasFinishedSetup=!1,this._shouldShowWidget=!1,this._hasProtectionInCart=!1,this.hasLoadedStrings=!1,this.fetchInterceptorCleanup=()=>{},this.intervalId=null,this._sellingPlanId=null,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>ve(t),post:(t,e)=>ve(t,{method:"POST",headers:{"Content-Type":"application/json","X-ShipAid":"1"},body:JSON.stringify(e)})},this.getElementsBySelector=t=>t?document.querySelectorAll(`${t}:not(#shipaid-checkout-button)`):[],this.addStylesIfNeeded=()=>{var t,e,i,o,r;const n=null==(o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.theme_checkout)?void 0:o.styles,a=n?`\n checkout-package-protection {\n ${n.checkoutWidget||""}\n width: var(--widget-width, 100%);\n }\n .shipaid-checkout-container {\n display: flex;\n ${n.checkoutContainer||""}\n justify-content: var(--container-x-position, center);\n }\n ${n.storeTheme||""}\n `.trim():"",s="[shipaid-hidden] { display: none !important; }"+(a?"\n"+a:""),d=document.getElementById("shipaid-styles");if(d)n&&!(null==(r=d.textContent)?void 0:r.includes(n.checkoutWidget||""))&&(d.textContent+="\n"+a);else{const t=document.createElement("style");t.id="shipaid-styles",t.textContent=s,document.head.appendChild(t)}}}shouldUpdate(t){return this.hasLoadedStrings&&super.shouldUpdate(t)}shouldPersistPopup(){return"true"===localStorage.getItem(`${_e}`)?"learn-more":null}setPopupKey(){this.persistPopup&&localStorage.setItem(`${_e}`,"true")}get nhost(){const t=`https://${"prod"===this.env?"gjiyysyzjwuculcymsvb":"staging"===this.env?"xfnjpunvafvudwuzwjlm":"local"}.graphql.us-east-1.nhost.run/v1`;return{request:async(e,i)=>{try{const o=await fetch(t,{method:"post",body:JSON.stringify({query:e,variables:i})});return await o.json()}catch(o){console.log(`Nhost Error: ${o}`)}}}}async runStoreFrontQuery(t,e){try{const i=new Headers;i.append("Content-Type","application/json"),i.append("X-Shopify-Storefront-Access-Token",this.storeAccessToken);const o={method:"POST",headers:i,body:JSON.stringify({query:t,variables:e})},r=await fetch(`https://${this.storeDomain}/api/2021-07/graphql.json`,o);if(!r.ok)throw new Error(`GraphQL request failed: ${r.statusText}`);const n=await r.json();if(n.errors)throw new Error(n.errors[0].message);return n.data}catch(i){throw console.error("GraphQL query error:",i),new Error("Failed to execute GraphQL query")}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(be("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,n,a;const s=this.currency||(null==(i=null==(e=window.Shopify)?void 0:e.currency)?void 0:i.active)||(null==(o=this._store)?void 0:o.currency)||"USD";if(null==(a=null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.widget)?void 0:a.currencyFormat){return this._store.widgetConfigurations.widget.currencyFormat.replace("_value_",Number(t)).replace("_currency_",s)}return new Intl.NumberFormat(void 0,{currency:s,style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}_handleRefreshCart(){if(this.refreshCart)return window.location.reload()}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(ue.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.calculateProtectionTotal(this._store,this._protectionProduct,t)}_findProtectionVariant(t){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.findProtectionVariant(this._store,this._protectionProduct,t)}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}_handleConfirmationPopup(){"confirmation"!==this._popup&&(this._popup="confirmation")}_updateProtection(){var t,e,i;const o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.removeWithConfirmation;if(this._hasProtectionInCart)return o?this._handleConfirmationPopup():this.removeProtection();this.addProtection()}async _fetchShipAidData(){var t,e,i,o,r;let n;if(n=this.storeDomain?this.storeDomain:(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),!n)throw new Error("No shop found in Shopify object.");try{let t,e;if(this.useCustomStoreFront)e=await this.nhost.request(xe,{store:n});else{t=new URL(window.location.href),t.pathname=this._apiEndpoint;const i={query:xe,variables:{store:n}};e=await this._fetch.post(t.toString(),i)}if(!e)throw new Error("Missing response for store query.");if(null==(o=e.errors)?void 0:o.length)throw new Error(e.errors[0].message);if(!(null==(r=e.data)?void 0:r.store))throw new Error("Missing store from store query response.");return e.data.store}catch(a){throw console.error(a),new Error(`Could not find a store for ${this._storeDomain}`)}}_findSellingPlanByName(t,e){for(const i of t){const t=i.node;for(const i of t.sellingPlans.edges){const t=i.node;if(e===t.name)return t}}return null}async _fetchSellingPlanFromVariant(t){var e,i,o,r,n,a,s,d,p,l,c,h,u;const m=(null==(e=window.Shopify)?void 0:e.shop)??(null==(o=null==(i=window.Shopify)?void 0:i.Checkout)?void 0:o.apiHost);if(!m)throw new Error("No shop found in Shopify object.");try{const e=new URL(window.location.href);e.pathname=this._apiEndpoint;const i={query:"query SellingPlanFromVariant($store: String!, $variantId: String!){\n sellingPlanFromVariant(input: {store: $store, variantId: $variantId })\n}",variables:{store:m,variantId:`gid://shopify/ProductVariant/${null==(r=this._protectionVariant)?void 0:r.id}`}},o=await this._fetch.post(e.toString(),i);if(!o)throw new Error("Missing response for selling plan query.");if(null==(n=o.errors)?void 0:n.length)throw new Error(o.errors[0].message);if(!(null==(a=o.data)?void 0:a.sellingPlanFromVariant))throw new Error("Missing variant from selling plan query response.");const g=(null==(d=null==(s=o.data.sellingPlanFromVariant)?void 0:s.sellingPlanGroups)?void 0:d.edges)||[],f=(null==(u=null==(h=null==(c=null==(l=null==(p=g[0])?void 0:p.node)?void 0:l.sellingPlans)?void 0:c.edges)?void 0:h[0])?void 0:u.node)||null;return this._findSellingPlanByName(g,t.name)||f}catch(g){console.error("Error during the query ====>",g)}}async _fetchCart(){try{if(this.useCustomStoreFront&&this.cartId){const t=await this.runStoreFrontQuery("query getCart($cartId: ID!){ cart( id: $cartId ) { id createdAt updatedAt lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } }",{cartId:this.cartId});return fe(t.cart)}return await this._fetch.get("/cart.js")}catch(t){throw ye(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){var t,e,i,o,r,n,a,s;try{let d;if(this.useCustomStoreFront){const p=await this.runStoreFrontQuery("query product($handle: String!) { product(handle: $handle) { id title images(first: 1) {edges { node { id url altText } } } handle variants(first: 100) { edges { node { id title price { amount } } } } } }",{handle:Ce});if(null==p?void 0:p.product){const l=p.product;d={id:l.id,title:l.title,image:{id:null==(o=null==(i=null==(e=null==(t=null==l?void 0:l.images)?void 0:t.edges)?void 0:e[0])?void 0:i.node)?void 0:o.id,src:null==(s=null==(a=null==(n=null==(r=null==l?void 0:l.images)?void 0:r.edges)?void 0:n[0])?void 0:a.node)?void 0:s.url},variants:l.variants.edges.map((t=>({id:t.node.id,price:t.node.price.amount})))}}}else d=(await this._fetch.get(`/products/${Ce}.json`)).product;return d}catch(d){throw ye(d.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addCartProtectionVariant(){var t,e;let i;if(this.useCustomStoreFront){const e=await this.runStoreFrontQuery("mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{merchandiseId:String(null==(t=this._protectionVariant)?void 0:t.id),quantity:1,sellingPlanId:this._sellingPlanId}]});i=fe(e.cartLinesAdd.cart)}else{const t={quantity:1,id:String(null==(e=this._protectionVariant)?void 0:e.id),selling_plan:this._sellingPlanId};i=await this._fetch.post("/cart/add.js",t)}return i}async updateCartProtectionVariant(t,e=null){var i,o;let r;if(this.useCustomStoreFront){const o=await this.runStoreFrontQuery("mutation RemoveItemToCart($cartId: ID!, $lines: [CartLineUpdateInput!]!) { cartLinesUpdate(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{id:String(e?e.key:null==(i=this._protectionCartItem)?void 0:i.key),quantity:t,sellingPlanId:this._sellingPlanId}]});r=fe(o.cartLinesUpdate.cart)}else{const i={quantity:t,id:String(e?e.key:null==(o=this._protectionCartItem)?void 0:o.key),selling_plan:this._sellingPlanId};r=await this._fetch.post("/cart/change.js",i)}return r}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i=await this.addCartProtectionVariant();await this._handleRefresh(i),this._setState("success")}catch(i){ye(i.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t=await this.updateCartProtectionVariant(0,this._protectionCartItem);await this._handleRefresh(t),this._cart=t,this._setState("success")}catch(t){ye(t.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async attemptAddProtection(){var t,e,i,o,r,n;if(!(null==(t=this._store)?void 0:t.widgetAutoOptIn))return;if(!(null==(e=this._cart)?void 0:e.items)||!(null==(i=this._cart)?void 0:i.item_count))return;const a=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),s=null==(r=this._cart)?void 0:r.items[a];if(this._hasProtectionInCart=!!s,1===this._cart.item_count&&s)return;!!sessionStorage.getItem(we)||!this._hasProtectionInCart&&(null==(n=this._cart)?void 0:n.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(we,JSON.stringify({loaded:!0})))}async handleMultipleProtectionVariants(){var t,e,i,o,r;if(!(null==(t=this._cart)?void 0:t.items)||!(null==(e=this._cart)?void 0:e.item_count))return;let n=0;if(null==(i=this._cart.items)||i.forEach((t=>{var e,i;(null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id)))&&n++})),n>1){const t=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),e=null==(r=this._cart)?void 0:r.items[t],i=await this.updateCartProtectionVariant(0,e);return await this._handleRefresh(i)}}learnMorePopupTemplate(){return F`
1172
1172
  <shipaid-popup-learn-more
1173
1173
  ?active=${"learn-more"===this._popup}
1174
- @close=${()=>{this.persistPopup&&localStorage.removeItem(`${we}`),this._popup=null}}
1174
+ @close=${()=>{this.persistPopup&&localStorage.removeItem(`${_e}`),this._popup=null}}
1175
1175
  ></shipaid-popup-learn-more>
1176
1176
  `}confirmationPopupTemplate(){return F`
1177
1177
  <shipaid-popup-confirmation
1178
1178
  ?active=${"confirmation"===this._popup}
1179
- @close=${()=>{this.persistPopup&&localStorage.removeItem(`${we}`),this._popup=null}}
1180
- @remove-protection=${()=>{this.removeProtection(),this.persistPopup&&localStorage.removeItem(`${we}`),this._popup=null}}
1179
+ @close=${()=>{this.persistPopup&&localStorage.removeItem(`${_e}`),this._popup=null}}
1180
+ @remove-protection=${()=>{this.removeProtection(),this.persistPopup&&localStorage.removeItem(`${_e}`),this._popup=null}}
1181
1181
  ></shipaid-popup-confirmation>
1182
1182
  `}contactlessCheckoutButtonTemplate(){this.addStylesIfNeeded();const t=this.getElementsBySelector(sessionStorage.getItem("shipaidWidgetTheme"));if(t.length)return t.forEach(((t,e)=>{var i,o,r;const n=`shipaid-checkout-container-${e}`;t.setAttribute("shipaid-hidden","");const a=t.className;let s=document.getElementById(n);s||(s=document.createElement("div"),s.id=n,s.style.width="100%",s.className="shipaid-checkout-container",t.insertAdjacentElement("afterend",s));const d=Number(null==(i=this._protectionVariant)?void 0:i.price)||0,p=(Number(null==(o=this._cart)?void 0:o.total_price)||0)/100,l=this._hasProtectionInCart?p:d+p,c=F`
1183
1183
  <svg width="1.5rem" height="1.5rem" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="4" class="shipaid-loader">
@@ -1267,7 +1267,7 @@ function Tt(t,e,i){return t?e():null==i?void 0:i()}const qt=h`
1267
1267
  @shipaid-about=${()=>{this._popup="learn-more",this.persistPopup&&this.setPopupKey()}}
1268
1268
  @shipaid-remove-protection=${async()=>{await this.removeProtection(),window.location.href="/checkout"}}
1269
1269
  ></checkout-package-protection>
1270
- `,s)})),W}createRenderRoot(){return this.useShipAidCheckout?this:super.createRenderRoot()}async getSubscription(t){var e;if(!(null==t?void 0:t.items)||!(null==t?void 0:t.item_count))return;const i=null==(e=null==t?void 0:t.items)?void 0:e.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));if(i){const t=await this._fetchSellingPlanFromVariant(i.selling_plan_allocation.selling_plan);return t?function(t){var e;return(null==(e=null==t?void 0:t.match(/\d+/))?void 0:e[0])??null}(t.id):null}return null}getCheckoutURL(){var t,e;return this._sellingPlanId?`/cart/add?id=${null==(t=this._protectionVariant)?void 0:t.id}&quantity=1&selling_plan=${this._sellingPlanId}&return_to=/checkout`:`/checkout?attributes[_shipaid-internal]=1&updates[${null==(e=this._protectionVariant)?void 0:e.id}]=1`}checkoutButtonTemplate(){var t,e,i,o,r,n,a;if(!document.getElementById("shipaid-styles")){const t=document.createElement("style");t.id="shipaid-styles",t.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(t)}if(!this.dataSelector)return void console.error("[shipaid-widget] we couldn't find the 'data-selector' attribute.");let s=null;if(this.shadowRootSelector){const t=document.querySelector(this.shadowRootSelector);if(!t||!t.shadowRoot)return void console.warn(`ShadowRoot not found in the element '${this.shadowRootSelector}'.`);s=t.shadowRoot.querySelector(`${this.dataSelector}:not(#shipaid-checkout-button)`)}else s=null==(t=this.getElementsBySelector(this.dataSelector))?void 0:t[0];if(!s)return void console.warn(`Button not found with selector '${this.dataSelector}'.`);s.setAttribute("shipaid-hidden","");const d=s.className,p=Number(null==(e=this._protectionVariant)?void 0:e.price)||0,l=(Number(null==(i=this._cart)?void 0:i.total_price)||0)/100,c=this._hasProtectionInCart?l:p+l,h=F`
1270
+ `,s)})),W}createRenderRoot(){return this.useShipAidCheckout?this:super.createRenderRoot()}async getSubscription(t){var e;if(!(null==t?void 0:t.items)||!(null==t?void 0:t.item_count))return;const i=null==(e=null==t?void 0:t.items)?void 0:e.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));if(i){const t=await this._fetchSellingPlanFromVariant(i.selling_plan_allocation.selling_plan);return t?function(t){var e;return(null==(e=null==t?void 0:t.match(/\d+/))?void 0:e[0])??null}(t.id):null}return null}checkoutButtonTemplate(){var t,e,i,o,r,n,a;if(!document.getElementById("shipaid-styles")){const t=document.createElement("style");t.id="shipaid-styles",t.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(t)}if(!this.dataSelector)return void console.error("[shipaid-widget] we couldn't find the 'data-selector' attribute.");let s=null;if(this.shadowRootSelector){const t=document.querySelector(this.shadowRootSelector);if(!t||!t.shadowRoot)return void console.warn(`ShadowRoot not found in the element '${this.shadowRootSelector}'.`);s=t.shadowRoot.querySelector(`${this.dataSelector}:not(#shipaid-checkout-button)`)}else s=null==(t=this.getElementsBySelector(this.dataSelector))?void 0:t[0];if(!s)return void console.warn(`Button not found with selector '${this.dataSelector}'.`);s.setAttribute("shipaid-hidden","");const d=s.className,p=Number(null==(e=this._protectionVariant)?void 0:e.price)||0,l=(Number(null==(i=this._cart)?void 0:i.total_price)||0)/100,c=this._hasProtectionInCart?l:p+l,h=F`
1271
1271
  <svg width="1.5rem" height="1.5rem" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="4" class="shipaid-loader">
1272
1272
  <circle cx="25" cy="25" r="20" stroke-opacity="0.5"/>
1273
1273
  <path d="M45 25a20 20 0 0 1-40 0" stroke="currentColor">
@@ -1455,7 +1455,7 @@ function Tt(t,e,i){return t?e():null==i?void 0:i()}const qt=h`
1455
1455
  </a>
1456
1456
  </div>
1457
1457
  </div>
1458
- `}async connectedCallback(){super.connectedCallback(),await async function(t,e=vt){const i=await e.loader(t,e);e.translationCache={},bt(t,i,e)}(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(t){const e=window.fetch;let i=!0;const o=async(o,r)=>{const n=e(o,r);if(i)try{await t([o,r],n)}catch(a){console.warn(a)}return await n};return window.fetch=o,()=>{window.fetch===o?window.fetch=e:i=!1}}((async(t,e)=>{var i,o,r,n;if(null==(o=null==(i=t[1])?void 0:i.headers)?void 0:o["X-ShipAid"])return;if(!t[0].startsWith("/cart/change")&&!t[0].startsWith("/cart/update"))return;const a=(null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.checkoutButtonSelector)||'button[type="submit"][name="checkout"][form="cart"]',s=document.querySelector(a);if(console.log("q",s),s){s.setAttribute("disabled","true"),console.debug("button","t");try{await e,await this.updateCart(),await this.updateProtection()}finally{s.removeAttribute("disabled"),console.debug("button","f")}}}))}disconnectedCallback(){var t;super.disconnectedCallback(),null==(t=this.fetchInterceptorCleanup)||t.call(this)}async updateProtection(){var t,e,i,o;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const r=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),n=null==(i=this._cart)?void 0:i.items[r];if(this._hasProtectionInCart=!!n,!this._store)return;const a=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&n&&(this._cart.total_price===(null==n?void 0:n.final_line_price)||!a)){const t=await this.updateCartProtectionVariant(0,n);return sessionStorage.removeItem(_e),await this._handleRefresh(t)}const s=this._findProtectionVariant(a);if(a?(this._protectionVariant=s,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==s?void 0:s.id))return this._shouldShowWidget=!1,void ye("No matching protection variant found.");if(!(null==(o=this._protectionVariant)?void 0:o.id))return void(this._shouldShowWidget=!1);if(this.useShipAidCheckout&&this.supportSubscriptions&&(this._sellingPlanId=await this.getSubscription(this._cart)),!n)return;if(this.supportSubscriptions&&!this.useShipAidCheckout){const t=this._cart.items.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));let e=!0;if(!t&&(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=null:t&&!(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=await this.getSubscription(this._cart):e=!1,e){const t=await this.updateCartProtectionVariant(1,n);await this._handleRefresh(t)}}if(s.id===n.variant_id){if(this._protectionCartItem={...n,index:r,position:r+1},1===n.quantity)return;const t=await this.updateCartProtectionVariant(1,n);return this._handleRefreshCart(),await this._handleRefresh(t)}const d={updates:{[n.variant_id]:0,[s.id]:1}},p=await this._fetch.post("/cart/update.js",d);await this._handleRefresh(p)}render(){return Mt(this,(async()=>{var t,e,i,o,r,n;const a=document.createElement("link");a.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),a.setAttribute("rel","stylesheet"),document.head.appendChild(a);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(s){return ye(s.message),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._dispatchEvent(ue.LOADED,this._store),setTimeout((async()=>{var t,e,i,o;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&(null==(e=this._cart)?void 0:e.item_count)&&(this.customerId&&this._store.excludedCustomersIdsAutoOptIn&&(null==(i=this._store.excludedCustomersIdsAutoOptIn)?void 0:i.length)&&this._store.excludedCustomersIdsAutoOptIn.includes(`gid://shopify/Customer/${this.customerId}`)||sessionStorage.getItem(_e)||!this._hasProtectionInCart&&(null==(o=this._cart)?void 0:o.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(_e,JSON.stringify({loaded:!0}))))}),500),void(this.disablePolling||this.useShipAidCheckout||(setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval),(null==(i=this._store)?void 0:i.widgetPollProtection)&&!this.intervalId&&(this.intervalId=setInterval((async()=>{await this.attemptAddProtection()}),400),localStorage.setItem(`polling-shipaid-protection_${this.intervalId}`,`${this.intervalId}`)),(null==(n=null==(r=null==(o=this._store)?void 0:o.widgetConfigurations)?void 0:r.widget)?void 0:n.pollVariantsCheck)&&setInterval((async()=>{await this.handleMultipleProtectionVariants()}),400)))):(be("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),Mt(this,(async()=>{await this.updateProtection()}),[this._store,this._cart]),Mt(this,(async()=>{dt(this.renderPopups(),document.body)}),[this._popup]),F`
1458
+ `}async connectedCallback(){super.connectedCallback(),await async function(t,e=vt){const i=await e.loader(t,e);e.translationCache={},bt(t,i,e)}(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(t){const e=window.fetch;let i=!0;const o=async(o,r)=>{const n=e(o,r);if(i)try{await t([o,r],n)}catch(a){console.warn(a)}return await n};return window.fetch=o,()=>{window.fetch===o?window.fetch=e:i=!1}}((async(t,e)=>{var i,o,r,n;if(null==(o=null==(i=t[1])?void 0:i.headers)?void 0:o["X-ShipAid"])return;if(!t[0].startsWith("/cart/change")&&!t[0].startsWith("/cart/update"))return;const a=(null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.checkoutButtonSelector)||'button[type="submit"][name="checkout"][form="cart"]',s=document.querySelector(a);if(console.log("q",s),s){s.setAttribute("disabled","true"),console.debug("button","t");try{await e,await this.updateCart(),await this.updateProtection()}finally{s.removeAttribute("disabled"),console.debug("button","f")}}}))}disconnectedCallback(){var t;super.disconnectedCallback(),null==(t=this.fetchInterceptorCleanup)||t.call(this)}async updateProtection(){var t,e,i,o;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const r=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),n=null==(i=this._cart)?void 0:i.items[r];if(this._hasProtectionInCart=!!n,!this._store)return;const a=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&n&&(this._cart.total_price===(null==n?void 0:n.final_line_price)||!a)){const t=await this.updateCartProtectionVariant(0,n);return sessionStorage.removeItem(we),await this._handleRefresh(t)}const s=this._findProtectionVariant(a);if(a?(this._protectionVariant=s,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==s?void 0:s.id))return this._shouldShowWidget=!1,void ye("No matching protection variant found.");if(!(null==(o=this._protectionVariant)?void 0:o.id))return void(this._shouldShowWidget=!1);if(this.useShipAidCheckout&&this.supportSubscriptions&&(this._sellingPlanId=await this.getSubscription(this._cart)),!n)return;if(this.supportSubscriptions&&!this.useShipAidCheckout){const t=this._cart.items.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));let e=!0;if(!t&&(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=null:t&&!(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=await this.getSubscription(this._cart):e=!1,e){const t=await this.updateCartProtectionVariant(1,n);await this._handleRefresh(t)}}if(s.id===n.variant_id){if(this._protectionCartItem={...n,index:r,position:r+1},1===n.quantity)return;const t=await this.updateCartProtectionVariant(1,n);return this._handleRefreshCart(),await this._handleRefresh(t)}const d={updates:{[n.variant_id]:0,[s.id]:1}},p=await this._fetch.post("/cart/update.js",d);await this._handleRefresh(p)}render(){return Mt(this,(async()=>{var t,e,i,o,r,n;const a=document.createElement("link");a.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),a.setAttribute("rel","stylesheet"),document.head.appendChild(a);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(s){return ye(s.message),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._dispatchEvent(ue.LOADED,this._store),setTimeout((async()=>{var t,e,i,o;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&(null==(e=this._cart)?void 0:e.item_count)&&(this.customerId&&this._store.excludedCustomersIdsAutoOptIn&&(null==(i=this._store.excludedCustomersIdsAutoOptIn)?void 0:i.length)&&this._store.excludedCustomersIdsAutoOptIn.includes(`gid://shopify/Customer/${this.customerId}`)||sessionStorage.getItem(we)||!this._hasProtectionInCart&&(null==(o=this._cart)?void 0:o.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(we,JSON.stringify({loaded:!0}))))}),500),void(this.disablePolling||(setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval),(null==(i=this._store)?void 0:i.widgetPollProtection)&&!this.intervalId&&(this.intervalId=setInterval((async()=>{await this.attemptAddProtection()}),400),localStorage.setItem(`polling-shipaid-protection_${this.intervalId}`,`${this.intervalId}`)),(null==(n=null==(r=null==(o=this._store)?void 0:o.widgetConfigurations)?void 0:r.widget)?void 0:n.pollVariantsCheck)&&setInterval((async()=>{await this.handleMultipleProtectionVariants()}),400)))):(be("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),Mt(this,(async()=>{await this.updateProtection()}),[this._store,this._cart]),Mt(this,(async()=>{dt(this.renderPopups(),document.body)}),[this._popup]),F`
1459
1459
  <style>
1460
1460
  :host {
1461
1461
  --shipaid-primary: #002bd6;
@@ -24,7 +24,7 @@ const s=window,d=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"
24
24
  * @license
25
25
  * Copyright 2017 Google LLC
26
26
  * SPDX-License-Identifier: BSD-3-Clause
27
- */;var m;const g=window,f=g.trustedTypes,v=f?f.emptyScript:"",b=g.reactiveElementPolyfillSupport,y={toAttribute(t,e){switch(e){case Boolean:t=t?v:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(o){i=null}}return i}},_=(t,e)=>e!==t&&(e==e||t==t),w={attribute:!0,type:String,converter:y,reflect:!1,hasChanged:_},C="finalized";let x=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const o=this._$Ep(i,e);void 0!==o&&(this._$Ev.set(o,i),t.push(o))})),t}static createProperty(t,e=w){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,o=this.getPropertyDescriptor(t,i,e);void 0!==o&&Object.defineProperty(this.prototype,t,o)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(o){const r=this[t];this[e]=o,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||w}static finalize(){if(this.hasOwnProperty(C))return!1;this[C]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(u(t))}else void 0!==t&&e.push(u(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{d?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),o=s.litNonce;void 0!==o&&i.setAttribute("nonce",o),i.textContent=e.cssText,t.appendChild(i)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=w){var o;const r=this.constructor._$Ep(t,i);if(void 0!==r&&!0===i.reflect){const n=(void 0!==(null===(o=i.converter)||void 0===o?void 0:o.toAttribute)?i.converter:y).toAttribute(e,i.type);this._$El=t,null==n?this.removeAttribute(r):this.setAttribute(r,n),this._$El=null}}_$AK(t,e){var i;const o=this.constructor,r=o._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=o.getPropertyOptions(r),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:y;this._$El=r,this[r]=n.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let o=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||_)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):o=!1),!this.isUpdatePending&&o&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(o){throw e=!1,this._$Ek(),o}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}};
27
+ */;var m;const g=window,f=g.trustedTypes,v=f?f.emptyScript:"",b=g.reactiveElementPolyfillSupport,y={toAttribute(t,e){switch(e){case Boolean:t=t?v:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(o){i=null}}return i}},w=(t,e)=>e!==t&&(e==e||t==t),_={attribute:!0,type:String,converter:y,reflect:!1,hasChanged:w},C="finalized";let x=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const o=this._$Ep(i,e);void 0!==o&&(this._$Ev.set(o,i),t.push(o))})),t}static createProperty(t,e=_){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,o=this.getPropertyDescriptor(t,i,e);void 0!==o&&Object.defineProperty(this.prototype,t,o)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(o){const r=this[t];this[e]=o,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||_}static finalize(){if(this.hasOwnProperty(C))return!1;this[C]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(u(t))}else void 0!==t&&e.push(u(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{d?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),o=s.litNonce;void 0!==o&&i.setAttribute("nonce",o),i.textContent=e.cssText,t.appendChild(i)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=_){var o;const r=this.constructor._$Ep(t,i);if(void 0!==r&&!0===i.reflect){const n=(void 0!==(null===(o=i.converter)||void 0===o?void 0:o.toAttribute)?i.converter:y).toAttribute(e,i.type);this._$El=t,null==n?this.removeAttribute(r):this.setAttribute(r,n),this._$El=null}}_$AK(t,e){var i;const o=this.constructor,r=o._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=o.getPropertyOptions(r),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:y;this._$El=r,this[r]=n.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let o=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||w)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):o=!1),!this.isUpdatePending&&o&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(o){throw e=!1,this._$Ek(),o}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}};
28
28
  /**
29
29
  * @license
30
30
  * Copyright 2017 Google LLC
@@ -41,22 +41,22 @@ var k;x[C]=!0,x.elementProperties=new Map,x.elementStyles=[],x.shadowRootOptions
41
41
  * Copyright 2017 Google LLC
42
42
  * SPDX-License-Identifier: BSD-3-Clause
43
43
  */
44
- const yt=2;class _t{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
44
+ const yt=2;class wt{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
45
45
  /**
46
46
  * @license
47
47
  * Copyright 2020 Google LLC
48
48
  * SPDX-License-Identifier: BSD-3-Clause
49
- */const wt=(t,e)=>{var i,o;const r=t._$AN;if(void 0===r)return!1;for(const n of r)null===(o=(i=n)._$AO)||void 0===o||o.call(i,e,!1),wt(n,e);return!0},Ct=t=>{let e,i;do{if(void 0===(e=t._$AM))break;i=e._$AN,i.delete(t),t=e}while(0===(null==i?void 0:i.size))},xt=t=>{for(let e;e=t._$AM;t=e){let i=e._$AN;if(void 0===i)e._$AN=i=new Set;else if(i.has(t))break;i.add(t),St(e)}};
49
+ */const _t=(t,e)=>{var i,o;const r=t._$AN;if(void 0===r)return!1;for(const n of r)null===(o=(i=n)._$AO)||void 0===o||o.call(i,e,!1),_t(n,e);return!0},Ct=t=>{let e,i;do{if(void 0===(e=t._$AM))break;i=e._$AN,i.delete(t),t=e}while(0===(null==i?void 0:i.size))},xt=t=>{for(let e;e=t._$AM;t=e){let i=e._$AN;if(void 0===i)e._$AN=i=new Set;else if(i.has(t))break;i.add(t),St(e)}};
50
50
  /**
51
51
  * @license
52
52
  * Copyright 2017 Google LLC
53
53
  * SPDX-License-Identifier: BSD-3-Clause
54
- */function kt(t){void 0!==this._$AN?(Ct(this),this._$AM=t,xt(this)):this._$AM=t}function $t(t,e=!1,i=0){const o=this._$AH,r=this._$AN;if(void 0!==r&&0!==r.size)if(e)if(Array.isArray(o))for(let n=i;n<o.length;n++)wt(o[n],!1),Ct(o[n]);else null!=o&&(wt(o,!1),Ct(o));else wt(this,t)}const St=t=>{var e,i,o,r;t.type==yt&&(null!==(e=(o=t)._$AP)&&void 0!==e||(o._$AP=$t),null!==(i=(r=t)._$AQ)&&void 0!==i||(r._$AQ=kt))};class At extends _t{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,i){super._$AT(t,e,i),xt(this),this.isConnected=t._$AU}_$AO(t,e=!0){var i,o;t!==this.isConnected&&(this.isConnected=t,t?null===(i=this.reconnected)||void 0===i||i.call(this):null===(o=this.disconnected)||void 0===o||o.call(this)),e&&(wt(this,t),Ct(this))}setValue(t){if(void 0===this._$Ct.strings)this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}class Pt extends At{constructor(){super(...arguments),this.langChangedSubscription=null,this.getValue=()=>""}renderValue(t){return this.getValue=t,this.subscribe(),this.getValue()}langChanged(t){this.setValue(this.getValue(t))}subscribe(){null==this.langChangedSubscription&&(this.langChangedSubscription=function(t,e){const i=e=>t(e.detail);return window.addEventListener(ut,i,e),()=>window.removeEventListener(ut,i)}(this.langChanged.bind(this)))}unsubscribe(){null!=this.langChangedSubscription&&this.langChangedSubscription()}disconnected(){this.unsubscribe()}reconnected(){this.subscribe()}}const Lt=(t=>(...e)=>({_$litDirective$:t,values:e}))(class extends Pt{render(t,e,i){return this.renderValue((()=>function(t,e,i=vt){let o=i.translationCache[t]||(i.translationCache[t]=i.lookup(t,i)||i.empty(t,i));return null!=(e=null!=e?ft(e):null)?i.interpolate(o,e,i):o}(t,e,i)))}});
54
+ */function kt(t){void 0!==this._$AN?(Ct(this),this._$AM=t,xt(this)):this._$AM=t}function $t(t,e=!1,i=0){const o=this._$AH,r=this._$AN;if(void 0!==r&&0!==r.size)if(e)if(Array.isArray(o))for(let n=i;n<o.length;n++)_t(o[n],!1),Ct(o[n]);else null!=o&&(_t(o,!1),Ct(o));else _t(this,t)}const St=t=>{var e,i,o,r;t.type==yt&&(null!==(e=(o=t)._$AP)&&void 0!==e||(o._$AP=$t),null!==(i=(r=t)._$AQ)&&void 0!==i||(r._$AQ=kt))};class At extends wt{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,i){super._$AT(t,e,i),xt(this),this.isConnected=t._$AU}_$AO(t,e=!0){var i,o;t!==this.isConnected&&(this.isConnected=t,t?null===(i=this.reconnected)||void 0===i||i.call(this):null===(o=this.disconnected)||void 0===o||o.call(this)),e&&(_t(this,t),Ct(this))}setValue(t){if(void 0===this._$Ct.strings)this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}class Pt extends At{constructor(){super(...arguments),this.langChangedSubscription=null,this.getValue=()=>""}renderValue(t){return this.getValue=t,this.subscribe(),this.getValue()}langChanged(t){this.setValue(this.getValue(t))}subscribe(){null==this.langChangedSubscription&&(this.langChangedSubscription=function(t,e){const i=e=>t(e.detail);return window.addEventListener(ut,i,e),()=>window.removeEventListener(ut,i)}(this.langChanged.bind(this)))}unsubscribe(){null!=this.langChangedSubscription&&this.langChangedSubscription()}disconnected(){this.unsubscribe()}reconnected(){this.subscribe()}}const Lt=(t=>(...e)=>({_$litDirective$:t,values:e}))(class extends Pt{render(t,e,i){return this.renderValue((()=>function(t,e,i=vt){let o=i.translationCache[t]||(i.translationCache[t]=i.lookup(t,i)||i.empty(t,i));return null!=(e=null!=e?ft(e):null)?i.interpolate(o,e,i):o}(t,e,i)))}});
55
55
  /**
56
56
  * @license
57
57
  * Copyright 2017 Google LLC
58
58
  * SPDX-License-Identifier: BSD-3-Clause
59
- */class zt extends _t{constructor(t){if(super(t),this.et=W,t.type!==yt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===W||null==t)return this.ft=void 0,this.et=t;if(t===H)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.et)return this.ft;this.et=t;const e=[t];return e.raw=e,this.ft={_$litType$:this.constructor.resultType,strings:e,values:[]}}}zt.directiveName="unsafeHTML",zt.resultType=1;const Et="__registered_effects";function It(t){const e=t;if(e[Et])return e;const i=function(t){if(!t.dispatchEvent||!t.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return t}(t),o=i.updated;return e[Et]={index:0,count:0,effects:[]},i.updated=t=>(e[Et].index=0,o(t)),e}function Mt(t,e,i){const o=function(t,e){const i=It(t),{index:o,count:r}=i[Et];return o===r?(i[Et].index++,i[Et].count++,i[Et].effects.push(e),e):(i[Et].index++,i[Et].effects[o])}(t,{on:e,observe:["__initial__dirty"]});o.observe.some(((t,e)=>i[e]!==t))&&o.on(),o.observe=i}
59
+ */class zt extends wt{constructor(t){if(super(t),this.et=W,t.type!==yt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===W||null==t)return this.ft=void 0,this.et=t;if(t===H)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.et)return this.ft;this.et=t;const e=[t];return e.raw=e,this.ft={_$litType$:this.constructor.resultType,strings:e,values:[]}}}zt.directiveName="unsafeHTML",zt.resultType=1;const Et="__registered_effects";function It(t){const e=t;if(e[Et])return e;const i=function(t){if(!t.dispatchEvent||!t.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return t}(t),o=i.updated;return e[Et]={index:0,count:0,effects:[]},i.updated=t=>(e[Et].index=0,o(t)),e}function Mt(t,e,i){const o=function(t,e){const i=It(t),{index:o,count:r}=i[Et];return o===r?(i[Et].index++,i[Et].count++,i[Et].effects.push(e),e):(i[Et].index++,i[Et].effects[o])}(t,{on:e,observe:["__initial__dirty"]});o.observe.some(((t,e)=>i[e]!==t))&&o.on(),o.observe=i}
60
60
  /**
61
61
  * @license
62
62
  * Copyright 2021 Google LLC
@@ -1168,16 +1168,16 @@ function Tt(t,e,i){return t?e():null==i?void 0:i()}const qt=h`
1168
1168
  .shipaid-prompt .prompt-footer .prompt-footer-badge svg {
1169
1169
  height:var(--shipaid-footer-badge-logo-height, 9px);
1170
1170
  }
1171
- `;var ue=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ue||{});var me=Object.defineProperty,ge=(t,e,i,o)=>{for(var r,n=void 0,a=t.length-1;a>=0;a--)(r=t[a])&&(n=r(e,i,n)||n);return n&&me(e,i,n),n};const fe=t=>({items:t.lines.edges.map((({node:t})=>({id:t.id,key:t.id,variant_id:t.merchandise.id,sku:t.merchandise.sku,final_line_price:parseFloat(t.cost.totalAmount.amount),quantity:t.quantity}))),total_price:parseFloat(t.cost.totalAmount.amount),item_count:t.lines.edges.length}),ve=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},be=t=>console.warn(`[ShipAid] ${t}`),ye=t=>console.error(`[ShipAid] ${t}`),_e="shipaid-protection",we="shipaid-protection-popup-show",Ce="shipaid-protection",xe="query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetPollProtection\n widgetShowCart\n excludedProductSkus\n excludedCustomersIdsAutoOptIn\n protectionSettings\n widgetConfigurations\n useCustomApp\n }\n}",ke=Object.assign({"./lang/de.json":()=>Promise.resolve().then((()=>Te)).then((t=>t.default)),"./lang/en.json":()=>Promise.resolve().then((()=>ce)).then((t=>t.default)),"./lang/es.json":()=>Promise.resolve().then((()=>Be)).then((t=>t.default)),"./lang/fr.json":()=>Promise.resolve().then((()=>Ge)).then((t=>t.default)),"./lang/it.json":()=>Promise.resolve().then((()=>ei)).then((t=>t.default)),"./lang/nl.json":()=>Promise.resolve().then((()=>di)).then((t=>t.default)),"./lang/pt.json":()=>Promise.resolve().then((()=>gi)).then((t=>t.default))});var $e;$e={loader:async t=>{if("en"===t)return le;const e=Reflect.get(ke,`./lang/${t}.json`);return e?await e():le}},vt=Object.assign(Object.assign({},vt),$e);const Se=class extends ct{constructor(){var t,e,i;super(...arguments),this.env="prod",this.useCustomStoreFront=!1,this.storeDomain="",this.storeAccessToken="",this.cartId="",this.disablePolling=!1,this.disableActions=!1,this.pollingInterval=2500,this.disableRefresh=!1,this.refreshCart=!1,this.persistPopup=!1,this.defaultToggleButton=!1,this.lang="en",this.currency=void 0,this.customerId=void 0,this.supportSubscriptions=!1,this.dataSelector="",this.shadowRootSelector="",this.useShipAidCheckout=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),this._hasFinishedSetup=!1,this._shouldShowWidget=!1,this._hasProtectionInCart=!1,this.hasLoadedStrings=!1,this.fetchInterceptorCleanup=()=>{},this.intervalId=null,this._sellingPlanId=null,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>ve(t),post:(t,e)=>ve(t,{method:"POST",headers:{"Content-Type":"application/json","X-ShipAid":"1"},body:JSON.stringify(e)})},this.getElementsBySelector=t=>t?document.querySelectorAll(`${t}:not(#shipaid-checkout-button)`):[],this.addStylesIfNeeded=()=>{var t,e,i,o,r;const n=null==(o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.theme_checkout)?void 0:o.styles,a=n?`\n checkout-package-protection {\n ${n.checkoutWidget||""}\n width: var(--widget-width, 100%);\n }\n .shipaid-checkout-container {\n display: flex;\n ${n.checkoutContainer||""}\n justify-content: var(--container-x-position, center);\n }\n ${n.storeTheme||""}\n `.trim():"",s="[shipaid-hidden] { display: none !important; }"+(a?"\n"+a:""),d=document.getElementById("shipaid-styles");if(d)n&&!(null==(r=d.textContent)?void 0:r.includes(n.checkoutWidget||""))&&(d.textContent+="\n"+a);else{const t=document.createElement("style");t.id="shipaid-styles",t.textContent=s,document.head.appendChild(t)}}}shouldUpdate(t){return this.hasLoadedStrings&&super.shouldUpdate(t)}shouldPersistPopup(){return"true"===localStorage.getItem(`${we}`)?"learn-more":null}setPopupKey(){this.persistPopup&&localStorage.setItem(`${we}`,"true")}get nhost(){const t=`https://${"prod"===this.env?"gjiyysyzjwuculcymsvb":"staging"===this.env?"xfnjpunvafvudwuzwjlm":"local"}.graphql.us-east-1.nhost.run/v1`;return{request:async(e,i)=>{try{const o=await fetch(t,{method:"post",body:JSON.stringify({query:e,variables:i})});return await o.json()}catch(o){console.log(`Nhost Error: ${o}`)}}}}async runStoreFrontQuery(t,e){try{const i=new Headers;i.append("Content-Type","application/json"),i.append("X-Shopify-Storefront-Access-Token",this.storeAccessToken);const o={method:"POST",headers:i,body:JSON.stringify({query:t,variables:e})},r=await fetch(`https://${this.storeDomain}/api/2021-07/graphql.json`,o);if(!r.ok)throw new Error(`GraphQL request failed: ${r.statusText}`);const n=await r.json();if(n.errors)throw new Error(n.errors[0].message);return n.data}catch(i){throw console.error("GraphQL query error:",i),new Error("Failed to execute GraphQL query")}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(be("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,n,a;const s=this.currency||(null==(i=null==(e=window.Shopify)?void 0:e.currency)?void 0:i.active)||(null==(o=this._store)?void 0:o.currency)||"USD";if(null==(a=null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.widget)?void 0:a.currencyFormat){return this._store.widgetConfigurations.widget.currencyFormat.replace("_value_",Number(t)).replace("_currency_",s)}return new Intl.NumberFormat(void 0,{currency:s,style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}_handleRefreshCart(){if(this.refreshCart)return window.location.reload()}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(ue.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.calculateProtectionTotal(this._store,this._protectionProduct,t)}_findProtectionVariant(t){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.findProtectionVariant(this._store,this._protectionProduct,t)}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}_handleConfirmationPopup(){"confirmation"!==this._popup&&(this._popup="confirmation")}_updateProtection(){var t,e,i;const o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.removeWithConfirmation;if(this._hasProtectionInCart)return o?this._handleConfirmationPopup():this.removeProtection();this.addProtection()}async _fetchShipAidData(){var t,e,i,o,r;let n;if(n=this.storeDomain?this.storeDomain:(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),!n)throw new Error("No shop found in Shopify object.");try{let t,e;if(this.useCustomStoreFront)e=await this.nhost.request(xe,{store:n});else{t=new URL(window.location.href),t.pathname=this._apiEndpoint;const i={query:xe,variables:{store:n}};e=await this._fetch.post(t.toString(),i)}if(!e)throw new Error("Missing response for store query.");if(null==(o=e.errors)?void 0:o.length)throw new Error(e.errors[0].message);if(!(null==(r=e.data)?void 0:r.store))throw new Error("Missing store from store query response.");return e.data.store}catch(a){throw console.error(a),new Error(`Could not find a store for ${this._storeDomain}`)}}_findSellingPlanByName(t,e){for(const i of t){const t=i.node;for(const i of t.sellingPlans.edges){const t=i.node;if(e===t.name)return t}}return null}async _fetchSellingPlanFromVariant(t){var e,i,o,r,n,a,s,d,p,l,c,h,u;const m=(null==(e=window.Shopify)?void 0:e.shop)??(null==(o=null==(i=window.Shopify)?void 0:i.Checkout)?void 0:o.apiHost);if(!m)throw new Error("No shop found in Shopify object.");try{const e=new URL(window.location.href);e.pathname=this._apiEndpoint;const i={query:"query SellingPlanFromVariant($store: String!, $variantId: String!){\n sellingPlanFromVariant(input: {store: $store, variantId: $variantId })\n}",variables:{store:m,variantId:`gid://shopify/ProductVariant/${null==(r=this._protectionVariant)?void 0:r.id}`}},o=await this._fetch.post(e.toString(),i);if(!o)throw new Error("Missing response for selling plan query.");if(null==(n=o.errors)?void 0:n.length)throw new Error(o.errors[0].message);if(!(null==(a=o.data)?void 0:a.sellingPlanFromVariant))throw new Error("Missing variant from selling plan query response.");const g=(null==(d=null==(s=o.data.sellingPlanFromVariant)?void 0:s.sellingPlanGroups)?void 0:d.edges)||[],f=(null==(u=null==(h=null==(c=null==(l=null==(p=g[0])?void 0:p.node)?void 0:l.sellingPlans)?void 0:c.edges)?void 0:h[0])?void 0:u.node)||null;return this._findSellingPlanByName(g,t.name)||f}catch(g){console.error("Error during the query ====>",g)}}async _fetchCart(){try{if(this.useCustomStoreFront&&this.cartId){const t=await this.runStoreFrontQuery("query getCart($cartId: ID!){ cart( id: $cartId ) { id createdAt updatedAt lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } }",{cartId:this.cartId});return fe(t.cart)}return await this._fetch.get("/cart.js")}catch(t){throw ye(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){var t,e,i,o,r,n,a,s;try{let d;if(this.useCustomStoreFront){const p=await this.runStoreFrontQuery("query product($handle: String!) { product(handle: $handle) { id title images(first: 1) {edges { node { id url altText } } } handle variants(first: 100) { edges { node { id title price { amount } } } } } }",{handle:Ce});if(null==p?void 0:p.product){const l=p.product;d={id:l.id,title:l.title,image:{id:null==(o=null==(i=null==(e=null==(t=null==l?void 0:l.images)?void 0:t.edges)?void 0:e[0])?void 0:i.node)?void 0:o.id,src:null==(s=null==(a=null==(n=null==(r=null==l?void 0:l.images)?void 0:r.edges)?void 0:n[0])?void 0:a.node)?void 0:s.url},variants:l.variants.edges.map((t=>({id:t.node.id,price:t.node.price.amount})))}}}else d=(await this._fetch.get(`/products/${Ce}.json`)).product;return d}catch(d){throw ye(d.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addCartProtectionVariant(){var t,e;let i;if(this.useCustomStoreFront){const e=await this.runStoreFrontQuery("mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{merchandiseId:String(null==(t=this._protectionVariant)?void 0:t.id),quantity:1,sellingPlanId:this._sellingPlanId}]});i=fe(e.cartLinesAdd.cart)}else{const t={quantity:1,id:String(null==(e=this._protectionVariant)?void 0:e.id),selling_plan:this._sellingPlanId};i=await this._fetch.post("/cart/add.js",t)}return i}async updateCartProtectionVariant(t,e=null){var i,o;let r;if(this.useCustomStoreFront){const o=await this.runStoreFrontQuery("mutation RemoveItemToCart($cartId: ID!, $lines: [CartLineUpdateInput!]!) { cartLinesUpdate(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{id:String(e?e.key:null==(i=this._protectionCartItem)?void 0:i.key),quantity:t,sellingPlanId:this._sellingPlanId}]});r=fe(o.cartLinesUpdate.cart)}else{const i={quantity:t,id:String(e?e.key:null==(o=this._protectionCartItem)?void 0:o.key),selling_plan:this._sellingPlanId};r=await this._fetch.post("/cart/change.js",i)}return r}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i=await this.addCartProtectionVariant();await this._handleRefresh(i),this._setState("success")}catch(i){ye(i.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t=await this.updateCartProtectionVariant(0,this._protectionCartItem);await this._handleRefresh(t),this._cart=t,this._setState("success")}catch(t){ye(t.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async attemptAddProtection(){var t,e,i,o,r,n;if(!(null==(t=this._store)?void 0:t.widgetAutoOptIn))return;if(!(null==(e=this._cart)?void 0:e.items)||!(null==(i=this._cart)?void 0:i.item_count))return;const a=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),s=null==(r=this._cart)?void 0:r.items[a];if(this._hasProtectionInCart=!!s,1===this._cart.item_count&&s)return;!!sessionStorage.getItem(_e)||!this._hasProtectionInCart&&(null==(n=this._cart)?void 0:n.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(_e,JSON.stringify({loaded:!0})))}async handleMultipleProtectionVariants(){var t,e,i,o,r;if(!(null==(t=this._cart)?void 0:t.items)||!(null==(e=this._cart)?void 0:e.item_count))return;let n=0;if(null==(i=this._cart.items)||i.forEach((t=>{var e,i;(null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id)))&&n++})),n>1){const t=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),e=null==(r=this._cart)?void 0:r.items[t],i=await this.updateCartProtectionVariant(0,e);return await this._handleRefresh(i)}}learnMorePopupTemplate(){return F`
1171
+ `;var ue=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(ue||{});var me=Object.defineProperty,ge=(t,e,i,o)=>{for(var r,n=void 0,a=t.length-1;a>=0;a--)(r=t[a])&&(n=r(e,i,n)||n);return n&&me(e,i,n),n};const fe=t=>({items:t.lines.edges.map((({node:t})=>({id:t.id,key:t.id,variant_id:t.merchandise.id,sku:t.merchandise.sku,final_line_price:parseFloat(t.cost.totalAmount.amount),quantity:t.quantity}))),total_price:parseFloat(t.cost.totalAmount.amount),item_count:t.lines.edges.length}),ve=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},be=t=>console.warn(`[ShipAid] ${t}`),ye=t=>console.error(`[ShipAid] ${t}`),we="shipaid-protection",_e="shipaid-protection-popup-show",Ce="shipaid-protection",xe="query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetPollProtection\n widgetShowCart\n excludedProductSkus\n excludedCustomersIdsAutoOptIn\n protectionSettings\n widgetConfigurations\n useCustomApp\n }\n}",ke=Object.assign({"./lang/de.json":()=>Promise.resolve().then((()=>Te)).then((t=>t.default)),"./lang/en.json":()=>Promise.resolve().then((()=>ce)).then((t=>t.default)),"./lang/es.json":()=>Promise.resolve().then((()=>Be)).then((t=>t.default)),"./lang/fr.json":()=>Promise.resolve().then((()=>Ge)).then((t=>t.default)),"./lang/it.json":()=>Promise.resolve().then((()=>ei)).then((t=>t.default)),"./lang/nl.json":()=>Promise.resolve().then((()=>di)).then((t=>t.default)),"./lang/pt.json":()=>Promise.resolve().then((()=>gi)).then((t=>t.default))});var $e;$e={loader:async t=>{if("en"===t)return le;const e=Reflect.get(ke,`./lang/${t}.json`);return e?await e():le}},vt=Object.assign(Object.assign({},vt),$e);const Se=class extends ct{constructor(){var t,e,i;super(...arguments),this.env="prod",this.useCustomStoreFront=!1,this.storeDomain="",this.storeAccessToken="",this.cartId="",this.disablePolling=!1,this.disableActions=!1,this.pollingInterval=2500,this.disableRefresh=!1,this.refreshCart=!1,this.persistPopup=!1,this.defaultToggleButton=!1,this.lang="en",this.currency=void 0,this.customerId=void 0,this.supportSubscriptions=!1,this.dataSelector="",this.shadowRootSelector="",this.useShipAidCheckout=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),this._hasFinishedSetup=!1,this._shouldShowWidget=!1,this._hasProtectionInCart=!1,this.hasLoadedStrings=!1,this.fetchInterceptorCleanup=()=>{},this.intervalId=null,this._sellingPlanId=null,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>ve(t),post:(t,e)=>ve(t,{method:"POST",headers:{"Content-Type":"application/json","X-ShipAid":"1"},body:JSON.stringify(e)})},this.getElementsBySelector=t=>t?document.querySelectorAll(`${t}:not(#shipaid-checkout-button)`):[],this.addStylesIfNeeded=()=>{var t,e,i,o,r;const n=null==(o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.theme_checkout)?void 0:o.styles,a=n?`\n checkout-package-protection {\n ${n.checkoutWidget||""}\n width: var(--widget-width, 100%);\n }\n .shipaid-checkout-container {\n display: flex;\n ${n.checkoutContainer||""}\n justify-content: var(--container-x-position, center);\n }\n ${n.storeTheme||""}\n `.trim():"",s="[shipaid-hidden] { display: none !important; }"+(a?"\n"+a:""),d=document.getElementById("shipaid-styles");if(d)n&&!(null==(r=d.textContent)?void 0:r.includes(n.checkoutWidget||""))&&(d.textContent+="\n"+a);else{const t=document.createElement("style");t.id="shipaid-styles",t.textContent=s,document.head.appendChild(t)}}}shouldUpdate(t){return this.hasLoadedStrings&&super.shouldUpdate(t)}shouldPersistPopup(){return"true"===localStorage.getItem(`${_e}`)?"learn-more":null}setPopupKey(){this.persistPopup&&localStorage.setItem(`${_e}`,"true")}get nhost(){const t=`https://${"prod"===this.env?"gjiyysyzjwuculcymsvb":"staging"===this.env?"xfnjpunvafvudwuzwjlm":"local"}.graphql.us-east-1.nhost.run/v1`;return{request:async(e,i)=>{try{const o=await fetch(t,{method:"post",body:JSON.stringify({query:e,variables:i})});return await o.json()}catch(o){console.log(`Nhost Error: ${o}`)}}}}async runStoreFrontQuery(t,e){try{const i=new Headers;i.append("Content-Type","application/json"),i.append("X-Shopify-Storefront-Access-Token",this.storeAccessToken);const o={method:"POST",headers:i,body:JSON.stringify({query:t,variables:e})},r=await fetch(`https://${this.storeDomain}/api/2021-07/graphql.json`,o);if(!r.ok)throw new Error(`GraphQL request failed: ${r.statusText}`);const n=await r.json();if(n.errors)throw new Error(n.errors[0].message);return n.data}catch(i){throw console.error("GraphQL query error:",i),new Error("Failed to execute GraphQL query")}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(be("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,n,a;const s=this.currency||(null==(i=null==(e=window.Shopify)?void 0:e.currency)?void 0:i.active)||(null==(o=this._store)?void 0:o.currency)||"USD";if(null==(a=null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.widget)?void 0:a.currencyFormat){return this._store.widgetConfigurations.widget.currencyFormat.replace("_value_",Number(t)).replace("_currency_",s)}return new Intl.NumberFormat(void 0,{currency:s,style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}_handleRefreshCart(){if(this.refreshCart)return window.location.reload()}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(ue.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.calculateProtectionTotal(this._store,this._protectionProduct,t)}_findProtectionVariant(t){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return e.findProtectionVariant(this._store,this._protectionProduct,t)}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}_handleConfirmationPopup(){"confirmation"!==this._popup&&(this._popup="confirmation")}_updateProtection(){var t,e,i;const o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.removeWithConfirmation;if(this._hasProtectionInCart)return o?this._handleConfirmationPopup():this.removeProtection();this.addProtection()}async _fetchShipAidData(){var t,e,i,o,r;let n;if(n=this.storeDomain?this.storeDomain:(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),!n)throw new Error("No shop found in Shopify object.");try{let t,e;if(this.useCustomStoreFront)e=await this.nhost.request(xe,{store:n});else{t=new URL(window.location.href),t.pathname=this._apiEndpoint;const i={query:xe,variables:{store:n}};e=await this._fetch.post(t.toString(),i)}if(!e)throw new Error("Missing response for store query.");if(null==(o=e.errors)?void 0:o.length)throw new Error(e.errors[0].message);if(!(null==(r=e.data)?void 0:r.store))throw new Error("Missing store from store query response.");return e.data.store}catch(a){throw console.error(a),new Error(`Could not find a store for ${this._storeDomain}`)}}_findSellingPlanByName(t,e){for(const i of t){const t=i.node;for(const i of t.sellingPlans.edges){const t=i.node;if(e===t.name)return t}}return null}async _fetchSellingPlanFromVariant(t){var e,i,o,r,n,a,s,d,p,l,c,h,u;const m=(null==(e=window.Shopify)?void 0:e.shop)??(null==(o=null==(i=window.Shopify)?void 0:i.Checkout)?void 0:o.apiHost);if(!m)throw new Error("No shop found in Shopify object.");try{const e=new URL(window.location.href);e.pathname=this._apiEndpoint;const i={query:"query SellingPlanFromVariant($store: String!, $variantId: String!){\n sellingPlanFromVariant(input: {store: $store, variantId: $variantId })\n}",variables:{store:m,variantId:`gid://shopify/ProductVariant/${null==(r=this._protectionVariant)?void 0:r.id}`}},o=await this._fetch.post(e.toString(),i);if(!o)throw new Error("Missing response for selling plan query.");if(null==(n=o.errors)?void 0:n.length)throw new Error(o.errors[0].message);if(!(null==(a=o.data)?void 0:a.sellingPlanFromVariant))throw new Error("Missing variant from selling plan query response.");const g=(null==(d=null==(s=o.data.sellingPlanFromVariant)?void 0:s.sellingPlanGroups)?void 0:d.edges)||[],f=(null==(u=null==(h=null==(c=null==(l=null==(p=g[0])?void 0:p.node)?void 0:l.sellingPlans)?void 0:c.edges)?void 0:h[0])?void 0:u.node)||null;return this._findSellingPlanByName(g,t.name)||f}catch(g){console.error("Error during the query ====>",g)}}async _fetchCart(){try{if(this.useCustomStoreFront&&this.cartId){const t=await this.runStoreFrontQuery("query getCart($cartId: ID!){ cart( id: $cartId ) { id createdAt updatedAt lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } }",{cartId:this.cartId});return fe(t.cart)}return await this._fetch.get("/cart.js")}catch(t){throw ye(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){var t,e,i,o,r,n,a,s;try{let d;if(this.useCustomStoreFront){const p=await this.runStoreFrontQuery("query product($handle: String!) { product(handle: $handle) { id title images(first: 1) {edges { node { id url altText } } } handle variants(first: 100) { edges { node { id title price { amount } } } } } }",{handle:Ce});if(null==p?void 0:p.product){const l=p.product;d={id:l.id,title:l.title,image:{id:null==(o=null==(i=null==(e=null==(t=null==l?void 0:l.images)?void 0:t.edges)?void 0:e[0])?void 0:i.node)?void 0:o.id,src:null==(s=null==(a=null==(n=null==(r=null==l?void 0:l.images)?void 0:r.edges)?void 0:n[0])?void 0:a.node)?void 0:s.url},variants:l.variants.edges.map((t=>({id:t.node.id,price:t.node.price.amount})))}}}else d=(await this._fetch.get(`/products/${Ce}.json`)).product;return d}catch(d){throw ye(d.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addCartProtectionVariant(){var t,e;let i;if(this.useCustomStoreFront){const e=await this.runStoreFrontQuery("mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{merchandiseId:String(null==(t=this._protectionVariant)?void 0:t.id),quantity:1,sellingPlanId:this._sellingPlanId}]});i=fe(e.cartLinesAdd.cart)}else{const t={quantity:1,id:String(null==(e=this._protectionVariant)?void 0:e.id),selling_plan:this._sellingPlanId};i=await this._fetch.post("/cart/add.js",t)}return i}async updateCartProtectionVariant(t,e=null){var i,o;let r;if(this.useCustomStoreFront){const o=await this.runStoreFrontQuery("mutation RemoveItemToCart($cartId: ID!, $lines: [CartLineUpdateInput!]!) { cartLinesUpdate(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",{cartId:this.cartId,lines:[{id:String(e?e.key:null==(i=this._protectionCartItem)?void 0:i.key),quantity:t,sellingPlanId:this._sellingPlanId}]});r=fe(o.cartLinesUpdate.cart)}else{const i={quantity:t,id:String(e?e.key:null==(o=this._protectionCartItem)?void 0:o.key),selling_plan:this._sellingPlanId};r=await this._fetch.post("/cart/change.js",i)}return r}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i=await this.addCartProtectionVariant();await this._handleRefresh(i),this._setState("success")}catch(i){ye(i.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t=await this.updateCartProtectionVariant(0,this._protectionCartItem);await this._handleRefresh(t),this._cart=t,this._setState("success")}catch(t){ye(t.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async attemptAddProtection(){var t,e,i,o,r,n;if(!(null==(t=this._store)?void 0:t.widgetAutoOptIn))return;if(!(null==(e=this._cart)?void 0:e.items)||!(null==(i=this._cart)?void 0:i.item_count))return;const a=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),s=null==(r=this._cart)?void 0:r.items[a];if(this._hasProtectionInCart=!!s,1===this._cart.item_count&&s)return;!!sessionStorage.getItem(we)||!this._hasProtectionInCart&&(null==(n=this._cart)?void 0:n.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(we,JSON.stringify({loaded:!0})))}async handleMultipleProtectionVariants(){var t,e,i,o,r;if(!(null==(t=this._cart)?void 0:t.items)||!(null==(e=this._cart)?void 0:e.item_count))return;let n=0;if(null==(i=this._cart.items)||i.forEach((t=>{var e,i;(null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id)))&&n++})),n>1){const t=null==(o=this._cart.items)?void 0:o.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),e=null==(r=this._cart)?void 0:r.items[t],i=await this.updateCartProtectionVariant(0,e);return await this._handleRefresh(i)}}learnMorePopupTemplate(){return F`
1172
1172
  <shipaid-popup-learn-more
1173
1173
  ?active=${"learn-more"===this._popup}
1174
- @close=${()=>{this.persistPopup&&localStorage.removeItem(`${we}`),this._popup=null}}
1174
+ @close=${()=>{this.persistPopup&&localStorage.removeItem(`${_e}`),this._popup=null}}
1175
1175
  ></shipaid-popup-learn-more>
1176
1176
  `}confirmationPopupTemplate(){return F`
1177
1177
  <shipaid-popup-confirmation
1178
1178
  ?active=${"confirmation"===this._popup}
1179
- @close=${()=>{this.persistPopup&&localStorage.removeItem(`${we}`),this._popup=null}}
1180
- @remove-protection=${()=>{this.removeProtection(),this.persistPopup&&localStorage.removeItem(`${we}`),this._popup=null}}
1179
+ @close=${()=>{this.persistPopup&&localStorage.removeItem(`${_e}`),this._popup=null}}
1180
+ @remove-protection=${()=>{this.removeProtection(),this.persistPopup&&localStorage.removeItem(`${_e}`),this._popup=null}}
1181
1181
  ></shipaid-popup-confirmation>
1182
1182
  `}contactlessCheckoutButtonTemplate(){this.addStylesIfNeeded();const t=this.getElementsBySelector(sessionStorage.getItem("shipaidWidgetTheme"));if(t.length)return t.forEach(((t,e)=>{var i,o,r;const n=`shipaid-checkout-container-${e}`;t.setAttribute("shipaid-hidden","");const a=t.className;let s=document.getElementById(n);s||(s=document.createElement("div"),s.id=n,s.style.width="100%",s.className="shipaid-checkout-container",t.insertAdjacentElement("afterend",s));const d=Number(null==(i=this._protectionVariant)?void 0:i.price)||0,p=(Number(null==(o=this._cart)?void 0:o.total_price)||0)/100,l=this._hasProtectionInCart?p:d+p,c=F`
1183
1183
  <svg width="1.5rem" height="1.5rem" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="4" class="shipaid-loader">
@@ -1267,7 +1267,7 @@ function Tt(t,e,i){return t?e():null==i?void 0:i()}const qt=h`
1267
1267
  @shipaid-about=${()=>{this._popup="learn-more",this.persistPopup&&this.setPopupKey()}}
1268
1268
  @shipaid-remove-protection=${async()=>{await this.removeProtection(),window.location.href="/checkout"}}
1269
1269
  ></checkout-package-protection>
1270
- `,s)})),W}createRenderRoot(){return this.useShipAidCheckout?this:super.createRenderRoot()}async getSubscription(t){var e;if(!(null==t?void 0:t.items)||!(null==t?void 0:t.item_count))return;const i=null==(e=null==t?void 0:t.items)?void 0:e.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));if(i){const t=await this._fetchSellingPlanFromVariant(i.selling_plan_allocation.selling_plan);return t?function(t){var e;return(null==(e=null==t?void 0:t.match(/\d+/))?void 0:e[0])??null}(t.id):null}return null}getCheckoutURL(){var t,e;return this._sellingPlanId?`/cart/add?id=${null==(t=this._protectionVariant)?void 0:t.id}&quantity=1&selling_plan=${this._sellingPlanId}&return_to=/checkout`:`/checkout?attributes[_shipaid-internal]=1&updates[${null==(e=this._protectionVariant)?void 0:e.id}]=1`}checkoutButtonTemplate(){var t,e,i,o,r,n,a;if(!document.getElementById("shipaid-styles")){const t=document.createElement("style");t.id="shipaid-styles",t.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(t)}if(!this.dataSelector)return void console.error("[shipaid-widget] we couldn't find the 'data-selector' attribute.");let s=null;if(this.shadowRootSelector){const t=document.querySelector(this.shadowRootSelector);if(!t||!t.shadowRoot)return void console.warn(`ShadowRoot not found in the element '${this.shadowRootSelector}'.`);s=t.shadowRoot.querySelector(`${this.dataSelector}:not(#shipaid-checkout-button)`)}else s=null==(t=this.getElementsBySelector(this.dataSelector))?void 0:t[0];if(!s)return void console.warn(`Button not found with selector '${this.dataSelector}'.`);s.setAttribute("shipaid-hidden","");const d=s.className,p=Number(null==(e=this._protectionVariant)?void 0:e.price)||0,l=(Number(null==(i=this._cart)?void 0:i.total_price)||0)/100,c=this._hasProtectionInCart?l:p+l,h=F`
1270
+ `,s)})),W}createRenderRoot(){return this.useShipAidCheckout?this:super.createRenderRoot()}async getSubscription(t){var e;if(!(null==t?void 0:t.items)||!(null==t?void 0:t.item_count))return;const i=null==(e=null==t?void 0:t.items)?void 0:e.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));if(i){const t=await this._fetchSellingPlanFromVariant(i.selling_plan_allocation.selling_plan);return t?function(t){var e;return(null==(e=null==t?void 0:t.match(/\d+/))?void 0:e[0])??null}(t.id):null}return null}checkoutButtonTemplate(){var t,e,i,o,r,n,a;if(!document.getElementById("shipaid-styles")){const t=document.createElement("style");t.id="shipaid-styles",t.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(t)}if(!this.dataSelector)return void console.error("[shipaid-widget] we couldn't find the 'data-selector' attribute.");let s=null;if(this.shadowRootSelector){const t=document.querySelector(this.shadowRootSelector);if(!t||!t.shadowRoot)return void console.warn(`ShadowRoot not found in the element '${this.shadowRootSelector}'.`);s=t.shadowRoot.querySelector(`${this.dataSelector}:not(#shipaid-checkout-button)`)}else s=null==(t=this.getElementsBySelector(this.dataSelector))?void 0:t[0];if(!s)return void console.warn(`Button not found with selector '${this.dataSelector}'.`);s.setAttribute("shipaid-hidden","");const d=s.className,p=Number(null==(e=this._protectionVariant)?void 0:e.price)||0,l=(Number(null==(i=this._cart)?void 0:i.total_price)||0)/100,c=this._hasProtectionInCart?l:p+l,h=F`
1271
1271
  <svg width="1.5rem" height="1.5rem" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="4" class="shipaid-loader">
1272
1272
  <circle cx="25" cy="25" r="20" stroke-opacity="0.5"/>
1273
1273
  <path d="M45 25a20 20 0 0 1-40 0" stroke="currentColor">
@@ -1455,7 +1455,7 @@ function Tt(t,e,i){return t?e():null==i?void 0:i()}const qt=h`
1455
1455
  </a>
1456
1456
  </div>
1457
1457
  </div>
1458
- `}async connectedCallback(){super.connectedCallback(),await async function(t,e=vt){const i=await e.loader(t,e);e.translationCache={},bt(t,i,e)}(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(t){const e=window.fetch;let i=!0;const o=async(o,r)=>{const n=e(o,r);if(i)try{await t([o,r],n)}catch(a){console.warn(a)}return await n};return window.fetch=o,()=>{window.fetch===o?window.fetch=e:i=!1}}((async(t,e)=>{var i,o,r,n;if(null==(o=null==(i=t[1])?void 0:i.headers)?void 0:o["X-ShipAid"])return;if(!t[0].startsWith("/cart/change")&&!t[0].startsWith("/cart/update"))return;const a=(null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.checkoutButtonSelector)||'button[type="submit"][name="checkout"][form="cart"]',s=document.querySelector(a);if(console.log("q",s),s){s.setAttribute("disabled","true"),console.debug("button","t");try{await e,await this.updateCart(),await this.updateProtection()}finally{s.removeAttribute("disabled"),console.debug("button","f")}}}))}disconnectedCallback(){var t;super.disconnectedCallback(),null==(t=this.fetchInterceptorCleanup)||t.call(this)}async updateProtection(){var t,e,i,o;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const r=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),n=null==(i=this._cart)?void 0:i.items[r];if(this._hasProtectionInCart=!!n,!this._store)return;const a=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&n&&(this._cart.total_price===(null==n?void 0:n.final_line_price)||!a)){const t=await this.updateCartProtectionVariant(0,n);return sessionStorage.removeItem(_e),await this._handleRefresh(t)}const s=this._findProtectionVariant(a);if(a?(this._protectionVariant=s,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==s?void 0:s.id))return this._shouldShowWidget=!1,void ye("No matching protection variant found.");if(!(null==(o=this._protectionVariant)?void 0:o.id))return void(this._shouldShowWidget=!1);if(this.useShipAidCheckout&&this.supportSubscriptions&&(this._sellingPlanId=await this.getSubscription(this._cart)),!n)return;if(this.supportSubscriptions&&!this.useShipAidCheckout){const t=this._cart.items.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));let e=!0;if(!t&&(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=null:t&&!(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=await this.getSubscription(this._cart):e=!1,e){const t=await this.updateCartProtectionVariant(1,n);await this._handleRefresh(t)}}if(s.id===n.variant_id){if(this._protectionCartItem={...n,index:r,position:r+1},1===n.quantity)return;const t=await this.updateCartProtectionVariant(1,n);return this._handleRefreshCart(),await this._handleRefresh(t)}const d={updates:{[n.variant_id]:0,[s.id]:1}},p=await this._fetch.post("/cart/update.js",d);await this._handleRefresh(p)}render(){return Mt(this,(async()=>{var t,e,i,o,r,n;const a=document.createElement("link");a.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),a.setAttribute("rel","stylesheet"),document.head.appendChild(a);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(s){return ye(s.message),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._dispatchEvent(ue.LOADED,this._store),setTimeout((async()=>{var t,e,i,o;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&(null==(e=this._cart)?void 0:e.item_count)&&(this.customerId&&this._store.excludedCustomersIdsAutoOptIn&&(null==(i=this._store.excludedCustomersIdsAutoOptIn)?void 0:i.length)&&this._store.excludedCustomersIdsAutoOptIn.includes(`gid://shopify/Customer/${this.customerId}`)||sessionStorage.getItem(_e)||!this._hasProtectionInCart&&(null==(o=this._cart)?void 0:o.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(_e,JSON.stringify({loaded:!0}))))}),500),void(this.disablePolling||this.useShipAidCheckout||(setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval),(null==(i=this._store)?void 0:i.widgetPollProtection)&&!this.intervalId&&(this.intervalId=setInterval((async()=>{await this.attemptAddProtection()}),400),localStorage.setItem(`polling-shipaid-protection_${this.intervalId}`,`${this.intervalId}`)),(null==(n=null==(r=null==(o=this._store)?void 0:o.widgetConfigurations)?void 0:r.widget)?void 0:n.pollVariantsCheck)&&setInterval((async()=>{await this.handleMultipleProtectionVariants()}),400)))):(be("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),Mt(this,(async()=>{await this.updateProtection()}),[this._store,this._cart]),Mt(this,(async()=>{dt(this.renderPopups(),document.body)}),[this._popup]),F`
1458
+ `}async connectedCallback(){super.connectedCallback(),await async function(t,e=vt){const i=await e.loader(t,e);e.translationCache={},bt(t,i,e)}(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(t){const e=window.fetch;let i=!0;const o=async(o,r)=>{const n=e(o,r);if(i)try{await t([o,r],n)}catch(a){console.warn(a)}return await n};return window.fetch=o,()=>{window.fetch===o?window.fetch=e:i=!1}}((async(t,e)=>{var i,o,r,n;if(null==(o=null==(i=t[1])?void 0:i.headers)?void 0:o["X-ShipAid"])return;if(!t[0].startsWith("/cart/change")&&!t[0].startsWith("/cart/update"))return;const a=(null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.checkoutButtonSelector)||'button[type="submit"][name="checkout"][form="cart"]',s=document.querySelector(a);if(console.log("q",s),s){s.setAttribute("disabled","true"),console.debug("button","t");try{await e,await this.updateCart(),await this.updateProtection()}finally{s.removeAttribute("disabled"),console.debug("button","f")}}}))}disconnectedCallback(){var t;super.disconnectedCallback(),null==(t=this.fetchInterceptorCleanup)||t.call(this)}async updateProtection(){var t,e,i,o;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const r=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),n=null==(i=this._cart)?void 0:i.items[r];if(this._hasProtectionInCart=!!n,!this._store)return;const a=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&n&&(this._cart.total_price===(null==n?void 0:n.final_line_price)||!a)){const t=await this.updateCartProtectionVariant(0,n);return sessionStorage.removeItem(we),await this._handleRefresh(t)}const s=this._findProtectionVariant(a);if(a?(this._protectionVariant=s,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==s?void 0:s.id))return this._shouldShowWidget=!1,void ye("No matching protection variant found.");if(!(null==(o=this._protectionVariant)?void 0:o.id))return void(this._shouldShowWidget=!1);if(this.useShipAidCheckout&&this.supportSubscriptions&&(this._sellingPlanId=await this.getSubscription(this._cart)),!n)return;if(this.supportSubscriptions&&!this.useShipAidCheckout){const t=this._cart.items.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));let e=!0;if(!t&&(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=null:t&&!(null==n?void 0:n.selling_plan_allocation)?this._sellingPlanId=await this.getSubscription(this._cart):e=!1,e){const t=await this.updateCartProtectionVariant(1,n);await this._handleRefresh(t)}}if(s.id===n.variant_id){if(this._protectionCartItem={...n,index:r,position:r+1},1===n.quantity)return;const t=await this.updateCartProtectionVariant(1,n);return this._handleRefreshCart(),await this._handleRefresh(t)}const d={updates:{[n.variant_id]:0,[s.id]:1}},p=await this._fetch.post("/cart/update.js",d);await this._handleRefresh(p)}render(){return Mt(this,(async()=>{var t,e,i,o,r,n;const a=document.createElement("link");a.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),a.setAttribute("rel","stylesheet"),document.head.appendChild(a);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(s){return ye(s.message),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._dispatchEvent(ue.LOADED,this._store),setTimeout((async()=>{var t,e,i,o;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&(null==(e=this._cart)?void 0:e.item_count)&&(this.customerId&&this._store.excludedCustomersIdsAutoOptIn&&(null==(i=this._store.excludedCustomersIdsAutoOptIn)?void 0:i.length)&&this._store.excludedCustomersIdsAutoOptIn.includes(`gid://shopify/Customer/${this.customerId}`)||sessionStorage.getItem(we)||!this._hasProtectionInCart&&(null==(o=this._cart)?void 0:o.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(we,JSON.stringify({loaded:!0}))))}),500),void(this.disablePolling||(setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval),(null==(i=this._store)?void 0:i.widgetPollProtection)&&!this.intervalId&&(this.intervalId=setInterval((async()=>{await this.attemptAddProtection()}),400),localStorage.setItem(`polling-shipaid-protection_${this.intervalId}`,`${this.intervalId}`)),(null==(n=null==(r=null==(o=this._store)?void 0:o.widgetConfigurations)?void 0:r.widget)?void 0:n.pollVariantsCheck)&&setInterval((async()=>{await this.handleMultipleProtectionVariants()}),400)))):(be("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(be("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),Mt(this,(async()=>{await this.updateProtection()}),[this._store,this._cart]),Mt(this,(async()=>{dt(this.renderPopups(),document.body)}),[this._popup]),F`
1459
1459
  <style>
1460
1460
  :host {
1461
1461
  --shipaid-primary: #002bd6;
@@ -135,7 +135,6 @@ export declare class ShipAidWidget extends LitElement {
135
135
  contactlessCheckoutButtonTemplate(): typeof nothing | undefined;
136
136
  createRenderRoot(): Element | ShadowRoot;
137
137
  getSubscription(_cart: ShopifyCart | undefined): Promise<string | null | undefined>;
138
- getCheckoutURL(): string;
139
138
  checkoutButtonTemplate(): import("lit").TemplateResult<1> | undefined;
140
139
  renderPopups(): import("lit").TemplateResult<1> | null;
141
140
  promptTemplate(): import("lit").TemplateResult<1> | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ui.shipaid.com",
3
3
  "private": false,
4
- "version": "0.3.96",
4
+ "version": "0.3.97",
5
5
  "type": "module",
6
6
  "main": "dist/widget.umd.js",
7
7
  "unpkg": "dist/widget.iife.js",