<?php
/**
 * Maho
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-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_Customer_Block_Form_Edit $this */
?>
<div class="page-title">
    <h1><?= $this->__('Edit Account Information') ?></h1>
</div>
<?= $this->getMessagesBlock()->toHtml() ?>
<form action="<?= $this->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" autocomplete="off">
    <div class="fieldset">
        <?= $this->getBlockHtml('formkey') ?>
        <h2 class="legend"><?= $this->__('Account Information') ?></h2>
        <ul class="form-list">
            <li class="fields">
                <?= $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>
            </li>
            <li>
                <label for="email" class="required"><em>*</em><?= $this->__('Email Address') ?></label>
                <div class="input-box">
                    <input type="text" name="email" id="email" value="<?= $this->escapeHtml($this->getCustomer()->getEmail()) ?>" title="<?= Mage::helper('core')->quoteEscape($this->__('Email Address')) ?>" class="input-text required-entry validate-email" />
                </div>
            </li>
        <?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
        <?php if ($_dob->isEnabled()): ?>
            <li><?= $_dob->setDate($this->getCustomer()->getDob())->toHtml() ?></li>
        <?php endif ?>
        <?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
        <?php if ($_taxvat->isEnabled()): ?>
            <li><?= $_taxvat->setTaxvat($this->getCustomer()->getTaxvat())->toHtml() ?></li>
        <?php endif ?>
        <?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
        <?php if ($_gender->isEnabled()): ?>
            <li><?= $_gender->setGender($this->getCustomer()->getGender())->toHtml() ?></li>
        <?php endif ?>
            <li>
                <label for="current_password" class="required"><em>*</em><?= Mage::helper('core')->quoteEscape($this->__('Current Password')) ?></label>
                <div class="input-box">
                    <!-- This is a dummy hidden field to trick firefox from auto filling the password -->
                    <input type="text" class="input-text no-display" name="dummy" id="dummy" />
                    <input type="password" title="<?= Mage::helper('core')->quoteEscape($this->__('Current Password')) ?>" class="input-text required-entry" name="current_password" id="current_password" autocomplete="off" />
                </div>
            </li>
            <li class="control">
                <input type="checkbox" name="change_password" id="change_password" value="1" onclick="setPasswordForm(this.checked)" title="<?= Mage::helper('core')->quoteEscape($this->__('Change Password')) ?>"<?php if($this->getCustomer()->getChangePassword()==1): ?> checked="checked"<?php endif ?> class="checkbox" /><label for="change_password"><?= $this->__('Change Password') ?></label>
            </li>
        </ul>
    </div>
    <div class="fieldset" style="display:none;">
        <h2 class="legend"><?= $this->__('Change Password') ?></h2>
        <ul class="form-list">
            <li class="fields">
                <div class="field">
                    <label for="password" class="required"><em>*</em><?= $this->__('New Password') ?></label>
                    <div class="input-box ">
                        <?php $minPasswordLength = $this->getCustomer()->getMinPasswordLength(); ?>
                        <input type="password"
                               title="<?= Mage::helper('core')->quoteEscape($this->__('New Password')) ?>"
                               class="input-text required-entry validate-password min-pass-length-<?= $minPasswordLength ?>"
                               name="password"
                               id="password"
                               autocomplete="new-password" />
                        <p class="form-instructions">
                            <?= $this->__('The minimum password length is %s', $minPasswordLength) ?>
                        </p>
                    </div>
                </div>
                <div class="field">
                    <label for="confirmation" class="required"><em>*</em><?= $this->__('Confirm New Password') ?></label>
                    <div class="input-box">
                        <input type="password" title="<?= Mage::helper('core')->quoteEscape($this->__('Confirm New Password')) ?>" class="input-text required-entry validate-cpassword" name="confirmation" id="confirmation" autocomplete="new-password" />
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="buttons-set">
        <p class="required"><?= $this->__('* Required Fields') ?></p>
        <p class="back-link"><a href="<?= $this->escapeUrl($this->getBackUrl()) ?>"><small>&laquo; </small><?= $this->__('Back') ?></a></p>
        <button type="submit" title="<?= Mage::helper('core')->quoteEscape($this->__('Save')) ?>" class="button"><?= $this->__('Save') ?></button>
    </div>
</form>
<script type="text/javascript">
    var dataForm = new VarienForm('form-validate', true);
    function setPasswordForm(arg) {
        const fieldset = document.querySelector('#password').closest('.fieldset');
        fieldset.style.display = arg ? '' : 'none';
    }

    <?php if($this->getCustomer()->getChangePassword()): ?>
    setPasswordForm(true);
    <?php endif ?>
</script>
