<?php
/**
 * OpenMage
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available at https://opensource.org/license/afl-3-0-php
 *
 * @category    design
 * @package     rwd_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
 * @copyright   Copyright (c) 2021-2022 The OpenMage Contributors (https://www.openmage.org)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Template for filter items block
 *
 * @see Mage_Catalog_Block_Layer_Filter
 */

$_dimHelper = Mage::helper('configurableswatches/swatchdimensions');
$_swatchInnerWidth = $_dimHelper->getInnerWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
$_swatchInnerHeight = $_dimHelper->getInnerHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
$_swatchOuterWidth = $_dimHelper->getOuterWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
$_swatchOuterHeight = $_dimHelper->getOuterHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER);
?>

<ol class="configurable-swatch-list">
    <?php foreach ($this->getItems() as $_item): ?>
        <?php
        $_hasItems = ($_item->getCount() > 0);
        $_label = $_item->getLabel();
        $_swatchUrl = Mage::helper('configurableswatches/productimg')->getGlobalSwatchUrl($_item, $_label, $_swatchInnerWidth, $_swatchInnerHeight);
        $_hasImage = (!empty($_swatchUrl));
        $_linkClass = 'swatch-link' . (($_hasImage) ? ' has-image' : '');
        $_linkCss = 'height:' . $_swatchOuterHeight . 'px; ' . ((!$_hasImage) ? 'min-' : '') . 'width:' . $_swatchOuterWidth . 'px;';
        $_lineHeight = $_swatchOuterHeight + 2;
        ?>
        <li<?php if ($_hasImage){ echo ' style="line-height: ' . $_lineHeight . 'px;"'; } ?>>
            <?php if ($_hasItems): ?>
                <a href="<?php echo $this->escapeUrl($_item->getUrl()) ?>" class="<?php echo $_linkClass ?>">
            <?php else: ?>
                <span class="<?php echo $_linkClass ?>">
            <?php endif ?>
                <span class="swatch-label"<?php if ($_hasImage){ echo ' style="' . $_linkCss . '"'; } ?>>
                    <?php if ($_hasImage): ?>
                        <img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_label; ?>" title="<?php echo $_label ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
                    <?php else: ?>
                        <?php echo $_label; ?>
                    <?php endif ?>
                </span>
                <?php if ($this->shouldDisplayProductCount()): ?>
                    <span class="count">(<?php echo $_item->getCount() ?>)</span>
                <?php endif ?>
            <?php if ($_hasItems): ?>
                </a>
            <?php else: ?>
                </span>
            <?php endif ?>
        </li>
    <?php endforeach ?>
</ol>
