<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_AdvancedLayeredNavigation
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
?>
<?php $swatchData = $block->getSwatchData();
$selectedOption = [];
if (!empty($swatchData['selected_value'])) {
    $selectedOption = explode('_', $swatchData['selected_value']);
}
?>
<div class="swatch-attribute swatch-layered
<?= /* @noEscape */  $block->escapeHtml($swatchData['attribute_code']) ?>"
     attribute-code="<?= /* @noEscape */  $block->escapeHtml($swatchData['attribute_code']) ?>" 
     attribute-id="<?= /* @noEscape */  $block->escapeHtml($swatchData['attribute_id']) ?>">
    <div class="swatch-attribute-options clearfix">
        <?php foreach ($swatchData['options'] as $option => $label) { ?>
            <a name="webkul-<?= /* @noEscape */  $block->escapeHtml($option) ?>" href="<?= /* @noEscape */  $block->escapeHtml($label['link']) ?>" class="swatch-option-link-layered">
                <?php if (isset($swatchData['swatches'][$option]['type'])) { ?>
                    <?php switch ($swatchData['swatches'][$option]['type']) {
                        case '3':
                            ?>
                            <div class="swatch-option 
                            <?php /* @escapeNotVerified */
                            if (in_array($option, $selectedOption)) {
                                echo $block->escapeHtml("selected");
                            }

                                 echo $block->escapeHtml($label['custom_style']) ?>"
                                         option-type="3"
                                         option-id="
                                            <?= /* @noEscape */  $block->escapeHtml($option) ?>"
                                         option-label="
                                            <?= /* @noEscape */  $block->escapeHtml($label['label']) ?>"
                                         option-tooltip-thumb=""
                                         option-tooltip-value=""
                                        ></div>
                                    <?php
                                  break;
                        case '2':
                            ?>
                            <?php $swatchThumbPath = $block->getSwatchPath(
                                'swatch_thumb',
                                $swatchData['swatches'][$option]['value']
                            ); ?>
                            <?php $swatchImagePath = $block->getSwatchPath(
                                'swatch_image',
                                $swatchData['swatches'][$option]['value']
                            ); ?>
                        <div class="swatch-option image 
                            <?php /* @escapeNotVerified */
                            if (in_array($option, $selectedOption)) {
                                echo $block->escapeHtml("selected");
                            }
                            echo $block->escapeHtml($label['custom_style']) ?>"
                                 option-type="2"
                                 option-id="
                                    <?= /* @noEscape */  $block->escapeHtml($option) ?>"
                                 option-label="
                                    <?= /* @noEscape */  $block->escapeHtml($label['label']) ?>"
                                 option-tooltip-thumb="
                                    <?= /* @noEscape */  $block->escapeHtml($swatchThumbPath) ?>"
                                 option-tooltip-value=""
                                 style="background: url(
                                        <?= /* @noEscape */  $block->escapeHtml($swatchImagePath) ?>)
                                  no-repeat center; background-size: initial;"></div>
                            <?php
                                  break;
                        case '1':
                            ?>
                            <div class="swatch-option color <?php /* @escapeNotVerified */
                            if (in_array($option, $selectedOption)) {
                                echo $block->escapeHtml("selected");
                            }
                                                                
                                echo $block->escapeHtml($label['custom_style']) ?>"
                                 option-type="1"
                                 option-id="
                                    <?= /* @noEscape */  $block->escapeHtml($option) ?>"
                                 option-label="
                                    <?= /* @noEscape */  $block->escapeHtml($label['label']) ?>"
                                 option-tooltip-thumb=""
                                 option-tooltip-value="
                                 <?= /* @noEscape */  $block->escapeHtml($swatchData['swatches'][$option]['value']) ?>"
                                 style="background: 
                                 <?= /* @noEscape */  $block->escapeHtml($swatchData['swatches'][$option]['value']) ?>
                                  no-repeat center; background-size: initial;"></div>
                                <?php
                                  break;
                        case '0':
                        default:
                            ?>
                            <div class="swatch-option text 
                            <?php /* @escapeNotVerified */
                            if (in_array($option, $selectedOption)) {
                                echo $block->escapeHtml("selected");
                            }
                            echo $block->escapeHtml($label['custom_style']) ?>"
                                option-type="0"
                                option-id="
                                <?= /* @noEscape */  $block->escapeHtml($option) ?>"
                                option-label="
                                <?= /* @noEscape */  $block->escapeHtml($label['label']) ?>"
                                option-tooltip-thumb=""
                                option-tooltip-value=""
                                >
                                <?= /* @noEscape */  $block->escapeHtml($label['label']) ?></div>
                    <?php   } ?>
                <?php } ?>
            </a>
        <?php } ?>
    </div>
</div>

<script>
    require(["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer"], function ($) {
        $('.swatch-layered.<?= /* @noEscape */  $block->escapeHtml($swatchData['attribute_code']) ?>')
            .find('[option-type="1"], [option-type="2"], [option-type="0"], [option-type="3"]')
            .SwatchRendererTooltip();
    });
</script>
<?php $params["_use_rewrite"] = true;
$data = json_encode(["url" => $block->getUrl('advancedlayerednavigation/index/setvalues'),
"clearUrl" => $block->getUrl('*/*/*', $params)]); ?>

<script type="text/x-magento-init">
{
    "body": {
        "Webkul_AdvancedLayeredNavigation/js/layerednavigation": <?= /* @noEscape */  $data ?>
    }
}
</script>