<?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)
 */
?>
<?php /** @var Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Method_Form $this */ ?>
<?php $_shippingRateGroups = $this->getShippingRates(); ?>
<?php if ($_shippingRateGroups): ?>
    <div id="order-shipping-method-choose" style="display:none">
    <dl class="shipment-methods">
    <?php foreach ($_shippingRateGroups as $code => $_rates): ?>
        <dt><strong><?= $this->escapeHtml($this->getCarrierName($code)) ?></strong></dt>
        <dd>
            <ul>
            <?php foreach ($_rates as $_rate): ?>
                <?php $_radioProperty = 'name="order[shipping_method]" type="radio" onclick="order.setShippingMethod(this.value)"' ?>
                <?php $_code=$_rate->getCode() ?>
                <li>
                   <?php if ($_rate->getErrorMessage()): ?>
                        <ul class="messages">
                            <li class="error-msg"><?= $this->escapeHtml($_rate->getErrorMessage()) ?></li>
                        </ul>
                   <?php else: ?>
                        <?php $_checked = $this->isMethodActive($_code) ? 'checked="checked"' : '' ?>
                        <input <?= $_radioProperty ?> value="<?= $_code ?>" id="s_method_<?= $_code ?>" <?= $_checked ?>/>
                        <label class="normal" for="s_method_<?= $_code ?>">
                            <?= $this->escapeHtml($_rate->getMethodTitle() ? $_rate->getMethodTitle() : $_rate->getMethodDescription()) ?> -
                            <strong>
                                <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
                                <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>

                                <?= $_excl ?>
                                <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                                    (<?= $this->__('Incl. Tax') ?> <?= $_incl ?>)
                                <?php endif ?>
                            </strong>
                        </label>
                   <?php endif ?>
                </li>
            <?php endforeach ?>
            </ul>
        </dd>
    <?php endforeach ?>
    </dl>
    </div>
    <?php if ($_rate = $this->getActiveMethodRate()): ?>
        <div id="order-shipping-method-info">
            <strong><?= $this->escapeHtml($this->getCarrierName($_rate->getCarrier())) ?></strong><br/>
            <?= $this->escapeHtml($_rate->getMethodTitle() ? $_rate->getMethodTitle() : $_rate->getMethodDescription()) ?> -
            <strong>
                <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
                <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>

                <?= $_excl ?>
                <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                    (<?= $this->__('Incl. Tax') ?> <?= $_incl ?>)
                <?php endif ?>
            </strong>
            <!--input type="text" class="input-text" style="width:70px"/-->
            <br/>
            <a href="#" onclick="$('order-shipping-method-info').hide();$('order-shipping-method-choose').show();return false">
                <?= Mage::helper('sales')->__('Click to change shipping method') ?>
            </a>
        </div>
    <?php else: ?>
        <script type="text/javascript">$('order-shipping-method-choose').show();</script>
    <?php endif ?>
<?php elseif($this->getIsRateRequest()): ?>
    <strong><?= Mage::helper('sales')->__('Sorry, no quotes are available for this order at this time.') ?></strong>
<?php else: ?>
    <div id="order-shipping-method-summary">
        <a href="#" onclick="order.loadShippingRates();return false">
            <?= Mage::helper('sales')->__('Get shipping methods and rates') ?>
        </a>
        <input type="hidden" name="order[has_shipping]" value="" class="required-entry" />
    </div>
<?php endif ?>
<div style="display:none;" id="shipping-method-overlay" class="overlay"><span><?= $this->__('Shipping method selection is not applicable') ?></span></div>
<script type="text/javascript">
order.overlay('shipping-method-overlay', <?php if ($this->getQuote()->isVirtual()): ?>false<?php else: ?>true<?php endif ?>);
order.overlay('address-shipping-overlay', <?php if ($this->getQuote()->isVirtual()): ?>false<?php else: ?>true<?php endif ?>);
</script>
