(()=>{"use strict";var e,t,i=function(){function e(t){this.settings=t,e._instance=this}return e.prototype.get_onchange_event_selector=function(){var e="";switch(this.settings.tax_based_on){case"billing":default:e="select#billing_country";break;case"shipping":e="select#billing_country, select#shipping_country, input#ship-to-different-address-checkbox"}return e+", #billing_company, #vat_number"},e.prototype.get_vat_country=function(){var e="#billing_country";return"shipping"===this.settings.tax_based_on&&jQuery('#ship-to-different-address input[type="checkbox"]').prop("checked")&&(e="#shipping_country"),jQuery(e).val()},e.prototype.must_hide_vat_number_field_for_base_country=function(e){return!this.settings.show_eu_vat_number_for_base_country&&e==this.settings.shop_base_country},e.prototype.country_has_vat_number_validator=function(e){return this.settings.vat_number_countries.includes(e)},e.prototype.is_eu_vat_country=function(e){return this.settings.eu_vat_countries.includes(e)},e.prototype.should_show_vat_number_for_country=function(e){return!this.must_hide_vat_number_field_for_base_country(e)&&this.country_has_vat_number_validator(e)},e.prototype.is_vat_number_required=function(e){if(this.must_hide_vat_number_field_for_base_country(e))return!1;var t=document.getElementById("billing_company"),i=(t?t.value.trim():"").length>0,n=this.is_eu_vat_country(e);return"required"===this.settings.vat_number_field_required||"required_for_eu_only"===this.settings.vat_number_field_required&&n||"required_if_company_field_filled"===this.settings.vat_number_field_required&&i||"required_if_company_field_filled_eu_only"===this.settings.vat_number_field_required&&i&&n},e.prototype.update_vat_number_field_visibility=function(){var t=this.get_vat_country(),i=this.is_vat_number_required(t),n=jQuery(e.vat_number_field);t&&this.should_show_vat_number_for_country(t)||i?n.fadeIn():(n.fadeOut(),e.vat_number_input.value=""),n.is(":visible")&&i?n.find(".form-row").addClass("validate-required"):n.find(".form-row").removeClass("validate-required")},e.prototype.set_vat_number_field_handlers=function(){var t=this;jQuery(this.get_onchange_event_selector()).on("change",(function(){t.update_vat_number_field_visibility(),t.validate_vat_number(t.get_vat_country(),e.vat_number_input.value)})),jQuery(e.vat_number_input).on("blur",(function(){t.validate_vat_number(t.get_vat_country(),e.vat_number_input.value)}))},e.prototype.set_self_certification_field_handlers=function(){var e=this;jQuery(this.get_onchange_event_selector()).on("change",(function(){e.update_self_certification_field()})),jQuery(document).on("wc_aelia_euva_eu_vat_number_validation_number_incomplete",(function(t,i,n){e.update_self_certification_field()})),jQuery(document).on("wc_aelia_euva_eu_vat_number_validation_complete",(function(t,i){e.update_self_certification_field()}))},e.instance=function(){if(!e._instance)throw new Error("Checkout handler has not been instantiated. Please call `Checkout.init()` before calling `Checkout.instance()`.");return e._instance},e.init=function(t){if(document.querySelectorAll(".woocommerce form.checkout").length<=0)console.log("Checkout form not found. EU VAT Assistant scripts not loaded.");else{var i=new e(t);if((e.vat_number_field=document.getElementById("vat_number_field"))&&(e.vat_number_input=document.getElementById("vat_number"))&&i.set_vat_number_field_handlers(),e.self_certification_field=document.getElementById("customer_location_self_certified_field")){var n=jQuery(e.self_certification_field).find(".description");jQuery(e.self_certification_field).find(".woocommerce-input-wrapper").before(n),i.update_self_certification_field(),i.set_self_certification_field_handlers()}jQuery("select#billing_country").change()}},e.prototype.validate_vat_number=function(t,i){if(i.includes(t)&&(i=i.slice(t.length)),t+(i=i.trim())!==this.last_vat_number){if(jQuery(e.vat_number_field).removeClass("woocommerce-invalid"),""===t||""===i.trim())return jQuery(e.vat_number_input).prop("valid",!1),this.is_vat_number_required(t)&&jQuery(e.vat_number_field).addClass("woocommerce-invalid"),void jQuery(document).trigger("wc_aelia_euva_eu_vat_number_validation_number_incomplete",t,i);this.last_vat_number=t+i;var n={action:"validate_vat_number",country:t,vat_number:i,_ajax_nonce:this.settings._ajax_nonce};jQuery.get(this.settings.ajax_url,n,(function(t){var i=!!t&&t.valid;jQuery(e.vat_number_input).prop("valid",i),jQuery(e.vat_number_field).toggleClass("woocommerce-invalid",!i),jQuery(document).trigger("wc_aelia_euva_eu_vat_number_validation_complete",t)})).fail((function(e){console.log("VAT validation request failed",e)}))}},e.prototype.update_self_certification_field=function(){if(e.self_certification_field){var t=!0;if(jQuery(e.vat_number_input).prop("valid")&&1==this.settings.hide_self_cert_field_with_valid_vat)t=!1;else switch(this.settings.show_self_cert_field){case"yes":break;case"conflict-only":t=!this.sufficient_location_evidence()}var i=this.settings.user_interface.self_certification_field_title;jQuery(e.self_certification_field).find(".self_certification_label").html(i.replace("{billing_country}",jQuery("#billing_country option:selected").text())),t?jQuery(e.self_certification_field).fadeIn():jQuery(e.self_certification_field).fadeOut()}},e.prototype.sufficient_location_evidence=function(){var e,t,i,n={},_=jQuery("#billing_country").val();if(n[_]=(null!==(e=n[_])&&void 0!==e?e:0)+1,this.settings.use_shipping_as_evidence&&jQuery("#ship-to-different-address-checkbox").is(":checked")&&jQuery("#shipping_country").length>0){var r=jQuery("#shipping_country").val();n[r]=(null!==(t=n[r])&&void 0!==t?t:0)+1}for(var a in n[this.settings.ip_address_country]=(null!==(i=n[this.settings.ip_address_country])&&void 0!==i?i:0)+1,n)if(""!=a&&n[a]>=2)return!0;return!1},e}();e=i.init,t=aelia_eu_vat_assistant_params,"loading"!=document.readyState?e(t):document.addEventListener("DOMContentLoaded",(function(){return e(t)}))})(); //# sourceMappingURL=index.js.map