<?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)
 */
?>
<?php
/**
 * Multishipping checkout shipping template
 *
 * @see Mage_Checkout_Block_Multishipping_Shipping
 * @var Mage_Checkout_Block_Multishipping_Shipping $this
 */
?>
<div class="multiple-checkout">
    <div class="page-title">
        <h1><?= $this->__('Select Shipping Method') ?></h1>
    </div>
    <?= $this->getMessagesBlock()->toHtml() ?>
    <form action="<?= $this->getPostActionUrl() ?>" method="post" id="shipping_method_form">
        <?php foreach ($this->getAddresses() as $_index => $_address): ?>
        <div class="col2-set">
            <h2 class="legend"><?= $this->__('Address %s of %s', ($_index+1), $this->getAddressCount()) ?></h2>
            <div class="col-1 col-narrow">
                <div class="box">
                    <div class="box-title">
                        <h3><?= $this->__('Shipping To') ?> <span class="separator">|</span> <a href="<?= $this->getAddressEditUrl($_address) ?>"><?= $this->__('Change') ?></a></h3>
                    </div>
                    <div class="box-content">
                        <address><?= $_address->format('html') ?></address>
                    </div>
                </div>
                <div class="box box-sp-methods">
                    <div class="pointer"></div>
                    <div class="box-title">
                        <h3><?= $this->__('Shipping Method') ?></h3>
                    </div>
                    <div class="box-content">
                        <?php if (!($_shippingRateGroups = $this->getShippingRates($_address))): ?>
                            <p><?= $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
                        <?php else: ?>
                        <dl class="sp-methods">
                            <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
                                <dt><?= $this->escapeHtml($this->getCarrierName($code)) ?></dt>
                                <dd>
                                    <ul>
                                    <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
                                        <li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"' ?>>
                                           <?php if ($_rate->getErrorMessage()): ?>
                                                <?= $this->escapeHtml($_rate->getCarrierTitle()) ?>: <?= $this->escapeHtml($_rate->getErrorMessage()) ?>
                                           <?php else: ?>
                                                <?php if ($_sole) : ?>
                                                <span class="no-display"><input type="radio" name="shipping_method[<?= $_address->getId() ?>]" value="<?= $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?= $_address->getId() ?>_<?= $_rate->getCode() ?>" checked="checked"/></span>
                                                <?php else: ?>
                                                <input type="radio" name="shipping_method[<?= $_address->getId() ?>]" value="<?= $_rate->getCode() ?>" id="s_method_<?= $_address->getId() ?>_<?= $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod($_address)) echo ' checked="checked"' ?> class="radio" />
                                                <?php endif ?>
                                                <label for="s_method_<?= $_address->getId() ?>_<?= $_rate->getCode() ?>"><?= $this->escapeHtml($_rate->getMethodTitle()) ?>
                                                <?php $_excl = $this->getShippingPrice($_address, $_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
                                                <?php $_incl = $this->getShippingPrice($_address, $_rate->getPrice(), true); ?>
                                                <?= $_excl ?>
                                                <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                                                    (<?= $this->__('Incl. Tax') ?> <?= $_incl ?>)
                                                <?php endif ?>
                                                </label>
                                           <?php endif ?>
                                        </li>
                                    <?php endforeach ?>
                                    </ul>
                                </dd>
                            <?php endforeach ?>
                        </dl>
                        <?php endif ?>
                    </div>
                </div>
            </div>
            <div class="col-2 col-wide">
                <?php if ($this->helper('core')->isModuleOutputEnabled('Mage_GiftMessage')): ?>
                    <?= $this->helper('giftmessage/message')->getInline('multishipping_adress_checkbox', $_address) ?>
                <?php endif ?>
                <h3><?= $this->__('Items') ?> <span class="separator">|</span> <a href="<?= $this->getItemsEditUrl($_address) ?>"><?= $this->__('Edit Items') ?></a></h3>
                <table class="data-table" id="shipping-table-<?= $_address->getId() ?>">
                    <col />
                    <col width="1" />
                    <thead>
                        <tr>
                            <th><?= $this->__('Product Name') ?></th>
                            <th class="a-center"><?= $this->__('Qty') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($this->getAddressItems($_address) as $_item): ?>
                        <tr>
                            <td>
                                <?= $this->getItemHtml($_item->getQuoteItem()) ?>
                            </td>
                            <td class="a-center"><?= $_item->getQty() ?></td>
                        </tr>
                    <?php endforeach ?>
                    </tbody>
                </table>
                <?php if ($this->helper('core')->isModuleOutputEnabled('Mage_GiftMessage')): ?>
                    <?= $this->helper('giftmessage/message')->getInline('multishipping_adress', $_address) ?>
                <?php endif ?>
            </div>
        </div>
        <?php endforeach ?>
        <?= $this->getChildHtml('checkout_billing_items') ?>
        <div class="buttons-set">
            <p class="back-link"><a href="<?= $this->getBackUrl() ?>"><small>&laquo; </small><?= $this->__('Back to Select Addresses') ?></a></p>
            <button data-action="checkout-continue-billing" type="submit" title="<?= Mage::helper('core')->quoteEscape($this->__('Continue to Billing Information')) ?>" class="button"><?= $this->__('Continue to Billing Information') ?></button>
        </div>
        <?= $this->getBlockHtml('formkey') ?>
    </form>
</div>
