<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
// phpcs:disable Magento2.Templates.ThisInTemplate
// phpcs:disable Generic.Files.LineLength
/** @var \Magento\Framework\Locale\LocaleFormatter $localeFormatter */
?>
<?php /** @var $block \Magento\Bundle\Block\Sales\Order\Items\Renderer */ ?>
<?php $parentItem = $block->getItem() ?>
<?php $_order = $block->getItem()->getOrderItem()->getOrder() ?>

<?php $items = $block->getChildren($parentItem) ?>
<?php $_index = 0 ?>

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

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

    <?php if ($_item->getOrderItem()->getParentItem()): ?>
        <?php $attributes = $block->getSelectionAttributes($_item) ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
            <tr class="options-label">
                <td class="col label" colspan="5">
                    <div class="option label"><?= $block->escapeHtml($attributes['option_label']) ?></div>
                </td>
            </tr>
            <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif; ?>
    <?php endif; ?>
    <tr id="order-item-row-<?= $block->escapeHtmlAttr($_item->getId()) ?>"
        class="<?php if ($_item->getOrderItem()->getParentItem()): ?>item-options-container
        <?php else: ?>item-parent
        <?php endif; ?>"
        <?php if ($_item->getOrderItem()->getParentItem()): ?>
            data-th="<?= $block->escapeHtmlAttr($attributes['option_label']) ?>"
        <?php endif; ?>>
    <?php if (!$_item->getOrderItem()->getParentItem()): ?>
        <td class="col name" data-th="<?= $block->escapeHtmlAttr(__('Product Name')) ?>">
            <strong class="product name product-item-name"><?= $block->escapeHtml($_item->getName()) ?></strong>
        </td>
    <?php else: ?>
        <td class="col value" data-th="<?= $block->escapeHtmlAttr(__('Product Name')) ?>"><?= $block->getValueHtml($_item) ?></td>
    <?php endif; ?>
    <td class="col sku" data-th="<?= $block->escapeHtmlAttr(__('SKU')) ?>"><?= $block->escapeHtml($_item->getSku()) ?></td>
    <td class="col price" data-th="<?= $block->escapeHtmlAttr(__('Price')) ?>">
        <?php if ($block->canShowPriceInfo($_item)): ?>
            <?= $block->getItemPriceHtml($_item) ?>
        <?php else: ?>
            &nbsp;
        <?php endif; ?>
    </td>
    <td class="col qty" data-th="<?= $block->escapeHtmlAttr(__('Qty Invoiced')) ?>">
        <?php if ($block->canShowPriceInfo($_item)): ?>
            <?= /* @noEscape */ $localeFormatter->formatNumber((float)$_item->getQty() * 1) ?>
        <?php else: ?>
            &nbsp;
        <?php endif; ?>
    </td>
    <td class="col subtotal" data-th="<?= $block->escapeHtmlAttr(__('Subtotal')) ?>">
        <?php if ($block->canShowPriceInfo($_item)): ?>
            <?= $block->getItemRowTotalHtml($_item) ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
    </tr>
<?php endforeach; ?>

<?php if ($_showlastRow && (($_options = $block->getItemOptions()) || $block->escapeHtml($_item->getDescription()))): ?>
    <tr>
        <td class="col options" colspan="5">
            <?php if ($_options = $block->getItemOptions()): ?>
                <dl class="item-options">
                    <?php foreach ($_options as $_option): ?>
                        <dt><?= $block->escapeHtml($_option['label']) ?></dt>
                        <?php if (!$block->getPrintStatus()): ?>
                            <?php $_formatedOptionValue = $block->getFormatedOptionValue($_option) ?>
                            <dd<?php if (isset($_formatedOptionValue['full_view'])): ?> class="tooltip wrapper"<?php endif; ?>>
                                <?= /* @noEscape */ $_formatedOptionValue['value'] ?>
                                <?php if (isset($_formatedOptionValue['full_view'])): ?>
                                    <div class="tooltip content">
                                        <dl class="item options">
                                            <dt><?= $block->escapeHtml($_option['label']) ?></dt>
                                            <dd><?= /* @noEscape */ $_formatedOptionValue['full_view'] ?></dd>
                                        </dl>
                                    </div>
                                <?php endif; ?>
                            </dd>
                        <?php else: ?>
                            <dd><?= $block->escapeHtml((isset($_option['print_value']) ? $_option['print_value']: $_option['value'])) ?></dd>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </dl>
            <?php endif; ?>
            <?= $block->escapeHtml($_item->getDescription()) ?>
        </td>
    </tr>
<?php endif; ?>
