PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
← All changes | assets/FluentCartCheckout.js +2 -2 1.6.1 → 1.6.5 View file →
@@ -1,5 +1,5 @@
1 -var At=Object.defineProperty;var lt=c=>{throw TypeError(c)};var Ot=(c,e,t)=>e in c?At(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var Dt=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports);var p=(c,e,t)=>Ot(c,typeof e!="symbol"?e+"":e,t),je=(c,e,t)=>e.has(c)||lt("Cannot "+t);var h=(c,e,t)=>(je(c,e,"read from private field"),t?t.call(c):e.get(c)),g=(c,e,t)=>e.has(c)?lt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(c):e.set(c,t),m=(c,e,t,i)=>(je(c,e,"write to private field"),i?i.call(c,t):e.set(c,t),t),f=(c,e,t)=>(je(c,e,"access private method"),t);import{C as v,P as Pt}from"./chunks/payment-loader.js?ver=1.6.1";import{U as te}from"./chunks/Url.js?ver=1.6.1";import{u as rt,t as at}from"./chunks/timezone.js?ver=1.6.1";import{d as W}from"./chunks/dayjs.min.js?ver=1.6.1";import"./chunks/Str.js?ver=1.6.1";import"./chunks/Arr.js?ver=1.6.1";import"./chunks/vue-router.js?ver=1.6.1";import"./chunks/vue.esm-bundler.js?ver=1.6.1";var Ft=Dt((Yt,qe)=>{class Wt{constructor(e,t={}){this.element=e,this.disabled=!1;const i=this.parseSelectElement();this.options=t.options||i||[];const s=t.placeholder===!1;this.searchPlaceholder="",this.placeholder="",s||(this.placeholder=t.placeholder||this.getPlaceholderFromSelect()||"Select an option...",this.searchPlaceholder=t.searchPlaceholder||"Type to search..."),this.clearable=t.clearable!==!1,this.onChange=t.onChange||(()=>{}),this.onSearch=t.onSearch||(()=>{});const n=this.getInitialSelection();this.selectedValue=n.value,this.selectedText=n.text,this.filteredOptions=[...this.options],this.highlightedIndex=-1,this.isOpen=!1,this.searchTerm="",this.init()}init(){this.createElements(),this.bindEvents(),this.render(),this.selectedValue&&(this.input.value=this.selectedText)}parseSelectElement(){if(this.element.tagName!=="SELECT")return null;const e=[];return this.element.querySelectorAll("option").forEach(i=>{(i.value||i.textContent.trim())&&e.push({value:i.value||i.textContent.trim(),text:i.textContent.trim()})}),e}getPlaceholderFromSelect(){if(this.element.tagName!=="SELECT")return null;if(this.element.hasAttribute("data-placeholder"))return this.element.getAttribute("data-placeholder");const e=this.element.querySelector("option");return e&&!e.value&&e.textContent.trim()?e.textContent.trim():null}getInitialSelection(){if(this.element.tagName!=="SELECT")return{value:null,text:""};const e=this.element.querySelector("option[selected]")||this.element.options[this.element.selectedIndex];return e&&e.value?{value:e.value,text:e.textContent.trim()}:{value:null,text:""}}createElements(){const e=this.element.tagName==="SELECT";let t,i=e&&this.element.parentNode.classList.contains("fct-custom-searchable-select"),s=null;if(i){t=this.element.parentNode;const n=t.querySelector(".fct-custom-searchable-select-container");n&&t.removeChild(n),s=t.querySelector("input")}else t=document.createElement("div"),t.className="fct-custom-searchable-select",e?(this.element.parentNode.insertBefore(t,this.element),t.appendChild(this.element)):(t.classList.add("custom-select-wrapper"),this.element.appendChild(t));e?(this.originalElement=this.element.cloneNode(!0),this.element.style.display="none"):this.originalElement=null,this.selectContainer=document.createElement("div"),this.selectContainer.className="fct-custom-searchable-select-container",this.input=document.createElement("input"),this.input.className="select-input",this.input.type="text",this.input.placeholder=this.placeholder+"*",this.input.addEventListener("keypress",n=>{this.isOpen||n.preventDefault()}),this.originalElement&&(this.originalElement.disabled&&this.disable(),this.originalElement.required&&(this.input.required=!0),this.originalElement.name&&(s?this.hiddenInput=s:(this.hiddenInput=document.createElement("input"),t.appendChild(this.hiddenInput)),this.hiddenInput.type="hidden",this.hiddenInput.name=this.originalElement.name)),this.arrow=document.createElement("div"),this.arrow.className="select-arrow",this.clearBtn=document.createElement("button"),this.clearBtn.className="clear-btn",this.clearBtn.innerHTML="×",this.clearBtn.type="button",this.dropdown=document.createElement("div"),this.dropdown.className="select-dropdown",this.selectContainer.appendChild(this.input),this.clearable&&this.selectContainer.appendChild(this.clearBtn),this.selectContainer.appendChild(this.arrow),this.selectContainer.appendChild(this.dropdown),t.appendChild(this.selectContainer),this.hiddenInput&&(this.hiddenInput.value=this.selectedValue||""),this.wrapper=t}bindEvents(){this.selectContainer.addEventListener("click",e=>{e.target!==this.clearBtn&&this.toggle()}),this.clearBtn.addEventListener("click",e=>{e.stopPropagation(),this.clear()}),this.input.addEventListener("focus",()=>{this.isOpen||this.open()}),this.input.addEventListener("input",e=>{this.searchTerm=e.target.value,this.filter(),this.onSearch(this.searchTerm)}),this.input.addEventListener("keydown",e=>{this.handleKeydown(e)}),this.dropdown.addEventListener("click",e=>{const t=e.target.closest(".select-option");if(t&&!t.classList.contains("no-options")){const i=t.dataset.value,s=t.textContent;this.select(i,s),this.close()}}),this.outsideClickHandler=e=>{this.element.contains(e.target)||this.close()},document.addEventListener("click",this.outsideClickHandler)}handleKeydown(e){switch(e.key){case"ArrowDown":e.preventDefault(),this.highlightNext();break;case"ArrowUp":e.preventDefault(),this.highlightPrev();break;case"Enter":if(e.preventDefault(),this.highlightedIndex>=0&&this.filteredOptions[this.highlightedIndex]){const t=this.filteredOptions[this.highlightedIndex];this.select(t.value,t.text)}break;case"Escape":this.close();break;case"Backspace":this.selectedValue&&this.clear();break}}open(){this.isOpen=!0,this.selectContainer.classList.add("open"),this.input.placeholder=this.searchPlaceholder,this.highlightedIndex=-1,this.input.value="",this.filter(),setTimeout(()=>this.input.focus(),0)}close(){this.isOpen=!1,this.selectContainer.classList.remove("open"),this.input.placeholder=this.placeholder,this.searchTerm="",this.input.value=this.selectedText,this.highlightedIndex=-1}toggle(){this.isOpen?this.close():this.open()}filter(){const e=this.searchTerm.toLowerCase();this.filteredOptions=this.options.filter(t=>t.text.toLowerCase().includes(e)),this.highlightedIndex=-1,this.renderOptions()}highlightNext(){this.filteredOptions.length!==0&&(this.highlightedIndex=Math.min(this.highlightedIndex+1,this.filteredOptions.length-1),this.updateHighlight())}highlightPrev(){this.filteredOptions.length!==0&&(this.highlightedIndex=Math.max(this.highlightedIndex-1,0),this.updateHighlight())}updateHighlight(){var t;const e=this.dropdown.querySelectorAll(".select-option:not(.no-options)");e.forEach((i,s)=>{i.classList.toggle("highlighted",s===this.highlightedIndex)}),this.highlightedIndex>=0&&((t=e[this.highlightedIndex])==null||t.scrollIntoView({block:"nearest"}))}select(e,t){this.selectedValue=e,this.selectedText=t,this.input.value=t,this.hiddenInput&&(this.hiddenInput.value=e||""),this.originalElement&&(this.originalElement.value=e||""),setTimeout(()=>{this.onChange(e,t),this.close()},10)}clear(){return this.select(null,""),this}addOption(e,t){const i={value:e,text:t};return this.options.push(i),(!this.isOpen||!this.searchTerm)&&this.filteredOptions.push(i),this.render(),this}removeOption(e){return this.options=this.options.filter(t=>t.value!==e),this.filteredOptions=this.filteredOptions.filter(t=>t.value!==e),this.selectedValue===e&&this.clear(),this.render(),this}setOptions(e,t=null,i=null){return(t||i)&&(i=i??"value",t=t??"text",e=e.map(s=>({value:s[i],text:s[t]}))),this.options=e||[],this.filteredOptions=[...this.options],this.selectedValue&&!this.options.find(s=>s.value===this.selectedValue)&&this.clear(),this.render(),this}getValue(){return this.selectedValue}getText(){return this.selectedText}getSelected(){return{value:this.selectedValue,text:this.selectedText}}setValue(e){const t=this.options.find(i=>i.value===e);return t?this.select(t.value,t.text):this.clear(),this}disable(){return this.input.disabled=!0,this.disabled=!0,this.selectContainer.classList.add("disabled"),this.element.classList.add("disabled"),this}enable(){return this.input.disabled=!1,this.disabled=!1,this.selectContainer.classList.remove("disabled"),this.element.classList.remove("disabled"),this}render(){this.renderOptions()}renderOptions(){if(this.dropdown.innerHTML="",this.filteredOptions.length===0){const e=document.createElement("div");e.className="select-option no-options",e.textContent=this.searchTerm?"No matches found":"No options available",this.dropdown.appendChild(e);return}this.filteredOptions.forEach((e,t)=>{const i=document.createElement("div");i.className="select-option",i.dataset.value=e.value,i.textContent=e.text,e.value===this.selectedValue&&i.classList.add("selected"),this.dropdown.appendChild(i)})}destroy(){document.removeEventListener("click",this.outsideClickHandler),this.element.innerHTML="",this.selectContainer.remove()}}const Te={init:function(c,e={}){const t=typeof c=="string"?document.querySelector(c):c;if(!t)throw new Error("Element not found");return new Wt(t,e)}};typeof qe<"u"&&qe.exports?qe.exports=Te:typeof define=="function"&&define.amd?define(function(){return Te}):window.customSelect=Te;const ie=(c,e,t={})=>{let i;e==="click"?i=MouseEvent:e==="change"?i=Event:e.includes("focus")?i=FocusEvent:i=UIEvent;const s=new i(e,{bubbles:!0,cancelable:!1,...t});c.dispatchEvent(s)},X=c=>ie(c,"click"),Fe=c=>ie(c,"change"),Mt=c=>ie(c,"focusin"),Nt=c=>ie(c,"focusout"),Bt=c=>ie(c,"modalopen"),Ue=c=>ie(c,"modalclose"),j=(c,e)=>c[e]!==void 0?c[e]:c.getAttribute(e),O=(c,e)=>c==null?void 0:c.classList.contains(e),T=(c,e)=>c==null?void 0:c.classList.add(e),E=(c,e)=>c==null?void 0:c.classList.remove(e),Vt={data:null,searchable:!0,showSelectedItems:!0,placeholder:"Select an option",searchtext:"Search",selectedtext:"selected",hideSelect:!0,onChange:null};var _,$e,Ke,ot,ct,dt,ht,ut,pt,Ze,ft,Le,gt;class H{constructor(e,t={}){g(this,_);if(!e)throw new Error("No element provided to NiceSelect");if(!(e instanceof Element))throw new Error("Invalid element provided to NiceSelect - must be a valid DOM element");const i=[];e.tagName==="SELECT"&&e.querySelectorAll("option").forEach(n=>{(n.value||n.textContent.trim())&&i.push({value:n.value||n.textContent.trim(),text:n.textContent.trim()})}),t.data==null&&(t.data=i),this.el=e,this.el._niceSelect=this,this.config={...Vt,...t},this.data=this.config.data,this.selectedOptions=[],this.placeholder=j(this.el,"placeholder")||this.config.placeholder,this.searchtext=j(this.el,"searchtext")||this.config.searchtext,this.selectedtext=j(this.el,"selectedtext")||this.config.selectedtext,this.dropdown=null,this.selectionList=null,this.multiple=j(this.el,"multiple"),this.disabled=j(this.el,"disabled"),this.onChange=this.config.onChange,f(this,_,$e).call(this),f(this,_,dt).call(this)}_renderSelectedItems(){if(this.multiple){let e="";window.getComputedStyle(this.dropdown).width==="auto"||this.selectedOptions.length<2?(this.selectedOptions.forEach((t,i,s)=>{let n=t.data.text;i!==s.length-1&&(n+=", "),e+=`<span class="current">${n||this.placeholder}</span>`}),e=e||this.placeholder):e=`${this.selectedOptions.length} ${this.selectedtext}`,this.dropdown.querySelector(".multiple-options").innerHTML=e}else{const e=this.selectedOptions.length>0?this.selectedOptions[0].data.text:this.placeholder,t=this.dropdown.querySelector(".current");t.innerHTML=e,this.selectedOptions.length>0&&(!this.selectedOptions[0].data.value||this.selectedOptions[0].data.value==="")?t.classList.add("empty-value"):t.classList.remove("empty-value")}}setSelected(e){let t=null;for(let s=0;s<this.options.length;s++)if(this.options[s].data.value===e){t=this.options[s];break}const i=t==null?void 0:t.element;i&&(i.click(),E(this.dropdown,"open"))}_renderItems(){const e=this.dropdown.querySelector("ul");this.options.forEach(t=>{t.data.value!==""&&(this.multiple&&this.config.showSelectedItems&&this._multipleListAdd(t),e.appendChild(this._renderItem(t)))})}_renderItem(e){const t=document.createElement("li");if(t.innerHTML=e.data.text,e.data.extra!==void 0&&t.appendChild(this._renderItemExtra(e.data.extra)),e.attributes.optgroup)T(t,"optgroup");else{t.setAttribute("data-value",e.data.value);const i=["option"];e.attributes.selected&&i.push("selected"),e.attributes.disabled&&i.push("disabled"),t.classList.add(...i),t.addEventListener("click",s=>this._onDropdownItemClicked(e,s))}return e.element=t,t}_renderItemExtra(e){const t=document.createElement("span");return t.innerHTML=e,T(t,"extra"),t}update(e=""){var i;let t=this;e!=""&&(t=e.target._niceSelect),f(i=t,_,Ze).call(i)}disable(){this.disabled||(this.disabled=!0,T(this.dropdown,"disabled"))}enable(){this.disabled&&(this.disabled=!1,E(this.dropdown,"disabled"))}clear(){f(this,_,pt).call(this),this.selectedOptions=[],this._renderSelectedItems(),this.update(),Fe(this.el)}destroy(){this.selectionList&&f(this,_,Le).call(this),this.dropdown&&(this.dropdown.remove(),this.el.classList.remove("hidden-select"))}focus(e=""){if(O(this.dropdown,"open")?this.multiple?e===this.dropdown.querySelector(".multiple-options")&&(E(this.dropdown,"open"),Ue(this.el)):(E(this.dropdown,"open"),Ue(this.el)):(T(this.dropdown,"open"),Bt(this.el)),O(this.dropdown,"open")){const i=this.dropdown.querySelector(".fct-nice-select-search");i&&(i.value="",i.focus());const s=this.dropdown.querySelector(".focus");s&&E(s,"focus");const n=this.dropdown.querySelector(".selected");n&&T(n,"focus"),this.dropdown.querySelectorAll("ul li").forEach(r=>r.style.display="")}else this.dropdown.focus()}_bindSearchEvent(){const e=this.dropdown.querySelector(".fct-nice-select-search");e&&(e.addEventListener("click",t=>t.stopPropagation()),e.addEventListener("input",t=>this._onSearchChanged(t)))}_onClicked(e){e.preventDefault(),this.focus(e.target)}_onDropdownItemClicked(e,t){const i=t.target;if(!O(i,"disabled")){if(this.multiple){let s;O(i,"selected")?(s=!1,E(i,"selected"),this.selectedOptions=this.selectedOptions.filter(n=>n.data!==e.data)):(s=!0,T(i,"selected"),this.selectedOptions.push(e)),e.data.selected=s,e.attributes.selected=s}else{this.dropdown.querySelectorAll("li.selected").forEach(n=>E(n,"selected")),T(i,"selected"),this.selectedOptions=[e];let s=this.options.find(n=>n.attributes.selected);s&&(s.data.selected=!1,s.attributes.selected=!1),e.data.selected=!0,e.attributes.selected=!0}this._renderSelectedItems(),f(this,_,ut).call(this),f(this,_,ft).call(this)}}setOnChange(e){this.onChange=e}_onClickedOutside(e){this.dropdown.contains(e.target)||(E(this.dropdown,"open"),Ue(this.el))}_onKeyPressed(e){const t=this.dropdown.querySelector(".focus"),i=O(this.dropdown,"open");if(e.keyCode===13)X(i?t:this.dropdown);else if(e.keyCode===40){if(!i)X(this.dropdown);else{const n=this._findNext(t);n&&(t&&E(t,"focus"),T(n,"focus"))}e.preventDefault()}else if(e.keyCode===38){if(!i)X(this.dropdown);else{const n=this._findPrev(t);n&&(t&&E(t,"focus"),T(n,"focus"))}e.preventDefault()}else if(e.keyCode===27&&i)X(this.dropdown);else if(e.keyCode===32&&i)return!1;const s=this.dropdown.querySelector(".focus");return s&&s.scrollIntoView({block:"center"}),!1}_findNext(e){let t=e?e.nextElementSibling:this.dropdown.querySelector(".list .option");for(;t;){if(!O(t,"disabled")&&t.style.display!=="none")return t;t=t.nextElementSibling}return null}_findPrev(e){let t=e?e.previousElementSibling:this.dropdown.querySelector(".list .option:last-child");for(;t;){if(!O(t,"disabled")&&t.style.display!=="none")return t;t=t.previousElementSibling}return null}_onSearchChanged(e){const t=e.target.value.toLowerCase();if(t==="")this.options.forEach(s=>{s.element&&(s.element.style.display="")});else if(O(this.dropdown,"open")){const s=new RegExp(t);this.options.forEach(n=>{n.element&&(n.element.style.display=s.test(n.data.text.toLowerCase())?"":"none")})}this.dropdown.querySelectorAll(".focus").forEach(s=>E(s,"focus"));const i=this._findNext(null);i&&T(i,"focus")}_triggerValidationMessage(e){e==="invalid"?(T(this.dropdown,"invalid"),E(this.dropdown,"valid")):(T(this.dropdown,"valid"),E(this.dropdown,"invalid"))}setOptions(e,t=null,i=null){if((t||i)&&(i=i??"value",t=t??"text",e=e.map(s=>({value:s[i],text:s[t],selected:s.selected||!1,disabled:s.disabled||!1,extra:s.extra}))),this.data=e||[],f(this,_,Ke).call(this,this.data),this.selectedOptions.length>0){const s=this.data.map(r=>r.value),n=this.selectedOptions.filter(r=>s.includes(r.data.value));n.length===0?this.clear():this.selectedOptions=n}return f(this,_,gt).call(this),f(this,_,Ze).call(this),this}_multipleListAdd(e){if(!this.multiple||e.data.disabled||e.data.value==""||!e.attributes.selected)return;if(this.selectionList==null)this.selectionList=document.createElement("ul"),this.selectionList.classList.add("select-selection-list"),this.el.after(this.selectionList);else if(this.selectionList.querySelector(`[data-value="${e.data.value}"]`)!=null)return;let t=document.createElement("li");t.classList.add("select-selection"),t.dataset.value=e.data.value;let i=`
1 +var At=Object.defineProperty;var lt=c=>{throw TypeError(c)};var Ot=(c,e,t)=>e in c?At(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var Dt=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports);var p=(c,e,t)=>Ot(c,typeof e!="symbol"?e+"":e,t),je=(c,e,t)=>e.has(c)||lt("Cannot "+t);var h=(c,e,t)=>(je(c,e,"read from private field"),t?t.call(c):e.get(c)),g=(c,e,t)=>e.has(c)?lt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(c):e.set(c,t),m=(c,e,t,i)=>(je(c,e,"write to private field"),i?i.call(c,t):e.set(c,t),t),f=(c,e,t)=>(je(c,e,"access private method"),t);import{C as v,P as Pt}from"./chunks/payment-loader.js?ver=1.6.5";import{U as te}from"./chunks/Url.js?ver=1.6.5";import{u as rt,t as at}from"./chunks/timezone.js?ver=1.6.5";import{d as W}from"./chunks/dayjs.min.js?ver=1.6.5";import"./chunks/Str.js?ver=1.6.5";import"./chunks/Arr.js?ver=1.6.5";import"./chunks/vue-router.js?ver=1.6.5";import"./chunks/vue.esm-bundler.js?ver=1.6.5";var Ft=Dt((Yt,qe)=>{class Wt{constructor(e,t={}){this.element=e,this.disabled=!1;const i=this.parseSelectElement();this.options=t.options||i||[];const s=t.placeholder===!1;this.searchPlaceholder="",this.placeholder="",s||(this.placeholder=t.placeholder||this.getPlaceholderFromSelect()||"Select an option...",this.searchPlaceholder=t.searchPlaceholder||"Type to search..."),this.clearable=t.clearable!==!1,this.onChange=t.onChange||(()=>{}),this.onSearch=t.onSearch||(()=>{});const n=this.getInitialSelection();this.selectedValue=n.value,this.selectedText=n.text,this.filteredOptions=[...this.options],this.highlightedIndex=-1,this.isOpen=!1,this.searchTerm="",this.init()}init(){this.createElements(),this.bindEvents(),this.render(),this.selectedValue&&(this.input.value=this.selectedText)}parseSelectElement(){if(this.element.tagName!=="SELECT")return null;const e=[];return this.element.querySelectorAll("option").forEach(i=>{(i.value||i.textContent.trim())&&e.push({value:i.value||i.textContent.trim(),text:i.textContent.trim()})}),e}getPlaceholderFromSelect(){if(this.element.tagName!=="SELECT")return null;if(this.element.hasAttribute("data-placeholder"))return this.element.getAttribute("data-placeholder");const e=this.element.querySelector("option");return e&&!e.value&&e.textContent.trim()?e.textContent.trim():null}getInitialSelection(){if(this.element.tagName!=="SELECT")return{value:null,text:""};const e=this.element.querySelector("option[selected]")||this.element.options[this.element.selectedIndex];return e&&e.value?{value:e.value,text:e.textContent.trim()}:{value:null,text:""}}createElements(){const e=this.element.tagName==="SELECT";let t,i=e&&this.element.parentNode.classList.contains("fct-custom-searchable-select"),s=null;if(i){t=this.element.parentNode;const n=t.querySelector(".fct-custom-searchable-select-container");n&&t.removeChild(n),s=t.querySelector("input")}else t=document.createElement("div"),t.className="fct-custom-searchable-select",e?(this.element.parentNode.insertBefore(t,this.element),t.appendChild(this.element)):(t.classList.add("custom-select-wrapper"),this.element.appendChild(t));e?(this.originalElement=this.element.cloneNode(!0),this.element.style.display="none"):this.originalElement=null,this.selectContainer=document.createElement("div"),this.selectContainer.className="fct-custom-searchable-select-container",this.input=document.createElement("input"),this.input.className="select-input",this.input.type="text",this.input.placeholder=this.placeholder+"*",this.input.addEventListener("keypress",n=>{this.isOpen||n.preventDefault()}),this.originalElement&&(this.originalElement.disabled&&this.disable(),this.originalElement.required&&(this.input.required=!0),this.originalElement.name&&(s?this.hiddenInput=s:(this.hiddenInput=document.createElement("input"),t.appendChild(this.hiddenInput)),this.hiddenInput.type="hidden",this.hiddenInput.name=this.originalElement.name)),this.arrow=document.createElement("div"),this.arrow.className="select-arrow",this.clearBtn=document.createElement("button"),this.clearBtn.className="clear-btn",this.clearBtn.innerHTML="×",this.clearBtn.type="button",this.dropdown=document.createElement("div"),this.dropdown.className="select-dropdown",this.selectContainer.appendChild(this.input),this.clearable&&this.selectContainer.appendChild(this.clearBtn),this.selectContainer.appendChild(this.arrow),this.selectContainer.appendChild(this.dropdown),t.appendChild(this.selectContainer),this.hiddenInput&&(this.hiddenInput.value=this.selectedValue||""),this.wrapper=t}bindEvents(){this.selectContainer.addEventListener("click",e=>{e.target!==this.clearBtn&&this.toggle()}),this.clearBtn.addEventListener("click",e=>{e.stopPropagation(),this.clear()}),this.input.addEventListener("focus",()=>{this.isOpen||this.open()}),this.input.addEventListener("input",e=>{this.searchTerm=e.target.value,this.filter(),this.onSearch(this.searchTerm)}),this.input.addEventListener("keydown",e=>{this.handleKeydown(e)}),this.dropdown.addEventListener("click",e=>{const t=e.target.closest(".select-option");if(t&&!t.classList.contains("no-options")){const i=t.dataset.value,s=t.textContent;this.select(i,s),this.close()}}),this.outsideClickHandler=e=>{this.element.contains(e.target)||this.close()},document.addEventListener("click",this.outsideClickHandler)}handleKeydown(e){switch(e.key){case"ArrowDown":e.preventDefault(),this.highlightNext();break;case"ArrowUp":e.preventDefault(),this.highlightPrev();break;case"Enter":if(e.preventDefault(),this.highlightedIndex>=0&&this.filteredOptions[this.highlightedIndex]){const t=this.filteredOptions[this.highlightedIndex];this.select(t.value,t.text)}break;case"Escape":this.close();break;case"Backspace":this.selectedValue&&this.clear();break}}open(){this.isOpen=!0,this.selectContainer.classList.add("open"),this.input.placeholder=this.searchPlaceholder,this.highlightedIndex=-1,this.input.value="",this.filter(),setTimeout(()=>this.input.focus(),0)}close(){this.isOpen=!1,this.selectContainer.classList.remove("open"),this.input.placeholder=this.placeholder,this.searchTerm="",this.input.value=this.selectedText,this.highlightedIndex=-1}toggle(){this.isOpen?this.close():this.open()}filter(){const e=this.searchTerm.toLowerCase();this.filteredOptions=this.options.filter(t=>t.text.toLowerCase().includes(e)),this.highlightedIndex=-1,this.renderOptions()}highlightNext(){this.filteredOptions.length!==0&&(this.highlightedIndex=Math.min(this.highlightedIndex+1,this.filteredOptions.length-1),this.updateHighlight())}highlightPrev(){this.filteredOptions.length!==0&&(this.highlightedIndex=Math.max(this.highlightedIndex-1,0),this.updateHighlight())}updateHighlight(){var t;const e=this.dropdown.querySelectorAll(".select-option:not(.no-options)");e.forEach((i,s)=>{i.classList.toggle("highlighted",s===this.highlightedIndex)}),this.highlightedIndex>=0&&((t=e[this.highlightedIndex])==null||t.scrollIntoView({block:"nearest"}))}select(e,t){this.selectedValue=e,this.selectedText=t,this.input.value=t,this.hiddenInput&&(this.hiddenInput.value=e||""),this.originalElement&&(this.originalElement.value=e||""),setTimeout(()=>{this.onChange(e,t),this.close()},10)}clear(){return this.select(null,""),this}addOption(e,t){const i={value:e,text:t};return this.options.push(i),(!this.isOpen||!this.searchTerm)&&this.filteredOptions.push(i),this.render(),this}removeOption(e){return this.options=this.options.filter(t=>t.value!==e),this.filteredOptions=this.filteredOptions.filter(t=>t.value!==e),this.selectedValue===e&&this.clear(),this.render(),this}setOptions(e,t=null,i=null){return(t||i)&&(i=i??"value",t=t??"text",e=e.map(s=>({value:s[i],text:s[t]}))),this.options=e||[],this.filteredOptions=[...this.options],this.selectedValue&&!this.options.find(s=>s.value===this.selectedValue)&&this.clear(),this.render(),this}getValue(){return this.selectedValue}getText(){return this.selectedText}getSelected(){return{value:this.selectedValue,text:this.selectedText}}setValue(e){const t=this.options.find(i=>i.value===e);return t?this.select(t.value,t.text):this.clear(),this}disable(){return this.input.disabled=!0,this.disabled=!0,this.selectContainer.classList.add("disabled"),this.element.classList.add("disabled"),this}enable(){return this.input.disabled=!1,this.disabled=!1,this.selectContainer.classList.remove("disabled"),this.element.classList.remove("disabled"),this}render(){this.renderOptions()}renderOptions(){if(this.dropdown.innerHTML="",this.filteredOptions.length===0){const e=document.createElement("div");e.className="select-option no-options",e.textContent=this.searchTerm?"No matches found":"No options available",this.dropdown.appendChild(e);return}this.filteredOptions.forEach((e,t)=>{const i=document.createElement("div");i.className="select-option",i.dataset.value=e.value,i.textContent=e.text,e.value===this.selectedValue&&i.classList.add("selected"),this.dropdown.appendChild(i)})}destroy(){document.removeEventListener("click",this.outsideClickHandler),this.element.innerHTML="",this.selectContainer.remove()}}const Te={init:function(c,e={}){const t=typeof c=="string"?document.querySelector(c):c;if(!t)throw new Error("Element not found");return new Wt(t,e)}};typeof qe<"u"&&qe.exports?qe.exports=Te:typeof define=="function"&&define.amd?define(function(){return Te}):window.customSelect=Te;const ie=(c,e,t={})=>{let i;e==="click"?i=MouseEvent:e==="change"?i=Event:e.includes("focus")?i=FocusEvent:i=UIEvent;const s=new i(e,{bubbles:!0,cancelable:!1,...t});c.dispatchEvent(s)},X=c=>ie(c,"click"),Fe=c=>ie(c,"change"),Mt=c=>ie(c,"focusin"),Nt=c=>ie(c,"focusout"),Bt=c=>ie(c,"modalopen"),Ue=c=>ie(c,"modalclose"),j=(c,e)=>c[e]!==void 0?c[e]:c.getAttribute(e),O=(c,e)=>c==null?void 0:c.classList.contains(e),T=(c,e)=>c==null?void 0:c.classList.add(e),E=(c,e)=>c==null?void 0:c.classList.remove(e),Vt={data:null,searchable:!0,showSelectedItems:!0,placeholder:"Select an option",searchtext:"Search",selectedtext:"selected",hideSelect:!0,onChange:null};var _,$e,Ke,ot,ct,dt,ht,ut,pt,Ze,ft,Le,gt;class H{constructor(e,t={}){g(this,_);if(!e)throw new Error("No element provided to NiceSelect");if(!(e instanceof Element))throw new Error("Invalid element provided to NiceSelect - must be a valid DOM element");const i=[];e.tagName==="SELECT"&&e.querySelectorAll("option").forEach(n=>{(n.value||n.textContent.trim())&&i.push({value:n.value||n.textContent.trim(),text:n.textContent.trim()})}),t.data==null&&(t.data=i),this.el=e,this.el._niceSelect=this,this.config={...Vt,...t},this.data=this.config.data,this.selectedOptions=[],this.placeholder=j(this.el,"placeholder")||this.config.placeholder,this.searchtext=j(this.el,"searchtext")||this.config.searchtext,this.selectedtext=j(this.el,"selectedtext")||this.config.selectedtext,this.dropdown=null,this.selectionList=null,this.multiple=j(this.el,"multiple"),this.disabled=j(this.el,"disabled"),this.onChange=this.config.onChange,f(this,_,$e).call(this),f(this,_,dt).call(this)}_renderSelectedItems(){if(this.multiple){let e="";window.getComputedStyle(this.dropdown).width==="auto"||this.selectedOptions.length<2?(this.selectedOptions.forEach((t,i,s)=>{let n=t.data.text;i!==s.length-1&&(n+=", "),e+=`<span class="current">${n||this.placeholder}</span>`}),e=e||this.placeholder):e=`${this.selectedOptions.length} ${this.selectedtext}`,this.dropdown.querySelector(".multiple-options").innerHTML=e}else{const e=this.selectedOptions.length>0?this.selectedOptions[0].data.text:this.placeholder,t=this.dropdown.querySelector(".current");t.innerHTML=e,this.selectedOptions.length>0&&(!this.selectedOptions[0].data.value||this.selectedOptions[0].data.value==="")?t.classList.add("empty-value"):t.classList.remove("empty-value")}}setSelected(e){let t=null;for(let s=0;s<this.options.length;s++)if(this.options[s].data.value===e){t=this.options[s];break}const i=t==null?void 0:t.element;i&&(i.click(),E(this.dropdown,"open"))}_renderItems(){const e=this.dropdown.querySelector("ul");this.options.forEach(t=>{t.data.value!==""&&(this.multiple&&this.config.showSelectedItems&&this._multipleListAdd(t),e.appendChild(this._renderItem(t)))})}_renderItem(e){const t=document.createElement("li");if(t.innerHTML=e.data.text,e.data.extra!==void 0&&t.appendChild(this._renderItemExtra(e.data.extra)),e.attributes.optgroup)T(t,"optgroup");else{t.setAttribute("data-value",e.data.value);const i=["option"];e.attributes.selected&&i.push("selected"),e.attributes.disabled&&i.push("disabled"),t.classList.add(...i),t.addEventListener("click",s=>this._onDropdownItemClicked(e,s))}return e.element=t,t}_renderItemExtra(e){const t=document.createElement("span");return t.innerHTML=e,T(t,"extra"),t}update(e=""){var i;let t=this;e!=""&&(t=e.target._niceSelect),f(i=t,_,Ze).call(i)}disable(){this.disabled||(this.disabled=!0,T(this.dropdown,"disabled"))}enable(){this.disabled&&(this.disabled=!1,E(this.dropdown,"disabled"))}clear(){f(this,_,pt).call(this),this.selectedOptions=[],this._renderSelectedItems(),this.update(),Fe(this.el)}destroy(){this.selectionList&&f(this,_,Le).call(this),this.dropdown&&(this.dropdown.remove(),this.el.classList.remove("hidden-select"))}focus(e=""){if(O(this.dropdown,"open")?this.multiple?e===this.dropdown.querySelector(".multiple-options")&&(E(this.dropdown,"open"),Ue(this.el)):(E(this.dropdown,"open"),Ue(this.el)):(T(this.dropdown,"open"),Bt(this.el)),O(this.dropdown,"open")){const i=this.dropdown.querySelector(".fct-nice-select-search");i&&(i.value="",i.focus());const s=this.dropdown.querySelector(".focus");s&&E(s,"focus");const n=this.dropdown.querySelector(".selected");n&&T(n,"focus"),this.dropdown.querySelectorAll("ul li").forEach(r=>r.style.display="")}else this.dropdown.focus()}_bindSearchEvent(){const e=this.dropdown.querySelector(".fct-nice-select-search");e&&(e.addEventListener("click",t=>t.stopPropagation()),e.addEventListener("input",t=>this._onSearchChanged(t)))}_onClicked(e){e.preventDefault(),this.focus(e.target)}_onDropdownItemClicked(e,t){const i=t.target;if(!O(i,"disabled")){if(this.multiple){let s;O(i,"selected")?(s=!1,E(i,"selected"),this.selectedOptions=this.selectedOptions.filter(n=>n.data!==e.data)):(s=!0,T(i,"selected"),this.selectedOptions.push(e)),e.data.selected=s,e.attributes.selected=s}else{this.dropdown.querySelectorAll("li.selected").forEach(n=>E(n,"selected")),T(i,"selected"),this.selectedOptions=[e];let s=this.options.find(n=>n.attributes.selected);s&&(s.data.selected=!1,s.attributes.selected=!1),e.data.selected=!0,e.attributes.selected=!0}this._renderSelectedItems(),f(this,_,ut).call(this),f(this,_,ft).call(this)}}setOnChange(e){this.onChange=e}_onClickedOutside(e){this.dropdown.contains(e.target)||(E(this.dropdown,"open"),Ue(this.el))}_onKeyPressed(e){const t=this.dropdown.querySelector(".focus"),i=O(this.dropdown,"open");if(e.keyCode===13)X(i?t:this.dropdown);else if(e.keyCode===40){if(!i)X(this.dropdown);else{const n=this._findNext(t);n&&(t&&E(t,"focus"),T(n,"focus"))}e.preventDefault()}else if(e.keyCode===38){if(!i)X(this.dropdown);else{const n=this._findPrev(t);n&&(t&&E(t,"focus"),T(n,"focus"))}e.preventDefault()}else if(e.keyCode===27&&i)X(this.dropdown);else if(e.keyCode===32&&i)return!1;const s=this.dropdown.querySelector(".focus");return s&&s.scrollIntoView({block:"center"}),!1}_findNext(e){let t=e?e.nextElementSibling:this.dropdown.querySelector(".list .option");for(;t;){if(!O(t,"disabled")&&t.style.display!=="none")return t;t=t.nextElementSibling}return null}_findPrev(e){let t=e?e.previousElementSibling:this.dropdown.querySelector(".list .option:last-child");for(;t;){if(!O(t,"disabled")&&t.style.display!=="none")return t;t=t.previousElementSibling}return null}_onSearchChanged(e){const t=e.target.value.toLowerCase();if(t==="")this.options.forEach(s=>{s.element&&(s.element.style.display="")});else if(O(this.dropdown,"open")){const s=new RegExp(t);this.options.forEach(n=>{n.element&&(n.element.style.display=s.test(n.data.text.toLowerCase())?"":"none")})}this.dropdown.querySelectorAll(".focus").forEach(s=>E(s,"focus"));const i=this._findNext(null);i&&T(i,"focus")}_triggerValidationMessage(e){e==="invalid"?(T(this.dropdown,"invalid"),E(this.dropdown,"valid")):(T(this.dropdown,"valid"),E(this.dropdown,"invalid"))}setOptions(e,t=null,i=null){if((t||i)&&(i=i??"value",t=t??"text",e=e.map(s=>({value:s[i],text:s[t],selected:s.selected||!1,disabled:s.disabled||!1,extra:s.extra}))),this.data=e||[],f(this,_,Ke).call(this,this.data),this.selectedOptions.length>0){const s=this.data.map(r=>r.value),n=this.selectedOptions.filter(r=>s.includes(r.data.value));n.length===0?this.clear():this.selectedOptions=n}return f(this,_,gt).call(this),f(this,_,Ze).call(this),this}_multipleListAdd(e){if(!this.multiple||e.data.disabled||e.data.value==""||!e.attributes.selected)return;if(this.selectionList==null)this.selectionList=document.createElement("ul"),this.selectionList.classList.add("select-selection-list"),this.el.after(this.selectionList);else if(this.selectionList.querySelector(`[data-value="${e.data.value}"]`)!=null)return;let t=document.createElement("li");t.classList.add("select-selection"),t.dataset.value=e.data.value;let i=`
2 2 <button type="button" class="small remove-select-selection">
3 3 <span class='remove-select-selection'>×</span>
4 4 </button>
5 5 `;i+=`<span class='selected-name'>${e.data.text}</span>`,t.innerHTML=i,this.selectionList.appendChild(t),t.querySelectorAll(".remove-select-selection").forEach(s=>s.addEventListener("click",this._multipleListRemove.bind(this)))}_multipleListRemove(e){if(this.selectionList==null||(e.target!=null&&(e=e.target),e.matches==null||!e.matches(".remove-select-selection")))return;let t=e.closest("li.select-selection"),i=this.options.find(s=>s.data.value===t.dataset.value).element;i&&i.matches(".selected")&&i.click()}}_=new WeakSet,$e=function(e=!0){this.data?f(this,_,Ke).call(this,this.data):f(this,_,ot).call(this,e),this.el.classList.remove("hidden-select"),f(this,_,ct).call(this),this.config.hideSelect&&this.el.classList.add("hidden-select"),f(this,_,ht).call(this)},Ke=function(e){this.options=e.map(t=>({data:t,attributes:{selected:!!t.selected,disabled:!!t.disabled,optgroup:t.value==="optgroup"}}))},ot=function(e){const t=Array.from(this.el.querySelectorAll("option,optgroup")),i=[],s=[];this.data=t.map(n=>{let r,l=n.selected;e&&n.selected&&!n.defaultSelected&&(l=!1),n.tagName==="OPTGROUP"?r={text:n.label,value:"optgroup"}:r={text:n.dataset.display??n.innerText,value:n.value,extra:n.dataset.extra,selected:l,disabled:n.disabled};const o={selected:l,disabled:n.disabled,optgroup:n.tagName==="OPTGROUP"},a={data:r,attributes:o,element:null};return i.push(a),o.selected&&s.push(a),r}),this.options=i,this.selectedOptions=s},ct=function(){const e=["fct-nice-select",j(this.el,"class")||"",this.disabled?"disabled":"",this.multiple?"has-multiple":""].filter(Boolean),t=this.config.searchable?`
@@ -14,5 +14,5 @@
14 14 <ul class="list"></ul>
15 15 </div>
16 16 </div>
17 17 `;this.el.insertAdjacentHTML("afterend",i),this.dropdown=this.el.nextElementSibling,this._renderSelectedItems(),this._renderItems()},dt=function(){this.el.addEventListener("invalid",()=>this._triggerValidationMessage("invalid")),window.addEventListener("click",e=>this._onClickedOutside(e)),this.el.addEventListener("change",this.update)},ht=function(){this.dropdown.addEventListener("click",e=>this._onClicked(e)),this.dropdown.addEventListener("keydown",e=>this._onKeyPressed(e)),this.dropdown.addEventListener("focusin",()=>Mt(this.el)),this.dropdown.addEventListener("focusout",()=>Nt(this.el)),this.config.searchable&&this._bindSearchEvent()},ut=function(){const e=this.el;if(this.selectedOptions.length>0?e.value=this.selectedOptions[0].data.value:(e.value="",e.selectedIndex=-1),this.options.forEach(t=>{let i=Array.from(e.options).find(s=>s.textContent===t.data.text);i==null&&(i=Array.from(e.options).find(s=>s.textContent===t.data.value)),i&&(t.attributes.selected?i.selected=!0:i.selected=!1)}),e.removeEventListener("change",this.update),Fe(e),this.onChange&&typeof this.onChange=="function"){this.onChange(e.value,e);const t=new Event("change",{bubbles:!0,cancelable:!0});e.dispatchEvent(t)}e.addEventListener("change",this.update)},pt=function(){if(this.multiple){const e=this.el;this.selectedOptions.forEach(t=>{const i=e.querySelector(`option[value="${t.data.value}"]`);i&&(i.selected=!1)})}else this.selectedOptions.length>0&&(this.el.selectedIndex=-1);Fe(this.el)},Ze=function(){if(this.dropdown){const e=O(this.dropdown,"open");f(this,_,Le).call(this),this.dropdown.remove(),this.data=null,f(this,_,$e).call(this,!1),e&&X(this.dropdown)}j(this.el,"disabled")?this.disable():this.enable()},ft=function(){this.config.showSelectedItems&&(f(this,_,Le).call(this),this.selectedOptions.forEach(e=>{this._multipleListAdd(e)}))},Le=function(){this.selectionList!=null&&(this.selectionList.remove(),this.selectionList=null)},gt=function(){this.el.innerHTML="",this.data.forEach(e=>{const t=document.createElement("option");t.value=e.value,t.textContent=e.text,t.selected=e.selected||!1,t.disabled=e.disabled||!1,e.extra&&(t.dataset.extra=e.extra),this.el.appendChild(t)})};var le,Xe;class I{static async getCountryInfo(e,t="billing"){return this.countryInfo[e]?{...this.countryInfo[e],cached:!0}:await f(this,le,Xe).call(this,null,e,t)}static getCountryCodeByTimeZone(e){return this.countryCodeByTimeZone[e]?this.countryCodeByTimeZone[e]:null}static async getCountryInfoByTimeZone(e,t="billing"){const i=this.getCountryCodeByTimeZone(e);return i&&this.countryInfo[i]?this.countryInfo[i]:await f(this,le,Xe).call(this,e,null,t)}}le=new WeakSet,Xe=async function(e,t,i="billing"){const s=e?{timezone:e}:{country_code:t};i&&(s.type=i);let n=v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes&fc_checkout_action=get_country_info`).toString();n=te.appendQueryParams(n,s);let r;return await fetch(n,{headers:{"X-WP-Nonce":window.fluentCartRestVars.rest.nonce},credentials:"include"}).then(async l=>{var o;l=await l.json(),r={...l},delete l.views,this.countryInfo[(o=l.country_info)==null?void 0:o.country_code]=l==null?void 0:l.country_info,l!=null&&l.fragments&&v.handleFragments(l.fragments)}),r==null?void 0:r.country_info},g(I,le),p(I,"countryInfo",window.fluentcart_checkout_info.country_info||{}),p(I,"countryCodeByTimeZone",{});window.fluent_cart_localization_service={getCountryInfo:I.getCountryInfo,getCountryCodeByTimeZone:I.getCountryCodeByTimeZone,getCountryInfoByTimeZone:I.getCountryInfoByTimeZone};var Q,Oe,G,De,Pe,oe,ce,de,y,mt,yt,re,wt,Qe,_t,Ge,bt,vt,St,Ct,kt,Et,xt,Tt,Lt;const z=class z{constructor(e){g(this,y);g(this,Oe,{});g(this,G);p(this,"form");g(this,De,null);g(this,Pe,null);g(this,oe,null);p(this,"isAllDigital");p(this,"translate",window.fluentcart.$t);g(this,ce,"");g(this,de,{".fct_error_billing_address_section_section":["billing_full_name","billing_first_name","billing_last_name","billing_company_name","billing_vat_number","billing_legal_registration_id","billing_address_1","billing_address_2","billing_city","billing_postcode","billing_country","billing_state","billing_phone"],".fct_error_shipping_address_section_section":["shipping_full_name","shipping_first_name","shipping_last_name","shipping_address_1","shipping_address_2","shipping_city","shipping_postcode","shipping_country","shipping_state","shipping_phone"]});var t,i;this.checkoutInfo=window.fluentcart_checkout_info,m(this,oe,e),m(this,G,window.fluentCartRestVars.rest.url),this.nonce=(t=window.fluentCartRestVars)==null?void 0:t.rest.nonce,this.addAddressUrl=`${h(this,G)}/customers/add-address`,this.findAddressUrl=`${h(this,G)}/customers/`,m(this,Pe,v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes&fc_checkout_action=update_address_select`)),this.isAllDigital=((i=window.fluentcart_checkout_vars)==null?void 0:i.is_all_digital.toString())==="1",W.extend(rt),W.extend(at),m(this,De,W.tz.guess()),m(this,ce,window.fluentcart_checkout_info.checkout_nonce)}init(){return h(z,Q)!==null?h(z,Q):(this.initAddressFieldModalAction(),m(z,Q,this),this.initialSetup(),this.bindErrorCleanupListeners(),this)}initialSetup(){document.querySelector("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button-wrapper]");const e=document.querySelector("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button].selected"),t=document.querySelector("[data-fluent-cart-checkout-page-form-address-modal-apply-button]");e&&t&&(t.dataset.addressId=e.dataset.id)}initAddressFieldModalAction(){document.addEventListener("click",e=>{const t=e.target.closest("[data-fluent-cart-checkout-page-form-address-modal-open-button]");if(t){const i=f(this,y,Ge).call(this,t);if(i){const d=i.value;t.parentNode.querySelectorAll("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button]").forEach(b=>b.classList.remove("selected"));const u=t.parentNode.querySelector(`[data-id='${d}']`);u&&u.classList.add("selected")}f(this,y,re).call(this);const s=f(this,y,yt).call(this,t),n=s.dataset.fluentCartAddressType,r=s.cloneNode(!0),l=r.querySelector("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button].selected"),o=r.querySelector("[data-fluent-cart-checkout-page-form-address-modal-apply-button]");l&&o&&(o.dataset.addressId=l.dataset.id,o.dataset.country=l.dataset.country,o.dataset.state=l.dataset.state,o.dataset.addressType=n),r.classList.remove("hidden"),r.classList.add("show"),f(this,y,Qe).call(this,r,t,n),f(this,y,_t).call(this,r,t),r.querySelectorAll("[data-fluent-cart-checkout-page-form-address-modal-close-button]").forEach(d=>{d.addEventListener("click",()=>r.remove())});const a=document.createElement("div");a.className="fluent-cart-checkout-page-form-address-modal-backdrop",a.addEventListener("click",()=>f(this,y,re).call(this)),r.appendChild(a),f(this,y,St).call(this,r),f(this,y,Et).call(this,r),f(this,y,Tt).call(this,r,n,t),f(this,y,wt).call(this,r),f(this,y,mt).call(this,r)}})}initStateSelect(e,t=null){var i,s;return(s=(i=t==null?void 0:t.address_locale)==null?void 0:i.state)!=null&&s.label,Te.init(e,{placeholder:!1,onChange:n=>{}})}initStateSelect2(e,t=null){var i,s;return(s=(i=t==null?void 0:t.address_locale)==null?void 0:i.state)!=null&&s.label,new H(e,{placeholder:!1,onChange:n=>{}})}onCountryChanged(e="billing",t){let i=[{text:"Select a option",value:""}];t==null||t.states.forEach(s=>{i.push({text:s.name,value:s.value})}),this.billingStateSelect.setOptions(i)}updateStateInput(e,t="billing"){var a,d,w;if(!e)return;const i=(d=(a=e==null?void 0:e.address_locale)==null?void 0:a.state)==null?void 0:d.hidden;e==null||e.states;const s="#"+t+"_state_wrapper";let n=this.form.querySelector("#"+t+"_state");if(!n)return;const r=((n==null?void 0:n.tagName)||"").toLowerCase(),l=((w=e==null?void 0:e.states)==null?void 0:w.length)||0,o=["select","select-one"].includes(r);if(i)this.form.querySelector(s).style.display="none";else if(this.form.querySelector(s).style.display="block",this.billingStateSelect!==null&&(this.billingStateSelect.destroy(),this.billingStateSelect=null),l===0)o&&(n=this.convertElementToType(n,"input"));else{o||(n=this.convertElementToType(n,"select"));let u=[];e==null||e.states.forEach(b=>{u.push({text:b.name,value:b.value})}),this.billingStateSelect=this.initStateSelect2(n,e).setOptions(u)}}convertElementToType(e,t){if(!e||!t)return;const i=document.createElement(t);return i.id=e.id,i.name=e.name,i.className=e.className,i.value=e.value,Array.from(e.attributes).forEach(s=>{s.name.startsWith("data-")&&i.setAttribute(s.name,s.value)}),e.parentNode.replaceChild(i,e),t==="input"&&(i.value=""),i}async getCountryInfo(e,t){const i=e?{timezone:e}:{country_code:t};let s=v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes&fc_checkout_action=get_country_info`).toString();s=te.appendQueryParams(s,i);let n=null;if(e||(n=h(this,Oe)[i.country_code]),n)return n;let r;return await fetch(s,{headers:{"X-WP-Nonce":window.fluentCartRestVars.rest.nonce},credentials:"include"}).then(async l=>{l=await l.json(),r=l==null?void 0:l.country_info,l!=null&&l.fragments&&v.handleFragments(l.fragments)}),r}removeValidationErrors(){document.querySelectorAll("[data-fluent-cart-checkout-page-form-input-wrapper]").forEach(e=>e.classList.remove("has-error")),document.querySelectorAll("[data-fluent-cart-checkout-page-form-error]").forEach(e=>e.innerHTML="")}showValidationErrors(e){const t=document.querySelectorAll("[data-fluent-cart-checkout-page-form-section]"),i=(e==null?void 0:e.errors)||{};t.forEach(n=>{Object.entries(h(this,de)).forEach(([r,l])=>{const o=n.querySelector(r);if(!o)return;const a={};l.forEach(d=>{i[d]&&(a[d]=i[d])}),Object.keys(a).length?(o.classList.add("show_error"),o.innerHTML=Object.entries(a).flatMap(([d,w])=>Object.values(w).map(u=>`<span data-fct-error-field="${d}">${u}</span>`)).join("")):(o.classList.remove("show_error"),o.innerHTML="")})});const s=Object.values(i).flatMap(n=>Object.values(n));s.length&&new Toastify({text:s.join("<br>")||"Validation Error!",className:"warning",escapeMarkup:!1,duration:3e3,style:{color:"#000",background:"#ffffff"}}).showToast()}clearFieldError(e){Object.entries(h(this,de)).forEach(([t,i])=>{if(!i.includes(e)||!this.form)return;const s=this.form.querySelector(t);if(!s)return;const n=s.querySelector(`[data-fct-error-field="${e}"]`);n&&(n.classList.add("fct-error-leave"),n.addEventListener("transitionend",()=>{n.remove(),s.querySelector("span")||s.classList.remove("show_error")},{once:!0}))})}bindErrorCleanupListeners(){const e=t=>{var s;const i=t.target;i.name&&(s=i.value)!=null&&s.trim()&&this.clearFieldError(i.name)};document.addEventListener("input",e),document.addEventListener("change",e)}saveCustomerData(e,t){var o;const i=h(this,oe).prepareFormData(),s=((o=window.fluentCartUtmManager)==null?void 0:o.get())||{};Object.keys(s).forEach(a=>{t&&i.append(`utm_data[${a}]`,s[a])});const n=new URLSearchParams;for(const[a,d]of i.entries())n.append(a,d);const r=v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes`),l=te.appendQueryParams(r.toString(),{fc_checkout_action:"save_checkout_data",data_key:e,data_value:t});window.fluent_cart_checkout_ui_service.setLoading("shippingMethodsWrapper"),fetch(l,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":h(this,ce)},credentials:"include",body:n}).then(a=>a.json()).then(a=>{var d,w,u,b,C,q,k,x,se,ne;if(a!=null&&a.changes){if((d=a==null?void 0:a.changes)!=null&&d.billing_address_id){const S=document.querySelector("#billing_address_id");S&&(S.value=(w=a==null?void 0:a.changes)==null?void 0:w.billing_address_id)}if((u=a==null?void 0:a.changes)!=null&&u.billing_company_name){const S=document.querySelector("#billing_company_name");S&&!S.value.trim()&&(S.value=(b=a==null?void 0:a.changes)==null?void 0:b.billing_company_name)}if((C=a==null?void 0:a.changes)!=null&&C.billing_legal_registration_id){const S=document.querySelector("#billing_legal_registration_id");S&&!S.value.trim()&&(S.value=(q=a==null?void 0:a.changes)==null?void 0:q.billing_legal_registration_id)}if((k=a==null?void 0:a.changes)!=null&&k.fct_billing_tax_id){const S=document.querySelector("#fct_billing_tax_id");S&&!S.value.trim()&&(S.value=(x=a==null?void 0:a.changes)==null?void 0:x.fct_billing_tax_id)}if((se=a==null?void 0:a.changes)!=null&&se.billing_full_name){const S=document.querySelector("#billing_full_name");S&&(S.value=(ne=a==null?void 0:a.changes)==null?void 0:ne.billing_full_name)}}a!=null&&a.fragments&&v.handleFragments(a.fragments),(a!=null&&a.shipping_charge_changes||a!=null&&a.tax_total_Changes)&&this.checkoutHandler.handleCheckoutAmountChanges()}).finally(()=>{window.fluent_cart_checkout_ui_service.finishLoading("shippingMethodsWrapper")})}};Q=new WeakMap,Oe=new WeakMap,G=new WeakMap,De=new WeakMap,Pe=new WeakMap,oe=new WeakMap,ce=new WeakMap,de=new WeakMap,y=new WeakSet,mt=function(e){const t=i=>{(i.key==="Escape"||i.keyCode===27)&&(f(this,y,re).call(this),document.removeEventListener("keydown",t))};document.addEventListener("keydown",t),e._escKeyHandler=t},yt=function(e){return e.closest("[data-fluent-cart-checkout-page-form-address-modal-wrapper]").querySelector("[data-fluent-cart-checkout-page-form-address-modal-body]")},re=function(){document.querySelectorAll("body > [data-fluent-cart-checkout-page-form-address-modal-body]").forEach(e=>{e._escKeyHandler&&document.removeEventListener("keydown",e._escKeyHandler),e.remove()})},wt=function(e){document.body.appendChild(e)},Qe=function(e,t,i){e.querySelectorAll("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button]").forEach(s=>{s.addEventListener("click",()=>{e.querySelectorAll("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button]").forEach(r=>r.classList.remove("selected")),s.classList.add("selected");const n=e.querySelector("[data-fluent-cart-checkout-page-form-address-modal-apply-button]");n&&(n.dataset.addressId=s.dataset.id,n.dataset.country=s.dataset.country,n.dataset.state=s.dataset.state,n.dataset.addressType=i)})})},_t=function(e,t){const i=e.querySelector("[data-fluent-cart-checkout-page-form-address-modal-apply-button]");i.closest("[data-fluent-cart-checkout-page-form-address-modal-body]").dataset.fluentCartAddressType,i&&i.addEventListener("click",()=>{const n=i.dataset.addressId;if(!n)return;const r=i.dataset.country,l=i.dataset.state,o=f(this,y,bt).call(this,t),a=f(this,y,Ge).call(this,t),d=i.dataset.addressType;if(a){const w=a.dataset.country,u=a.dataset.state;if(w!==r||u!==l){a.value=n,a.dataset.country=r,a.dataset.state=l;const b=new Event("change",{bubbles:!0,cancelable:!0});a.dispatchEvent(b),window.dispatchEvent(new CustomEvent("fluentCartNotifyAddressCountryChanged",{detail:{country:r,state:l,input:a,addressType:d}}))}}o&&f(this,y,vt).call(this,n,o,d),f(this,y,re).call(this)})},Ge=function(e){const t=e.closest("[data-fluent-cart-checkout-page-form-address-select-wrapper]");return(t==null?void 0:t.querySelector("[data-fluent-cart-checkout-page-form-address-input]"))??null},bt=function(e){const t=e.closest("[data-fluent-cart-checkout-page-form-address-select-wrapper]");return(t==null?void 0:t.querySelector("[data-fluent-cart-checkout-page-form-address-info-wrapper]"))??null},vt=function(e,t,i){this.saveCustomerData(i+"_address_id",e)},St=function(e){e.querySelectorAll("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-button]").forEach(t=>{t.addEventListener("click",()=>f(this,y,Ct).call(this,e,t))})},Ct=function(e,t){e.querySelector("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button-wrapper]").classList.add("hide");const i=e.querySelector("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-form-wrapper]");this.form=i,this.formType=i.querySelector("#billing_state")||i.querySelector("#billing_country")?"billing":"shipping",f(this,y,kt).call(this,i),i.classList.add("show"),t.parentNode.style.display="none"},kt=async function(e){var l,o,a,d;let t=null;const i="#"+this.formType+"_state",s="#"+this.formType+"_country",n=e.querySelector(s),r=e.querySelector(i);n&&(o=(l=n.nextElementSibling)==null?void 0:l.classList)!=null&&o.contains("fct-nice-select")&&n.nextElementSibling.remove(),r&&((d=(a=r.nextElementSibling)==null?void 0:a.classList)!=null&&d.contains("fct-nice-select")&&r.nextElementSibling.remove(),this.billingStateSelect=new H(r,{placeholder:!1,data:null})),n&&new H(n,{placeholder:this.translate("Select a Country"),clearable:!1,data:null,onChange:async w=>{if(w){const u=await I.getCountryInfo(w);this.updateStateInput(u,this.formType)}else e.querySelector(i).value="",this.billingStateSelect.setOptions([])}}),r&&this.onCountryChanged(this.formType,t)},Et=function(e){e.addEventListener("click",t=>{const i=t.target.closest("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-cancel-button]");i&&f(this,y,xt).call(this,e,i)})},xt=function(e,t){e.querySelector("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button-wrapper]").classList.remove("hide"),e.querySelector("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button-wrapper]").classList.add("show"),e.querySelector("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-form-wrapper]").classList.remove("show"),e.querySelector("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-form-wrapper]").classList.add("hide"),e.querySelector("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-button]").parentNode.style.display=""},Tt=function(e,t,i){const s=e.querySelector("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-form-wrapper]"),n=s.cloneNode(!0),r=document.createElement("form");r.appendChild(n),s.replaceWith(r);const l=this.isAllDigital?"digital":"physical";r.addEventListener("submit",o=>{var w;o.preventDefault();const a=new FormData(r);a.append("type",t),a.append("product_type",l);const d=`${t}_label`;if(((w=a.get(d))==null?void 0:w.length)>15){new Toastify({text:this.translate("Label must not exceed 15 characters."),className:"warning",duration:900}).showToast();return}f(this,y,Lt).call(this,e,a,i)})},Lt=function(e,t,i){this.removeValidationErrors();let s=v.buildUrl(this.addAddressUrl.toString()).toString();fetch(s,{method:"POST",body:t,headers:{"X-WP-Nonce":this.nonce}}).then(async n=>{if(n.ok)return await n.json();throw this.showValidationErrors(await n.json()),Error("Failed to submit form")}).then(n=>{n.fragment&&(Array.isArray(n.fragment)?n.fragment:[n.fragment]).forEach(d=>{if(d.type!=="replace")return;const w=e.querySelector(d.selector);w&&(w.outerHTML=d.content);const u=e.dataset.fluentCartAddressType,b=document.querySelector(`[data-fluent-cart-address-type="${u}"]:not(body > *)`);if(b){const C=b.querySelector(d.selector);C&&(C.outerHTML=d.content)}});const r=e.querySelector("[data-fluent-cart-checkout-page-form-address-modal-address-selector-button-wrapper]");r&&(r.classList.remove("hide"),r.classList.remove("show"));const l=e.querySelector("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-form-wrapper]");l&&(l.classList.remove("show"),l.classList.add("hide"));const o=e.querySelector("[data-fluent-cart-checkout-page-form-address-show-add-new-modal-button]");o&&(o.parentNode.style.display=""),n.message&&new Toastify({text:n.message,className:"info",duration:900}).showToast(),f(this,y,Qe).call(this,e,i,e.dataset.fluentCartAddressType)}).catch(n=>{})},g(z,Q,null);let ze=z;var P,We,he,ue,pe,fe,J,ge,A,U,me,Y,M,qt,Je,It;class Ht{constructor(e){g(this,M);g(this,P);g(this,We);g(this,he);g(this,ue);g(this,pe);g(this,fe);g(this,J);g(this,ge);g(this,A,[]);g(this,U,!1);g(this,me,!1);p(this,"translate",window.fluentcart.$t);g(this,Y,"");var t;m(this,P,e),m(this,We,window.fluentcart_checkout_vars.rest.url),m(this,me,((t=window.fluentcart_checkout_vars)==null?void 0:t.disable_coupons.toString())==="yes"),m(this,he,v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes&fc_checkout_action=apply_coupon`)),m(this,ue,v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes&fc_checkout_action=remove_coupon`)),m(this,Y,window.fluentcart_checkout_info.checkout_nonce),m(this,pe,"[data-fluent-cart-checkout-page-coupon-container]"),m(this,fe,"[data-fluent-cart-checkout-page-coupon-field-toggle]"),m(this,J,"[data-fluent-cart-checkout-page-coupon-validate]"),m(this,ge,"[data-fluent-cart-checkout-page-form-input-wrapper]")}init(){setTimeout(()=>{f(this,M,qt).call(this)},300),window.addEventListener("fluentCartNotifySummaryViewUpdated",()=>{}),window.fluentCartCouponService=this}getCoupons(){return h(this,A)}addCoupon(e){h(this,A).push(e)}removeCouponByCode(e){m(this,A,h(this,A).filter(t=>t!==e)),this.removeCouponFromUrl(e)}removeCouponFromUrl(e){const t=new URL(window.location.href),i=t.searchParams,s=i.get("coupons");if(s){const n=s.split(",").filter(l=>l!==e).join(",");n?i.set("coupons",n):i.delete("coupons");const r=t.pathname+"?"+i.toString();history.replaceState(null,"",r)}}}P=new WeakMap,We=new WeakMap,he=new WeakMap,ue=new WeakMap,pe=new WeakMap,fe=new WeakMap,J=new WeakMap,ge=new WeakMap,A=new WeakMap,U=new WeakMap,me=new WeakMap,Y=new WeakMap,M=new WeakSet,qt=function(){h(this,me)||(h(this,P).addEventListener("pointerdown",e=>{e.target.closest(h(this,J))&&(e.preventDefault(),f(this,M,Je).call(this))}),h(this,P).addEventListener("click",e=>{if(e.target.closest(h(this,J))){if(h(this,U)){e.preventDefault();return}e.stopPropagation()}})),h(this,P).addEventListener("click",e=>{const t=e.target.closest(h(this,fe));if(!t)return;e.preventDefault();const i=document.querySelector(h(this,pe));if(i){const s=i.querySelector(h(this,ge));if(s){const l=s.querySelector("input");l&&setTimeout(()=>l.focus(),0)}const n=i.hasAttribute("hidden")||i.style.display==="none"||!i.style.display;n?(i.removeAttribute("hidden"),i.style.display="block"):(i.setAttribute("hidden",""),i.style.removeProperty("display"));const r=t.parentElement.parentElement;r&&r.classList.toggle("is_coupon_active",n)}}),h(this,P).addEventListener("click",e=>{const t=e.target.closest("[data-remove-coupon]");if(!t||!t.closest("[data-fluent-cart-checkout-page-applied-coupon]"))return;e.preventDefault();const s=t.dataset.coupon??t.getAttribute("data-coupon");f(this,M,It).call(this,s)}),h(this,P).addEventListener("keypress",e=>{e.target.id==="coupon"&&e.key==="Enter"&&(e.preventDefault(),f(this,M,Je).call(this))})},Je=function(){m(this,U,!0);const e=document.getElementById("coupon").value,t=document.getElementById("billing_email").value,i=te.appendQueryParams(h(this,he).toString(),{coupon_code:e,customer_email:t});fetch(i,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":h(this,Y)},credentials:"include"}).then(s=>(m(this,U,!1),s.ok?s.json():s.json().then(n=>{throw new Error(n.message)}))).then(s=>{v.handleFragments(s.fragments),m(this,A,s.applied_coupons),document.getElementById("coupon").value="",h(this,A).includes(e)?(new Toastify({text:this.translate("Applied Successfully"),className:"info",duration:3e3}).showToast(),window.dispatchEvent(new CustomEvent("fluentCartNotifyCouponApplied",{detail:{response:s}})),window.dispatchEvent(new CustomEvent("fluentCartCheckoutDataChanged",{detail:{response:s}}))):new Toastify({text:this.translate("Coupon cannot be applied"),className:"info",duration:3e3}).showToast()}).catch(s=>{m(this,U,!1),new Toastify({text:`<span class="warn warning"></span>${s.message}`,className:"warning",escapeMarkup:!1,duration:3e3,close:!1}).showToast()})},It=function(e){this.removeCouponByCode(e),fetch(h(this,ue)+"&coupon_code="+e,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":h(this,Y)},credentials:"include"}).then(t=>t.ok?(new Toastify({text:this.translate("Coupon removed!"),className:"info",duration:3e3}).showToast(),t.json()):t.text().then(i=>{throw new Error(i)})).then(t=>{m(this,A,t.applied_coupons),t.fragments&&v.handleFragments(t.fragments),window.dispatchEvent(new CustomEvent("fluentCartNotifyCouponRemoved",{detail:{response:t}})),window.dispatchEvent(new CustomEvent("fluentCartCheckoutDataChanged",{detail:{response:t}}))}).catch(t=>{this.addCoupon(e)})};var ee,ye;const N=class N{constructor(e,t){g(this,ee,null);p(this,"formWrapper");p(this,"checkoutHandler",null);p(this,"onReady",null);p(this,"defaultCountry",null);g(this,ye,"");p(this,"translate",window.fluentcart.$t);var i;this.formWrapper=e.form,this.checkoutHandler=e,this.isAllDigital=((i=window.fluentcart_checkout_vars)==null?void 0:i.is_all_digital.toString())==="1",m(this,ye,window.fluentcart_checkout_info.checkout_nonce),W.extend(rt),W.extend(at),m(this,ee,W.tz.guess()),this.onReady=t,this.initCustomBillingSelect()}static init(e,t){return N.instance===null&&(N.instance=new N(e,t)),window.fluent_cart_address_service=N.instance,N.instance}async initCustomBillingSelect(){var w,u,b,C,q;let e=this.formWrapper.querySelector("#billing_country");if(!e)return;let t="";const i=this.formWrapper.querySelector("#billing_address_id"),s=((w=i==null?void 0:i.dataset)==null?void 0:w.country)||"";e.value?t=e.value:s&&(t=s);let n=null;const r=!t;(!e||!h(this,ee)&&!t)&&(t=window.fluentcart_checkout_info.store_country),t?n=await I.getCountryInfo(t):(n=await I.getCountryInfoByTimeZone(h(this,ee)),r&&(n!=null&&n.country_code)&&this.saveCustomerData("billing_country",n==null?void 0:n.country_code)),e&&n&&(e.value=n==null?void 0:n.country_code),n.cached&&r&&this.saveCustomerData("billing_country",n==null?void 0:n.country_code);let l=this.formWrapper.querySelector("#billing_state"),o="";l&&(o=l.value),this.stateLabel="State",n&&((b=(u=n.address_locale)==null?void 0:u.state)!=null&&b.label)&&(this.stateLabel=(q=(C=n.address_locale)==null?void 0:C.state)==null?void 0:q.label),l&&(this.billingStateSelect=new H(l,{placeholder:this.stateLabel,data:null}));let a="";e&&(a=e.value),this.defaultCountry=a,e&&(this.billingCountrySelect=new H(e,{placeholder:"Select a Country",clearable:!1,data:null})),e&&a&&this.billingCountrySelect.setSelected(a),e&&e.value===a&&l&&this.billingStateSelect.setSelected(o);const d=this;if(e&&(this.billingCountrySelect.setOnChange(async k=>{if(window.fluent_cart_checkout_ui_service.setComponentState("billingStateSelect","loading"),k){const x=await I.getCountryInfo(k);d.saveCustomerData("billing_country",k),x&&window.fluent_cart_checkout_ui_service.setComponentState("billingStateSelect","enable"),window.fluent_cart_shipping_service&&window.fluent_cart_shipping_service.shippingToDifferent===!1&&(x.views?window.fluent_cart_shipping_service.updateShippingMethodsView({view:x.views.shipping_methods,status:!0}):window.fluent_cart_shipping_service.handleBillingAddressChange(k)),this.updateStateInput(x,"billing")}else this.formWrapper.querySelector("#billing_state")&&(this.formWrapper.querySelector("#billing_state").value="",this.billingStateSelect.setOptions([]))}),this.onCountryChanged("billing",n,n==null?void 0:n.country_code)),this.updateStateInput(n,"billing"),l&&this.billingStateSelect,this.isAllDigital)typeof this.onReady=="function"&&this.onReady();else{const k={response:n,defaultCountry:a,defaultState:o};this.initCustomShippingSelect(k)}}initCustomShippingSelect(e){var a,d,w;const t=this.formWrapper.querySelector("#shipping_state"),i=this.formWrapper.querySelector("#shipping_country"),s=this.formWrapper.querySelector("#shipping_address_id"),n=((a=s==null?void 0:s.dataset)==null?void 0:a.country)||"",r=((d=s==null?void 0:s.dataset)==null?void 0:d.state)||"";if(!t||!i)return;let l="";i!=null&&i.value?l=i.value:n&&(l=n);let o="";t!=null&&t.value?o=t.value:r&&(o=r),t&&(this.shippingStateSelect=new H(t,{placeholder:this.stateLabel,data:null})),i&&(this.shippingCountrySelect=new H(i,{placeholder:!1,clearable:!1,data:null})),l||(l=e.defaultCountry),o||(o=e.defaultState),this.defaultCountry=l,i&&this.shippingCountrySelect.setSelected(l),l&&this.shippingStateSelect.setSelected(o),i&&(this.shippingCountrySelect.setOnChange(async u=>{if(window.fluent_cart_checkout_ui_service.setComponentState("shippingStateSelect","loading"),u){const b=await I.getCountryInfo(u,"shipping");b&&window.fluent_cart_checkout_ui_service.setComponentState("shippingStateSelect","enable"),window.fluent_cart_shipping_service&&(b.views?window.fluent_cart_shipping_service.updateShippingMethodsView({view:b.views.shipping_methods,status:!0}):window.fluent_cart_shipping_service.handleShippingAddressChange(u)),this.updateStateInput(b,"shipping")}else this.formWrapper.querySelector("#shipping_state").value="",this.shippingStateSelect.setOptions([])}),this.onCountryChanged("shipping",e.response,(w=e.response)==null?void 0:w.country_code)),typeof this.onReady=="function"&&this.onReady()}onCountryChanged(e="billing",t,i=""){var o,a;const s=this.formWrapper.querySelector("#"+e+"_state"),r=this.formWrapper.querySelector("#"+e+"_country").value;let l="";if(s&&(l=s.value),t!=null&&t.states){let d=[{text:"Select an option",value:""}];if(t==null||t.states.forEach(w=>{d.push({text:w.name,value:w.value})}),e==="billing"){if(s){this.billingStateSelect&&this.billingStateSelect.setOptions(d),r&&this.billingStateSelect.setSelected(l);const w=this;this.billingStateSelect.setOnChange(async u=>{w.saveCustomerData("billing_state",u)})}}else if(s){this.shippingStateSelect&&this.shippingStateSelect.setOptions(d),r&&this.shippingStateSelect.setSelected(l);const w=this;this.shippingStateSelect.setOnChange(async u=>{w.saveCustomerData("shipping_state",u)})}}this.showHideState((a=(o=t==null?void 0:t.address_locale)==null?void 0:o.state)==null?void 0:a.hidden,e)}updateStateInput(e,t="billing"){var d,w,u,b,C,q,k,x,se,ne,S;if(!e)return;const i=(w=(d=e==null?void 0:e.address_locale)==null?void 0:d.state)==null?void 0:w.hidden;e==null||e.states;const s="#"+t+"_state_wrapper";let n=this.formWrapper.querySelector("#"+t+"_state");const r=((n==null?void 0:n.tagName)||"").toLowerCase(),l=((u=e==null?void 0:e.states)==null?void 0:u.length)||0,o=["select","select-one"].includes(r);if(!n)return;const a=n.value;if(i)this.formWrapper.querySelector(s).style.display="none";else{if(this.formWrapper.querySelector(s).style.display="block",t==="billing"&&this.billingStateSelect!==null&&(this.billingStateSelect.destroy(),this.billingStateSelect=null),t==="shipping"&&this.shippingStateSelect!==null&&(this.shippingStateSelect.destroy(),this.shippingStateSelect=null),l===0){if(o){let R="State";e&&((C=(b=e.address_locale)==null?void 0:b.state)!=null&&C.label)&&(R=(k=(q=e.address_locale)==null?void 0:q.state)==null?void 0:k.label),n=this.convertElementToType(n,"input",R),n.addEventListener("change",()=>{this.saveCustomerData(n.name,n.value)})}}else{o||(n=this.convertElementToType(n,"select"),n.addEventListener("change",()=>{this.saveCustomerData(n.name,n.value)}));let R="State";e&&((se=(x=e.address_locale)==null?void 0:x.state)!=null&&se.label)&&(R=(S=(ne=e.address_locale)==null?void 0:ne.state)==null?void 0:S.label);let He=[{text:this.translate("Select %s",R),value:""}];if(e==null||e.states.forEach(Z=>{He.push({text:Z.name,value:Z.value})}),t==="shipping"){this.shippingStateSelect=this.initStateSelect(n,e,R).setOptions(He),this.shippingStateSelect.setSelected(a);const Z=this;this.shippingStateSelect.setOnChange(async Re=>{Z.saveCustomerData("shipping_state",Re)})}else{this.billingStateSelect=this.initStateSelect(n,e,R).setOptions(He),this.billingStateSelect.setSelected(a);const Z=this;this.billingStateSelect.setOnChange(async Re=>{Z.saveCustomerData("shipping_state",Re)})}}n.closest("[data-fluent-cart-checkout-page-form-input-wrapper]")}}initStateSelect(e,t=null,i=!1){var s,n;return(n=(s=t==null?void 0:t.address_locale)==null?void 0:s.state)!=null&&n.label,new H(e,{placeholder:i,onChange:r=>{}})}convertElementToType(e,t,i=null){if(!e||!t)return;const s=document.createElement(t);s.id=e.id,s.name=e.name,s.className=e.className,s.value=e.value,Array.from(e.attributes).forEach(r=>{r.name.startsWith("data-")&&s.setAttribute(r.name,r.value)}),i&&s.setAttribute("placeholder",i);const n=e.parentNode;return n&&n.replaceChild(s,e),t==="input"&&(s.value=""),s}showHideState(e,t="billing"){let i="#"+t+"_state_wrapper";this.formWrapper.querySelector("#"+t+"_state"),this.formWrapper.querySelector(i)&&(e?this.formWrapper.querySelector(i).style.display="none":this.formWrapper.querySelector(i).style.display="block")}saveCustomerData(e,t){var o;const i=this.checkoutHandler.prepareFormData(),s=((o=window.fluentCartUtmManager)==null?void 0:o.get())||{};Object.keys(s).forEach(a=>{t&&i.append(`utm_data[${a}]`,s[a])});const n=new URLSearchParams;for(const[a,d]of i.entries())n.append(a,d);const r=v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes`),l=te.appendQueryParams(r.toString(),{fc_checkout_action:"save_checkout_data",data_key:e,data_value:t});window.fluent_cart_checkout_ui_service.setLoading("shippingMethodsWrapper"),fetch(l,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":h(this,ye)},credentials:"include",body:n}).then(a=>a.json()).then(a=>{a!=null&&a.fragments&&v.handleFragments(a.fragments),(a!=null&&a.shipping_charge_changes||a!=null&&a.tax_total_Changes)&&this.checkoutHandler.handleCheckoutAmountChanges()}).finally(()=>{window.fluent_cart_checkout_ui_service.finishLoading("shippingMethodsWrapper")})}};ee=new WeakMap,ye=new WeakMap,p(N,"instance",null);let Ie=N;var we;const B=class B{constructor(e){p(this,"checkoutHandler",null);p(this,"form",null);g(this,we,"");this.checkoutHandler=e,this.form=e.form,m(this,we,window.fluentcart_checkout_info.checkout_nonce),this.bindEvents()}static init(e){return B.instance===null&&(B.instance=new B(e)),window.fluent_cart_checkout_data_watcher=B.instance,B.instance}bindEvents(){const e=["billing_country","shipping_country"];for(const s of e){const n=document.getElementById(s);n&&n.addEventListener("change",this.debounce(r=>{this.saveCustomerData(s,r.target.value)},400))}const t=["billing_state","shipping_state"];for(const s of t){const n=document.getElementById(s);n&&n.addEventListener("change",this.debounce(r=>{r.target.value==="Select State"||r.target.value===""||this.saveCustomerData(s,r.target.value)},400))}const i=["billing_address","billing_full_name","billing_email","billing_address_1","billing_city","billing_postcode","billing_company_name","billing_legal_registration_id","billing_phone","shipping_address","shipping_full_name","shipping_address_1","shipping_city","shipping_postcode","shipping_company_name","shipping_phone"];for(let s of i){const n=document.getElementById(s);n&&n.addEventListener("change",this.debounce(r=>{s==="shipping_address"&&(s="shipping_address_id"),s==="billing_address"&&(s="billing_address_id"),this.saveCustomerData(s,r.target.value)},400))}window.addEventListener("change",s=>{const n=s.target;n&&n.name==="_fct_pay_method"&&n.checked&&this.saveCustomerData("_fct_pay_method",n.value)}),window.addEventListener("change",s=>{const n=s.target;n&&n.name==="fc_shipping_method"&&n.checked&&this.saveCustomerData("shipping_method_id",n.value)}),this.form.addEventListener("change",s=>{const n=s.target;if(!n||!n.matches("[data-fluent-cart-checkout-page-tax-id]"))return;const r=n.closest("[data-fluent-cart-checkout-page-tax-wrapper]");r&&r.querySelector("[data-fluent-cart-checkout-page-tax-apply-btn]")||this.saveCustomerData("fct_billing_tax_id",n.value.trim())}),document.addEventListener("change",s=>{s.target.matches('input[name="ship_to_different"]')&&this.saveCustomerData("ship_to_different",s.target.checked?"yes":"no")}),document.addEventListener("change",s=>{if(!s.target.matches("[data-fluent-cart-b2b-toggle]"))return;const n=s.target.checked;this.handleB2BToggle(n,s.target),this.saveCustomerData("is_business",n?"yes":"no")})}handleB2BToggle(e,t=null){const i=document.querySelector("[data-fluent-cart-b2b-section]"),s=t||document.querySelector("[data-fluent-cart-b2b-toggle]");i&&(i.style.display=e?"":"none",i.querySelectorAll('input[data-b2b-required="yes"]').forEach(n=>{n.required=e,e?n.setAttribute("aria-required","true"):n.removeAttribute("aria-required")})),s&&s.setAttribute("aria-expanded",e?"true":"false")}debounce(e,t){let i;return(...s)=>{clearTimeout(i),i=setTimeout(()=>e.apply(this,s),t)}}saveCustomerData(e,t){var o;const i=this.checkoutHandler.prepareFormData(),s=((o=window.fluentCartUtmManager)==null?void 0:o.get())||{};Object.keys(s).forEach(a=>{t&&i.append(`utm_data[${a}]`,s[a])});const n=new URLSearchParams;for(const[a,d]of i.entries())n.append(a,d);const r=v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_checkout_routes`),l=te.appendQueryParams(r.toString(),{fc_checkout_action:"save_checkout_data",data_key:e,data_value:t});fetch(l,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":h(this,we)},credentials:"include",body:n}).then(a=>a.json()).then(a=>{a!=null&&a.fragments&&v.handleFragments(a.fragments),(a!=null&&a.shipping_charge_changes||a!=null&&a.tax_total_Changes)&&this.checkoutHandler.handleCheckoutAmountChanges()})}};we=new WeakMap,p(B,"instance",null);let Ae=B;const V=class V{constructor(e,t){p(this,"countries",[]);p(this,"states",{});p(this,"shippingToDifferent",!1);p(this,"billingCountry",null);p(this,"shippingCountry",null);p(this,"loadingShippingInfo",!1);p(this,"countryCode","");p(this,"state","");p(this,"billingState","");p(this,"shippingState","");p(this,"formWrapper");p(this,"shippingContainer");p(this,"checkoutHandler",null);p(this,"currentShippingMethodId",null);p(this,"translate",window.fluentcart.$t);this.formWrapper=e,this.checkoutHandler=t,this.shippingContainer=this.formWrapper.querySelector("[data-fluent-cart-checkout-page-shipping-method-wrapper]"),this.bindDelegatedListeners(),this.countryCode=window.fluent_cart_address_service.defaultCountry}static init(e,t){return V.instance===null&&(V.instance=new V(e,t)),Ie.init(this,()=>{Ae.init(this)}),window.fluent_cart_shipping_service=V.instance,V.instance}getShippingContainer(){return this.shippingContainer=this.formWrapper.querySelector("[data-fluent-cart-checkout-page-shipping-method-wrapper]"),this.shippingContainer}bindDelegatedListeners(){const e=document.getElementById("ship_to_different");e&&(this.shippingToDifferent=e.checked);const t=document.getElementById("billing_address");t&&(this.billingCountry=t.dataset.country);const i=document.getElementById("shipping_address");i&&(this.shippingCountry=i.dataset.country),this.formWrapper.addEventListener("change",s=>{if(s.target.id==="ship_to_different"){this.handleShipToDifferentChange(s.target.checked);return}if(s.target.id==="billing_address"){this.countryCode=s.target.dataset.country,this.state=s.target.dataset.state,this.fetchCountryShippingMethods();return}if(s.target.id==="billing_country"){this.billingCountry=s.target.value,this.handleCountryChange(s.target.value);return}if(s.target.id==="shipping_country"){this.shippingCountry=s.target.value,this.handleCountryChange(s.target.value);return}if(s.target.id==="shipping_address"){this.countryCode=s.target.dataset.country,this.state=s.target.dataset.state,this.fetchCountryShippingMethods();return}if(s.target.matches('select[name="shipping_state"]')){this.shippingState=s.target.value,this.handleStateChange();return}if(s.target.matches('select[name="billing_state"]')){this.billingState=s.target.value,this.handleStateChange();return}if(s.target.matches('input[name="fc_shipping_method"]')){this.handleShippingMethodChange(s.target.value);return}})}bindShipToDifferentListener(){const e=document.getElementById("ship_to_different");if(e){this.shippingToDifferent=e.checked;const t=this;e.addEventListener("change",function(){t.handleShipToDifferentChange.bind(t)(this.checked)})}}handleShipToDifferentChange(e){this.shippingToDifferent=e;const t=document.getElementById("shipping_address");if(t&&t.dataset.country&&this.shippingToDifferent)this.countryCode=t.dataset.country,this.state=t.dataset.state,this.fetchCountryShippingMethods();else{let i="",s="";this.shippingToDifferent?(this.formWrapper.querySelector("#shipping_country")&&(i=this.formWrapper.querySelector("#shipping_country").value),this.formWrapper.querySelector("#shipping_state")&&(s=this.formWrapper.querySelector("#shipping_state").value)):(this.formWrapper.querySelector("#billing_country")&&(i=this.formWrapper.querySelector("#billing_country").value),this.formWrapper.querySelector("#billing_state")&&(s=this.formWrapper.querySelector("#billing_state").value)),this.countryCode=i,this.state=s,this.fetchCountryShippingMethods()}}bindBillingCountryListener(){const e=document.getElementById("billing_address");if(e){const i=this;this.billingCountry=e.dataset.country,e.addEventListener("change",function(){const s=this.dataset.country;i.handleBillingAddressChange.bind(i)(s)});return}const t=document.getElementById("billing_country");t&&(this.billingCountry=t.value,t.addEventListener("change",function(){}))}bindShippingCountryListener(){const e=document.getElementById("shipping_address");if(e){const i=this;this.shippingCountry=e.dataset.country,e.addEventListener("change",function(){const s=this.dataset.country;i.handleShippingAddressChange.bind(i)(s)});return}const t=document.getElementById("shipping_country");t&&(this.shippingCountry=t.value,t.addEventListener("change",function(){}))}handleBillingAddressChange(e){this.billingCountry=e,this.shippingToDifferent||(this.shippingCountry=e)}handleCountryChange(){this.shippingToDifferent?this.countryCode=this.shippingCountry:this.countryCode=this.billingCountry}handleShippingAddressChange(e){this.shippingToDifferent?this.shippingCountry=e:this.shippingCountry=this.billingCountry}handleStateChange(){this.shippingToDifferent?this.state=this.shippingState:this.state=this.billingState,this.fetchCountryShippingMethods()}fetchCountryShippingMethods(){}updateShippingMethodsView(e){var i;if(e.status===!1){if(e.fragments){v.handleFragments(e.fragments);return}this.shippingContainer.innerHTML=e.view||`<div class="fct-empty-text">${e.message}</div>`;return}this.getShippingContainer()&&(this.getShippingContainer().innerHTML=e.view),(i=this.checkoutHandler)==null||i.buttons.removeAttribute("disabled");let t="";this.getShippingContainer()&&(t=this.getShippingContainer().querySelectorAll('input[name="fc_shipping_method"]')),t.length>0&&this.selectDefaultShippingMethod(t)}bindShippingMethodChangeListener(){this.currentShippingMethodId=null,this.setShippingMethodIdToForm();const e=this.shippingContainer.querySelectorAll('input[name="fc_shipping_method"]');e.length>0&&this.selectDefaultShippingMethod(e)}selectDefaultShippingMethod(e){e[0].checked=!0,setTimeout(()=>{this.handleShippingMethodChange(e[0].value)},0)}setShippingMethodIdToForm(){const e=this.getShippingContainer().querySelector('input[name="fc_selected_shipping_method"]');e&&(e.value=this.currentShippingMethodId)}handleShippingMethodChange(e){}};p(V,"instance",null);let Ye=V;const D=class D{constructor(e){p(this,"formWrapper",null);p(this,"states",{loading:"loading",enable:"enable",disable:"disable",loadingAndDisabled:"loadingAndDisabled"});p(this,"viewsStates",{});p(this,"views",{billingCountry:null,billingState:null,billingStateSelect:null,shippingCountry:null,shippingState:null,shippingStateSelect:null,checkoutButton:null,shippingMethodsWrapper:null});this.formWrapper=e.form,this.initViews()}static init(e){return D.instance===null&&(D.instance=new D(e),window.dispatchEvent(new CustomEvent("checkout_ui_service_initialized",{detail:{service:D.instance}}))),window.fluent_cart_checkout_ui_service=D.instance,D.instance}initViews(){this.views.billingCountry=this.formWrapper.querySelector("#billing_country"),this.views.billingState=this.formWrapper.querySelector("#billing_state"),this.views.billingState&&(this.views.billingStateSelect=this.views.billingState.closest("#billing_state_wrapper")),this.views.shippingCountry=this.formWrapper.querySelector("#shipping_country"),this.views.shippingState=this.formWrapper.querySelector("#shipping_state"),this.views.shippingState&&(this.views.shippingStateSelect=this.views.shippingState.closest("#shipping_state_wrapper")),this.views.shippingMethodsWrapper=this.formWrapper.querySelector("[data-fluent-cart-checkout-page-shipping-methods-wrapper]"),this.views.checkoutButton=this.formWrapper.querySelector("#fluent_cart_order_btn")}setCheckoutButtonText(e){this.views.checkoutButton&&(this.views.checkoutButton.innerHTML=e)}enableCheckoutButton(){this.initViews(),this.setComponentState("checkoutButton",this.states.enable)}disableCheckoutButton(){this.initViews(),this.setComponentState("checkoutButton",this.states.disable)}hideCheckoutButton(){this.initViews(),this.hideComponent("checkoutButton")}showCheckoutButton(){this.initViews(),this.showComponent("checkoutButton")}isCheckoutButtonDisabled(){return this.viewsStates.hasOwnProperty("checkoutButton")?this.viewsStates.checkoutButton!==this.states.enable:!1}setComponentState(e,t){this.views[e]&&(t===this.states.enable&&(this.views[e].removeAttribute("disabled"),this.views[e].dataset.loading=""),t===this.states.disable&&this.views[e].setAttribute("disabled","disabled"),t===this.states.loading&&(this.views[e].dataset.loading="loading"),t===this.states.loadingAndDisabled&&(this.views[e].setAttribute("disabled","disabled"),this.views[e].dataset.loading="loading"),this.viewsStates[e]=t)}hideComponent(e){this.views[e]&&(this.views[e].style.display="none")}showComponent(e,t="block"){this.views[e]&&(this.views[e].style.display=t)}setLoading(e){this.views[e]&&(this.views[e].classList.add("fct-loading"),this.views[e].setAttribute("fct-loading","1"))}finishLoading(e){this.views[e]&&(this.views[e].classList.remove("fct-loading"),this.views[e].removeAttribute("fct-loading"))}};p(D,"instance",null);let et=D;const F=class F{constructor(e){p(this,"checkoutHandler",null);p(this,"form",null);p(this,"taxWrapper",null);p(this,"applyBtn",null);p(this,"loader",null);p(this,"taxIdInput",null);p(this,"errorWrapper",null);p(this,"taxRemoveBtn",null);p(this,"validNoteWrapper",null);p(this,"validNote",null);p(this,"translate",window.fluentcart.$t);var t,i,s,n,r,l,o;this.checkoutHandler=e,this.form=e==null?void 0:e.form,this.taxWrapper=this.form.querySelector("[data-fluent-cart-checkout-page-tax-wrapper]"),this.applyBtn=(t=this.taxWrapper)==null?void 0:t.querySelector("[data-fluent-cart-checkout-page-tax-apply-btn]"),this.loader=(i=this.taxWrapper)==null?void 0:i.querySelector("[data-fluent-cart-checkout-page-tax-loading]"),this.taxIdInput=(s=this.taxWrapper)==null?void 0:s.querySelector("[data-fluent-cart-checkout-page-tax-id]"),this.errorWrapper=(n=this.taxWrapper)==null?void 0:n.querySelector("[data-fluent-cart-checkout-page-form-error]"),this.taxRemoveBtn=(r=this.taxWrapper)==null?void 0:r.querySelector("[data-fluent-cart-tax-remove-btn]"),this.validNoteWrapper=(l=this.taxWrapper)==null?void 0:l.querySelector("[data-fluent-cart-tax-valid-note-wrapper]"),this.validNote=(o=this.taxWrapper)==null?void 0:o.querySelector("[data-fluent-cart-tax-valid-note]"),this.bindDelegatedEvents(),this.syncFromServerState(),window.addEventListener("fluentCartFragmentsReplaced",()=>{this.syncFromServerState()})}static init(e){return F.instance===null&&(F.instance=new F(e)),F.instance}syncFromServerState(){const e=this.getTaxWrapper();if(!e)return;const t=e.querySelector("[data-fluent-cart-tax-valid-note-wrapper]");!t||t.dataset.vatValid!=="true"||this.showSuccess()}getTaxWrapper(){return this.taxWrapper=this.form.querySelector("[data-fluent-cart-checkout-page-tax-wrapper]"),this.taxWrapper}getTaxElements(){const e=this.getTaxWrapper();return e?{applyBtn:e.querySelector("[data-fluent-cart-checkout-page-tax-apply-btn]"),loader:e.querySelector("[data-fluent-cart-checkout-page-tax-loading]"),taxIdInput:e.querySelector("[data-fluent-cart-checkout-page-tax-id]"),errorWrapper:e.querySelector("[data-fluent-cart-checkout-page-form-error]"),taxRemoveBtn:e.querySelector("[data-fluent-cart-tax-remove-btn]"),validNoteWrapper:e.querySelector("[data-fluent-cart-tax-valid-note-wrapper]")}:{}}bindDelegatedEvents(){this.form.addEventListener("click",e=>{if(e.target.matches("[data-fluent-cart-checkout-page-tax-apply-btn]")){e.preventDefault(),this.validateVatHandler();return}if(e.target.matches("[data-fluent-cart-tax-remove-btn]")){e.preventDefault(),this.removeVat();return}}),this.form.addEventListener("keydown",e=>{e.target.matches("[data-fluent-cart-checkout-page-tax-id]")&&e.key==="Enter"&&(e.preventDefault(),this.validateVatHandler())})}validateVatHandler(){var i,s;const e=this.getTaxElements();if(!e.applyBtn)return;const t=(s=(i=e.taxIdInput)==null?void 0:i.value)==null?void 0:s.trim();if(!t){this.clearError();return}this.validateVat(t)}async validateVat(e){var s;const t=v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_validate_vat`).toString(),i=new URLSearchParams({vat_number:e,_wpnonce:((s=window.fluentcart_checkout_info)==null?void 0:s.checkout_nonce)||""}).toString();try{this.startLoading();const n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},credentials:"include",body:i}),r=await n.json();if(!n.ok||(r==null?void 0:r.success)===!1){const o=(r==null?void 0:r.message)||(r==null?void 0:r.message)||this.translate("Invalid VAT number");return this.showError(o),!1}const l=r==null?void 0:r.tax_data;return r!=null&&r.fragments&&v.handleFragments(r.fragments),this.syncBillingCompanyName(l==null?void 0:l.name),this.clearError(),this.showSuccess(),!0}catch{return this.showError(this.translate("Validation service unavailable. Please try again.")),!1}finally{this.endLoading()}}syncBillingCompanyName(e){var i;if(!e)return;const t=(i=this.form)==null?void 0:i.querySelector("#billing_company_name");!t||t.value===e||(t.value=e)}async removeVat(){var i;if(!confirm(this.translate("Are you sure you want to remove VAT?")))return;const e=v.buildUrl(`${window.fluentcart_checkout_vars.ajaxurl}?action=fluent_cart_remove_vat`).toString(),t=new URLSearchParams({_wpnonce:((i=window.fluentcart_checkout_info)==null?void 0:i.checkout_nonce)||""}).toString();try{this.startLoading();const s=await fetch(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},credentials:"include",body:t}),n=await s.json();if(!s.ok||(n==null?void 0:n.success)===!1){this.showError((n==null?void 0:n.message)||this.translate("Failed to remove VAT"));return}this.clearError(),this.clearSuccess(),n!=null&&n.fragments&&v.handleFragments(n.fragments);const r=this.getTaxElements();r.taxIdInput&&(r.taxIdInput.value=""),window.location.reload()}catch{this.showError(this.translate("Could not remove VAT, please try again."))}finally{this.endLoading()}}showError(e){var s;const t=this.getTaxElements(),i=this.getTaxWrapper();i==null||i.classList.add("has-error"),(s=t.taxIdInput)==null||s.setAttribute("aria-invalid","true"),t.errorWrapper&&(t.errorWrapper.textContent=e||this.translate("Invalid VAT number"),t.errorWrapper.style.display="block")}clearError(){var i;const e=this.getTaxElements(),t=this.getTaxWrapper();t==null||t.classList.remove("has-error"),(i=e.taxIdInput)==null||i.removeAttribute("aria-invalid"),e.errorWrapper&&(e.errorWrapper.textContent="",e.errorWrapper.style.display=""),this.clearSuccess()}showSuccess(){const e=this.getTaxElements();this.getTaxWrapper()&&e.validNoteWrapper&&(e.validNoteWrapper.classList.remove("is-hidden"),e.validNoteWrapper.removeAttribute("aria-hidden"))}clearSuccess(){const e=this.getTaxElements();this.getTaxWrapper()&&e.validNoteWrapper&&(e.validNoteWrapper.classList.add("is-hidden"),e.validNoteWrapper.setAttribute("aria-hidden","true"))}startLoading(){var t,i;const e=this.getTaxElements();e.loader&&(e.loader.style.display="block",e.loader.textContent=this.translate("Validating...")),(e.applyBtn||e.taxIdInput)&&((t=e.taxIdInput)==null||t.setAttribute("disabled","disabled"),(i=e.applyBtn)==null||i.setAttribute("disabled","disabled")),this.clearError()}endLoading(){var t,i;const e=this.getTaxElements();e.loader&&(e.loader.style.display="none"),(e.applyBtn||e.taxIdInput)&&((t=e.taxIdInput)==null||t.removeAttribute("disabled"),(i=e.applyBtn)==null||i.removeAttribute("disabled")),e.errorWrapper&&(e.errorWrapper.style.display="block")}};p(F,"instance",null);let tt=F;class Rt{constructor(e=null){this.checkoutHandler=e,this.pendingTokenPromise=null,this.pendingResolve=null,this.inVisibleMode=!1,this.visibleModeActive=!1,this.fadeTimer=null,this.autoRetryCount=0,this.setupGlobalCallback(),this.autoRenderWidget()}setupGlobalCallback(){window.fluentCartTurnstileHandlerInstance=this,window.fluentCartTurnstileCallback=function(e){var t;(t=window.fluentCartTurnstileHandlerInstance)==null||t.handleToken(e)}}isEnabled(){var e,t;return(t=(e=window.fluentcart_checkout_vars)==null?void 0:e.turnstile)==null?void 0:t.enabled}autoRenderWidget(){if(!this.isEnabled())return;const e=document.querySelector("[data-fluent-cart-turnstile-widget] .cf-turnstile"),t=document.querySelector("[data-fluent-cart-turnstile-widget]");if(e&&!(!this.isEnabled()&&(t==null?void 0:t.getAttribute("data-turnstile-active"))!=="yes")){if(typeof turnstile>"u"){let i=0;const s=setInterval(()=>{i++,typeof turnstile<"u"?(clearInterval(s),this.renderAndExecute(e)):i>=50&&clearInterval(s)},100);return}this.renderAndExecute(e)}}renderAndExecute(e){var i,s;if(e.getAttribute("data-widget-id"))return;const t=e.getAttribute("data-sitekey")||((s=(i=window.fluentcart_checkout_vars)==null?void 0:i.turnstile)==null?void 0:s.site_key);if(t)try{const n=turnstile.render(e,{sitekey:t,execution:"render",callback:this.handleToken.bind(this),"expired-callback":this.handleExpired.bind(this),"error-callback":this.handleError.bind(this),size:"flexible",appearance:"interaction-only",theme:"auto"});n&&e.setAttribute("data-widget-id",n)}catch{}}handleExpired(){window.fluentCartTurnstileToken=null}handleError(){if(window.fluentCartTurnstileToken=null,this.autoRetryCount++,this.autoRetryCount<=2){const e=document.querySelector("[data-fluent-cart-turnstile-widget] .cf-turnstile"),t=e&&e.getAttribute("data-widget-id");if(t&&typeof turnstile<"u"){setTimeout(()=>{try{turnstile.reset(t)}catch{}},0);return}}setTimeout(()=>this.switchToVisibleMode(),0)}switchToVisibleMode(){var n,r;if(this.visibleModeActive)return;const e=document.querySelector("[data-fluent-cart-turnstile-widget]");if(!e||typeof turnstile>"u")return;const t=e.querySelector(".cf-turnstile"),i=t&&t.getAttribute("data-sitekey")||((r=(n=window.fluentcart_checkout_vars)==null?void 0:n.turnstile)==null?void 0:r.site_key);if(!i)return;if(this.inVisibleMode=!0,this.visibleModeActive=!0,t){const l=t.getAttribute("data-widget-id");try{l&&turnstile.remove(l)}catch{}t.remove()}const s=document.createElement("div");s.className="cf-turnstile",s.setAttribute("data-sitekey",i),e.appendChild(s),e.style.opacity="1",e.style.transition="";try{const l=turnstile.render(s,{sitekey:i,execution:"render",callback:this.handleToken.bind(this),"expired-callback":this.handleExpired.bind(this),"error-callback":()=>{},size:"flexible",appearance:"always",theme:"auto"});l&&s.setAttribute("data-widget-id",l)}catch{this.visibleModeActive=!1}}reset(){if(!this.isEnabled())return;if(this.fadeTimer&&(clearTimeout(this.fadeTimer),this.fadeTimer=null,this.hideAndRemoveWidget()),this.pendingResolve){const i=this.pendingResolve;this.pendingResolve=null,this.pendingTokenPromise=null,i(null)}if(this.pendingTokenPromise=null,this.pendingResolve=null,this.inVisibleMode=!1,this.visibleModeActive=!1,this.autoRetryCount=0,window.fluentCartTurnstileToken=null,typeof turnstile>"u")return;const e=document.querySelector("[data-fluent-cart-turnstile-widget] .cf-turnstile");if(!e)return;const t=e.getAttribute("data-widget-id");if(t)try{turnstile.reset(t)}catch{}}async handleCheckoutSecurityVerification(e){var i,s,n,r,l;if(!this.isEnabled())return!0;const t=await this.getToken();return t?(e.append("cf_turnstile_token",t),!0):((i=this.checkoutHandler)!=null&&i.cleanupAfterProcessing&&this.checkoutHandler.cleanupAfterProcessing(),this.inVisibleMode?new Toastify({text:((n=(s=this.checkoutHandler)==null?void 0:s.translate)==null?void 0:n.call(s,"Please complete the security verification above, then try again."))||"Please complete the security verification above, then try again.",className:"warning",duration:4e3}).showToast():(new Toastify({text:((l=(r=this.checkoutHandler)==null?void 0:r.translate)==null?void 0:l.call(r,"Security check failed. Please refresh the page and try again."))||"Security check failed. Please refresh the page and try again.",className:"warning",duration:3e3}).showToast(),this.reset()),!1)}async verifyAndAppendToken(e,t,i){if(!this.isEnabled())return!0;const s=await this.getToken();return s?(e.append("cf_turnstile_token",s),!0):(i&&i(),new Toastify({text:t("Security check failed. Please refresh the page and try again."),className:"warning",duration:3e3}).showToast(),this.reset(),!1)}async getToken(){var s,n;if(!this.isEnabled()||(typeof turnstile>"u"&&await new Promise(r=>{let l=0;const o=setInterval(()=>{l++,(typeof turnstile<"u"||l>=100)&&(clearInterval(o),r())},100)}),typeof turnstile>"u"))return null;if(window.fluentCartTurnstileToken)return window.fluentCartTurnstileToken;const e=document.querySelector("[data-fluent-cart-turnstile-widget]");if(!e)return null;let t=e.querySelector(".cf-turnstile");t||(t=document.createElement("div"),t.className="cf-turnstile",e.appendChild(t));let i=t.getAttribute("data-widget-id");if(!i){const r=t.getAttribute("data-sitekey")||((n=(s=window.fluentcart_checkout_vars)==null?void 0:s.turnstile)==null?void 0:n.site_key);if(!r)return null;try{i=turnstile.render(t,{sitekey:r,execution:"render",callback:this.handleToken.bind(this),"expired-callback":this.handleExpired.bind(this),"error-callback":this.handleError.bind(this),size:"flexible",appearance:"interaction-only",theme:"auto"}),i&&t.setAttribute("data-widget-id",i)}catch{return null}}return this.pendingTokenPromise?this.pendingTokenPromise:(this.pendingTokenPromise=new Promise(r=>{let l=0;const o=150;this.pendingResolve=r;const a=()=>{if(window.fluentCartTurnstileToken){const d=window.fluentCartTurnstileToken;this.pendingTokenPromise=null,this.pendingResolve=null,r(d);return}if(this.inVisibleMode){this.switchToVisibleMode(),this.pendingTokenPromise=null,this.pendingResolve=null,r(null);return}if(l>=o){this.pendingTokenPromise=null,this.pendingResolve=null,r(null);return}l++,setTimeout(a,100)};a()}),this.pendingTokenPromise)}resolvePendingToken(e){if(!this.pendingResolve)return;const t=this.pendingResolve;this.pendingResolve=null,this.pendingTokenPromise=null,t(e)}handleToken(e){if(!e)return;this.inVisibleMode=!1,this.visibleModeActive=!1,this.autoRetryCount=0,window.fluentCartTurnstileToken=e,this.resolvePendingToken(e);const t=document.querySelector("[data-fluent-cart-turnstile-widget]");t&&t.offsetHeight>0?this.fadeTimer=setTimeout(()=>{t.style.overflow="hidden",t.style.maxHeight=t.scrollHeight+"px",t.offsetHeight,t.style.transition="opacity 0.15s ease, max-height 0.15s ease, margin 0.15s ease",t.style.opacity="0",t.style.maxHeight="0px",t.style.marginTop="0px",t.style.marginBottom="0px",this.fadeTimer=setTimeout(()=>{this.fadeTimer=null,this.hideAndRemoveWidget()},200)},800):this.hideAndRemoveWidget()}hideAndRemoveWidget(){const e=document.querySelector("[data-fluent-cart-turnstile-widget] .cf-turnstile");if(e){if(typeof turnstile<"u"){const t=e.getAttribute("data-widget-id");try{t&&turnstile.remove(t)}catch{}}e.remove()}}}var _e,L,be,nt,$,ve,Me,Ne,Se,Ce,K,ke,Be,Ve,Ee,xe,st;const ae=class ae{constructor(e,t,i){g(this,xe);g(this,L,null);g(this,be);g(this,nt,[]);g(this,$,null);g(this,ve,null);g(this,Me);g(this,Ne);g(this,Se,null);g(this,Ce,!1);g(this,K);g(this,ke);g(this,Be,!1);g(this,Ve,!1);p(this,"checkoutUiService");p(this,"translate",window.fluentcart.$t);g(this,Ee,{".fct_error_billing_personal_information_section":["billing_full_name","billing_first_name","billing_last_name","billing_email","billing_company_name","fct_billing_tax_id"],".fct_error_billing_address_section_section":["billing_address_1","billing_address_2","billing_city","billing_postcode","billing_country","billing_state","billing_phone"],".fct_error_shipping_address_section_section":["shipping_full_name","shipping_address_1","shipping_address_2","shipping_city","shipping_postcode","shipping_country","shipping_state","shipping_phone"],".fct_error_agree_terms_section":["agree_terms"]});var s,n,r,l,o,a,d;if(W.extend(rt),W.extend(at),m(this,ve,W.tz.guess()),h(ae,_e)!==null)return h(ae,_e);this.form=t,this.settings=i,m(this,Me,window.fluentCartRestVars.rest.url),this.checkoutInfo=window.fluentcart_checkout_info,m(this,Be,((s=window.fluentcart_checkout_info)==null?void 0:s.is_zero_payment)==="yes"),m(this,Ve,((n=window.fluentcart_checkout_info)==null?void 0:n.has_subscription)=="yes"),this.nonce=(r=this.checkoutInfo)==null?void 0:r.rest.nonce,this.checkoutUrl=(l=this.checkoutInfo)==null?void 0:l.order_confirmation_url,this.checkoutUrl=v.buildUrl(this.checkoutUrl),m(this,Ne,(o=window.fluentcart_checkout_vars)==null?void 0:o.submit_button),m(this,Se,this.form.querySelector("[data-fluent-cart-ship-to-different-address]")),m(this,K,this.form.querySelector("[data-fluent-cart-checkout-order-notes-toggle]")),m(this,ke,this.form.querySelector("[data-fluent-cart-checkout-order-notes-wrapper]")),this.isAllDigital=((a=window.fluentcart_checkout_vars)==null?void 0:a.is_all_digital.toString())==="1",this.buttons=this.form.querySelector("[data-fluent-cart-checkout-page-checkout-button]"),this.checkoutUiService=et.init(this),m(this,L,new Pt({form:this.form,orderHandler:this.handleOrder.bind(this),checkoutHandler:this})),m(this,$,new Rt(this)),new ze(this).init(),new Ht(this.form).init(),Ie.init(this,()=>{setTimeout(()=>{Ae.init(this),this.isAllDigital||Ye.init(this.form,this)},1e3)}),this.form.querySelector("[data-fluent-cart-checkout-page-tax-wrapper]")&&tt.init(this),this.init(),this.handleShippingForm(t),this.loadPaymentEmbedModules(),this.formatErrorFields(),this.handleCartItemsCollapse(),this.handleCouponItemsCollapse(),this.isCartLocked=((d=window.fluentcart_checkout_vars)==null?void 0:d.is_cart_locked.toString())==="yes",this.setDefaultCountry(),this.setupDeleteCartItemHandler(),this.handleCountryChange(),this.handlePhoneInput(),this.handleOrderNotesToggle()}handleCountryChange(){var e;(e=h(this,Se))==null||e.addEventListener("change",t=>{m(this,Ce,t.target.checked)})}async setDefaultCountry(){}handleCheckoutAmountChanges(){}async load(){try{const e=await this.loadCartItems();return e&&m(this,be,e),h(this,be)}catch{}}async loadCartItems(){try{return await h(this,xe,st).getCart()}catch(e){throw e}}setupDeleteCartItemHandler(){const e=this;document.addEventListener("click",async t=>{if(t.target.matches("[data-fluent-cart-checkout-item-remove-button]")){const s=t.target.dataset.fluentCartCheckoutItemId;try{await h(e,xe,st).removeProduct(s);const n=await e.load();(!n||Object.keys(n).length===0)&&location.reload()}catch{}}})}formatErrorFields(){document.querySelectorAll("[data-fluent-cart-checkout-page-form-section]").forEach(t=>{t.querySelectorAll("[data-fluent-cart-checkout-page-form-error]").forEach(s=>{const n=s.cloneNode(!0);s.remove(),t.appendChild(n)})})}init(){this.bindErrorCleanupListeners(),this.form.addEventListener("submit",e=>{e.preventDefault(),e.detail===void 0&&this.handleOrder(e)}),this.buttons&&this.buttons.addEventListener("click",e=>{e.preventDefault(),this.form.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0}))})}loadPaymentEmbedModules(){h(this,L).load()}handleShippingForm(e){this.disableRequiredShipping();const t=this,i=e.querySelector("[data-fluent-cart-ship-to-different-address]"),s=e.querySelector("[data-fluent-cart-checkout-page-shipping-fields]");i!=null&&i.checked&&(m(this,Ce,!0),s.style.display="block",s.querySelectorAll('input[data-required="disabled"]').forEach(r=>{r.dataset.required="yes",r.required=!0})),i&&i.addEventListener("change",function(n){const r=e.querySelector("[data-fluent-cart-checkout-page-shipping-fields]");this.checked?(r.style.display="block",r.querySelectorAll('input[data-required="disabled"]').forEach(o=>{o.dataset.required="yes",o.required=!0})):t.disableRequiredShipping()})}disableRequiredShipping(){const e=this.form.querySelector("[data-fluent-cart-checkout-page-shipping-fields]");e&&(e.style.display="none",e.querySelectorAll('input[data-required="yes"]').forEach(i=>{i.dataset.required="disabled",i.required=!1}))}buttonState(e,t,i="disabled"){i==="disabled"?h(this,L).disableCheckoutButton(t):i==="hide"?h(this,L).hideCheckoutButton():h(this,L).enableCheckoutButton(t),this.form.classList.add("fluent_cart_"+e)}async handleOrder(e){var o,a;if(this.checkoutUiService.isCheckoutButtonDisabled())return;document.querySelectorAll(".fct-error-message").forEach(d=>d.remove()),this.payMethod=h(this,L).payMethod;const i=window["is_"+this.payMethod+"_ready"];if(this.payMethod!=="offline_payment"&&!i)return window.dispatchEvent(new CustomEvent("fluent_cart_validate_checkout_"+this.payMethod)),!1;h(this,L).disableCheckoutButton(this.translate("Processing Order..."));const s='<div class="fct-loader-spinner"></div>';let n=document.querySelector(".fct-order-processing");n?n.classList.remove("fct-loader-hidden"):(n=this.createProcessingDiv(s),document.body.appendChild(n)),this.removeValidationErrors();const r=(o=window.fluentCartCheckout)==null?void 0:o.beforeCheckoutCallbacks;let l=!0;if(Array.isArray(r)){for(let d of r)if(typeof d=="function"){let w=await d({paymentLoader:h(this,L)});l=l&&w}}if(l===!1){this.cleanupAfterProcessing();return}try{const d=this.prepareFormData();if(!await h(this,$).handleCheckoutSecurityVerification(d))return!1;this.removeValidationErrors();const u=await(await this.submitCheckoutForm(d)).json();if(h(this,$)&&h(this,$).reset(),u.status==="success")return(a=window.fluentCartUtmManager)==null||a.clear(),this.handleSuccessfulResponse(u),u;{if(u!=null&&u.errors&&typeof(u==null?void 0:u.errors)=="object"){let C="";for(const q in u.errors){this.handleErrorMessage(u.errors,q);const k=u.errors[q],x=Object.values(k)[0];C+=x+`
18 -`}return new Toastify({text:C,className:"warning",duration:1500}).showToast(),this.cleanupAfterProcessing(),!1}this.showValidationErrors(u==null?void 0:u.errors);let b=(u==null?void 0:u.message)||(u==null?void 0:u.message);return b&&this.showProductValidationError(b),this.cleanupAfterProcessing(),!1}}catch{return this.cleanupAfterProcessing(),!1}}handleErrorMessage(e,t){document.querySelectorAll("[data-fct-checkout-form-section]").forEach(s=>{Object.entries(h(this,Ee)).forEach(([n,r])=>{const l=s.querySelector(n);if(!l)return;const o=this.getFieldsPriorityBaseErrors(e,r);Array.isArray(o)&&o.length?(l.classList.add("show_error"),l.innerHTML=o.map(a=>`<span data-fct-error-field="${a.field}">${a.message}</span>`).join("")):(l.classList.remove("show_error"),l.innerHTML="")})})}getFieldsPriorityBaseErrors(e,t){const i=[];return t.forEach(s=>{const n=e[s];if(n){if(n.required){i.push({field:s,message:n.required});return}Object.entries(n).forEach(([r,l])=>{r!=="required"&&i.push({field:s,message:l})})}}),i}clearFieldError(e){Object.entries(h(this,Ee)).forEach(([t,i])=>{if(!i.includes(e))return;const s=document.querySelector(t);if(!s)return;const n=s.querySelector(`[data-fct-error-field="${e}"]`);n&&(n.classList.add("fct-error-leave"),n.addEventListener("transitionend",()=>{n.remove(),s.querySelector("span")||s.classList.remove("show_error")},{once:!0}))})}bindErrorCleanupListeners(){const e=t=>{var s;const i=t.target;i.name&&(s=i.value)!=null&&s.trim()&&this.clearFieldError(i.name)};document.addEventListener("input",e),document.addEventListener("change",e)}createProcessingDiv(e){const t=document.createElement("div");return t.className="fct-order-processing",t.innerHTML=e+"<br/><div class='loading-status'>"+this.translate("Order Processing...")+"</div><div class='fct-browser-notify'>"+this.translate("Please Don't close the browser")+"</div>",t}prepareFormData(){const e=new FormData(this.form);e.append("_wpnonce",this.nonce);const t=window.fluentCartUtmManager.get();return Object.keys(t).forEach(i=>{const s=t[i];s&&e.append(`utm_data[${i}]`,s)}),e}async submitCheckoutForm(e){e.append("user_tz",h(this,ve));const t=new URLSearchParams,i=new Set;for(const[n,r]of e.entries())i.has(n)||(t.append(n,r),i.add(n));let s=this.checkoutUrl.toString();return await fetch(s,{method:"POST",headers:{"X-WP-Nonce":window.fluentCartCheckout.nonce,"Content-Type":"application/x-www-form-urlencoded"},body:t})}async handleSuccessfulResponse(e){var s,n,r;const t=(s=window.fluentCartCheckout)==null?void 0:s.afterCheckoutCallbacks;if(Array.isArray(t))for(let l of t)typeof l=="function"&&await l(e);!new URLSearchParams(window.location.search).has("fct_cart_hash")&&window.fluentCartCart&&window.fluentCartCart.broadcastCartCleared(),e!=null&&e.redirect_to&&(this.buttonState("order_processing",this.translate("Please wait..."),e==null?void 0:e.buttonState),window.self!==window.top?window.top.location.href=e.redirect_to:window.location.href=e.redirect_to),(e==null?void 0:e.actionName)==="custom"?window.dispatchEvent(new CustomEvent("fluent_cart_payment_next_action_"+(e==null?void 0:e.nextAction),{detail:{response:e}})):(e==null?void 0:e.actionName)==="redirect"&&(window.self!==window.top?window.top.location.href=(n=e==null?void 0:e.payment_args)==null?void 0:n.checkout_url:window.location.href=(r=e==null?void 0:e.payment_args)==null?void 0:r.checkout_url)}cleanupAfterProcessing(){const e=document.querySelector(".fct-order-processing");e&&e.classList.add("fct-loader-hidden"),h(this,L).enableCheckoutButton(this.translate("Place Order"))}removeValidationErrors(){document.querySelectorAll("[data-fluent-cart-checkout-page-form-input-wrapper]").forEach(e=>{e.classList.remove("has-error")}),document.querySelectorAll("[data-fluent-cart-checkout-page-form-error]").forEach(e=>{e.innerHTML=""}),document.querySelectorAll("[data-fluent-cart-checkout-page-form-section]").forEach(e=>{e.classList.remove("has-error")})}showProductValidationError(e=this.translate("Error! Please update cart items!")){new Toastify({text:'<span class="warn warning"></span>'+e,className:"warning",escapeMarkup:!1,duration:3e3,close:!0,style:{color:"#000",background:"#ffffff"}}).showToast()}showValidationErrors(e){if(!(!e||Object.keys(e).length<1))for(const t in e){const i=document.querySelectorAll("[data-fluent-cart-checkout-page-form-section]"),s=this.form.querySelector("#"+t);if(s){s.closest("[data-fluent-cart-checkout-page-form-input-wrapper]")&&s.closest("[data-fluent-cart-checkout-page-form-input-wrapper]").classList.add("has-error"),i.forEach(r=>r.classList.add("has-error"));const n=e[t];if(typeof n=="object"){let r="",l=0;const o=Object.entries(n).length;for(const d in n){r+=n[d],l!==o&&(r+="<br>"),l++;break}new Toastify({text:r,className:"warning",escapeMarkup:!1,duration:1500,style:{color:"#000",background:"#ffffff"}}).showToast(),t==="order_notes"&&new Toastify({text:'<span class="warn error"></span>'+r,className:"error",escapeMarkup:!1,duration:1500,style:{color:"#000",background:"#ffffff"}}).showToast();const a=`[data-fluent-cart-checkout-page-form-error][for="${s.name}"]`;document.querySelector(a).innerHTML=r,document.querySelector(a).classList.add("show_error")}}else if(t==="shipping_method"){const n=document.querySelector("[data-fluent-cart-checkout-page-shipping-methods-wrapper]");n&&(n.classList.add("has-error"),n.querySelector("[data-fluent-cart-checkout-page-form-error]").innerHTML=e[t])}else new Toastify({text:'<span class="warn warning"></span>'+this.translate("Validation Error! Please fill required fields!"),className:"warning",escapeMarkup:!1,duration:1300,style:{color:"#000",background:"#ffffff"}}).showToast()}}handleCartItemsCollapse(){this.form.addEventListener("click",e=>{e.target.closest("[data-fluent-cart-checkout-cart-items-toggle]")&&this.form.querySelector("[data-fluent-cart-checkout-page-cart-items-wrapper]").classList.toggle("box_closed")})}handleCouponItemsCollapse(){const e=document.querySelector("[data-fluent-cart-checkout-coupon-items-toggle]"),t=document.querySelector("[data-fluent-cart-checkout-coupon-items-wrapper]");e&&t&&e.addEventListener("click",()=>{e.classList.toggle("active"),t.style.display=t.style.display==="none"?"block":"none"})}handlePhoneInput(){const e=document.querySelector("[data-fluent-cart-checkout-page-form-input-wrapper][id='billing_phone_wrapper'] input"),t=document.querySelector("[data-fluent-cart-checkout-page-form-input-wrapper][id='shipping_phone_wrapper'] input"),i=s=>{s&&s.value.length>15&&(s.value=s.value.substring(0,15))};e&&(e.addEventListener("input",()=>i(e)),e.addEventListener("paste",()=>{setTimeout(()=>i(e),0)})),t&&(t.addEventListener("input",()=>i(t)),t.addEventListener("paste",()=>{setTimeout(()=>i(t),0)}))}handleOrderNotesToggle(){this.form.querySelectorAll("[data-fct-item-toggle-control]").forEach(t=>{t.addEventListener("click",()=>{const i=t.closest("[data-fct-item-toggle]");i&&i.classList.toggle("active")})}),h(this,K)&&h(this,K).addEventListener("click",()=>{h(this,K).classList.toggle("active"),h(this,ke).classList.toggle("active")})}};_e=new WeakMap,L=new WeakMap,be=new WeakMap,nt=new WeakMap,$=new WeakMap,ve=new WeakMap,Me=new WeakMap,Ne=new WeakMap,Se=new WeakMap,Ce=new WeakMap,K=new WeakMap,ke=new WeakMap,Be=new WeakMap,Ve=new WeakMap,Ee=new WeakMap,xe=new WeakSet,st=function(){return window.fluentCartCart},g(ae,_e,null);let it=ae;window.CheckoutHelper=v;let jt={checkoutPageContainer:null,init(){if(this.checkoutPageContainer=document.querySelector("[data-fluent-cart-checkout-page]"),!this.checkoutPageContainer)return;let c=this.checkoutPageContainer.querySelector("form[data-fluent-cart-checkout-page-checkout-form]");return new it(this,c,{})}};window.addEventListener("load",function(){var i;const c=document.querySelector("[data-fluent-cart-checkout-item-wrapper]");document.querySelector("[data-fluent-cart-checkout-subtotal]"),document.querySelectorAll("[data-fluent-cart-checkout-estimated-total]");let e=window.fluentcart_checkout_vars.ajaxurl+"?action=fluent_cart_checkout_routes&fc_checkout_action=get_checkout_summary_view";c&&window.addEventListener("fluentCartNotifyCartDrawerItemChanged",function(){fetch(v.buildUrl(e).toString(),{headers:{"X-WP-Nonce":window.fluentCartRestVars.rest.nonce},credentials:"include"}).then(s=>s.json()).then(s=>{s.fragments&&v.handleFragments(s.fragments),window.dispatchEvent(new CustomEvent("fluentCartCheckoutDataChanged",{detail:{response:s}}))}).catch(s=>{})},!1),window.fluentCartCheckout=jt.init(),window.fluentCartCheckout&&(window.fluentCartCheckout.beforeCheckoutCallbacks=[],window.fluentCartCheckout.afterCheckoutCallbacks=[]);const t=(i=window.fluentcart_checkout_vars)==null?void 0:i.notices;Array.isArray(t)&&t.length>0&&t.forEach(s=>{const n=document.createElement("span"),r=document.createElement("span");r.className="warn warning";const l=document.createElement("span");l.textContent=s,n.appendChild(r),n.appendChild(l),new Toastify({node:n,className:"warning",duration:6e3,close:!1,style:{color:"#000",background:"#ffffff"}}).showToast()}),setTimeout(()=>{window.dispatchEvent(new CustomEvent("fluent_cart_after_checkout_js_loaded",{}))},500)})});export default Ft();
18 +`}return new Toastify({text:C,className:"warning",duration:1500}).showToast(),this.cleanupAfterProcessing(),!1}this.showValidationErrors(u==null?void 0:u.errors);let b=(u==null?void 0:u.message)||(u==null?void 0:u.message);return b&&this.showProductValidationError(b),this.cleanupAfterProcessing(),!1}}catch{return this.cleanupAfterProcessing(),!1}}handleErrorMessage(e,t){document.querySelectorAll("[data-fct-checkout-form-section]").forEach(s=>{Object.entries(h(this,Ee)).forEach(([n,r])=>{const l=s.querySelector(n);if(!l)return;const o=this.getFieldsPriorityBaseErrors(e,r);Array.isArray(o)&&o.length?(l.classList.add("show_error"),l.innerHTML=o.map(a=>`<span data-fct-error-field="${a.field}">${a.message}</span>`).join("")):(l.classList.remove("show_error"),l.innerHTML="")})})}getFieldsPriorityBaseErrors(e,t){const i=[];return t.forEach(s=>{const n=e[s];if(n){if(n.required){i.push({field:s,message:n.required});return}Object.entries(n).forEach(([r,l])=>{r!=="required"&&i.push({field:s,message:l})})}}),i}clearFieldError(e){Object.entries(h(this,Ee)).forEach(([t,i])=>{if(!i.includes(e))return;const s=document.querySelector(t);if(!s)return;const n=s.querySelector(`[data-fct-error-field="${e}"]`);n&&(n.classList.add("fct-error-leave"),n.addEventListener("transitionend",()=>{n.remove(),s.querySelector("span")||s.classList.remove("show_error")},{once:!0}))})}bindErrorCleanupListeners(){const e=t=>{var s;const i=t.target;i.name&&(s=i.value)!=null&&s.trim()&&this.clearFieldError(i.name)};document.addEventListener("input",e),document.addEventListener("change",e)}createProcessingDiv(e){const t=document.createElement("div");return t.className="fct-order-processing",t.innerHTML=e+"<br/><div class='loading-status'>"+this.translate("Order Processing...")+"</div><div class='fct-browser-notify'>"+this.translate("Please Don't close the browser")+"</div>",t}prepareFormData(){var i;const e=new FormData(this.form);e.append("_wpnonce",this.nonce);const t=((i=window.fluentCartUtmManager)==null?void 0:i.get())||{};return Object.keys(t).forEach(s=>{const n=t[s];n&&e.append(`utm_data[${s}]`,n)}),e}async submitCheckoutForm(e){e.append("user_tz",h(this,ve));const t=new URLSearchParams,i=new Set;for(const[n,r]of e.entries())i.has(n)||(t.append(n,r),i.add(n));let s=this.checkoutUrl.toString();return await fetch(s,{method:"POST",headers:{"X-WP-Nonce":window.fluentCartCheckout.nonce,"Content-Type":"application/x-www-form-urlencoded"},body:t})}async handleSuccessfulResponse(e){var s,n,r;const t=(s=window.fluentCartCheckout)==null?void 0:s.afterCheckoutCallbacks;if(Array.isArray(t))for(let l of t)typeof l=="function"&&await l(e);!new URLSearchParams(window.location.search).has("fct_cart_hash")&&window.fluentCartCart&&window.fluentCartCart.broadcastCartCleared(),e!=null&&e.redirect_to&&(this.buttonState("order_processing",this.translate("Please wait..."),e==null?void 0:e.buttonState),window.self!==window.top?window.top.location.href=e.redirect_to:window.location.href=e.redirect_to),(e==null?void 0:e.actionName)==="custom"?window.dispatchEvent(new CustomEvent("fluent_cart_payment_next_action_"+(e==null?void 0:e.nextAction),{detail:{response:e}})):(e==null?void 0:e.actionName)==="redirect"&&(window.self!==window.top?window.top.location.href=(n=e==null?void 0:e.payment_args)==null?void 0:n.checkout_url:window.location.href=(r=e==null?void 0:e.payment_args)==null?void 0:r.checkout_url)}cleanupAfterProcessing(){const e=document.querySelector(".fct-order-processing");e&&e.classList.add("fct-loader-hidden"),h(this,L).enableCheckoutButton(this.translate("Place Order"))}removeValidationErrors(){document.querySelectorAll("[data-fluent-cart-checkout-page-form-input-wrapper]").forEach(e=>{e.classList.remove("has-error")}),document.querySelectorAll("[data-fluent-cart-checkout-page-form-error]").forEach(e=>{e.innerHTML=""}),document.querySelectorAll("[data-fluent-cart-checkout-page-form-section]").forEach(e=>{e.classList.remove("has-error")})}showProductValidationError(e=this.translate("Error! Please update cart items!")){new Toastify({text:'<span class="warn warning"></span>'+e,className:"warning",escapeMarkup:!1,duration:3e3,close:!0,style:{color:"#000",background:"#ffffff"}}).showToast()}showValidationErrors(e){if(!(!e||Object.keys(e).length<1))for(const t in e){const i=document.querySelectorAll("[data-fluent-cart-checkout-page-form-section]"),s=this.form.querySelector("#"+t);if(s){s.closest("[data-fluent-cart-checkout-page-form-input-wrapper]")&&s.closest("[data-fluent-cart-checkout-page-form-input-wrapper]").classList.add("has-error"),i.forEach(r=>r.classList.add("has-error"));const n=e[t];if(typeof n=="object"){let r="",l=0;const o=Object.entries(n).length;for(const d in n){r+=n[d],l!==o&&(r+="<br>"),l++;break}new Toastify({text:r,className:"warning",escapeMarkup:!1,duration:1500,style:{color:"#000",background:"#ffffff"}}).showToast(),t==="order_notes"&&new Toastify({text:'<span class="warn error"></span>'+r,className:"error",escapeMarkup:!1,duration:1500,style:{color:"#000",background:"#ffffff"}}).showToast();const a=`[data-fluent-cart-checkout-page-form-error][for="${s.name}"]`;document.querySelector(a).innerHTML=r,document.querySelector(a).classList.add("show_error")}}else if(t==="shipping_method"){const n=document.querySelector("[data-fluent-cart-checkout-page-shipping-methods-wrapper]");n&&(n.classList.add("has-error"),n.querySelector("[data-fluent-cart-checkout-page-form-error]").innerHTML=e[t])}else new Toastify({text:'<span class="warn warning"></span>'+this.translate("Validation Error! Please fill required fields!"),className:"warning",escapeMarkup:!1,duration:1300,style:{color:"#000",background:"#ffffff"}}).showToast()}}handleCartItemsCollapse(){this.form.addEventListener("click",e=>{e.target.closest("[data-fluent-cart-checkout-cart-items-toggle]")&&this.form.querySelector("[data-fluent-cart-checkout-page-cart-items-wrapper]").classList.toggle("box_closed")})}handleCouponItemsCollapse(){const e=document.querySelector("[data-fluent-cart-checkout-coupon-items-toggle]"),t=document.querySelector("[data-fluent-cart-checkout-coupon-items-wrapper]");e&&t&&e.addEventListener("click",()=>{e.classList.toggle("active"),t.style.display=t.style.display==="none"?"block":"none"})}handlePhoneInput(){const e=document.querySelector("[data-fluent-cart-checkout-page-form-input-wrapper][id='billing_phone_wrapper'] input"),t=document.querySelector("[data-fluent-cart-checkout-page-form-input-wrapper][id='shipping_phone_wrapper'] input"),i=s=>{s&&s.value.length>15&&(s.value=s.value.substring(0,15))};e&&(e.addEventListener("input",()=>i(e)),e.addEventListener("paste",()=>{setTimeout(()=>i(e),0)})),t&&(t.addEventListener("input",()=>i(t)),t.addEventListener("paste",()=>{setTimeout(()=>i(t),0)}))}handleOrderNotesToggle(){this.form.querySelectorAll("[data-fct-item-toggle-control]").forEach(t=>{t.addEventListener("click",()=>{const i=t.closest("[data-fct-item-toggle]");i&&i.classList.toggle("active")})}),h(this,K)&&h(this,K).addEventListener("click",()=>{h(this,K).classList.toggle("active"),h(this,ke).classList.toggle("active")})}};_e=new WeakMap,L=new WeakMap,be=new WeakMap,nt=new WeakMap,$=new WeakMap,ve=new WeakMap,Me=new WeakMap,Ne=new WeakMap,Se=new WeakMap,Ce=new WeakMap,K=new WeakMap,ke=new WeakMap,Be=new WeakMap,Ve=new WeakMap,Ee=new WeakMap,xe=new WeakSet,st=function(){return window.fluentCartCart},g(ae,_e,null);let it=ae;window.CheckoutHelper=v;let jt={checkoutPageContainer:null,init(){if(this.checkoutPageContainer=document.querySelector("[data-fluent-cart-checkout-page]"),!this.checkoutPageContainer)return;let c=this.checkoutPageContainer.querySelector("form[data-fluent-cart-checkout-page-checkout-form]");return new it(this,c,{})}};window.addEventListener("load",function(){var i;const c=document.querySelector("[data-fluent-cart-checkout-item-wrapper]");document.querySelector("[data-fluent-cart-checkout-subtotal]"),document.querySelectorAll("[data-fluent-cart-checkout-estimated-total]");let e=window.fluentcart_checkout_vars.ajaxurl+"?action=fluent_cart_checkout_routes&fc_checkout_action=get_checkout_summary_view";c&&window.addEventListener("fluentCartNotifyCartDrawerItemChanged",function(){fetch(v.buildUrl(e).toString(),{headers:{"X-WP-Nonce":window.fluentCartRestVars.rest.nonce},credentials:"include"}).then(s=>s.json()).then(s=>{s.fragments&&v.handleFragments(s.fragments),window.dispatchEvent(new CustomEvent("fluentCartCheckoutDataChanged",{detail:{response:s}}))}).catch(s=>{})},!1),window.fluentCartCheckout=jt.init(),window.fluentCartCheckout&&(window.fluentCartCheckout.beforeCheckoutCallbacks=[],window.fluentCartCheckout.afterCheckoutCallbacks=[]);const t=(i=window.fluentcart_checkout_vars)==null?void 0:i.notices;Array.isArray(t)&&t.length>0&&t.forEach(s=>{const n=document.createElement("span"),r=document.createElement("span");r.className="warn warning";const l=document.createElement("span");l.textContent=s,n.appendChild(r),n.appendChild(l),new Toastify({node:n,className:"warning",duration:6e3,close:!1,style:{color:"#000",background:"#ffffff"}}).showToast()}),setTimeout(()=>{window.dispatchEvent(new CustomEvent("fluent_cart_after_checkout_js_loaded",{}))},500)})});export default Ft();