<?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)
 */
?>
<div class="page-title">
    <h1><?= $this->__('Address Books') ?></h1>
</div>
<?= $this->getMessagesBlock()->toHtml() ?>
<table width="100%">
    <tr>
        <td style="width:50%;"><h3>Default</h3>
            <table width="100%">
            <?php if (!empty($primaryAddresses)): ?>
                <?php foreach($primaryAddresses as $_address): ?>
                <tr>
                    <td>
                    <address>
                        <?= $_address->format('html') ?>
                    </address>
                    <p>
                        <strong><a href="<?= $this->getUrl('customer/address/form', ['address' => $_address->getAddressId()]) ?>" class="red-link"><?= $this->__('Edit Address') ?></a></strong>
                    </p>
                    </td>
                </tr>
                <?php endforeach ?>
            <?php else: ?>
                <tr>
                    <td>
                        <p><?= $this->__('You have no default entries in your address book.') ?></p>
                    </td>
                </tr>
            <?php endif ?>
            </table>
        </td>
        <td style="width:50%;"><h3><?= $this->__('Additional Address Entries') ?></h3>
            <table width="100%">
            <?php if (!empty($alternativeAddresses)): ?>
                <?php foreach($alternativeAddresses as $_address): ?>
                <tr>
                    <td>
                        <address>
                            <?= $_address->format('html') ?>
                        </address>
                        <p>
                            <strong><a href="<?= $this->getUrl('customer/address/form', ['address' => $_address->getAddressId()]) ?>" class="red-link"><?= $this->__('Edit Address') ?></a></strong><span class="separator">&nbsp;|&nbsp;</span><strong><a href="#" onclick="return deleteAddress('<?= $_address->getAddressId() ?>');" class="red-link"><?= $this->__('Delete Address') ?></a></strong>
                        </p>
                    </td>
                </tr>
                <?php endforeach ?>
            <?php else: ?>
                <tr>
                    <td>
                        <p><?= $this->__('You have no additional entries in your address book.') ?></p>
                    </td>
                </tr>
            <?php endif ?>
            </table>
        </td>
    </tr>
</table>
<div class="buttons-set">
    <p class="back-link"><a href="<?= $this->getUrl('customer/account/') ?>"><small>&laquo; </small><?= $this->__('Back') ?></a></p>
    <button type="button" onclick="window.location='<?= $this->getUrl('customer/address/form') ?>';" class="button"><?= $this->__('New Address') ?></button>
</div>
<script type="text/javascript">
    function deleteAddress(addressId) {
        if (confirm("<?= Mage::helper('core')->jsQuoteEscape($this->__('Are you sure you want to delete this address?')) ?>")) {
            window.location = "<?= $this->getUrl('customer/address/delete') ?>address/" + addressId + "/";
        }
        return false;
    }
</script>
