<?php
// @codingStandardsIgnoreFile

$order = $block->getOrder();
?>
<div class="cs-table cs-table--tablet-small order-items">
    <table 
        class="cs-table__body | table-order-items" 
        id="my-orders-table" 
        summary="<?php /* @escapeNotVerified */ echo __('Items Ordered') ?>"
    >
        <caption class="cs-visually-hidden"><?php /* @escapeNotVerified */ echo __('Items Ordered') ?></caption>
        <thead class="cs-table__head">
            <tr>
                <th class="cs-table__col-head | name"><?php /* @escapeNotVerified */ echo __('Product Name') ?></th>
                <th class="cs-table__col-head | sku"><?php /* @escapeNotVerified */ echo __('SKU') ?></th>
                <th class="cs-table__col-head | price"><?php /* @escapeNotVerified */ echo __('Price') ?></th>
                <th class="cs-table__col-head | qty"><?php /* @escapeNotVerified */ echo __('Qty') ?></th>
                <th class="cs-table__col-head | subtotal"><?php /* @escapeNotVerified */ echo __('Subtotal') ?></th>
            </tr>
        </thead>
        <?php 
            $items = $order->getItemsCollection();  
            $index = 0;  
            $count = $items->count(); 
            $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);
                $itemId = $item->getId();
                ?>
                <tr>
                    <td class="cs-table__col | options" colspan="5">
                        <a 
                            href="#"
                            id="order-item-gift-message-link-<?php /* @escapeNotVerified */ echo $itemId ?>"
                            class="action show"
                            aria-controls="order-item-gift-message-<?php /* @escapeNotVerified */ echo $itemId ?>"
                            data-item-id="<?php /* @escapeNotVerified */ echo $itemId ?>"
                        >
                            <?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 $itemId ?>"
                            role="region" 
                            aria-expanded="false" 
                            tabindex="-1"
                        >
                            <a 
                                href="#"
                                title="<?php /* @escapeNotVerified */ echo __('Close') ?>"
                                aria-controls="order-item-gift-message-<?php /* @escapeNotVerified */ echo $itemId ?>"
                                data-item-id="<?php /* @escapeNotVerified */ echo $itemId ?>"
                                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 class="cs-table__foot">
            <?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; ?>
