<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-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_Adminhtml_Block_Sales_Order_Abstract $this */
?>
<?php $_order = $this->getOrder() ?>
<div>
    <div id="order-messages">
        <?= $this->getChildHtml('order_messages') ?>
    </div>
    <?= $this->getChildHtml('order_info') ?>
    <input type="hidden" name="order_id" value="<?= $_order->getId() ?>"/>
    <?php if ($_order->getIsVirtual()): ?>
    <div class="box-right">
    <?php else: ?>
    <div class="box-left">
    <?php endif ?>
        <!--Payment Method-->
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4><?= Mage::helper('sales')->__('Payment Information') ?></h4>
            </div>
            <fieldset>
                <?= $this->getPaymentHtml() ?>
                <div><?= Mage::helper('sales')->__('Order was placed using %s', $_order->getOrderCurrencyCode()) ?></div>
                <?php if ($_order->getCouponCode()): ?>
                    <div><?= Mage::helper('sales')->__('Coupon code used: %s (%s)', $this->escapeHtml($_order->getCouponCode()), $this->escapeHtml($_order->getDiscountDescription())) ?></div>
                <?php endif; ?>
            </fieldset>
        </div>
    </div>
    <?php if (!$_order->getIsVirtual()): ?>
    <div class="box-right">
        <!--Shipping Method-->
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4><?= Mage::helper('sales')->__('Shipping &amp; Handling Information') ?></h4>
            </div>
            <fieldset>
                <?php  if ($_order->getTracksCollection()->count()) : ?>
                <a href="#" id="linkId" onclick="popWin('<?= $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','width=800,height=600,resizable=yes,scrollbars=yes')" title="<?= $this->quoteEscape($this->__('Track Order')) ?>"><?= $this->__('Track Order') ?></a>
                <br/>
                    <?php foreach ($_order->getTracksCollection() as $_track): ?>
                        <div>
                            <?php $trackNumber = $_track->getNumber();?>
                            <strong><?= $_track->getTitle() ?></strong>
                            <span data-copy-text="<?= $trackNumber ?>"><?= $trackNumber ?></span>
                        </div> 
                    <?php endforeach; ?>
                <?php endif ?>
                <?php if ($_order->getShippingDescription()): ?>
                    <strong><?= $this->escapeHtml($_order->getShippingDescription()) ?></strong>

                    <?php if ($this->helper('tax')->displayShippingPriceIncludingTax()): ?>
                        <?php $_excl = $this->displayShippingPriceInclTax($_order); ?>
                    <?php else: ?>
                        <?php $_excl = $this->displayPriceAttribute('shipping_amount', false, ' '); ?>
                    <?php endif ?>
                    <?php $_incl = $this->displayShippingPriceInclTax($_order); ?>

                    <?= $_excl ?>
                    <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                        (<?= $this->__('Incl. Tax') ?> <?= $_incl ?>)
                    <?php endif ?>
                <?php else: ?>
                    <?= $this->helper('sales')->__('No shipping information available') ?>
                <?php endif ?>
            </fieldset>
        </div>
    </div>
    <?php endif ?>
    <div class="clear"></div>
    <?= $this->getGiftOptionsHtml() ?>
    <div class="clear"></div>
    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4><?= Mage::helper('sales')->__('Items Ordered') ?></h4>
        </div>
    </div>
    <?= $this->getItemsHtml() ?>
    <div class="clear"></div>

    <div class="box-left">
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4><?= Mage::helper('sales')->__('Comments History') ?></h4>
            </div>
            <fieldset><?= $this->getChildHtml('order_history') ?></fieldset>
        </div>
    </div>
    <div class="box-right entry-edit">
        <div class="entry-edit-head"><h4><?= Mage::helper('sales')->__('Order Totals') ?></h4></div>
        <div class="order-totals"><?= $this->getChildHtml('order_totals') ?></div>
    </div>
    <div class="clear"></div>
</div>

<?= $this->getChildHtml('popup_window') ?>
<script type="text/javascript">
//<![CDATA[
    /**
     * Retrieve gift options tooltip content
     */
    function getGiftOptionsTooltipContent(itemId) {
        var contentLines = [];
        var headerLine = null;
        var contentLine = null;

        $$('#gift_options_data_' + itemId + ' .gift-options-tooltip-content').each(function (element) {
            if (element.down(0)) {
                headerLine = element.down(0).innerHTML;
                contentLine = element.down(0).next().innerHTML;
                if (contentLine.length > 30) {
                    contentLine = contentLine.slice(0,30) + '...';
                }
                contentLines.push(headerLine + ' ' + contentLine);
            }
        });
        return contentLines.join('<br/>');
    }
    giftOptionsTooltip.setTooltipContentLoaderFunction(getGiftOptionsTooltipContent);
//]]>
</script>
