import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{s as state}from"./mutations2.js";import{d as createOrUpdateCheckout}from"./index4.js";import{f as formBusy}from"./getters3.js";import{c as createErrorNotice}from"./mutations3.js";import{u as updateFormState}from"./mutations5.js";import{d as defineCustomElement$a}from"./sc-button2.js";import{d as defineCustomElement$9}from"./dropdown.js";import{d as defineCustomElement$8}from"./sc-form-control2.js";import{d as defineCustomElement$7}from"./sc-icon2.js";import{d as defineCustomElement$6}from"./sc-input2.js";import{d as defineCustomElement$5}from"./sc-menu2.js";import{d as defineCustomElement$4}from"./sc-menu-item2.js";import{d as defineCustomElement$3}from"./sc-spinner2.js";import{d as defineCustomElement$2}from"./sc-tax-id-input2.js";import{d as defineCustomElement$1}from"./sc-visually-hidden2.js";const scOrderTaxIdInputCss=":host{display:block}",ScOrderTaxIdInputStyle0=scOrderTaxIdInputCss,ScOrderTaxIdInput=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.show=!1,this.otherLabel=void 0,this.caGstLabel=void 0,this.auAbnLabel=void 0,this.gbVatLabel=void 0,this.euVatLabel=void 0,this.helpText=void 0,this.taxIdTypes=void 0,this.required=!1,this.taxIdTypesData=[]}handleTaxIdTypesChange(){this.taxIdTypesData="string"==typeof this.taxIdTypes?JSON.parse(this.taxIdTypes):this.taxIdTypes}async reportValidity(){return this.input.reportValidity()}getStatus(){var e,t,s,a,i;return"eu_vat"!==(null===(t=null===(e=state.checkout)||void 0===e?void 0:e.tax_identifier)||void 0===t?void 0:t.number_type)||"apply_reverse_charge"===(null===(s=state.taxProtocol)||void 0===s?void 0:s.eu_vat_unverified_behavior)?"unknown":(null===(i=null===(a=state.checkout)||void 0===a?void 0:a.tax_identifier)||void 0===i?void 0:i.eu_vat_verified)?"valid":"invalid"}async updateOrder(e){try{updateFormState("FETCH"),state.checkout=await createOrUpdateCheckout({id:state.checkout.id,data:{tax_identifier:e}}),updateFormState("RESOLVE")}catch(e){console.error(e),createErrorNotice(e),updateFormState("REJECT")}}componentWillLoad(){this.handleTaxIdTypesChange()}isRequired(){var e,t,s,a;return!!this.required||(!(null===(e=this.taxIdTypesData)||void 0===e?void 0:e.length)||this.taxIdTypesData.includes("eu_vat"))&&(null===(t=state.taxProtocol)||void 0===t?void 0:t.eu_vat_required)&&"eu_vat"===(null===(a=null===(s=state.checkout)||void 0===s?void 0:s.tax_identifier)||void 0===a?void 0:a.number_type)}render(){var e,t,s,a,i,o,n;return h("sc-tax-id-input",{key:"621a7eb23f1662a020cc3c5838794b7215bf2492",ref:e=>this.input=e,show:this.show,number:null===(t=null===(e=state.checkout)||void 0===e?void 0:e.tax_identifier)||void 0===t?void 0:t.number,type:(null===(a=null===(s=state.checkout)||void 0===s?void 0:s.tax_identifier)||void 0===a?void 0:a.number_type)||(null===(i=this.taxIdTypesData)||void 0===i?void 0:i[0])||"eu_vat",country:null===(n=null===(o=state.checkout)||void 0===o?void 0:o.shipping_address)||void 0===n?void 0:n.country,status:this.getStatus(),loading:formBusy(),onScChange:e=>{e.stopImmediatePropagation(),this.updateOrder(e.detail)},otherLabel:this.otherLabel,caGstLabel:this.caGstLabel,auAbnLabel:this.auAbnLabel,gbVatLabel:this.gbVatLabel,euVatLabel:this.euVatLabel,help:this.helpText,taxIdTypes:this.taxIdTypesData,required:this.isRequired()})}static get watchers(){return{taxIdTypes:["handleTaxIdTypesChange"]}}static get style(){return ScOrderTaxIdInputStyle0}},[1,"sc-order-tax-id-input",{show:[4],otherLabel:[1,"other-label"],caGstLabel:[1,"ca-gst-label"],auAbnLabel:[1,"au-abn-label"],gbVatLabel:[1,"gb-vat-label"],euVatLabel:[1,"eu-vat-label"],helpText:[1,"help-text"],taxIdTypes:[1,"tax-id-types"],required:[4],taxIdTypesData:[32],reportValidity:[64]},void 0,{taxIdTypes:["handleTaxIdTypesChange"]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-order-tax-id-input","sc-button","sc-dropdown","sc-form-control","sc-icon","sc-input","sc-menu","sc-menu-item","sc-spinner","sc-tax-id-input","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-order-tax-id-input":customElements.get(e)||customElements.define(e,ScOrderTaxIdInput);break;case"sc-button":customElements.get(e)||defineCustomElement$a();break;case"sc-dropdown":customElements.get(e)||defineCustomElement$9();break;case"sc-form-control":customElements.get(e)||defineCustomElement$8();break;case"sc-icon":customElements.get(e)||defineCustomElement$7();break;case"sc-input":customElements.get(e)||defineCustomElement$6();break;case"sc-menu":customElements.get(e)||defineCustomElement$5();break;case"sc-menu-item":customElements.get(e)||defineCustomElement$4();break;case"sc-spinner":customElements.get(e)||defineCustomElement$3();break;case"sc-tax-id-input":customElements.get(e)||defineCustomElement$2();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$1()}}))}export{ScOrderTaxIdInput as S,defineCustomElement as d};