1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[25132],{5132(e,t,i){i.r(t),i.d(t,{default:()=>o});var s=i(4335),n=i(9068);class o extends s.A{static #e=this.options={countrySelectSelector:".country-select",initialCountryAttribute:"data-initial-country-id",countryStateSelectSelector:".country-state-select",initialCountryStateAttribute:"data-initial-country-state-id",countryStatePlaceholderSelector:'[data-placeholder-option="true"]',vatIdFieldInput:"#vatIds",zipcodeFieldInput:'[data-input-name="zipcodeInput"]',vatIdRequired:"data-vat-id-required",stateRequired:"data-state-required",stateDisplayed:"data-display-state-in-registration",zipcodeRequired:"data-zipcode-required",scopeElementSelector:null,prefix:null};init(){this.initClient(),this.initSelects(),this._getFormFieldToggleInstance(),this._formFieldToggleInstance&&this._formFieldToggleInstance.$emitter.subscribe("onChange",this._onFormFieldToggleChange.bind(this))}initClient(){this._client=new n.A}initSelects(){this.scopeElement=this.el,this.options.scopeElementSelector&&(this.scopeElement=document.querySelector(this.options.scopeElementSelector));let{countrySelectSelector:e,countryStateSelectSelector:t,initialCountryAttribute:i,initialCountryStateAttribute:s}=o.options,n=this.scopeElement.querySelector(e),r=this.scopeElement.querySelector(t),d=n.getAttribute(i),a=r.getAttribute(s),l=n.options[n.selectedIndex],u=!!l.getAttribute(this.options.vatIdRequired),c=document.querySelector(this.options.vatIdFieldInput),p=!!l.getAttribute(this.options.stateRequired),h=this._getStateDisplayed(l,p),g=this.scopeElement.querySelectorAll(this.options.zipcodeFieldInput),q=!!l.getAttribute(this.options.zipcodeRequired);n.addEventListener("change",this.onChangeCountry.bind(this)),d&&(this.requestStateData(d,a,p,h),q&&this._updateZipcodeFields(g,q),c&&this._updateVatIdField(c,u))}onChangeCountry(e){let t=e.target.value,i=e.target.options[e.target.selectedIndex],s=!!i.getAttribute(this.options.stateRequired),n=this._getStateDisplayed(i,s);this.requestStateData(t,null,s,n);let o=!!i.getAttribute(this.options.vatIdRequired),r=document.querySelector(this.options.vatIdFieldInput),d=this.scopeElement.querySelectorAll(this.options.zipcodeFieldInput),a=!!i.getAttribute(this.options.zipcodeRequired);this._updateZipcodeFields(d,a),r&&this._updateVatIdField(r,o)}requestStateData(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=!(arguments.length>3)||void 0===arguments[3]||arguments[3];fetch(`${window.router["frontend.country.country-data"]}?countryId=${encodeURIComponent(e)}`,{headers:{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/json"}}).then(e=>e.json()).then(e=>this._updateStateSelect(e.states,i,t,s))}_updateVatIdField(e,t){this._differentShippingCheckbox&&"billingAddress"===this.options.prefix||(t?window.formValidation.setFieldRequired(e):window.formValidation.setFieldNotRequired(e))}_updateZipcodeFields(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e&&e.forEach(e=>{!0===t?window.formValidation.setFieldRequired(e):window.formValidation.setFieldNotRequired(e)})}_updateStateSelect(e,t,i){let s=!(arguments.length>3)||void 0===arguments[3]||arguments[3],n=this.scopeElement.querySelector(this.options.countryStateSelectSelector),o=n.querySelector(this.options.countryStatePlaceholderSelector);this._removeStateOptions(n),this._addStateOptions(t||s?e:[],i,n),t?(window.formValidation.setFieldRequired(n),o.setAttribute("disabled","disabled")):(window.formValidation.setFieldNotRequired(n),o.removeAttribute("disabled"))}_removeStateOptions(e){let t=`option:not(${this.options.countryStatePlaceholderSelector})`,i=e;e||(i=this.scopeElement.querySelector(this.options.countryStateSelectSelector)),i.querySelectorAll(t).forEach(e=>e.remove())}_addStateOptions(e,t,i){let s=i;if(i||(s=this.scopeElement.querySelector(this.options.countryStateSelectSelector)),0===e.length){s.parentNode.classList.add("d-none"),s.setAttribute("disabled","disabled");return}e.map(e=>
1this._createStateOptionEl(e,t)).forEach(e=>{s.append(e)}),s.parentNode.classList.remove("d-none"),s.removeAttribute("disabled")}_createStateOptionEl(e,t){let i=document.createElement("option");return i.setAttribute("value",e.id),i.innerText=e.translated.name,e.id===t&&i.setAttribute("selected","selected"),i}_getFormFieldToggleInstance(){let e=document.querySelector('[data-form-field-toggle-target=".js-form-field-toggle-shipping-address"]');e&&(this._formFieldToggleInstance=window.PluginManager.getPluginInstanceFromElement(e,"FormFieldToggle"))}_onFormFieldToggleChange(e){this._differentShippingCheckbox=e.target.checked;let t=this._differentShippingCheckbox?".register-shipping":".register-billing",i=document.querySelector(t).querySelector(this.options.countrySelectSelector),s=!!i.options[i.selectedIndex].getAttribute(this.options.vatIdRequired),n=document.querySelector(this.options.vatIdFieldInput);n&&this._updateVatIdField(n,s)}_getStateDisplayed(e,t){if(t||!e.hasAttribute(this.options.stateDisplayed))return!0;let i=e.getAttribute(this.options.stateDisplayed);return""!==i&&"0"!==i&&"false"!==i}}},9068(e,t,i){i.d(t,{A:()=>s});class s{constructor(){this._request=null,this._errorHandlingInternal=!1}get(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"application/json",s=this._createPreparedRequest("GET",e,i);return this._sendRequest(s,null,t)}post(e,t,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";s=this._getContentType(t,s);let n=this._createPreparedRequest("POST",e,s);return this._sendRequest(n,t,i)}delete(e,t,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";s=this._getContentType(t,s);let n=this._createPreparedRequest("DELETE",e,s);return this._sendRequest(n,t,i)}patch(e,t,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";s=this._getContentType(t,s);let n=this._createPreparedRequest("PATCH",e,s);return this._sendRequest(n,t,i)}abort(){if(this._request)return this._request.abort()}setErrorHandlingInternal(e){this._errorHandlingInternal=e}_registerOnLoaded(e,t){t&&(!0===this._errorHandlingInternal?(e.addEventListener("load",()=>{t(e.responseText,e)}),e.addEventListener("abort",()=>{console.warn(`the request to ${e.responseURL} was aborted`)}),e.addEventListener("error",()=>{console.warn(`the request to ${e.responseURL} failed with status ${e.status}`)}),e.addEventListener("timeout",()=>{console.warn(`the request to ${e.responseURL} timed out`)})):e.addEventListener("loadend",()=>{t(e.responseText,e)}))}_sendRequest(e,t,i){return this._registerOnLoaded(e,i),e.send(t),e}_getContentType(e,t){return e instanceof FormData&&(t=!1),t}_createPreparedRequest(e,t,i){return this._request=new XMLHttpRequest,this._request.open(e,t),this._request.setRequestHeader("X-Requested-With","XMLHttpRequest"),i&&this._request.setRequestHeader("Content-type",i),this._request}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.