<?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;

use DJExtensions\DJCatalog2\YOOtheme\Builder\Source\ItemHelper;
$app = \Joomla\CMS\Factory::getApplication();
$fieldData = ItemHelper::getExtraField($props['field']);
if(empty($fieldData))return;


$stringifyName = JFilterOutput::stringURLSafe($props['label']);
$fieldName = 'f_'.$fieldData->alias;


$currentOptions = $app->input->get($fieldName);
// Element
$el = $this->el('div', [

    'class' => [
        'uk-form-controls'
    ],
    'style' => [
         $props['css'],

    ]

]);


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

    'class' => [
        'uk-margin[-{option_margin}]',
        'uk-align-[{option_align}]' => $props['option_align'],
        'uk-margin-remove-top' => $props['option_margin'] !== 'remove' && $props['option_margin_remove_top'],
        'uk-margin-remove-bottom' => $props['option_margin'] !== 'remove' && $props['option_margin_remove_bottom'],
    ]

]);

?>

<?= $el($props, $attrs) ?>
<?php if (isset($props['show_label']) && $props['show_label']) : ?>
    <label class="uk-form-label"><?php echo JText::_($props['label']); ?></label>
<?php endif; ?>
<div></div>
<?php if (count($fieldData->options)) : ?>

    <?php foreach ($fieldData->options as $option) : ?>
        <div>
            <label class="uk-flex">
                <div>
                    <input <?php if(isset($currentOptions) && $currentOptions) echo((in_array($option->id, $currentOptions)) ? 'checked="checked"' : '') ?>
                            value="<?php echo $option->id ?>" type="checkbox"
                            name="<?php echo $fieldName ?>[]"
                            class="uk-checkbox <?php echo(($props['submit']) ? 'dj-content-filters-autosubmit' : '') ?>">
                </div>
                <div class="uk-margin-small-left"><?php echo(($option->value) ? $option->value : $option) ?></div>
            </label>
        </div>


    <?php endforeach; ?>

<?php endif; ?>

<div style="clear: both"></div>

<?= $el->end() ?>

