!function(e){"use strict";window.fusionWooFiltersAjax=window.fusionWooFiltersAjax||{},e(document).on("submit",".widget_price_filter form",function(o){o.preventDefault();const t=new URLSearchParams(e(this).serialize());window.fusionWooFiltersAjax.load(window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,t))}),e(document).on("click",".widget_layered_nav_filters a",function(o){if(o.preventDefault(),e(this).closest("li").hasClass("awb-clear-all-filters")){const e=new URL(window.location.href),o=new URLSearchParams(e.search);return[...o.keys()].filter(e=>e.startsWith("filter_")||e.startsWith("query_type_")||["product_cat","min_price","max_price","rating_filter","product_brand","paged","page"].includes(e)).forEach(e=>o.delete(e)),e.search=o.toString(),void window.fusionWooFiltersAjax.load(e.toString())}const t=new URLSearchParams(new URL(e(this).attr("href"),window.location.origin).search);window.fusionWooFiltersAjax.load(window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,t,!0))}),e(document).on("click",".woocommerce-widget-layered-nav a, .widget_rating_filter a, .widget_brand_nav a, .awb-woo-filters-brands a, .awb-woo-filters-attribute a, .awb-woo-filters-rating a",function(o){o.preventDefault();const t=e(this),a=new URLSearchParams(new URL(t.attr("href"),window.location.origin).search);if(!t.closest(".widget_rating_filter").length&&!t.closest(".awb-woo-filters-rating").length||a.has("rating_filter")||a.set("rating_filter",""),!t.closest(".widget_brand_nav").length&&!t.closest(".awb-woo-filters-brands").length||a.has("filter_product_brand")||a.set("filter_product_brand",""),t.closest(".awb-woo-filters-attribute").length){const e=t.closest(".awb-woo-filters-attribute").attr("class").split(" ").find(e=>e.startsWith("awb-attribute-type-"));if(e){const o=e.replace("awb-attribute-type-","");a.has("filter_"+o)||a.set("filter_"+o,"")}}if(t.closest(".woocommerce-widget-layered-nav").length){const e=t.closest(".woocommerce-widget-layered-nav").attr("class").split(" ").find(e=>e.startsWith("widget_layered_nav-"));if(e){const o=e.replace("widget_layered_nav-","");a.has("filter_"+o)||a.set("filter_"+o,"")}}window.fusionWooFiltersAjax.load(window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,a))}),"off"!==fusionWooFiltersAjaxVars.woo_ajax_categories&&(e(document).on("click",".awb-woo-filters-categories a",function(o){const t=e(this),a=t.data("slug");if("filter_directly"===fusionWooFiltersAjaxVars.woo_ajax_categories&&a){o.preventDefault();const r=new URLSearchParams(window.location.search),i=new URLSearchParams;return r.get("product_cat")===a?(i.set("product_cat",""),t.closest("li").removeClass("chosen")):(i.set("product_cat",a),e(".awb-woo-filters-categories li").removeClass("chosen"),t.closest("li").addClass("chosen")),void window.fusionWooFiltersAjax.load(window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,i),!0)}if("page_change"===fusionWooFiltersAjaxVars.woo_ajax_categories){o.preventDefault();const e=new URLSearchParams(window.location.search),a=["filter_","query_type_","min_price","max_price","rating_filter","product_brand","orderby"],r=new URLSearchParams;e.forEach((e,o)=>{a.some(e=>o.startsWith(e))&&r.set(o,e)});const i=window.fusionWooFiltersAjax.mergeQueryParams(t.attr("href"),r);window.fusionWooFiltersAjax.load(i,!0,!0)}}),e(document).on("change",".awb-woo-filters-categories select",function(o){o.preventDefault();const t=e(this).val(),a=new URLSearchParams;a.set("product_cat",t),"filter_directly"===fusionWooFiltersAjaxVars.woo_ajax_categories?window.fusionWooFiltersAjax.load(window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,a),!0):"page_change"===fusionWooFiltersAjaxVars.woo_ajax_categories&&window.fusionWooFiltersAjax.load(window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,a),!0,!0)})),e(document).on("submit",".woocommerce-widget-layered-nav-dropdown",function(o){o.preventDefault();const t=new URLSearchParams(e(this).serialize());let a=null;if(t.has("filter")&&t.has("taxonomy")){const e=t.get("taxonomy").replace("pa_",""),o=new URLSearchParams;o.set("filter_"+e,t.get("filter")),a=window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,o)}else for(const[e,o]of t.entries())if(e.startsWith("filter_")){let t=o;if(o.includes("?")||o.includes("/"))try{t=new URL(o,window.location.origin).searchParams.get(e)||""}catch(e){t=""}t||(a=window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,new URLSearchParams(e+"=")));break}a?window.fusionWooFiltersAjax.load(a):window.fusionWooFiltersAjax.load(window.fusionWooFiltersAjax.mergeQueryParams(window.location.href,t))})}(jQuery);