<script data-reload="filter-script">
   {* @formatter:off *}
   var $filter = $('[data-filter="wrapper"]').data("wpjCategoryFilter");

   if ($filter) {
      {ifmodule INDEXED_FILTER}
      {get_filter_url_generator view=$view assign='urlGenerator'}
      {$url = $urlGenerator->generateUrl()}
      $filter.setUrlAndTitle('{$url.url nofilter}', {$body.category.meta_title|default:$view->getTitle()|json_encode nofilter});
      {/ifmodule}

      $filter.updateItemsState({
         {$filterCampaigns = []}
         {foreach $cfg.Products.Flags as $id => $flag}
            {if $flag.in_filter}
               {$filterCampaigns[$id] = $id}
            {/if}
         {/foreach}
         {if $filterCampaigns}
            {$body.dynamic_filter.campaigns = $body.dynamic_filter.filter->getCampaigns($filterCampaigns) scope="global"}
            {if $body.dynamic_filter.campaigns}
               {foreach $body.dynamic_filter.campaigns.values as  $campaign_key => $campaign}
                  '{$cfg.Products.Flags[$campaign_key].plural|strip_accent}': {$body.dynamic_filter.filter->getCampaigns([{$campaign_key}])|json_encode nofilter},
               {/foreach}
            {/if}
         {/if}
         {ifmodule PRODUCERS}
         'vyrobce': {$body.dynamic_filter.filter->getProducers()|json_encode nofilter},
         {/ifmodule}
         'cena': {$body.dynamic_filter.filter->getPriceRange()|json_encode nofilter},
         {foreach $body.dynamic_filter.parameters as $id => $parameter}
            {$inputId = $parameter.name|strip_accent}
            {$values = $body.dynamic_filter.filter->getParameter($id, $parameter.value_type)}
            '{$inputId}': { 'values': {$values.values|json_encode nofilter} },
         {/foreach}

         {foreach $body.dynamic_filter.variations as $id => $label}
            {if $label.convertor}
               {$inputId = $label.name|cat:'-size-convertion'|strip_accent}
               {$values = $body.dynamic_filter.filter->getSizeConvertionVariation($label.convertor)}
            {else}
               {$inputId = $label.name|strip_accent}
               {$values = $body.dynamic_filter.filter->getVariation($label.id)}
            {/if}
            '{$inputId}': { 'values': {$values.values|json_encode nofilter} },
         {/foreach}

          {$labels = $body.dynamic_filter.filter->getLabels()}
          'labels': { 'values': {$labels|json_encode:JSON_FORCE_OBJECT nofilter} },
          {$quantityDiscounts = $body.dynamic_filter.filter->getQuantityDiscounts()}
          'quantityDiscounts': {$quantityDiscounts|json_encode:JSON_FORCE_OBJECT nofilter},

         '': ''
      });

      {block "filter-script-ajax-apend"}{/block}
   }{* @formatter:on *}
</script>
