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

// @codingStandardsIgnoreFile

?>
<?php /** @var $block \Magento\Bundle\Block\Sales\Order\Items\Renderer */ ?>
<?php $_item = $block->getItem() ?>
<?php $_order = $block->getOrder() ?>

<?php $parentItem = $block->getItem() ?>
<?php $items = array_merge([$parentItem], $parentItem->getChildrenItems()); ?>

<?php if ($block->getItemOptions() || $_item->getDescription() || $this->helper('Magento\GiftMessage\Helper\Message')->isMessagesAllowed('order_item', $_item) && $_item->getGiftMessageId()): ?>
    <?php $_showlastRow = true ?>
<?php else: ?>
    <?php $_showlastRow = false ?>
<?php endif; ?>

<?php $_prevOptionId = '' ?>

<?php foreach ($items as $_item): ?>

    <?php if ($_item->getParentItem()): ?>
        <?php $attributes = $block->getSelectionAttributes($_item) ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
            <tr class="bundle-option-label">
                <td colspan="3">
                    <strong><em><?= /* @escapeNotVerified */  $attributes['option_label'] ?></em></strong>
                </td>
            </tr>
            <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif; ?>
    <?php endif; ?>
    <?php if (!$_item->getParentItem()): ?>
        <tr class="bundle-item bundle-parent">
            <td class="item-info">
                <p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
                <p class="sku"><?= /* @escapeNotVerified */  __('SKU') ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
            </td>
            <td class="item-qty">
                <?= /* @escapeNotVerified */  $_item->getQtyOrdered() * 1 ?>
            </td>
            <td class="item-price">
                <?= /* @escapeNotVerified */  $block->getItemPrice($_item) ?>
            </td>
        </tr>
    <?php else: ?>
        <tr class="bundle-item bundle-option-value">
            <td class="item-info" colspan="3">
                <p><?= $block->getValueHtml($_item) ?></p>
            </td>
        </tr>
    <?php endif; ?>

<?php endforeach; ?>

<?php if ($_showlastRow): ?>
    <tr>
        <td colspan="3" class="item-extra">
            <?php if ($block->getItemOptions()): ?>
            <dl>
                <?php foreach ($block->getItemOptions() as $option): ?>
                <dt><strong><em><?= /* @escapeNotVerified */  $option['label'] ?></em></strong></dt>
                            <dd><?= /* @escapeNotVerified */  $option['value'] ?></dd>
                <?php endforeach; ?>
            </dl>
            <?php endif; ?>
            <?php if ($_item->getGiftMessageId() && $_giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessage($_item->getGiftMessageId())): ?>
                <table class="message-gift">
                    <tr>
                        <td>
                            <h3><?= /* @escapeNotVerified */  __('Gift Message') ?></h3>
                            <strong><?= /* @escapeNotVerified */  __('From:') ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
                            <br /><strong><?= /* @escapeNotVerified */  __('To:') ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
                            <br /><strong><?= /* @escapeNotVerified */  __('Message:') ?></strong>
                            <br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
                        </td>
                    </tr>
                </table>
            <?php endif; ?>
        </td>
    </tr>
<?php endif; ?>
