<?php
/**
 * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
 */
?>
<?php // @codingStandardsIgnoreFile ?>
<?php /** @var Magento\Shipping\Block\Adminhtml\View\Form $block */ ?>
<?php $_order = $block->getShipment()->getOrder() ?>
<?= $block->getChildHtml('order_info') ?>
<section class="admin__page-section order-shipment-billing-shipping">
    <div class="admin__page-section-title">
        <span class="title"><?= $block->escapeHtml(__('Payment &amp; Shipping Method')) ?></span>
    </div>
    <div class="admin__page-section-content">

        <?php /* Billing Address */ ?>
        <div class="admin__page-section-item order-payment-method">
            <div class="admin__page-section-item-title">
                <span class="title"><?= $block->escapeHtml(__('Payment Information')) ?></span>
            </div>
            <div class="admin__page-section-item-content">
                <div><?= /* @noEscape */ $block->getChildHtml('order_payment') ?></div>
                <div class="order-payment-currency"><?= $block->escapeHtml(__('The order was placed using %1.', $_order->getOrderCurrencyCode())) ?></div>
            </div>
        </div>

        <?php /* Shipping Address */ ?>
        <div class="admin__page-section-item order-shipping-address">
            <div class="admin__page-section-item-title">
                <span class="title"><?= $block->escapeHtml(__('Shipping and Tracking Information')) ?></span>
            </div>
            <div class="admin__page-section-item-content">
                <div class="shipping-description-wrapper">
                    <?php if ($block->getShipment()->getTracksCollection()->count()) : ?>
                        <p>
                            <a href="#" id="linkId" onclick="popWin('<?= $block->escapeUrl($this->helper(\Magento\Shipping\Helper\Data::class)->getTrackingPopupUrlBySalesModel($block->getShipment())) ?>','trackshipment','width=800,height=600,resizable=yes,scrollbars=yes')" title="<?= $block->escapeHtml(__('Track this shipment')) ?>"><?= $block->escapeHtml(__('Track this shipment')) ?></a>
                        </p>
                    <?php endif; ?>
                    <div class="shipping-description-title">
                        <?= $block->escapeHtml($_order->getShippingDescription()) ?>
                    </div>

                    <?= $block->escapeHtml(__('Total Shipping Charges')) ?>:

                    <?php if ($this->helper(\Magento\Tax\Helper\Data::class)->displayShippingPriceIncludingTax()) : ?>
                        <?php $_excl = $block->displayShippingPriceInclTax($_order); ?>
                    <?php else : ?>
                        <?php $_excl = $block->displayPriceAttribute('shipping_amount', false, ' '); ?>
                    <?php endif; ?>
                    <?php $_incl = $block->displayShippingPriceInclTax($_order); ?>

                    <?= /* @noEscape */ $_excl ?>
                    <?php if ($this->helper(\Magento\Tax\Helper\Data::class)->displayShippingBothPrices() && $_incl != $_excl) : ?>
                        (<?= $block->escapeHtml(__('Incl. Tax')) ?> <?= /* @noEscape */  $_incl ?>)
                    <?php endif; ?>
                </div>
                <?php if ($block->canCreateShippingLabel()) : ?>
                <p>
                    <?= /* @noEscape */ $block->getCreateLabelButton() ?>
                    <?php if ($block->getShipment()->getShippingLabel()) : ?>
                        <?= /* @noEscape */ $block->getPrintLabelButton() ?>
                    <?php endif ?>
                    <?php if ($block->getShipment()->getPackages()) : ?>
                        <?= /* @noEscape */ $block->getShowPackagesButton() ?>
                    <?php endif ?>
                </p>
                <?php endif ?>
                <?= /* @noEscape */ $block->getChildHtml('shipment_tracking') ?>

                <?= /* @noEscape */ $block->getChildHtml('shipment_packaging') ?>
                <script>
                    require([
                        'jquery',
                        'prototype'
                    ], function (jQuery) {
                        var setCallbacks = function () {
                            window.packaging.setConfirmPackagingCallback(function () {
                                window.packaging.sendCreateLabelRequest();
                            });
                            window.packaging.setLabelCreatedCallback(function () {
                                setLocation("<?= $block->escapeUrl($block->getUrl(
                                    'adminhtml/order_shipment/view',
                                    ['shipment_id' => $block->getShipment()->getId()]
                                )); ?>");
                            });
                        };

                        if (jQuery(document).data('packagingInited')) {
                            setCallbacks();
                        } else {
                            jQuery(document).on('packaging:inited', setCallbacks);
                        }
                    });
                </script>
            </div>
        </div>
    </div>
</section>

<?= /* @noEscape */ $block->getChildHtml('documentation_listing') ?>
<?= /* @noEscape */ $block->getChildHtml('package_listing') ?>

<section class="admin__page-section">
    <div class="admin__page-section-title">
        <span class="title"><?= $block->escapeHtml(__('Items Shipped')) ?></span>
    </div>
    <?= /* @noEscape */ $block->getChildHtml('shipment_items') ?>
</section>

<section class="admin__page-section">
    <div class="admin__page-section-content">
        <?= /* @noEscape */ $block->getChildHtml('export_details') ?>
        <?= /* @noEscape */ $block->getChildHtml('addon_listing') ?>
    </div>
</section>

<section class="admin__page-section">
    <div class="admin__page-section-title">
        <span class="title"><?= $block->escapeHtml(__('Order Total')) ?></span>
    </div>
    <div class="admin__page-section-content">
        <?= /* @noEscape */ $block->getChildHtml('shipment_packed') ?>

        <div class="admin__page-section-item order-comments-history">
            <div class="admin__page-section-item-title">
                <span class="title"><?= $block->escapeHtml(__('Shipment History')) ?></span>
            </div>
            <div class="admin__page-section-item-content"><?= /* @noEscape */ $block->getChildHtml('order_comments') ?></div>
        </div>
    </div>
</section>
