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

// @codingStandardsIgnoreFile

/** @var \Magento\Sales\Block\Order\Items $block */
?>
    <div class="table-wrapper order-items">
        <table class="data table table-order-items" id="my-orders-table" summary="<?php /* @escapeNotVerified */ echo __('Items Ordered') ?>">
            <caption class="table-caption"><?php /* @escapeNotVerified */ echo __('Items Ordered') ?></caption>
            <thead>
            <?php if($block->isPagerDisplayed()): ?>
                <tr>
                    <td colspan="5" data-block="order-items-pager-top" class="order-pager-wrapper order-pager-wrapper-top">
                        <?php echo $block->getPagerHtml() ?>
                    </td>
                </tr>
            <?php endif ?>
            <tr>
                <th class="col name"><?php /* @escapeNotVerified */ echo __('Product Name') ?></th>
                <th class="col sku"><?php /* @escapeNotVerified */ echo __('SKU') ?></th>
                <th class="col price"><?php /* @escapeNotVerified */ echo __('Price') ?></th>
                <th class="col qty"><?php /* @escapeNotVerified */ echo __('Qty') ?></th>
                <th class="col subtotal"><?php /* @escapeNotVerified */ echo __('Subtotal') ?></th>
            </tr>
            </thead>
            <?php $items = $block->getItems(); ?>
            <?php $giftMessage = ''?>
            <?php foreach ($items as $item): ?>
                <?php if ($item->getParentItem()) continue; ?>
                <tbody>
                <?php echo $block->getItemHtml($item) ?>
                <?php if ($this->helper('Magento\GiftMessage\Helper\Message')->isMessagesAllowed('order_item', $item) && $item->getGiftMessageId()): ?>
                    <?php $giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessageForEntity($item); ?>
                    <tr>
                        <td class="col options" colspan="5">
                            <a href="#"
                                id="order-item-gift-message-link-<?php /* @escapeNotVerified */ echo $item->getId() ?>"
                                class="action show"
                                aria-controls="order-item-gift-message-<?php /* @escapeNotVerified */ echo $item->getId() ?>"
                                data-item-id="<?php /* @escapeNotVerified */ echo $item->getId() ?>">
                                <?php /* @escapeNotVerified */ echo __('Gift Message') ?>
                            </a>
                            <?php $giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessageForEntity($item); ?>
                            <div class="order-gift-message" id="order-item-gift-message-<?php /* @escapeNotVerified */ echo $item->getId() ?>" role="region" aria-expanded="false" tabindex="-1">
                                <a href="#"
                                   title="<?php /* @escapeNotVerified */ echo __('Close') ?>"
                                   aria-controls="order-item-gift-message-<?php /* @escapeNotVerified */ echo $item->getId()?>"
                                   data-item-id="<?php /* @escapeNotVerified */ echo $item->getId()?>"
                                   class="action close">
                                    <?php /* @escapeNotVerified */ echo __('Close') ?>
                                </a>
                                <dl class="item-options">
                                    <dt class="item-sender"><strong class="label"><?php /* @escapeNotVerified */ echo __('From') ?></strong><?php echo $block->escapeHtml($giftMessage->getSender()) ?></dt>
                                    <dt class="item-recipient"><strong class="label"><?php /* @escapeNotVerified */ echo __('To') ?></strong><?php echo $block->escapeHtml($giftMessage->getRecipient()) ?></dt>
                                    <dd class="item-message"><?php /* @escapeNotVerified */ echo $this->helper('Magento\GiftMessage\Helper\Message')->getEscapedGiftMessage($item) ?></dd>
                                </dl>
                            </div>
                        </td>
                    </tr>
                <?php endif ?>
                </tbody>
            <?php endforeach; ?>
            <tfoot>
            <?php if($block->isPagerDisplayed()): ?>
                <tr>
                    <td colspan="5" data-block="order-items-pager-bottom" class="order-pager-wrapper order-pager-wrapper-bottom">
                        <?php echo $block->getPagerHtml();?>
                    </td>
                </tr>
            <?php endif ?>
            <?php echo $block->getChildHtml('order_totals') ?>
            </tfoot>
        </table>
    </div>
<?php if ($giftMessage): ?>
    <script type="text/x-magento-init">
    {
        "a.action.show, a.action.close": {
            "giftMessage": {}
        }
    }
</script>
<?php endif; ?>
