<?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)
 */

/**
 * @var Mage_Bundle_Block_Catalog_Product_Price $this
 */
/**
 * @var Mage_Core_Helper_Data $_coreHelper
 * @var Mage_Weee_Helper_Data $_weeeHelper
 * @var Mage_Tax_Helper_Data $_taxHelper
 */
$_coreHelper = $this->helper('core');
$_weeeHelper = $this->helper('weee');
$_taxHelper  = $this->helper('tax');

/**
 * @var Mage_Catalog_Model_Product $_product
 * @var Mage_Bundle_Model_Product_Price $_priceModel
 */
$_product     = $this->getProduct();
$_priceModel  = $_product->getPriceModel();

list($_minimalPriceTax, $_maximalPriceTax) = $_priceModel->getTotalPrices($_product, null, null, false);
list($_minimalPriceInclTax, $_maximalPriceInclTax) = $_priceModel->getTotalPrices($_product, null, true, false);

$_weeeTaxAmount = 0;
?>
<?php
if ($_product->getPriceType() == 1) {
    $_weeeTaxAmount = $_weeeHelper->getAmountForDisplay($_product);
    $_weeeTaxAmountInclTaxes = $_weeeTaxAmount;
    if ($_weeeHelper->isTaxable()) {
        $_attributes = $_weeeHelper->getProductWeeeAttributesForRenderer($_product, null, null, null, true);
        $_weeeTaxAmountInclTaxes = $_weeeHelper->getAmountInclTaxes($_attributes);
    }
    if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, [0, 1, 4])) {
        $_minimalPriceTax     += $_weeeTaxAmount;
        $_minimalPriceInclTax += $_weeeTaxAmountInclTaxes;
        $_maximalPriceTax     += $_weeeTaxAmount;
        $_maximalPriceInclTax += $_weeeTaxAmountInclTaxes;
    }
    if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 2)) {
        $_minimalPriceInclTax += $_weeeTaxAmountInclTaxes;
        $_maximalPriceInclTax += $_weeeTaxAmountInclTaxes;
    }

    if ($_weeeHelper->typeOfDisplay($_product, [1, 2, 4])) {
        $_weeeTaxAttributes = $_weeeHelper->getProductWeeeAttributesForRenderer($_product, null, null, null, true);
    }
}
?>

<div class="price-box">
        <?php if ($_product->getPriceView()): ?>
            <p class="minimal-price">
                <span class="price-label"><?= $this->__('As low as') ?>:</span>
                <?php if ($this->displayBothPrices()): ?>
                    <span class="price-excluding-tax">
                        <span class="label"><?= $_taxHelper->__('Excl. Tax:') ?></span>
                        <?= $_coreHelper->currency($_minimalPriceTax) ?>
                    </span>
                    <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                        <span class="weee">(<small>
                            <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if ($_weeeHelper->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?= $_weeeSeparator ?>
                                <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                    <?php endif ?>
                    <span class="price-including-tax">
                        <span class="label"><?= $_taxHelper->__('Incl. Tax:') ?></span>
                        <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                    </span>
            <?php else: ?>
                <?php if ($_taxHelper->displayPriceIncludingTax()): ?>
                    <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                <?php else: ?>
                    <?= $_coreHelper->currency($_minimalPriceTax) ?>
                <?php endif ?>
                <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                    <span class="weee">(<small>
                        <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                            <?php if ($_weeeHelper->typeOfDisplay($_product, [2, 4])): ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                            <?php else: ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                            <?php endif ?>

                            <?= $_weeeSeparator ?>
                            <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                            <?php $_weeeSeparator = ' + '; ?>
                        <?php endforeach ?>
                    </small>)</span>
                <?php endif ?>
                <?php if ($_weeeHelper->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                    <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                <?php endif ?>
            <?php endif ?>
            </p>
        <?php else: ?>
            <?php if ($_minimalPriceTax <> $_maximalPriceTax): ?>
            <p class="price-from">
                <span class="price-label"><?= $this->__('From') ?>:</span>
                <?php if ($this->displayBothPrices()): ?>
                    <span class="price-excluding-tax">
                        <span class="label"><?= $_taxHelper->__('Excl. Tax:') ?></span>
                        <?= $_coreHelper->currency($_minimalPriceTax) ?>
                    </span>
                    <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                        <span class="weee">(<small>
                            <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if ($_weeeHelper->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?= $_weeeSeparator ?>
                                <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                    <?php endif ?>
                    <span class="price-including-tax">
                        <span class="label"><?= $_taxHelper->__('Incl. Tax:') ?></span>
                        <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                    </span>
                <?php else: ?>
                    <?php if ($_taxHelper->displayPriceIncludingTax()) : ?>
                        <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                    <?php else: ?>
                        <?= $_coreHelper->currency($_minimalPriceTax) ?>
                    <?php endif ?>
                    <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                        <span class="weee">(<small>
                            <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if ($_taxHelper->displayPriceIncludingTax() || $_weeeHelper->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?= $_weeeSeparator ?>
                                <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                    <?php endif ?>
                    <?php if ($_weeeHelper->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                        <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                    <?php endif ?>
                <?php endif ?>
            </p>
                <p class="price-to">
                    <span class="price-label"><?= $this->__('To') ?>:</span>
                    <?php if ($this->displayBothPrices()): ?>
                        <span class="price-excluding-tax">
                            <span class="label"><?= $_taxHelper->__('Excl. Tax:') ?></span>
                            <?= $_coreHelper->currency($_maximalPriceTax) ?>
                        </span>
                        <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                            <span class="weee">(<small>
                                <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                    <?php if ($_weeeHelper->typeOfDisplay($_product, [2, 4])): ?>
                                        <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                                    <?php else: ?>
                                        <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                    <?php endif ?>

                                    <?= $_weeeSeparator ?>
                                    <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                                    <?php $_weeeSeparator = ' + '; ?>
                                <?php endforeach ?>
                            </small>)</span>
                        <?php endif ?>
                        <span class="price-including-tax">
                            <span class="label"><?= $_taxHelper->__('Incl. Tax') ?></span>
                            <?= $_coreHelper->currency($_maximalPriceInclTax) ?>
                        </span>
                    <?php else: ?>
                    <?php if ($_taxHelper->displayPriceIncludingTax()) : ?>
                        <?= $_coreHelper->currency($_maximalPriceInclTax) ?>
                    <?php else: ?>
                        <?= $_coreHelper->currency($_maximalPriceTax) ?>
                    <?php endif ?>
                        <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                            <span class="weee">(<small>
                                <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                    <?php if ($_taxHelper->displayPriceIncludingTax() || $_weeeHelper->typeOfDisplay($_product, [2, 4])): ?>
                                        <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                                    <?php else: ?>
                                        <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                    <?php endif ?>

                                    <?= $_weeeSeparator ?>
                                    <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                                    <?php $_weeeSeparator = ' + '; ?>
                                <?php endforeach ?>
                            </small>)</span>
                        <?php endif ?>
                        <?php if ($_weeeHelper->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                            <?= $_coreHelper->currency($_maximalPriceInclTax) ?>
                        <?php endif ?>
                    <?php endif ?>
                </p>
            <?php else: ?>
                <?php if ($this->displayBothPrices()): ?>
                    <span class="price-excluding-tax">
                        <span class="label"><?= $_taxHelper->__('Excl. Tax:') ?></span>
                        <?= $_coreHelper->currency($_minimalPriceTax) ?>
                    </span>
                    <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                        <span class="weee">(<small>
                            <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if ($_weeeHelper->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?= $_weeeSeparator ?>
                                <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                    <?php endif ?>
                    <span class="price-including-tax">
                        <span class="label"><?= $_taxHelper->__('Incl. Tax:') ?></span>
                        <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                    </span>
                <?php else: ?>
                    <?= $_coreHelper->currency($_minimalPriceTax) ?>
                    <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($_product, [2, 1, 4])): ?>
                        <span class="weee">(<small>
                            <?php $_weeeSeparator = ''; foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if ($_taxHelper->displayPriceIncludingTax()): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount()+$_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?= $_weeeSeparator ?>
                                <?= $_weeeTaxAttribute->getName() ?>: <?= $_coreHelper->currency($amount, true, true) ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                    <?php endif ?>
                    <?php if ($_weeeHelper->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                        <?php if ($_taxHelper->displayPriceIncludingTax()) : ?>
                            <?= $_coreHelper->currency($_minimalPriceInclTax) ?>
                        <?php else: ?>
                            <?= $_coreHelper->currency($_minimalPriceTax + $_weeeTaxAmount) ?>
                        <?php endif ?>
                    <?php endif ?>
                <?php endif ?>
            <?php endif ?>
        <?php endif ?>
</div>
