<?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 $attributes = $this->getSelectionAttributes($_item) ?>
    <?php if ($_item->getOrderItem()->getParentItem()): ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
        <tr>
            <td><div class="option-label"><?= $this->escapeHtml($attributes['option_label']) ?></div></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td class="last">&nbsp;</td>
        </tr>
        <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif ?>
    <?php endif ?>
    <tr<?= (++$_index==$_count && !$_showlastRow)?' class="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 class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
                    <span class="price-excl-tax">
                        <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
                            <span class="label"><?= $this->__('Excl. Tax') ?>:</span>
                        <?php endif ?>

                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, [0, 1, 4], 'sales')): ?>
                            <?php
                            echo $this->displayPrices(
                                $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
                                $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
                            );
                            ?>
                        <?php else: ?>
                            <?= $this->displayPrices($_item->getBasePrice(), $_item->getPrice()) ?>
                        <?php endif ?>


                        <?php if (Mage::helper('weee')->getApplied($_item)): ?>
                            <br />
                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_amount'], $tax['amount']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><small><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_amount'], $tax['amount']) ?></small></span>
                                <?php endforeach ?>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_amount'], $tax['amount']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php endif ?>

                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <br />
                                <span class="nobr"><?= Mage::helper('weee')->__('Total') ?>:<br />
                                <?php
                                echo $this->displayPrices(
                                    $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
                                    $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
                                );
                                ?>
                                </span>
                            <?php endif ?>
                        <?php endif ?>
                    </span>
                    <br />
                <?php endif ?>
                <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
                    <span class="price-incl-tax">
                        <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
                            <span class="label"><?= $this->__('Incl. Tax') ?>:</span>
                        <?php endif ?>
                        <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
                        <?php $_baseIncl = $this->helper('checkout')->getBasePriceInclTax($_item); ?>

                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, [0, 1, 4], 'sales')): ?>
                            <?= $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)) ?>
                        <?php else: ?>
                            <?= $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxDisposition(), $_incl-$_item->getWeeeTaxDisposition()) ?>
                        <?php endif ?>

                        <?php if (Mage::helper('weee')->getApplied($_item)): ?>
                            <br />
                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><small><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']) ?></small></span>
                                <?php endforeach ?>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php endif ?>

                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <br />
                                <span class="nobr"><?= Mage::helper('weee')->__('Total') ?>:<br /> <?= $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)) ?></span>
                            <?php endif ?>
                        <?php endif ?>
                    </span>
                <?php endif ?>
            <?php else: ?>
                &nbsp;
            <?php endif ?>
        </td>
        <td class="a-center">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?= $_item->getQty()*1 ?>
            <?php else: ?>
                &nbsp;
                        <?php endif ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
                    <span class="price-excl-tax">
                        <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
                            <span class="label"><?= $this->__('Excl. Tax') ?>:</span>
                        <?php endif ?>

                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, [0, 1, 4], 'sales')): ?>
                            <?php
                            echo $this->displayPrices(
                                $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
                                $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
                            );
                            ?>
                        <?php else: ?>
                            <?= $this->displayPrices($_item->getBaseRowTotal(), $_item->getRowTotal()) ?>
                        <?php endif ?>


                        <?php if (Mage::helper('weee')->getApplied($_item)): ?>
                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_row_amount'], $tax['row_amount']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><small><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_row_amount'], $tax['row_amount']) ?></small></span>
                                <?php endforeach ?>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_row_amount'], $tax['row_amount']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php endif ?>

                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <br />
                                <span class="nobr"><?= Mage::helper('weee')->__('Total') ?>:<br />
                                <?php
                                echo $this->displayPrices(
                                    $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
                                    $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
                                );
                                ?>
                                </span>
                            <?php endif ?>
                        <?php endif ?>
                    </span>
                    <br />
                <?php endif ?>
                <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
                    <span class="price-incl-tax">
                        <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
                            <span class="label"><?= $this->__('Incl. Tax') ?>:</span>
                        <?php endif ?>
                        <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
                        <?php $_baseIncl = $this->helper('checkout')->getBaseSubtotalInclTax($_item); ?>
                        <?php if (Mage::helper('weee')->typeOfDisplay($_item, [0, 1, 4], 'sales')): ?>
                            <?= $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)) ?>
                        <?php else: ?>
                            <?= $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxRowDisposition(), $_incl-$_item->getWeeeTaxRowDisposition()) ?>
                        <?php endif ?>


                        <?php if (Mage::helper('weee')->getApplied($_item)): ?>

                            <br />
                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><small><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']) ?></small></span>
                                <?php endforeach ?>
                            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                                <small>
                                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                                    <span class="nobr"><?= $tax['title'] ?>: <?= $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']) ?></span>
                                <?php endforeach ?>
                                </small>
                            <?php endif ?>

                            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                                <br /><span class="nobr"><?= Mage::helper('weee')->__('Total') ?>:<br /> <?= $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)) ?></span>
                            <?php endif ?>
                        <?php endif ?>
                    </span>
                <?php endif ?>
                </span>
            <?php else: ?>
                &nbsp;
            <?php endif ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?= $this->displayPriceAttribute('tax_amount') ?>
            <?php else: ?>
                &nbsp;
                        <?php endif ?>
        </td>
        <td class="a-right">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?= $this->displayPriceAttribute('discount_amount') ?>
            <?php else: ?>
                &nbsp;
                        <?php endif ?>
        </td>
        <td class="a-right last">
            <?php if ($this->canShowPriceInfo($_item)): ?>
                <?php echo $this->displayPrices(
                    $_item->getBaseRowTotal() - $_item->getBaseDiscountAmount() + $_item->getBaseTaxAmount() + $_item->getBaseHiddenTaxAmount() + $_item->getBaseWeeeTaxAppliedRowAmount(),
                    $_item->getRowTotal() - $_item->getDiscountAmount() + $_item->getTaxAmount() + $_item->getHiddenTaxAmount() + $_item->getWeeeTaxAppliedRowAmount()
                ) ?>
            <?php else: ?>
                &nbsp;
            <?php endif ?>
        </td>
    </tr>
<?php endforeach ?>
<?php if($_showlastRow): ?>
    <tr class="border">
        <td>
            <?php if ($this->getOrderOptions()): ?>
                <dl class="item-options">
                <?php foreach ($this->getOrderOptions() 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 endif ?>
            <?= $this->escapeHtml($this->getItem()->getDescription()) ?>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="last">&nbsp;</td>
    </tr>
<?php endif ?>
