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

/** @var \Magento\Multishipping\Block\Checkout\Overview $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>

<?php
/** @var \Magento\Tax\Helper\Data $taxHelper */
$taxHelper = $block->getData('taxHelper');
/** @var \Magento\Checkout\Helper\Data $checkoutHelper */
$checkoutHelper = $block->getData('checkoutHelper');
?>
<?php $errors = $block->getCheckoutData()->getAddressErrors(); ?>
<?php foreach ($errors as $addressId => $error): ?>
    <div class="message message-error error">
        <?= $block->escapeHtml($error); ?>
        <?= $block->escapeHtml(__('Please see')); ?>
        <a href="#<?= $block->escapeHtml($block->getCheckoutData()->getAddressAnchorName($addressId)); ?>">
            <?= $block->escapeHtml(__('details below')); ?></a>.
    </div>
<?php endforeach;?>
<form action="<?= $block->escapeUrl($block->getPostActionUrl()); ?>"
      method="post"
      id="review-order-form"
      data-mage-init='{"orderOverview": {}, "validation":{}}'
      class="form multicheckout order-review">
    <?= /* @noEscape */ $block->getBlockHtml('formkey'); ?>
    <div class="block block-billing">
        <div class="content-heading"><h3 class="title"><?= $block->escapeHtml(__('Billing Information')); ?></h3></div>
        <div class="block-content">
            <div class="box box-billing-address">
                <?php $address = $block->getBillingAddress() ?>
                <h4 class="box-title">
                    <span><?= $block->escapeHtml(__('Billing Address')); ?></span>

                </h4>
                <div class="box-content">
                    <address>
                        <?= /* @noEscape */ $address->format('html') ?>
                    </address>
                </div>
                <a href="<?= $block->escapeUrl($block->getEditBillingAddressUrl($address)); ?>"
                   class="action btn btn-secondary btn-xs edit"><span><?= $block->escapeHtml(__('Change')); ?></span></a>
            </div>
            <div class="box box-billing-method">
                <h4 class="box-title">
                    <span><?= $block->escapeHtml(__('Payment Method')); ?></span>

                </h4>
                <div class="box-content">
                    <input type="hidden"
                           name="payment[cc_number]"
                           value="<?= $block->escapeHtml($block->getPayment()->getCcNumber()) ?>" />
                    <input type="hidden"
                           name="payment[cc_cid]"
                           value="<?= $block->escapeHtml($block->getPayment()->getCcCid()) ?>" />
                    <?= /* @noEscape */ $block->getPaymentHtml() ?>
                </div>
                <a href="<?= $block->escapeUrl($block->getEditBillingUrl()); ?>"
                   class="action btn btn-secondary btn-xs edit"><span><?= $block->escapeHtml(__('Change')); ?></span></a>
            </div>
        </div>
    </div>
    <div class="block block-shipping">
        <div class="content-heading"><h3 class="title"><?= $block->escapeHtml(__('Shipping Information')); ?></h3></div>
        <?php $mergedCells = ($taxHelper->displayCartBothPrices() ? 2 : 1); ?>
        <?php foreach ($block->getShippingAddresses() as $index => $address): ?>
            <div class="block-content">
                <a name="<?= $block->escapeHtml($block->getCheckoutData()
                    ->getAddressAnchorName($address->getId())); ?>"></a>
                <h4 class="title">
                    <span><?= $block->escapeHtml(__('Address')); ?> <?= $block->escapeHtml($index + 1); ?>
                        <span>
                            <?= $block->escapeHtml(__('of')); ?>
                            <?= $block->escapeHtml($block->getShippingAddressCount())?>
                        </span>
                    </span>
                </h4>
                <?php if ($error = $block->getCheckoutData()->getAddressError($address)): ?>
                    <div class="error-description"><?= $block->escapeHtml($error); ?></div>
                <?php endif;?>
                <div class="box box-shipping-address">
                    <strong class="box-title">
                        <span><?= $block->escapeHtml(__('Shipping To')); ?></span>

                    </strong>
                    <div class="box-content">
                        <address>
                            <?= /* @noEscape */ $address->format('html') ?>
                        </address>
                    </div>
                    <a href="<?= $block->escapeUrl($block->getEditShippingAddressUrl($address)); ?>"
                       class="action btn btn-secondary btn-xs edit"><span><?= $block->escapeHtml(__('Change')); ?></span></a>
                </div>
                <div class="box box-shipping-method">
                    <strong class="box-title">
                        <span><?= $block->escapeHtml(__('Shipping Method')); ?></span>

                    </strong>
                    <?php if ($_rate = $block->getShippingAddressRate($address)): ?>
                        <div class="box-content">
                            <?= $block->escapeHtml($_rate->getCarrierTitle()) ?>
                            (<?= $block->escapeHtml($_rate->getMethodTitle()) ?>)
                            <?php
                            $exclTax = $block->getShippingPriceExclTax($address);
                            $inclTax = $block->getShippingPriceInclTax($address);
                            $displayBothPrices = $taxHelper->displayShippingBothPrices() && $inclTax !== $exclTax;
                            ?>
                            <?php if ($displayBothPrices): ?>
                                <span class="price-including-tax"
                                      data-label="<?= $block->escapeHtml(__('Incl. Tax')); ?>">
                                    <?= /* @noEscape */ $inclTax ?>
                                </span>
                                <span class="price-excluding-tax"
                                      data-label="<?= $block->escapeHtml(__('Excl. Tax')); ?>">
                                    <?= /* @noEscape */ $exclTax; ?>
                                </span>
                            <?php else: ?>
                                <?= /* @noEscape */ $inclTax ?>
                            <?php  endif; ?>
                        </div>
                    <?php endif; ?>
                    <a href="<?= $block->escapeUrl($block->getEditShippingUrl()); ?>"
                       class="action btn btn-secondary btn-xs edit"><span><?= $block->escapeHtml(__('Change')); ?></span></a>
                </div>
                <div class="box box-items">
                    <div class="box-content">
                        <div class="order-review-wrapper table-wrapper">
                            <table class="items data table table-order-review"
                                   id="overview-table-<?= $block->escapeHtml($address->getId()); ?>">
                                <caption class="table-caption"><?= $block->escapeHtml(__('Order Review')); ?></caption>
                                <thead>
                                <tr>
                                    <th class="col item" scope="col"><?= $block->escapeHtml(__('Item')); ?>
                                        <a href="<?= $block->escapeUrl($block->getAddressesEditUrl()); ?>"
                                           class="action edit">
                                            <span class="fa fa-pencil"></span>
                                        </a>
                                    </th>
                                    <th class="col price" scope="col"><?= $block->escapeHtml(__('Price')); ?></th>
                                    <th class="col qty" scope="col"><?= $block->escapeHtml(__('Qty')); ?></th>
                                    <th class="col subtotal" scope="col"><?= $block->escapeHtml(__('Subtotal')); ?></th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($block->getShippingAddressItems($address) as $item): ?>
                                    <?= /* @noEscape */ $block->getRowItemHtml($item) ?>
                                <?php endforeach; ?>
                                </tbody>
                                <tfoot>
                                    <?= /* @noEscape */ $block->renderTotals(
                                        $block->getShippingAddressTotals($address)
                                    ); ?>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>

    <?php if ($block->getQuote()->hasVirtualItems()): ?>
    <div class="block block-other">
        <?php $billingAddress = $block->getQuote()->getBillingAddress(); ?>
        <a name="<?= $block->escapeHtml($block->getCheckoutData()
            ->getAddressAnchorName($billingAddress->getId())); ?>"></a>
        <div class="box-title"><h4><?= $block->escapeHtml(__('Other items in your order')); ?></h4></div>
        <?php if ($error = $block->getCheckoutData()->getAddressError($billingAddress)): ?>
                <div class="error-description"><?= $block->escapeHtml($error); ?></div>
        <?php endif;?>
        <div class="block-content">
            <strong class="subtitle">
                <span><?= $block->escapeHtml(__('Items')); ?></span>
                <a href="<?= $block->escapeUrl($block->getVirtualProductEditUrl()); ?>"
                   class="action edit"><span class="fa fa-pencil"></span></a>
            </strong>
            <?php $mergedCells = ($taxHelper->displayCartBothPrices() ? 2 : 1); ?>
            <div class="order-review-wrapper table-wrapper">
                <table class="items data table table-order-review" id="virtual-overview-table">
                    <caption class="table-caption"><?= $block->escapeHtml(__('Items')); ?></caption>
                    <thead>
                        <tr>
                            <th class="col item" scope="col"><?= $block->escapeHtml(__('Product Name')); ?></th>
                            <th class="col price" scope="col"><?= $block->escapeHtml(__('Price')); ?></th>
                            <th class="col qty" scope="col"><?= $block->escapeHtml(__('Qty')); ?></th>
                            <th class="col subtotal" scope="col"><?= $block->escapeHtml(__('Subtotal')); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($block->getVirtualItems() as $_item): ?>
                            <?= /* @noEscape */ $block->getRowItemHtml($_item) ?>
                        <?php endforeach; ?>
                    </tbody>
                    <tfoot>
                    <?= /* @noEscape */ $block->renderTotals($block->getBillingAddressTotals()); ?>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?= /* @noEscape */ $block->getChildHtml('items_after') ?>

    <div id="checkout-review-submit" class="checkout-review">
        <?= /* @noEscape */ $block->getChildHtml('agreements') ?>
        <div class="grand totals">
            <strong class="mark"><?= $block->escapeHtml(__('Grand Total:')); ?></strong>
            <strong class="amount">
                <?= /* @noEscape */ $checkoutHelper->formatPrice($block->getTotal()); ?>
            </strong>
        </div>
        <div class="actions-toolbar action-finish-checkout" id="review-buttons-container">
            <?= $block->getChildHtml('captcha') ?>
            <button type="submit"
                    class="action btn btn-primary btn-lg submit"
                    id="review-button"><span><?= $block->escapeHtml(__('Place Order')); ?></span>
            </button>
            <a href="<?= $block->escapeUrl($block->getBackUrl()); ?>" class="action back">
                <span><?= $block->escapeHtml(__('Back to Billing Information')); ?></span>
            </a>
            <span id="review-please-wait"
                  class="please-wait load indicator"
                  data-text="<?= $block->escapeHtml(__('Submitting order information...')); ?>">
                <span><?= $block->escapeHtml(__('Submitting order information...')); ?></span>
            </span>
            <?= /* @noEscape */ $secureRenderer->renderStyleAsTag('display: none;', 'span#review-please-wait') ?>
        </div>
    </div>
</form>
