<?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="content-heading">
                <h3 class="title"><?= $block->escapeHtml(__('Address %1 <span>of %2</span>', ($_index + 1), $block->getAddressCount()), ['span']) ?></h3>
            </div>
            <div class="block-content">
                <div class="box-address-method">
                    <div class="line">
                        <div class="col-des-4 col-tb-4 col-mb-12 margin-bottom40">
                            <div class="box box-shipping-address">
                                <h4 class="box-title">
                                    <span><?= $block->escapeHtml(__('Shipping To')) ?></span>
                                </h4>
                                <div class="box-content">
                                    <address><?= /* @noEscape */
                                        $_address->format('html') ?></address>
                                </div>
                                <a href="<?= $block->escapeUrl($block->getAddressEditUrl($_address)) ?>"
                                   class="btn btn-secondary btn-xs action edit">
                                    <span><?= $block->escapeHtml(__('Change Address')) ?></span>
                                </a>
                            </div>
                        </div>
                        <div class="col-des-4 col-tb-4 col-mb-12 margin-bottom40">
                            <div class="box box-shipping-method">
                                <h4 class="box-title">
                                    <span><?= $block->escapeHtml(__('Shipping Method')) ?></span>
                                </h4>
                                <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">
                                                        <?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>
                    </div>
                </div>
                <div class="box box-items">
                    <h4 class="box-title">
                        <span><?= $block->escapeHtml(__('Items')) ?></span>
                    </h4>
                    <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>
                        <a href="<?= $block->escapeUrl($block->getItemsEditUrl($_address)) ?>"
                           class="btn btn-xs btn-secondary action edit"><span><?= $block->escapeHtml(__('Edit Items')) ?></span></a>
                    </div>
                </div>
            </div>
        </div>
    <?php endforeach; ?>
    <?= $block->getChildHtml('checkout_billing_items') ?>
    <div class="actions-toolbar-form">
        <a href="<?= $block->escapeUrl($block->getBackUrl()) ?>"
           class="action btn btn-full btn-default back"><span><?= $block->escapeHtml(__('Back to Select Addresses')) ?></span></a>
        <button class="action btn btn-full btn-primary continue" type="submit">
            <span><?= $block->escapeHtml(__('Continue to Billing Information')) ?></span></button>
    </div>
</form>
