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C3B,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,IAAI,EAAE,IAAI,CAAC,QAAQ,EACnB,UAAU,EAAE,IAAI,CAAC,cAAc,EAC/B,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,GACV,EACnB;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["checkoutState"],"sources":["src/components/controllers/checkout-form/order-tax-id-input/sc-order-tax-id-input.css?tag=sc-order-tax-id-input&encapsulation=shadow","src/components/controllers/checkout-form/order-tax-id-input/sc-order-tax-id-input.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, h, Method, Prop, State, Watch } from '@stencil/core';\nimport { state as checkoutState } from '@store/checkout';\nimport { __ } from '@wordpress/i18n';\nimport { createOrUpdateCheckout } from '../../../../services/session';\n\nimport { Address, Checkout, TaxIdentifier } from '../../../../types';\nimport { formBusy } from '@store/form/getters';\nimport { createErrorNotice } from '@store/notices/mutations';\nimport { updateFormState } from '@store/form/mutations';\n\n@Component({\n tag: 'sc-order-tax-id-input',\n styleUrl: 'sc-order-tax-id-input.css',\n shadow: true,\n})\nexport class ScOrderTaxIdInput {\n /** The tax id input */\n private input: HTMLScTaxIdInputElement;\n\n /** Force show the field. */\n @Prop() show: boolean = false;\n\n /** Other zones label */\n @Prop() otherLabel: string;\n\n /** GST zone label */\n @Prop() caGstLabel: string;\n\n /** AU zone label */\n @Prop() auAbnLabel: string;\n\n /** UK zone label */\n @Prop() gbVatLabel: string;\n\n /** EU zone label */\n @Prop() euVatLabel: string;\n\n /** Help text */\n @Prop() helpText: string;\n\n /** Tax ID Types which will be shown Eg: '[\"eu_vat\", \"gb_vat\"]' */\n @Prop() taxIdTypes: string | string[];\n\n /** Whether tax input is required */\n @Prop() required: boolean = false;\n\n /** Tax ID Types data as array */\n @State() taxIdTypesData: string[] = [];\n\n @Watch('taxIdTypes')\n handleTaxIdTypesChange() {\n this.taxIdTypesData = typeof this.taxIdTypes === 'string' ? JSON.parse(this.taxIdTypes) : this.taxIdTypes;\n }\n\n @Method()\n async reportValidity() {\n return this.input.reportValidity();\n }\n\n getStatus() {\n if (checkoutState.checkout?.tax_identifier?.number_type !== 'eu_vat') {\n return 'unknown';\n }\n if (checkoutState.taxProtocol?.eu_vat_unverified_behavior === 'apply_reverse_charge') {\n return 'unknown';\n }\n return (checkoutState.checkout?.tax_identifier as TaxIdentifier)?.eu_vat_verified ? 'valid' : 'invalid';\n }\n\n async updateOrder(tax_identifier: { number: string; number_type: string }) {\n try {\n updateFormState('FETCH');\n checkoutState.checkout = (await createOrUpdateCheckout({\n id: checkoutState.checkout.id,\n data: { tax_identifier },\n })) as Checkout;\n updateFormState('RESOLVE');\n } catch (e) {\n console.error(e);\n createErrorNotice(e);\n updateFormState('REJECT');\n }\n }\n\n componentWillLoad() {\n this.handleTaxIdTypesChange();\n }\n\n isRequired() {\n // If the block has explicitly set required, use that value.\n if (this.required) {\n return true;\n }\n\n // Only apply EU VAT requirement if eu_vat is one of the allowed tax types.\n // If taxIdTypesData is empty, all types are allowed.\n const isEuVatAllowed = !this.taxIdTypesData?.length || this.taxIdTypesData.includes('eu_vat');\n\n // Fall back to EU VAT protocol requirement only if EU VAT is an allowed type.\n return isEuVatAllowed && checkoutState.taxProtocol?.eu_vat_required && checkoutState.checkout?.tax_identifier?.number_type === 'eu_vat';\n }\n\n render() {\n return (\n <sc-tax-id-input\n ref={el => (this.input = el as HTMLScTaxIdInputElement)}\n show={this.show}\n number={checkoutState.checkout?.tax_identifier?.number}\n type={checkoutState.checkout?.tax_identifier?.number_type || this.taxIdTypesData?.[0] || 'eu_vat'}\n country={(checkoutState.checkout?.shipping_address as Address)?.country}\n status={this.getStatus()}\n loading={formBusy()}\n onScChange={e => {\n e.stopImmediatePropagation();\n this.updateOrder(e.detail);\n }}\n otherLabel={this.otherLabel}\n caGstLabel={this.caGstLabel}\n auAbnLabel={this.auAbnLabel}\n gbVatLabel={this.gbVatLabel}\n euVatLabel={this.euVatLabel}\n help={this.helpText}\n taxIdTypes={this.taxIdTypesData}\n required={this.isRequired()}\n ></sc-tax-id-input>\n );\n }\n}\n"],"version":3}