<?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();
$field = ItemHelper::getExtraField($props['field']);
if(empty($field))return;
$el = $this->el('div', [

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

	]

]);

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


$currentOptions = $app->input->get($fieldName);

?>
<?= $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; ?>
<?php if ($field->type == 'color' || $field->type == 'multicolor') { echo '<div class="djc_color_filters">'; } ?>
<?php foreach ($field->options as $x) {
	$optionParams = json_decode($x->params);
	$colorStyle = '';
	if ($field->type == 'color' || $field->type == 'multicolor') {
		if ($optionParams->hexcode) {
			$colorStyle .= 'background-color: ' . $optionParams->hexcode.';';
		}
		if ($colorStyle == '') {
			$colorStyle = 'background-color: #ccc;)';
		}
	}
	$colorStyle .= '
	 width: '.$props['width'].'px;
	 height: '.$props['height'].'px;
	 display:inline-block;
	 border-radius: '.$props['border_radius'].'px;
	 border: '.$props['border_size'].'px '.$props['border_style'].' '.$props['border_color'].';
	 cursor: pointer;'

?>
        <div class="form-check">
            <label class="form-check-label">
                <input hidden <?php if(isset($currentOptions) && $currentOptions) echo((in_array($x->id, $currentOptions)) ? 'checked="checked"' : '') ?>  type="checkbox" name="<?php echo 'f_'.$field->alias; ?>[]" value="<?php echo $x->id?>"  class="form-check-input dj-content-filters-autosubmit" />
				<?php if ($field->type == 'color' || $field->type == 'multicolor') {?>
                    <span class="djc_color_filter">
				<span class="djc_color_filter-bg" style="<?php echo $colorStyle; ?>">
				</span>
                        <?php if($props['showName'] == true) {?>
				<span class="djc_color_filter-name"><?php echo $x->value; ?></span> <?php } ?>
			</span>
				<?php } ?>
            </label>
        </div>
	<?php } ?>
</div>
<?= $el->end() ?>

