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

// @codingStandardsIgnoreFile

?>
<?php /** @var $block \Magento\Bundle\Block\Sales\Order\Items\Renderer */ ?>

<?php $parentItem = $block->getItem() ?>
<?php $items = array_merge([$parentItem->getOrderItem()], $parentItem->getOrderItem()->getChildrenItems()) ?>
<?php $shipItems = $block->getChildren($parentItem) ?>
<?php $_count = count($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>

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

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

    <?php if ($_item->getParentItem()): ?>
        <?php $attributes = $block->getSelectionAttributes($_item) ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
            <tr class="options-label">
                <td colspan="3" class="col label"><div class="option label"><?php /* @escapeNotVerified */ echo $attributes['option_label'] ?></div></td>
            </tr>
            <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif; ?>
    <?php endif; ?>
    <tr id="order-item-row-<?php /* @escapeNotVerified */ echo $_item->getId() ?>" class="<?php if ($_item->getParentItem()): ?>item-options-container<?php else: ?>item-parent<?php endif; ?>"<?php if ($_item->getParentItem()): ?> data-th="<?php /* @escapeNotVerified */ echo $attributes['option_label'] ?>"<?php endif; ?>>
        <?php if (!$_item->getParentItem()): ?>
            <td class="col name" data-th="<?php echo $block->escapeHtml(__('Product Name')); ?>">
                <strong class="product name product-item-name"><?php echo $block->escapeHtml($_item->getName()) ?></strong>
            </td>
        <?php else: ?>
            <td class="col value" data-th="<?php echo $block->escapeHtml(__('Product Name')); ?>"><?php echo $block->getValueHtml($_item) ?></td>
        <?php endif; ?>
        <td class="col sku" data-th="<?php echo $block->escapeHtml(__('SKU')); ?>"><?php echo $block->escapeHtml($_item->getSku()) ?></td>
        <td class="col qty" data-th="<?php echo $block->escapeHtml(__('Qty Shipped')); ?>">
            <?php if (($block->isShipmentSeparately() && $_item->getParentItem()) || (!$block->isShipmentSeparately() && !$_item->getParentItem())): ?>
                <?php if (isset($shipItems[$_item->getId()])): ?>
                    <?php /* @escapeNotVerified */ echo $shipItems[$_item->getId()]->getQty()*1 ?>
                <?php elseif ($_item->getIsVirtual()): ?>
                    <?php /* @escapeNotVerified */ echo __('N/A') ?>
                <?php else: ?>
                    0
                <?php endif; ?>
            <?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="3">
            <?php if ($_options = $block->getItemOptions()): ?>
                <dl class="item-options">
                    <?php foreach ($_options as $_option) : ?>
                        <dt><?php echo $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; ?>>
                                <?php /* @escapeNotVerified */ echo $_formatedOptionValue['value'] ?>
                                <?php if (isset($_formatedOptionValue['full_view'])): ?>
                                    <div class="tooltip content">
                                        <dl class="item options">
                                            <dt><?php echo $block->escapeHtml($_option['label']) ?></dt>
                                            <dd><?php /* @escapeNotVerified */ echo $_formatedOptionValue['full_view'] ?></dd>
                                        </dl>
                                    </div>
                                <?php endif; ?>
                            </dd>
                        <?php else: ?>
                            <dd><?php echo $block->escapeHtml((isset($_option['print_value']) ? $_option['print_value'] : $_option['value'])) ?></dd>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </dl>
            <?php endif; ?>
            <?php echo $block->escapeHtml($_item->getDescription()) ?>
        </td>
    </tr>
<?php endif; ?>
