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

// phpcs:disable Generic.Files.LineLength
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper
?>
<?php
/**
 * Ship to multiple address template
 *
 * @var $block \Magento\Multishipping\Block\Checkout\Addresses
 */
?>
<form id="checkout_multishipping_form"
      data-mage-init='{
          "multiShipping": {"itemsQty": <?= /* @noEscape */ (int)$block->getCheckout()->getQuote()->getItemsSummaryQty() ?>},
          "cartUpdate": {
               "validationURL": "<?= $block->escapeUrl($block->getUrl('multishipping/checkout/checkItems')) ?>",
               "eventName": "updateMulticartItemQty"
          }}'
      action="<?= $block->escapeUrl($block->getPostActionUrl()) ?>"
      method="post"
      class="multicheckout address form">
    <div class="content-heading">
        <h2><?= $block->escapeHtml(__('Please select a shipping address for applicable items.')) ?></h2>
    </div>
    <input type="hidden" name="continue" value="0" id="can_continue_flag"/>
    <input type="hidden" name="new_address" value="0" id="add_new_address_flag"/>
    <div class="table-wrapper">
        <table class="items data table multiship-addresses-table" id="multiship-addresses-table">
            <caption class="table-caption">
                <?= $block->escapeHtml(__('Please select a shipping address for applicable items.')) ?>
            </caption>
            <thead>
            <tr>
                <th class="col product" scope="col"><?= $block->escapeHtml(__('Product')) ?></th>
                <th class="col qty" scope="col"><?= $block->escapeHtml(__('Qty')) ?></th>
                <th class="col address" scope="col"><?= $block->escapeHtml(__('Send To')) ?></th>
                <th class="col actions" scope="col">&nbsp;</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($block->getItems() as $_index => $_item): ?>
                <?php if ($_item->getQuoteItem()): ?>
                    <tr>
                        <td class="col product" data-th="<?= $block->escapeHtml(__('Product')) ?>">
                            <?= $block->getItemHtml($_item->getQuoteItem()) ?>
                        </td>
                        <td class="col qty" data-th="<?= $block->escapeHtml(__('Qty')) ?>">
                            <div class="field qty">
                                <label for="ship-<?= $block->escapeHtml($_index) ?>-<?= $block->escapeHtml($_item->getQuoteItemId()) ?>-qty"
                                       class="label">
                                    <span><?= $block->escapeHtml(__('Qty')) ?></span>
                                </label>
                                <div class="control">
                                    <input type="number"
                                           data-multiship-item-id="<?= $block->escapeHtml($_item->getSku()) ?>"
                                           id="ship-<?= $block->escapeHtml($_index) ?>-<?= $block->escapeHtml($_item->getQuoteItemId()) ?>-qty"
                                           name="ship[<?= $block->escapeHtml($_index) ?>][<?= $block->escapeHtml($_item->getQuoteItemId()) ?>][qty]"
                                           value="<?= $block->escapeHtml($_item->getQty()) ?>"
                                           size="2"
                                           min="0"
                                           class="input-text qty"
                                           data-validate="{number: true, required:true, 'validate-greater-than-zero':true}"/>
                                </div>
                            </div>
                        </td>
                        <td class="col address" data-th="<?= $block->escapeHtml(__('Send To')) ?>">
                            <?php if ($_item->getProduct()->getIsVirtual()): ?>
                                <div class="applicable">
                                    <?= $block->escapeHtml(__('A shipping selection is not applicable.')) ?>
                                </div>
                            <?php else: ?>
                                <div class="field address">
                                    <label for="ship_<?= $block->escapeHtml($_index) ?>_<?= $block->escapeHtml($_item->getQuoteItemId()) ?>_address"
                                           class="label">
                                        <span><?= $block->escapeHtml(__('Send To')) ?></span>
                                    </label>
                                    <div class="control">
                                        <?= $block->getAddressesHtmlSelect($_item, $_index) ?>
                                    </div>
                                </div>
                            <?php endif; ?>
                        </td>
                        <td class="col actions" data-th="<?= $block->escapeHtml(__('Actions')) ?>">
                            <a href="#"
                               title="<?= $block->escapeHtml(__('Remove Item')) ?>"
                               data-post='<?= /* @noEscape */
                                $this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
                                   ->getPostData($block->getItemDeleteUrl($_item))
                                ?>'
                               class="action delete"
                               data-multiship-item-remove="">
                                <span class="fa fa-times"></span>
                            </a>
                        </td>
                    </tr>
                <?php endif; ?>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <div class="actions-toolbar-table">
        <div class="line">
            <div class="col-des-4 col-tb-4 col-mb-12">
                <button type="submit"
                        data-multiship-item-update=""
                        class="action btn-full btn btn-default update"
                        data-role="can-continue"
                        data-flag="0">
                    <span><?= $block->escapeHtml(__('Update Qty &amp; Addresses')) ?></span>
                </button>
            </div>
            <div class="col-des-4 col-tb-4 col-mb-12">
                <button type="button"
                        title="<?= $block->escapeHtml(__('Enter a New Address')) ?>"
                        class="action btn-full btn btn-primary add"
                        data-role="add-new-address">
                    <span><?= $block->escapeHtml(__('Enter a New Address')) ?></span>
                </button>
            </div>
            <div class="col-des-4 col-tb-4 col-mb-12">
                <button type="submit"
                        title="<?= $block->escapeHtml(__('Go to Shipping Information')) ?>"
                        class="action btn btn-secondary btn-full continue<?= $block->isContinueDisabled() ? ' disabled' : '' ?>"
                        data-role="can-continue"
                        data-flag="1"
                    <?php if ($block->isContinueDisabled()): ?>
                        disabled="disabled"
                    <?php endif; ?>>
                    <span><?= $block->escapeHtml(__('Go to Shipping Information')) ?></span>
                </button>
            </div>
        </div>
    </div>
</form>
