"use strict";function createGlobalFilterState(){var t="/",e="=",r={};function i(){var i=Object.keys(r).map(function(t){var i=r[t];return[t,JSON.stringify(i)].join(e)}).join(t),n=i?"#"+i:location.pathname+location.search;window.history.replaceState(null,document.title,n),$(window).trigger("hashchange")}function n(t){return JSON.parse(JSON.stringify(t))}return{get:function(t){return r[t]},getAll:function(t){return n(t||r)},hasActiveFilters:function(t){return!(!r[t]||!r[t].length)},set:function(t,e,n){(n||r)[t]=e,n||i()},setEncapsulated:function(t,e){var i=n(r);return this.set(t,e,i),{getAll:this.getAll.bind(null,i)}},importState:function(t){r=n(t)},clear:function(){r={},i()},reset:function(t){delete r[t],i()},init:function(){var r,i,n=(r=decodeURIComponent((/#(.*)$/.exec(location.hash)||[])[1]),i={},r&&r.length&&(i=r.split(t).reduce(function(t,r){var i,n=r.split(e),o=n[0],a=n[1];if(o&&a)try{i=JSON.parse(a),t[o]=i}catch(t){console.error("Error parsing filter-value JSON of category:",o)}return t},{})),i);this.importState(n)}}}function createProductHandler(){var t=$(".mm-articles");return{getProductCategorySelector:function(t){return"[data-category='"+t+"']"},getAttrValueSelector:function(t,e){var r="[data-"+t,i="]";return[{prefix:"='[",suffix:"]'"},{prefix:"^='[",suffix:",'"},{prefix:"*=',",suffix:",'"},{prefix:"$=',",suffix:"]'"}].map(function(t){return[r,t.prefix,JSON.stringify(e),t.suffix,i].join("")}).join(",")},hasProductsForSelector:function(e,r){return t.filter(e).is(r)},hasActiveProductsForSelector:function(e,r){return t.filter(e).filter(":visible").is(r)},doesProductMatchFilterState:function(t,e){var r=$(t);return Object.keys(e).every(function(t){var i=e[t],n=r.data(t),o=!1;return n&&n.length&&(o=i.some(function(t){return n.indexOf(t)>=0})),o})},hasProductsForFilterState:function(e){return t.get().some(function(t){return this.doesProductMatchFilterState(t,e)}.bind(this))},showMatchingProducts:function(e){var r=0;Object.keys(e).length?t.each(function(t,i){var n=$(i);this.doesProductMatchFilterState(i,e)?(n.show(),r++):n.hide()}.bind(this)):(t.show(),r=t.length),$(window).trigger({type:"filteringDone",activeProductCount:r})}}}function SelectFilterCategory(t){var e=$(t.domEl),r=e.closest(".filter-box"),i=t.productHandler,n=t.globalFilterState,o=t.onFilterChange,a=e.data("change-handler-disabled"),c=e.data("clear-state"),l=e.data("static-visibility"),u=e.data("filter-rel"),s=$("select.filter-item",e),f=$("option[selected]",s),d=f.length?f:$("option[data-default='true']",s),h=$("option:not([data-default='true'])",s);function g(){var t,e=(t=h.filter(":checked")).length?[t.val()]:[];c?(n.clear(),e&&e.length&&n.set(u,e),$(window).trigger({type:"filterStatusCleared"})):e&&e.length?n.set(u,e):n.reset(u)}function v(){g(),"function"==typeof o&&o()}function p(){var t=d.val();s.val(t).trigger("render")}this.updateFilterVisibility=function(){var t,e,o=!1;l||(t=n.getAll(),(e=n.hasActiveFilters(u))||p(),h.each(function(e,r){var n,a,c,l=$(r),s=l.val(),f={};f[u]=[s],n=window._.defaults(f,t),a=i.hasProductsForFilterState(n)||l.is(":checked"),c=l,a?c.removeAttr("disabled").show():c.attr("disabled",!0).hide(),!o&&a&&(o=!0)}),e||o?r.show():r.hide())},this.setStoredFilterState=function(){var t=(n.get(u)||[])[0];t?s.val(t).trigger("render"):p()},this.init=function(){this.setStoredFilterState(),a||s.on("change",v)}}function InputFilterCategory(t){var e=$(t.domEl),r=e.closest(".filter-box"),i=t.productHandler,n=t.globalFilterState,o=t.onFilterChange,a=r.data("category"),c=e.data("filter-rel"),l=$("div.filter-item input:not([data-default='true'])",e);function u(){var t=l.filter(":checked").get().map(function(t){return $(t).val()});t&&t.length?n.set(c,t):n.reset(c)}function s(){u(),"function"==typeof o&&o()}this.updateFilterVisibility=function(){var t=n.hasActiveFilters(c),e=i.getProductCategorySelector(a),o=!1;l.each(function(r,a){var l,u,s,f,d=$(a),h=d.val(),g=i.getAttrValueSelector(c,h),v=d.is(":checked")||(t?(l=h,u=n.setEncapsulated(c,[l]),i.hasProductsForFilterState(u.getAll())):i.hasActiveProductsForSelector(e,g));!o&&v&&(o=v),s=v,f=d.closest(".filter-item"),s?f.show():f.hide()}),t||o?r.show():r.hide()},this.setStoredFilterState=function(){var t=n.get(c);l.screwDefaultButtons("uncheck"),l.prop("checked",!1),t&&t.length&&t.forEach(function(t){var e=l.filter("[value='"+t+"']");e.screwDefaultButtons&&e.screwDefaultButtons("check"),e.prop("checked",!0)})},this.init=function(){this.setStoredFilterState(),a||console.error("!prodCategoryName:",a,">> categoryEl:",e),l.on("change",s)}}window.initProductFilter=function(){var t,e,r=$("form.filter-items"),i=createGlobalFilterState(),n=createProductHandler();function o(t){var e,r,i,n=$(t.target),o=n.closest(".filter"),a=$(".filter-category-wrapper",o);e=a,i=n.val(),e.hide(),i&&((r=e.filter("."+i)).show(),r.trigger({type:"activeCategoryChanged"}))}function a(){t().forEach(function(t){t.updateFilterVisibility()})}function c(){var t;t=i.getAll(),n.showMatchingProducts(t),a()}function l(t){var e=$(t.target).data("filter-rel");i.reset(e),c()}function u(){t().forEach(function(t){t.setStoredFilterState()})}i.init(),e=$("form.filter-items").get().map(function(t){var e=$(t),r={domEl:t,productHandler:n,globalFilterState:i,onFilterChange:c};return e.is(".select-form")?new SelectFilterCategory(r):new InputFilterCategory(r)}),t=function(){return e},a(),t().forEach(function(t){t.init()}),$("select[name='filter_category']").each(function(t,e){$(e).on("change",o),o({target:e})}),c(),r.on("reset",l),$(window).on("filterStatusCleared",u)};
//# sourceMappingURL=productfilter.min.js.map