<?php
/**
 * Maho
 *
 * @category    design
 * @package     base_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
/**
 * Multishipping checkout billing information
 *
 * @see Mage_Checkout_Block_Multishipping_Billing
 * @var Mage_Checkout_Block_Multishipping_Billing $this
 */
?>
<div class="multiple-checkout">
    <div class="page-title">
        <h1><?= $this->__('Billing Information') ?></h1>
    </div>
    <?= $this->getMessagesBlock()->toHtml() ?>
    <script src="<?= Mage::getBaseUrl('js') ?>varien/payment.js" type="text/javascript"></script>
    <form action="<?= $this->getPostActionUrl() ?>" method="post" id="multishipping-billing-form">
        <div class="col2-set">
            <div class="col-1 col-narrow">
                <div class="box">
                    <div class="box-title">
                        <h2><?= $this->__('Billing Address') ?> <span class="separator">|</span> <a href="<?= $this->getSelectAddressUrl() ?>"><?= $this->__('Change') ?></a></h2>
                    </div>
                    <div class="box-content">
                        <?php $_address=$this->getAddress() ?>
                        <address><?= $_address->format('html') ?></address>
                    </div>
                </div>
            </div>
            <div class="col-2 col-wide">
                <div class="box">
                    <div class="box-title">
                        <h2><?= $this->__('Payment Method') ?></h2>
                    </div>
                    <div class="box-content">
                        <div class="tool-tip" id="payment-tool-tip" style="display:none;">
                            <div class="btn-close"><a href="#" id="payment-tool-tip-close" title="<?= Mage::helper('core')->quoteEscape($this->__('Close')) ?>"><?= $this->__('Close') ?></a></div>
                            <div class="tool-tip-content"><img src="<?= $this->getSkinUrl('images/cvv.gif') ?>" alt="<?= Mage::helper('core')->quoteEscape($this->__('Card Verification Number Visual Reference')) ?>" title="<?= Mage::helper('core')->quoteEscape($this->__('Card Verification Number Visual Reference')) ?>" /></div>
                        </div>
                        <!-- Payment methods forms list -->
                        <dl class="sp-methods">
                        <?php
                            $_methods       = $this->getMethods();
                            $_methodsCount  = count($_methods);
                        ?>
                        <?php foreach ($_methods as $_method): $_code = $_method->getCode() ?>
                            <dt>
                                <?php if ($_methodsCount > 1): ?>
                                <input type="radio" id="p_method_<?= $_code ?>" value="<?= $_code ?>" name="payment[method]" title="<?= $this->escapeHtml($_method->getTitle()) ?>" onclick="payment.switchMethod('<?= $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif ?> class="radio" />
                                <?php else: ?>
                                <span class="no-display"><input type="radio" id="p_method_<?= $_code ?>" value="<?= $_code ?>" name="payment[method]" checked="checked" class="radio" /></span>
                                <?php endif ?>
                                <label for="p_method_<?= $_code ?>"><?= $this->escapeHtml($_method->getTitle()) ?></label>
                            </dt>
                            <?php if($html = $this->getChildHtml('payment.method.'.$_code)) : ?>
                            <dd>
                                <?= $html ?>
                            </dd>
                            <?php endif ?>
                        <?php endforeach ?>
                        </dl>
                        <?= $this->getChildHtml('checkout_billing_items') ?>
                    </div>
                </div>
            </div>
        </div>
        <div class="buttons-set">
            <p class="back-link"><a href="<?= $this->getBackUrl() ?>"><small>&laquo; </small><?= $this->__('Back to Shipping Information') ?></a></p>
            <button id="payment-continue" type="submit" title="<?= Mage::helper('core')->quoteEscape($this->__('Continue to Review Your Order')) ?>" class="button"><?= $this->__('Continue to Review Your Order') ?></button>
        </div>
        <?= $this->getBlockHtml('formkey') ?>
    </form>
    <script type="text/javascript">
        var payment = new paymentForm('multishipping-billing-form');
        var quoteBaseGrandTotal = <?= (float)$this->getQuoteBaseGrandTotal() ?>;

        function toggleToolTip(event) {
            const toolTip = document.getElementById('payment-tool-tip');
            if (toolTip) {
                toolTip.style.display = toolTip.style.display === 'none' ? 'block' : 'none';
            }
            event.preventDefault();
        }

        const closeButton = document.getElementById('payment-tool-tip-close');
        if (closeButton) {
            closeButton.addEventListener('click', toggleToolTip);
        }

        document.querySelectorAll('.cvv-what-is-this').forEach(element => {
            element.addEventListener('click', toggleToolTip);
        });
    </script>
</div>
