<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2018-2024 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/** @var Mage_Bundle_Block_Adminhtml_Sales_Order_Items_Renderer $this */
?>
<?php $_item = $this->getItem() ?>
<?php $items = $this->getChilds($_item); ?>
<?php $_count = count ($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>

<?php if($this->getOrderOptions() || $_item->getDescription()): ?>
    <?php $_showlastRow = true ?>
<?php else: ?>
    <?php $_showlastRow = false ?>
<?php endif ?>

<?php foreach ($items as $_item): ?>
    <?php $this->setPriceDataObject($_item) ?>
    <?php if ($_item->getOrderItem()->getParentItem()): ?>
        <?php $attributes = $this->getSelectionAttributes($_item) ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
        <tr>
            <td><div class="option-label"><?= $this->escapeHtml($attributes['option_label']) ?></div></td>
            <td>&nbsp;</td>
            <td class="last">&nbsp;</td>
        </tr>
        <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif ?>
    <?php endif ?>
    <tr class="<?= (++$_index==$_count && !$_showlastRow)?'border':'' ?>">
        <?php if (!$_item->getOrderItem()->getParentItem()): ?>
        <td><h5 class="title"><?= $this->escapeHtml($_item->getName()) ?></h5>
            <div>
                <strong><?= $this->helper('sales')->__('SKU') ?>:</strong>
                <?= implode('<br />', Mage::helper('catalog')->splitSku($this->escapeHtml($_item->getSku()))) ?>
            </div>
        </td>
        <?php else: ?>
        <td><div class="option-value"><?= $this->getValueHtml($_item) ?></div></td>
        <?php endif ?>
        <td>
            <?php if ($this->isShipmentSeparately($_item)): ?>
                <?= $this->getColumnHtml($_item, 'qty') ?>
            <?php else: ?>
                &nbsp;
            <?php endif ?>
        </td>
        <td class="last">
            <?php if ($this->isShipmentSeparately($_item)): ?>
                <input type="text" class="input-text" name="shipment[items][<?= $_item->getOrderItemId() ?>]" value="<?= $_item->getQty()*1 ?>" />
            <?php else: ?>
                &nbsp;
            <?php endif ?>
        </td>
    </tr>
<?php endforeach ?>
<?php if($_showlastRow): ?>
    <tr class="border">
        <td>
            <?php if ($this->getOrderOptions($_item->getOrderItem())): ?>
                <dl class="item-options">
                <?php foreach ($this->getOrderOptions($_item->getOrderItem()) as $option): ?>
                    <dt><?= $this->escapeHtml($option['label']) ?></dt>
                    <dd>
                    <?php if (isset($option['custom_view']) && $option['custom_view']): ?>
                        <?= $option['value'] ?>
                    <?php else: ?>
                        <?= Mage::helper('core/string')->truncate($option['value'], 55, '', $_remainder) ?>
                        <?php if ($_remainder):?>
                            ... <span id="<?= $_id = 'id' . uniqid()?>"><?= $_remainder ?></span>
                            <script type="text/javascript">
                            $('<?= $_id ?>').hide();
                            $('<?= $_id ?>').up().observe('mouseover', function(){$('<?= $_id ?>').show();});
                            $('<?= $_id ?>').up().observe('mouseout',  function(){$('<?= $_id ?>').hide();});
                            </script>
                        <?php endif ?>
                    <?php endif ?>
                    </dd>
                <?php endforeach ?>
                </dl>
                        <?php else: ?>
                &nbsp;
                        <?php endif ?>
            <?= $this->escapeHtml($_item->getDescription()) ?>
        </td>
        <td>&nbsp;</td>
        <td class="last">&nbsp;</td>
    </tr>
<?php endif ?>
