<?php
/**
 * @package DJ-Catalog2-Yootheme
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */
defined('_JEXEC') or die;
$el = $this->el('div');
$grid = $this->el('div', [

    'class' => [
        'uk-child-width-{grid_width}',
        'uk-grid-{column_gap}',
        'uk-flex-middle {@vertical_align}',
        'lena-filter-grid'
    ],

    'uk-grid' => true,
]);

$column = $this->el('div', [

    'class' => [
        'uk-width-{grid_width}@{grid_breakpoint}',
        'uk-flex-last@{grid_breakpoint} {@position: right}',
        'lena-filter-column'
    ],

]);

$flatAttributes = array();
$attributeValuesMap = array();
foreach ($node->props['variables'] as $attributeId => $attributeValues) {
    foreach ($attributeValues as $attributeValue) {
        $flatAttributes[] = array(
            'attributeId' => $attributeId,
            'attributeValue' => $attributeValue
        );
    }
}
// czy zmiana kontekstu?
$app = \JFactory::getApplication();
$catmain = $app->input->get('catc');
$fieldsMap =  array();



?>

<form action="<?php echo JUri::current() ?>" method="GET" class="lena-filters-form" enctype="application/x-www-form-urlencoded">

    <?= $el($props, $attrs) ?>
    <?= $grid($props, $attrs) ?>
    <?php foreach ($children as $groups) : ?>

        <?php foreach ($groups->attributes as $child) : ?>
            <?= $column($props, $this->render("{$__dir}/template_column", compact(array('props', 'child')))) ?>

            <?php
            $tmpOptions = array();
            foreach ($child->options as $index => $option) {
                $attributeValuesMap[$child->id][$option] = $child->optionValues[$index];
            }
            ?>
        <?php $fieldsMap[$child->id] = $child->name ?>
        <?php endforeach; ?>

    <?php endforeach; ?>

    </div>

        <?php if (count($node->props['variables'])) : ?>
            <div class="uk-border-pill sd-tag uk-background-muted uk-text-small uk-padding-small uk-margin-small-left uk-margin-small-top lena-clear-tags">
                <span class="uk-text"><?php echo JText::_('PLG_SYSTEM_DJC2YOOTHEME_CLEAR_ALL') ?> (<span
                            class="sd-tags-counter"><?php echo count($flatAttributes) ?></span>) </span> <span
                        uk-icon="icon: close"> </span>
            </div>
            <?php foreach ($node->props['variables'] as $attributeId => $attributeValues) : ?>
                <?php foreach ($attributeValues as $attributeValue) : ?>
                    <?php if (isset($attributeValuesMap[$attributeId][$attributeValue])) : ?>
                        <div class="uk-border-pill sd-tag uk-text-small uk-padding-small uk-margin-small-left uk-margin-small-top"
                             data-attribute="<?php echo $attributeId ?>" data-option="<?php echo $attributeValue ?>">
                            <span class="uk-text"><?php echo $fieldsMap[$attributeId] . ' - ' . $attributeValuesMap[$attributeId][$attributeValue] ?> </span>
                            <span uk-icon="icon: close"> </span>
                        </div>
                    <?php endif; ?>

                <?php endforeach; ?>

            <?php endforeach; ?>
        <?php endif; ?>
    </div>
    <?php if(!empty($catmain) && $catmain === 'true') : ?>
    <input type="hidden" name="catc" value="true">
    <?php endif; ?>
</form>

