{% sw_extends '@Storefront/storefront/component/account/register.html.twig' %}
{% block component_account_register_form %}
{% set defaultCountriesEU = constant('Acris\\Tax\\Components\\Service\\VatIdValidationService::DEFAULT_SPECIFIC_COUNTRIES') %}
{% set countriesVatIdPattern = [] %}
{% set countriesVatIdPatternWithCountryIds = [] %}
{% set checkCountriesVatIdPattern = [] %}
{% set checkCountriesFormatPattern = [] %}
{% set checkCountryIsoCodes = [] %}
{% set countryIdsIsoCodes = [] %}
{% for country in page.countries %}
{% if country.vatIdPattern is not empty %}
{% set countriesVatIdPattern = countriesVatIdPattern|merge([country.vatIdPattern]) %}
{% set countriesVatIdPatternWithCountryIds = countriesVatIdPatternWithCountryIds|merge({(country.vatIdPattern): country.id}) %}
{% if country.translated.customFields is not empty and country.translated.customFields.acris_tax_specific_country_validate_vat_id is not empty and country.translated.customFields.acris_tax_specific_country_validate_vat_id == true %}
{% set checkCountriesVatIdPattern = checkCountriesVatIdPattern|merge({(country.id): country.translated.customFields.acris_tax_specific_country_validate_vat_id}) %}
{% endif %}
{% set checkCountriesFormatPattern = checkCountriesFormatPattern|merge({(country.id): country.checkVatIdPattern}) %}
{% set checkCountryIsoCodes = checkCountryIsoCodes|merge({(country.iso): country.checkVatIdPattern}) %}
{% set countryIdsIsoCodes = countryIdsIsoCodes|merge({(country.iso): country.id}) %}
{% endif %}
{% endfor %}
{% set taxPluginOptions = {
token: sw_csrf('frontend.acris-tax.vat-id-validation', {"mode": "token"}),
postUrl: path('frontend.acris-tax.vat-id-validation'),
defaultCountriesEU: defaultCountriesEU,
countryVatIdPatterns: countriesVatIdPattern,
countryIdsWithPattern: countriesVatIdPatternWithCountryIds,
checkCountriesVatIdPattern: checkCountriesVatIdPattern,
checkCountriesFormatPattern: checkCountriesFormatPattern,
checkCountryIsoCodes: checkCountryIsoCodes,
countryIdsIsoCodes: countryIdsIsoCodes,
validateFormat: config("AcrisTaxCS.config").validateVatIDFormatAllEUCountries,
validateApiService: config("AcrisTaxCS.config").VatIDAPIValidationAllEUCountries,
assignCategory: config("AcrisTaxCS.config").fillInCountryAutomatically,
entry: 'register'
} %}
<div class="acris-tax-vat-id-validation" data-acris-tax="true" data-acris-tax-validation="true" data-acris-tax-validation-options="{{ taxPluginOptions|json_encode }}">
{{ parent() }}
</div>
{% endblock %}