<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Tax\Block\Adminhtml\Rate\Form $tmpBlock */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>

<?php /** @var \Magento\Directory\Helper\Data $jsonHelper */
$jsonHelper = $tmpBlock->getData('directoryHelper');
$regionJson = /* @noEscape */ $jsonHelper->getRegionJson();
$scriptString = <<<script
require([
    "jquery",
    "mage/adminhtml/form"
], function(jQuery){

    var updater = new RegionUpdater('tax_country_id', 'tax_region', 'tax_region_id', {$regionJson}, 'disable');
    updater.disableRegionValidation();

    (function ($) {
        $(document).ready(function () {
            'use strict';

            var zipIsRange = $('#zip_is_range')
                .on('change.zipRange', function(){
                    var elem = $(this),
                        zipIsRangeChecked = elem.is(':checked'),
                        zipFrom = $('.field-zip_from'),
                        zipTo = $('.field-zip_to'),
                        zipCode = $('.field-tax_postcode'),
                        setState = function(element, visibility) {
                            var input = element.find(':input');
                            if (visibility) {
                                element
                                    .addClass('required')
                                    .removeClass('hidden');
                                input.addClass('required-entry');
                            } else {
                                element
                                    .removeClass('required')
                                    .addClass('hidden');
                                input.removeClass('required-entry');
                            }
                        };
                    elem.val(zipIsRangeChecked ? 1 : 0);
                    setState(zipCode, !zipIsRangeChecked);
                    setState(zipFrom, zipIsRangeChecked);
                    setState(zipTo, zipIsRangeChecked);
                });
            if (zipIsRange.val()) {
                zipIsRange.attr({checked: 'checked'})
            }
            zipIsRange.trigger('change');
        });
    })(jQuery);

    window.updater = updater;
});
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
