<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2022-2024 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/** @var Mage_Install_Block_Locale $this */
?>
<div class="page-head">
    <h3><?= $this->__('Localization') ?></h3>
</div>
<?= $this->getMessagesBlock()->toHtml() ?>

<form action="<?= $this->getPostUrl() ?>" method="get" id="form-validate">
<fieldset class="group-select">
 <legend><?= $this->__('Locale') ?></legend>
    <h4 class="legend"><?= $this->__('Locale settings') ?></h4>
    <ul>
        <li>
            <div class="input-box">
                <label for="locale"><?= $this->__('Locale') ?> <span class="required">*</span></label><br/>
                <?= $this->getLocaleSelect() ?>
            </div>
        </li>
        <li>
            <div class="input-box">
                <label for="timezone"><?= $this->__('Time Zone') ?> <span class="required">*</span></label><br/>
                <?= $this->getTimezoneSelect() ?>
            </div>
            <div class="input-box">
                <label for="currency"><?= $this->__('Default Currency') ?> <span class="required">*</span></label><br/>
                <?= $this->getCurrencySelect() ?>
            </div>
        </li>
    </ul>
</fieldset>
<div class="button-set">
    <p class="required">* <?= $this->__('Required Fields') ?></p>
    <button class="form-button" type="submit"><span><?= $this->__('Continue') ?></span></button>
</div>
</form>
<script type="text/javascript">
    const changeLocale = (event) => {
        const elem = event.target;
        if (elem) {
            const timezoneValue = document.getElementById('timezone').value;
            const currencyValue = document.getElementById('currency').value;
            const url = `<?= $this->getChangeUrl() ?>locale/${elem.value}/?timezone=${timezoneValue}&currency=${currencyValue}`;
            window.location.href = url;
        }
    };

    const dataForm = new VarienForm('form-validate');
    const localeElement = document.getElementById('locale');
    if (localeElement) {
        localeElement.addEventListener('change', changeLocale);
    }
</script>
