<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// phpcs:disable Magento2.Files.LineLength, Magento2.Templates.ThisInTemplate

?>
<?php
/**
 * Multishipping checkout shipping template
 *
 * @var $block \Magento\Multishipping\Block\Checkout\Shipping
 */
?>
<form action="<?= $block->escapeUrl($block->getPostActionUrl()) ?>" method="post" id="shipping_method_form" class="form multicheckout shipping">
    <?php foreach ($block->getAddresses() as $_index => $_address) : ?>
    <div class="block block-shipping">
        <div class="block-title"><strong><?= $block->escapeHtml(__('Address %1 <span>of %2</span>', ($_index+1), $block->getAddressCount()), ['span']) ?></strong></div>
        <div class="block-content">
            <div class="box box-shipping-address">
                <strong class="box-title">
                    <span><?= $block->escapeHtml(__('Shipping To')) ?></span>
                    <a href="<?= $block->escapeUrl($block->getAddressEditUrl($_address)) ?>" class="action edit">
                        <span><?= $block->escapeHtml(__('Change')) ?></span>
                    </a>
                </strong>
                <div class="box-content">
                    <address><?= /* @noEscape */ $_address->format('html') ?></address>
                </div>
            </div>
            <div class="box box-shipping-method">
                <strong class="box-title">
                    <span><?= $block->escapeHtml(__('Shipping Method')) ?></span>
                </strong>
                <div class="box-content">
                    <?php if (!($_shippingRateGroups = $block->getShippingRates($_address))) : ?>
                        <p><?= $block->escapeHtml(__('Sorry, no quotes are available for this order right now.')) ?></p>
                    <?php else : ?>
                    <dl class="items methods-shipping">
                        <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates) : ?>
                            <dt class="item-title"><?= $block->escapeHtml($block->getCarrierName($code)) ?></dt>
                            <dd class="item-content">
                                <fieldset class="fieldset">
                                    <legend class="legend">
                                        <span><?= $block->escapeHtml($block->getCarrierName($code)) ?></span>
                                    </legend><br>
                                    <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate) : ?>
                                    <div class="field choice">
                                        <?php if ($_rate->getErrorMessage()) : ?>
                                        <strong><?= $block->escapeHtml($_rate->getCarrierTitle()) ?>: <?= $block->escapeHtml($_rate->getErrorMessage()) ?></strong>
                                        <?php else : ?>
                                        <div class="control">
                                            <?php if ($_sole) : ?>
                                                <input type="radio" name="shipping_method[<?= (int) $_address->getId() ?>]" value="<?= $block->escapeHtmlAttr($_rate->getCode()) ?>" id="s_method_<?= (int) $_address->getId() ?>_<?= $block->escapeHtmlAttr($_rate->getCode()) ?>" class="radio solo method" checked="checked"/>
                                            <?php else : ?>
                                                <input type="radio" name="shipping_method[<?= (int) $_address->getId() ?>]" value="<?= $block->escapeHtmlAttr($_rate->getCode()) ?>" id="s_method_<?= (int) $_address->getId() ?>_<?= $block->escapeHtmlAttr($_rate->getCode()) ?>" <?= ($_rate->getCode()===$block->getAddressShippingMethod($_address)) ? ' checked="checked"' : '' ?> class="radio" />
                                            <?php endif; ?>
                                        </div>
                                        <label for="s_method_<?= (int) $_address->getId() ?>_<?= $block->escapeHtmlAttr($_rate->getCode()) ?>">
                                            <?= $block->escapeHtml($_rate->getMethodTitle()) ?>
                                            <?php $_excl = $block->getShippingPrice($_address, $_rate->getPrice(), $this->helper(Magento\Tax\Helper\Data::class)->displayShippingPriceIncludingTax()); ?>
                                            <?php $_incl = $block->getShippingPrice($_address, $_rate->getPrice(), true); ?>
                                            <?php if ($this->helper(Magento\Tax\Helper\Data::class)->displayShippingBothPrices() && $_incl != $_excl) : ?>
                                            <span class="price-including-tax" data-label="<?= $block->escapeHtml(__('Incl. Tax')) ?>">
                                            <?php endif; ?>
                                                <?= $block->escapeHtml($_incl, ['span']) ?>
                                            <?php if ($this->helper(Magento\Tax\Helper\Data::class)->displayShippingBothPrices() && $_incl != $_excl) : ?>
                                            </span>
                                            <?php endif; ?>
                                            <?php if ($this->helper(Magento\Tax\Helper\Data::class)->displayShippingBothPrices() && $_incl != $_excl) : ?>
                                            <span class="price-excluding-tax" data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">
                                                <?= $block->escapeHtml($_excl, ['span']) ?>
                                            </span>
                                            <?php endif; ?>
                                        </label>
                                        <?php endif ?>
                                    </div>
                                    <?php endforeach; ?>
                                </fieldset>
                            </dd>
                        <?php endforeach; ?>
                    </dl>
                    <?php endif; ?>
                    <?= /* @noEscape */ $block->getItemsBoxTextAfter($_address) ?>
                </div>
            </div>
            <div class="box box-items">
                <strong class="box-title">
                    <span><?= $block->escapeHtml(__('Items')) ?></span>
                    <a href="<?= $block->escapeUrl($block->getItemsEditUrl($_address)) ?>" class="action edit"><span><?= $block->escapeHtml(__('Edit Items')) ?></span></a>
                </strong>
                <div class="box-content">
                    <div class="table-wrapper">
                        <table class="items data table" id="shipping-table-<?= (int) $_address->getId() ?>">
                            <caption class="table-caption"><?= $block->escapeHtml(__('Items')) ?></caption>
                            <thead>
                            <tr>
                                <th class="col item" scope="col"><?= $block->escapeHtml(__('Product Name')) ?></th>
                                <th class="col qty" scope="col"><?= $block->escapeHtml(__('Qty')) ?></th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($block->getAddressItems($_address) as $_item) : ?>
                                <tr>
                                    <td class="col item" data-th="<?= $block->escapeHtmlAttr(__('Product Name')) ?>"><?= $block->getItemHtml($_item->getQuoteItem()) ?></td>
                                    <td class="col qty" data-th="<?= $block->escapeHtmlAttr(__('Qty')) ?>"><?= $block->escapeHtml($_item->getQty()) ?></td>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php endforeach; ?>
    <?= $block->getChildHtml('checkout_billing_items') ?>
    <div class="actions-toolbar">
        <div class="primary">
            <button class="action primary continue" type="submit"><span><?= $block->escapeHtml(__('Continue to Billing Information')) ?></span></button>
        </div>
        <div class="secondary">
            <a href="<?= $block->escapeUrl($block->getBackUrl()) ?>" class="action back"><span><?= $block->escapeHtml(__('Back to Select Addresses')) ?></span></a>
        </div>
    </div>
</form>
