!function(e){woodmartThemeModule.$document.on("wdShopPageInit",function(){woodmartThemeModule.ajaxSearch()}),e.each(["frontend/element_ready/wd_search.default"],function(e,a){woodmartThemeModule.wdElementorAddAction(a,function(){woodmartThemeModule.ajaxSearch()})}),woodmartThemeModule.ajaxSearch=function(){void 0!==e.fn.devbridgeAutocomplete&&(e("form.woodmart-ajax-search").each(function(){var a=e(this),t=parseInt(a.data("count")),d=parseInt(a.data("thumbnail")),s=parseInt(a.data("symbols_count")),n=a.find('[name="product_cat"]'),r=a.parent(),o=a.data("post_type"),l=woodmart_settings.ajaxurl+"?action=woodmart_ajax_search",c=parseInt(a.data("price")),i=a.data("sku"),u=a.parents(".wd-search-full-screen").length,h=a.parents(".wd-search-full-screen-2").length,w=a.parents(".wd-search-dropdown").length,p=r.find(`.wd-search-results${u||h?"":" > "}.wd-scroll-content`),m=r.find(".wd-search-results"),f=a.data("include_cat_search");function g(t){0!==a.parents(".wd-search-form.wd-display-form.wd-with-overlay").length&&e(".wd-close-side").trigger("wdCloseSideAction",["open"===t?"show":"hide","click"])}t>0&&(l+="&number="+t),l+="&post_type="+o,n.length&&""!==n.val()&&(l+="&product_cat="+n.val()),f&&"yes"===f&&(l+="&include_cat_search="+f),a.find('[type="text"]').on("focus keyup cat_selected",function(r){let v=e(this),_={action:"woodmart_ajax_search",number:t>0?t:void 0,post_type:o};if(v.hasClass("wd-search-inited")||(v.devbridgeAutocomplete({serviceUrl:l,appendTo:p,minChars:s,deferRequestBy:woodmart_settings.ajax_search_delay,onHide:function(e,t){h&&m.removeClass("wd-no-results");var d=h?a.parent().parent():a.parent(),s="function"==typeof woodmartThemeModule.beforeSearchcontent&&d.find(".wd-search-history, .wd-search-requests, .wd-search-area").length;t||s||g("close"),s||d.find(".wd-search-results").removeClass("wd-opened"),t||h||u?d.removeClass("wd-searched"):s||setTimeout(function(){d.removeClass("wd-searched")},400)},onSearchStart:function(){a.addClass("wd-search-loading")},beforeRender:function(t){w||g("open"),e(t).find(".wd-not-found-msg").parent().addClass("wd-not-found");var d=e(t).find(".wd-suggestion:not(.wd-not-found)").length>0;if(e(t).find('[class*="wd-type-"]')||(d=t[0].childElementCount>2),d){var s=a.serializeArray(),n=a.attr("action")+"?"+e.param(s);e(t).append('<a class="wd-all-results" href="'+n+'">'+woodmart_settings.all_results+"</a>")}e(t).removeAttr("style")},onSelect:function(e){e.permalink.length>0&&(window.location.href=e.permalink),a.parent().find(".wd-search-results").removeClass("wd-opened")},onSearchComplete:function(){a.removeClass("wd-search-loading"),woodmartThemeModule.$document.trigger("wood-images-loaded")},formatResult:function(e,t){"&"===t&&(t="&#038;");var s="("+t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")+")",n="";if(e.divider&&(n+=' <div class="suggestion-divider-title title">'+e.divider+"</div>"),d&&e.thumbnail&&(n+=' <div class="wd-suggestion-thumb">'+e.thumbnail+"</div>"),e.value&&(n+=' <div class="wd-suggestion-content wd-set-mb reset-last-child">',n+='<div class="wd-entities-title">'+e.value.replace(new RegExp(s,"gi"),"<strong>$1</strong>").replace(/&lt;(\/?strong)&gt;/g,"<$1>")+"</div>"),i&&e.sku&&(n+=' <p class="wd-suggestion-sku">'+e.sku+"</p>"),c&&e.price&&(n+=' <p class="price">'+e.price+"</p>"),e.value&&(n+=" </div>"),e.permalink){var r="";e.value&&(r=`aria-label="${e.value.replace(/(<([^>]+)>)/gi,"")}"`),n+=` <a class="wd-fill" href="${e.permalink}" ${r}></a>`}return e.products_not_found&&(n='<span class="wd-not-found-msg">'+e.value+"</span>"),h&&(e.no_results?m.addClass("wd-no-results"):m.removeClass("wd-no-results")),u||h||m.addClass("wd-opened"),h?a.parent().parent().addClass("wd-searched"):a.parent().addClass("wd-searched"),n}}),v.addClass("wd-search-inited")),n.length&&"cat_selected"===r.type){""!==n.val()&&(_.product_cat=n.val());let e=a.find('[type="text"]').devbridgeAutocomplete(),t=woodmart_settings.ajaxurl+"?"+new URLSearchParams(_).toString();f&&"yes"===f&&(t+="&include_cat_search="+f),e.setOptions({serviceUrl:t}),e.hide(),e.onValueChange()}}),woodmartThemeModule.$document.on("click",function(t){var d=t.target;e(d).is(".wd-search-form")||e(d).parents().is(".wd-search-form")||e(d).is(".wd-search-full-screen")||e(d).parents().is(".wd-search-full-screen")||e(d).is(".wd-clear-search")||a.find('[type="text"]').devbridgeAutocomplete("hide")}),e(".wd-search-results > .wd-scroll-content").on("click",function(e){e.stopPropagation()})}),e(".wd-header-search.wd-display-dropdown > a").on("click",function(e){e.preventDefault()}))},e(document).ready(function(){woodmartThemeModule.ajaxSearch()}),window.addEventListener("wdUpdatedHeader",function(){woodmartThemeModule.ajaxSearch()})}(jQuery);