`),l+=`${s.name}`,l+=`+${s.dialCode}`,d.insertAdjacentHTML("beforeend",l)}}_h(t=!1){let e=this.a.getAttribute("value"),i=this.a.value,s=e&&e.charAt(0)==="+"&&(!i||i.charAt(0)!=="+")?e:i,r=this._5(s),d=L(s),{initialCountry:l}=this.d;if(r&&!d)this._v(s);else if(l!=="auto"||t){let a=l?l.toLowerCase():"";a&&this._y(a,!0)?this._z(a):r&&d?this._z("us"):this._z()}s&&this._u(s)}_i(){this._j(),this.d.allowDropdown&&this._i2(),(this.hiddenInput||this.hiddenInputCountry)&&this.a.form&&this._i0()}_i0(){this._a14=()=>{this.hiddenInput&&(this.hiddenInput.value=this.getNumber()),this.hiddenInputCountry&&(this.hiddenInputCountry.value=this.getSelectedCountryData().iso2||"")},this.a.form?.addEventListener("submit",this._a14)}_i2(){this._a9=e=>{this.dropdownContent.classList.contains("iti__hide")?this.a.focus():e.preventDefault()};let t=this.a.closest("label");t&&t.addEventListener("click",this._a9),this._a10=()=>{this.dropdownContent.classList.contains("iti__hide")&&!this.a.disabled&&!this.a.readOnly&&this._n()},this.selectedCountry.addEventListener("click",this._a10),this._a11=e=>{this.dropdownContent.classList.contains("iti__hide")&&["ArrowUp","ArrowDown"," ","Enter"].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),this._n()),e.key==="Tab"&&this._2()},this.k.addEventListener("keydown",this._a11)}_i3(){this.d.utilsScript&&!window.intlTelInputUtils?window.intlTelInputGlobals.documentReady()?window.intlTelInputGlobals.loadUtils(this.d.utilsScript):window.addEventListener("load",()=>{window.intlTelInputGlobals.loadUtils(this.d.utilsScript)}):this.i0(),this.d.initialCountry==="auto"&&!this.s.iso2?this._i4():this.h()}_i4(){window.intlTelInputGlobals.autoCountry?this.handleAutoCountry():window.intlTelInputGlobals.startedLoadingAutoCountry||(window.intlTelInputGlobals.startedLoadingAutoCountry=!0,typeof this.d.geoIpLookup=="function"&&this.d.geoIpLookup((t="")=>{let e=t.toLowerCase();e&&this._y(e,!0)?(window.intlTelInputGlobals.autoCountry=e,setTimeout(()=>y("handleAutoCountry"))):(this._h(!0),y("rejectAutoCountryPromise"))},()=>{this._h(!0),y("rejectAutoCountryPromise")}))}_j(){let{strictMode:t,formatAsYouType:e}=this.d,i=!1;this._a12=n=>{this._v(this.a.value)&&this._8();let s=n&&n.data&&/[^+0-9]/.test(n.data),r=n&&n.inputType==="insertFromPaste"&&this.a.value;if(s||r&&!t?i=!0:/[^+0-9]/.test(this.a.value)||(i=!1),e&&!i){let d=this.a.selectionStart||0,a=this.a.value.substring(0,d).replace(/[^+0-9]/g,"").length,p=n&&n.inputType==="deleteContentForward",c=this._9(),u=U(a,c,d,p);this.a.value=c,this.a.setSelectionRange(u,u)}},this.a.addEventListener("input",this._a12),t&&(this._handleKeydownEvent=n=>{if(n.key.length===1&&!n.altKey&&!n.ctrlKey&&!n.metaKey){let s=this.a.selectionStart===0&&n.key==="+",r=/^[0-9]$/.test(n.key),d=s||r,l=this._6(),a=window.intlTelInputUtils.getCoreNumber(l,this.s.iso2),p=this.maxCoreNumberLength&&a.length>=this.maxCoreNumberLength;(!d||p)&&n.preventDefault()}},this.a.addEventListener("keydown",this._handleKeydownEvent))}_j2(t){let e=parseInt(this.a.getAttribute("maxlength")||"",10);return e&&t.length>e?t.substr(0,e):t}_trigger(t){let e=new Event(t,{bubbles:!0,cancelable:!0});this.a.dispatchEvent(e)}_n(){let{fixDropdownWidth:t,countrySearch:e}=this.d;if(t&&(this.dropdownContent.style.width=`${this.a.offsetWidth}px`),this.dropdownContent.classList.remove("iti__hide"),this.selectedCountry.setAttribute("aria-expanded","true"),this._o(),this.b&&!e)this._x(this.b,!1),this._3(this.b,!0);else{let i=this.countryList.firstElementChild;i&&(this._x(i,!1),this.countryList.scrollTop=0),e&&this.searchInput.focus()}this._p(),this.u.classList.add("iti__arrow--up"),this._trigger("open:countrydropdown")}_o(){if(this.d.dropdownContainer&&this.d.dropdownContainer.appendChild(this.dropdown),!this.d.useFullscreenPopup){let t=this.a.getBoundingClientRect(),e=document.documentElement.scrollTop,i=t.top+e,n=this.dropdownContent.offsetHeight,s=i+this.a.offsetHeight+n
e,d=!this.d.countrySearch&&!s&&r;if(P(this.dropdownContent,"iti__dropdown-content--dropup",d),this.d.dropdownContainer){let l=d?0:this.a.offsetHeight;this.dropdown.style.top=`${i+l}px`,this.dropdown.style.left=`${t.left+document.body.scrollLeft}px`,this._a4=()=>this._2(),window.addEventListener("scroll",this._a4)}}}_p(){this._a0=n=>{let s=n.target?.closest(".iti__country");s&&this._x(s,!1)},this.countryList.addEventListener("mouseover",this._a0),this._a1=n=>{let s=n.target?.closest(".iti__country");s&&this._1(s)},this.countryList.addEventListener("click",this._a1);let t=!0;this._a2=()=>{t||this._2(),t=!1},document.documentElement.addEventListener("click",this._a2);let e="",i=null;if(this._a3=n=>{["ArrowUp","ArrowDown","Enter","Escape"].includes(n.key)&&(n.preventDefault(),n.stopPropagation(),n.key==="ArrowUp"||n.key==="ArrowDown"?this._q(n.key):n.key==="Enter"?this._r():n.key==="Escape"&&this._2()),!this.d.countrySearch&&/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(n.key)&&(n.stopPropagation(),i&&clearTimeout(i),e+=n.key.toLowerCase(),this._s(e),i=setTimeout(()=>{e=""},1e3))},document.addEventListener("keydown",this._a3),this.d.countrySearch){let n=()=>{let r=this.searchInput.value.trim();r?this._p3(r):this._p3("",!0)},s=null;this._a7=()=>{s&&clearTimeout(s),s=setTimeout(()=>{n(),s=null},100)},this.searchInput.addEventListener("input",this._a7),this.searchInput.addEventListener("click",r=>r.stopPropagation())}}_p3(t,e=!1){let i=!0;this.countryList.innerHTML="";let n=I(t);for(let s=0;s1&&(e=t==="ArrowUp"?this.countryList.lastElementChild:this.countryList.firstElementChild),e){this._3(e,!1);let i=!this.d.countrySearch;this._x(e,i)}}_r(){this.c&&this._1(this.c)}_s(t){for(let e=0;ed){e&&(c+=u);let m=s-l;i.scrollTop=c-m}}_4(t){let e=this.a.value,i=`+${t}`,n;if(e.charAt(0)==="+"){let s=this._5(e);s?n=e.replace(s,i):n=i,this.a.value=n}}_5(t,e){let i="";if(t.charAt(0)==="+"){let n="";for(let s=0;s{let i=document.createElement("script");i.onload=()=>{y("handleUtils"),t&&t()},i.onerror=()=>{y("rejectUtilsScriptPromise"),e&&e()},i.className="iti-load-utils",i.async=!0,i.src=o,document.body.appendChild(i)},O=o=>!window.intlTelInputUtils&&!window.intlTelInputGlobals.startedLoadingUtilsScript?(window.intlTelInputGlobals.startedLoadingUtilsScript=!0,new Promise((t,e)=>F(o,t,e))):null;if(typeof window=="object"){let o={defaults:T,documentReady:()=>document.readyState==="complete",getCountryData:()=>C,getInstance:t=>{let e=t.getAttribute("data-intl-tel-input-id");return e?o.instances[e]:null},instances:{},loadUtils:O,version:"21.0.0"};window.intlTelInputGlobals=o}var R=(o,t)=>{let e=new b(o,t);return e._init(),o.setAttribute("data-intl-tel-input-id",e.id.toString()),window.intlTelInputGlobals.instances[e.id]=e,e},B=R;return M(z);})(); return factoryOutput.default; })); function initAmQuoteCartDrawer() { return { open: false, isLoading: false, quotecart: {}, maxItemsToDisplay: 10, showSku: true, itemsCount: 0, totalCartAmount: 0, getData (data) { if (data.quotecart) { this.quotecart = data.quotecart; this.itemsCount = data.quotecart.items && data.quotecart.items.length || 0; this.totalCartAmount = this.quotecart.summary_count; this.removedItems = []; this.setQuoteItems(); } this.isLoading = false; if (this.itemsCount > 0) { this.quoteSubmitted = false; } }, quoteItems: [], getItemCountTitle () { return hyva.strf('(%0 of %1)', this.maxItemsToDisplay, this.itemsCount) }, setQuoteItems () { this.quoteItems = this.quotecart.items && this.quotecart.items.sort((a, b) => b.item_id - a.item_id) || []; if (this.maxItemsToDisplay > 0) { this.quoteItems = this.quoteItems.slice(0, parseInt(this.maxItemsToDisplay, 10)); } }, deleteItemFromQuote (itemId) { this.isLoading = true; const formKey = hyva.getFormKey(); const postUrl = BASE_URL + 'amasty_quote/sidebar/removeItem/'; fetch(postUrl, { "headers": { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", }, "body": "form_key=" + formKey + "&item_id=" + itemId, "method": "POST", "mode": "cors", "credentials": "include" }).then(response => { if (response.redirected) { window.location.href = response.url; } else if (response.ok) { return response.json(); } else { window.dispatchMessages && window.dispatchMessages([{ type: 'warning', text: 'Could\u0020not\u0020remove\u0020item\u0020from\u0020quote.' }]); this.isLoading = false; } }).then(result => { window.dispatchMessages && window.dispatchMessages([{ type: result.success ? 'success' : 'error', text: result.success ? 'You\u0020removed\u0020the\u0020item.' : result.error_message }], result.success ? 5000 : 0) window.dispatchEvent(new CustomEvent('reload-customer-section-data')); }); }, updateItemQty(form, itemId) { if (!form.action) return; if (this.itemQty === 0) { this.deleteItemFromQuote(itemId) return; } this.isLoading = true; const action = BASE_URL + 'amasty_quote/sidebar/updateItemQty/'; const formData = new FormData(form); formData.append('form_key', hyva.getFormKey()); if (!formData.uenc) { formData.append('uenc', hyva.getUenc()); } fetch(action, { body: formData, method: 'POST', mode: "cors", credentials: "include" }).then((result) => { return result.text() }).then((content) => { hyva.replaceDomElement('#maincontent', content); }).catch((error) => { window.dispatchMessages && window.dispatchMessages([{ type: 'error', text: 'Something\u0020went\u0020wrong.\u0020Please\u0020try\u0020again.' }]); }).finally(() => { this.isLoading = false; }) }, openCartDrawer () { this.$root.showModal(); this.open = true; this.scrollLock(true); }, closeCartDrawer () { this.$root.close(); this.open = false; this.scrollLock(false); }, cartListeners: { ['@private-content-loaded.window'] (event) { this.getData(event.detail.data); }, ['@click'] (event) { if (this.onDialogBackdropClickHelper(event, this.$root)) return; this.closeCartDrawer(); }, ['@toggle-amquote.window'] (event) { this.toggleAmCartDrawer(event); }, ['@keydown.window.escape'] () { this.closeCartDrawer(); } }, toggleAmCartDrawer (event) { if (event.detail.isOpen) { this.open = event.detail.isOpen; } else { this.open = !this.open; } if (this.open) { this.$root.showModal(); } else { this.$root.close(); } this.scrollLock(this.open); }, scrollLock (use = true) { document.documentElement.style.scrollbarGutter = use ? "stable" : ""; document.body.style.overflow = use ? "hidden" : ""; }, onDialogBackdropClickHelper (event, target) { const rect = target.getBoundingClientRect(); const isInDialog = rect.top <= event.clientY && event.clientY <= rect.top + rect.height && rect.left <= event.clientX && event.clientX <= rect.left + rect.width; return isInDialog; }, selectors: { visibleFields: ':is(input:not([type=hidden],[type=password]), textarea:not([type=hidden]))', }, quoteId: 0, controller: new AbortController(), quoteSubmitting: false, quoteSubmitted: false, initForm: function () { input = this.$refs.quoteDetailsForm.phone_number const iti = window.intlTelInputGlobals.getInstance(input); if (!iti) { window.intlTelInput(input, { utilsScript: "https://www.icronshop.com/static/version1726258117/frontend/GlobalHostings/icronshop/en_US//intl-tel-input/utils.js", placeholderNumberType: 'FIXED_LINE', autoPlaceholder: 'aggressive', countrySearch: false, initialCountry: 'GB', showSelectedDialCode: true, onlyCountries: ["DZ","AS","AD","AO","AI","AQ","AG","AW","AU","AT","BS","BH","BD","BB","BE","BZ","BM","BT","BV","IO","VG","BN","BG","CA","BQ","KY","CX","CC","KM","CK","HR","CU","CW","CY","CZ","DK","DJ","DM","DO","EG","SV","GQ","ER","EE","SZ","ET","FK","FO","FJ","FI","FR","PF","TF","DE","GI","GR","GL","GD","GP","GT","GG","GW","HM","HN","HK","HU","IS","IN","ID","IE","IM","IL","IT","JM","JP","JE","JO","KZ","KI","XK","KW","KG","LV","LB","LS","LI","LT","LU","MO","MG","MY","MV","ML","MT","MH","MQ","MR","MU","YT","FM","MD","MC","MN","ME","MS","MM","NA","NR","NP","NL","NC","NZ","NI","NU","NF","MK","MP","NO","PW","PS","PA","PG","PH","PN","PL","PT","QA","RO","RW","RE","WS","SM","SA","SN","RS","SC","SG","SX","SK","SI","SB","ZA","GS","KR","ES","LK","BL","SH","KN","LC","MF","PM","VC","SJ","SE","CH","SY","ST","TW","TJ","TZ","TH","TL","TG","TK","TO","TT","TN","TR","TM","TC","TV","UM","VI","UA","AE","GB","US","UZ","VA","VN","WF","AX"] }); } this.initFieldsValue(); }, initFieldsValue: function () { const sectionData = JSON.parse(hyva.getBrowserStorage().getItem('mage-cache-storage')); const shippingAddressFromData = this.getShippingAddressFromData(sectionData); Array.from(this.$refs.quoteDetailsForm.querySelectorAll(this.selectors.visibleFields)) .forEach((input) => { const persistedAttributeValue = shippingAddressFromData.amasty_quote_attributes['data.' + input.name]; if (input.name === 'phone_number') { if (window.intlTelInputGlobals && persistedAttributeValue) { const phoneNumber = this.$refs.quoteDetailsForm.phone_number const iti = window.intlTelInputGlobals.getInstance(phoneNumber); iti.setNumber(persistedAttributeValue) } } else { !!persistedAttributeValue && (input.value = persistedAttributeValue); } }); }, getShippingAddressFromData: function (sectionData) { let shippingAddressFromData = {}; if (sectionData) { shippingAddressFromData = sectionData['checkout-data']?.shippingAddressFromData ?? {}; } shippingAddressFromData = { ...shippingAddressFromData, amasty_quote_attributes: shippingAddressFromData.amasty_quote_attributes ?? {} } shippingAddressFromData.amasty_quote_attributes.quote_id = this.quoteId; return shippingAddressFromData; }, saveQuoteAttributes: function (attributes) { const sectionData = JSON.parse(hyva.getBrowserStorage().getItem('mage-cache-storage')); const checkoutData = sectionData['checkout-data'] ?? {}; checkoutData.shippingAddressFromData = { ...this.getShippingAddressFromData(sectionData) }; checkoutData.shippingAddressFromData.amasty_quote_attributes = { quote_id: this.quoteId, ...attributes }; sectionData['checkout-data'] = { ...checkoutData }; hyva.getBrowserStorage().setItem('mage-cache-storage', JSON.stringify(sectionData)); }, persistFieldValues: function () { const fieldValues = {}; Array.from(this.$refs.quoteDetailsForm.querySelectorAll(this.selectors.visibleFields)).forEach((input) => { if (!input.value) { return; } let value = input.value if (input.name === 'phone_number') { const phoneNumber = this.$refs.quoteDetailsForm.phone_number const iti = window.intlTelInputGlobals.getInstance(phoneNumber); value = iti.getNumber() } fieldValues['data.' + input.name] = value; }); this.saveQuoteAttributes(fieldValues); }, updateRemark: function () { const remarkValue = this.$refs.quoteDetailsForm.remark.value; this.abortUpdateRemark(); fetch( `${BASE_URL}rest/${CURRENT_STORE_CODE}/V1/amasty_quote/updateRemark/`, { method: 'PUT', headers: {'Content-Type': 'application/json'}, signal: this.controller.signal, body: JSON.stringify({ 'remark': remarkValue }) } ).finally(() => { }); }, abortUpdateRemark: function () { this.controller.abort(); this.controller = new AbortController(); }, submitQuote: function () { this.quoteSubmitting = true; this.validate() .then(() => { this.quoteSubmitting = true; const phoneNumberInput = this.$refs.quoteDetailsForm.phone_number const iti = window.intlTelInputGlobals.getInstance(phoneNumberInput); const phoneNumber = iti.getNumber() const name = this.$refs.quoteDetailsForm.name.value.split(' '); const email = this.$refs.quoteDetailsForm.quoteemail.value; const remark = this.$refs.quoteDetailsForm.remark.value; let formData = new FormData(); formData.append('form_key', hyva.getFormKey()) formData.append('update_cart_action', 'submit') formData.append('firstname', name[0]); formData.append('lastname', name.slice(1).join(' ')); formData.append('email', email); formData.append('remarks', remark) formData.append('quote_entity[phone_number]', phoneNumber); const items = this.$refs.quoteDetailsForm.querySelectorAll('.quoteitem'); [...items].forEach(item => { formData.append(item.name, item.value) }); const postUrl = `${BASE_URL}amasty_quote/cart/updatePost` fetch(postUrl, { "body": formData, "method": "POST", "mode": "cors", "credentials": "include" }).then(response => { return response.json(); }).then(result => { if (result.ok) { setTimeout(() => { this.quoteSubmitted = true; }, 200); } else { window.dispatchMessages && window.dispatchMessages([{ type: 'error', text: result.error_message }]); } }) }) .catch((invalid) => { if (invalid.length > 0) { invalid[0].focus(); } }).finally(() => { setTimeout(() => { this.quoteSubmitting = false; }, 200); setTimeout(() => { window.dispatchEvent(new CustomEvent('reload-customer-section-data')); }, 2000) }); } } }