<?php
/**
 * Maho
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2023 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)
 */
?>
<?php
/**
 * Edit customer address template
 *
 * @var Mage_Customer_Block_Address_Edit $this
 */
?>
<?php if($this->getTitle()): ?>
<div class="page-title">
    <h1><?= $this->getTitle() ?></h1>
</div>
<?php endif ?>
<?= $this->getMessagesBlock()->toHtml() ?>
<form action="<?= $this->getSaveUrl() ?>" method="post" id="form-validate">
    <div class="fieldset">
    <?= $this->getBlockHtml('formkey') ?>
    <input type="hidden" name="success_url" value="<?= $this->getSuccessUrl() ?>" />
    <input type="hidden" name="error_url" value="<?= $this->getErrorUrl() ?>" />
        <h2 class="legend"><?= $this->__('Contact Information') ?></h2>
        <ul class="form-list">
            <li class="fields">
                <?= $this->getNameBlockHtml() ?>
            </li>
            <li class="wide">
                <label for="company"><?= $this->__('Company') ?></label>
                <div class="input-box">
                    <input type="text" name="company" id="company" title="<?= Mage::helper('core')->quoteEscape($this->__('Company')) ?>" value="<?= $this->escapeHtml($this->getAddress()->getCompany()) ?>" class="input-text <?= $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
                </div>
            </li>
            <li class="fields">
                <div class="field">
                    <label for="telephone" class="required"><em>*</em><?= $this->__('Telephone') ?></label>
                    <div class="input-box">
                        <input type="text" name="telephone" value="<?= $this->escapeHtml($this->getAddress()->getTelephone()) ?>" title="<?= Mage::helper('core')->quoteEscape($this->__('Telephone')) ?>" class="input-text  <?= $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" id="telephone" />
                    </div>
                </div>
                <div class="field">
                    <label for="fax"><?= $this->__('Fax') ?></label>
                    <div class="input-box">
                        <input type="text" name="fax" id="fax" title="<?= Mage::helper('core')->quoteEscape($this->__('Fax')) ?>" value="<?= $this->escapeHtml($this->getAddress()->getFax()) ?>" class="input-text <?= $this->helper('customer/address')->getAttributeValidationClass('fax') ?>" />
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="fieldset">
        <h2 class="legend"><?= $this->__('Address') ?></h2>
        <ul class="form-list">
        <?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
            <li class="wide">
                <label for="street_1" class="required"><em>*</em><?= $this->__('Street Address') ?></label>
                <div class="input-box">
                    <input type="text" name="street[]" value="<?= $this->escapeHtml($this->getAddress()->getStreet(1)) ?>" title="<?= Mage::helper('core')->quoteEscape($this->__('Street Address')) ?>" id="street_1" class="input-text <?= $_streetValidationClass ?>" />
                </div>
            </li>
        <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
        <?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
            <li class="wide">
                <div class="input-box">
                    <input type="text" name="street[]" value="<?= $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>" title="<?= Mage::helper('core')->quoteEscape($this->__('Street Address %s', $_i)) ?>" id="street_<?= $_i ?>" class="input-text <?= $_streetValidationClass ?>" />
                </div>
            </li>
        <?php endfor ?>
            <?php if ($this->helper('customer/address')->isVatAttributeVisible()) : ?>
            <li class="wide">
                <label for="vat_id"><?= $this->__('VAT Number') ?></label>
                <div class="input-box">
                    <input type="text" name="vat_id" value="<?= $this->escapeHtml($this->getAddress()->getVatId()) ?>" title="<?= Mage::helper('core')->quoteEscape($this->__('VAT Number')) ?>" id="vat_id" class="input-text <?= $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?>" />
                </div>
            </li>
            <?php endif ?>
            <li class="fields">
                <div class="field">
                    <label for="city" class="required"><em>*</em><?= $this->__('City') ?></label>
                    <div class="input-box">
                        <input type="text" name="city" value="<?= $this->escapeHtml($this->getAddress()->getCity()) ?>"  title="<?= Mage::helper('core')->quoteEscape($this->__('City')) ?>" class="input-text <?= $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
                    </div>
                </div>
                <div class="field">
                    <label for="region_id" class="required"><em>*</em><?= $this->__('State/Province') ?></label>
                    <div class="input-box">
                        <select id="region_id" name="region_id" title="<?= Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>" class="validate-select" style="display:none;">
                           <option value=""><?= $this->__('Please select region, state or province') ?></option>
                        </select>
                        <script type="text/javascript">
                            document.getElementById('region_id').defaultValue = "<?= $this->getAddress()->getRegionId() ?>";
                        </script>
                        <input type="text" id="region" name="region" value="<?= $this->escapeHtml($this->getAddress()->getRegion()) ?>"  title="<?= Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>" class="input-text <?= $this->helper('customer/address')->getAttributeValidationClass('region') ?>" />
                    </div>
                </div>
            </li>
            <li class="fields">
                <div class="field">
                    <label for="zip" class="required"><em>*</em><?= $this->__('Zip/Postal Code') ?></label>
                    <div class="input-box">
                        <input type="text" name="postcode" value="<?= $this->escapeHtml($this->getAddress()->getPostcode()) ?>" title="<?= Mage::helper('core')->quoteEscape($this->__('Zip/Postal Code')) ?>" id="zip" class="input-text validate-zip-international <?= $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
                    </div>
                </div>
                <div class="field">
                    <label for="country" class="required"><em>*</em><?= $this->__('Country') ?></label>
                    <div class="input-box">
                        <?= $this->getCountryHtmlSelect() ?>
                    </div>
                </div>
            </li>
            <li<?php if($this->canSetAsDefaultBilling()) echo ' class="control"' ?>>
                <?php if($this->isDefaultBilling()): ?>
                    <strong><?= $this->__('Default Billing Address') ?></strong>
                <?php elseif($this->canSetAsDefaultBilling()): ?>
                    <input type="checkbox" id="primary_billing" name="default_billing" value="1" title="<?= Mage::helper('core')->quoteEscape($this->__('Use as My Default Billing Address')) ?>" class="checkbox" /><label for="primary_billing"><?= $this->__('Use as my default billing address') ?></label>
                <?php else: ?>
                    <input type="hidden" name="default_billing" value="1" />
                <?php endif ?>
            </li>
            <li<?php if($this->canSetAsDefaultShipping()) echo ' class="control"' ?>>
                <?php if($this->isDefaultShipping()): ?>
                    <strong><?= $this->__('Default Shipping Address') ?></strong>
                <?php elseif($this->canSetAsDefaultShipping()): ?>
                    <input type="checkbox" id="primary_shipping" name="default_shipping" value="1" title="<?= Mage::helper('core')->quoteEscape($this->__('Use as My Default Shipping Address')) ?>" class="checkbox" /><label for="primary_shipping"><?= $this->__('Use as my default shipping address') ?></label>
                <?php else: ?>
                    <input type="hidden" name="default_shipping" value="1" />
                <?php endif ?>
            </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 data-action="save-customer-address" type="submit" title="<?= Mage::helper('core')->quoteEscape($this->__('Save Address')) ?>" class="button"><?= $this->__('Save Address') ?></button>
    </div>
</form>
<script type="text/javascript">
    var dataForm = new VarienForm('form-validate', true);
    new RegionUpdater('country', 'region', 'region_id', <?= Mage::helper('directory')->getRegionJsonByStore() ?>, undefined, 'zip');
</script>
