"use strict";window.rafAsync=()=>new Promise((e=>{requestAnimationFrame(e)})),window.waitForObject=objectname=>{try{eval(objectname)}catch(e){return window.rafAsync().then((()=>window.waitForObject(objectname)))}return Promise.resolve(!0)};const cin_ajax_search=()=>{const e=$('input[name="qs"]').attr("name",""),t=e.data("searchurl"),r=$("<div/>").addClass("cin_ajaxsearch_display"),a=$(".min-chars-hint"),n=$(".no-result-hint"),s=e.data("mincharacters");var o=!1,i=1,c=[],l="";const d=window.AjaxSearchHandlebars.compile($("#resultList").html());function u(e,t=300){let r;return(...a)=>{clearTimeout(r),r=setTimeout((()=>{e.apply(this,a)}),t)}}function f(e){e=parseInt(void 0===e?1:e),i=e;var t=cin_ajaxsearch_settings.pagesize,a=c.articles.length,n=e*t,s=n-t,o={articles:c.articles.slice(s,n),total:a,currentPage:e,pageCount:Math.ceil(a/t),size:t,darfPreiseSehen:c.darfPreiseSehen,darfPreiseSehenText:c.darfPreiseSehenText,lang:cin_ajaxsearch_lang,maxResults:cin_ajaxsearch_settings.resultcount};console.log(o),r.html(d(o)).show(),r.append('<div class="display-progress bs-progress d-none">'),$("button.pushtobasket",r).on("click",h),$(".pagination a",r).on("click",p),r.animate({scrollTop:0})}function p(e){e.preventDefault(),e.stopPropagation();var t=e.target.dataset.page;if(t)f(t);else switch(e.target.innerText){case"<":f(i-1);break;case">":f(i+1)}}function h(e){e.preventDefault(),e.stopPropagation();let t=window.ProgressLoader.setProgress("display");const r=$(e.target).data("kartikel"),a=$(`input[name="quantity-${r}"]`).val();let n=new FormData,s={name:"pushToBasket",params:{productID:r,amount:a,properties:{jtl_token:$(".min-chars-hint").attr("token")}}};n.append("io",JSON.stringify(s));let o=new XMLHttpRequest;o.open("POST","/io"),o.addEventListener("load",(()=>{let e=new FormData;e.append("io",JSON.stringify({name:"getBasketItems",params:[]}));let r=new XMLHttpRequest;r.open("POST","/io"),r.addEventListener("load",(()=>{let e=JSON.parse(r.response);$(".cart-icon-dropdown.nav-item.dropdown").replaceWith($(e.varAssigns[0].value.cTemplate))})),r.addEventListener("error",(e=>{console.log(e,r.error)})),r.addEventListener("loadend",(()=>window.ProgressLoader.endProgress(t))),r.send(e)})),o.addEventListener("error",(e=>{console.log(e,o.error),window.ProgressLoader.endProgress(t)})),o.send(n)}function g(e){var t=null;return e.each((function(e,r){return null===r.offsetParent||(t=$(r),!1)})),t}"on"===$("form.cin_ajaxsearch_form").data().preventdefault&&$("form.cin_ajaxsearch_form").on("submit",(function(e){return e.preventDefault(),!1})),r.css({backgroundColor:"#ffffffff",borderRadius:e.css("border-bottom-left-radius"),borderColor:e.css("border-left-color")}),e.parent().css({position:"relative",zIndex:100}),e.closest("form").on("submit",(function(){e.attr("name","qs")})),e.on("keyup",u((()=>(e.val(g(e).val()),void function(){var i=g(e).val().trim();if(n.hide(),i.length>0&&i.length<s)return a.fadeIn(50),void r.fadeOut(50);if(a.fadeOut(50),0!==i.length){if(!o&&i!=l){o=!0,l=i;let e=window.ProgressLoader.setProgress("search");$.post(t,{qs:i},(e=>{(c=e).articles.length>0?(f(),n.hide()):(r.hide(),n.show()),o=!1}),"json").always((function(){window.ProgressLoader.endProgress(e)}))}}else r.fadeOut(50)}())),200)),e.on("focus",(function(t){$(t.target).closest(".search-wrapper").append(r),r.html().length>0&&g(e).val().trim().length>=s&&r.fadeIn(50)})),$(window).on("resize",u((()=>function(){var t=$("#content-wrapper #content"),a=t.width()+t.offset().left,n=g(e).offset(),s=550,o=n.left;a<s&&(s=a,o=0);n.left+s>a&&(o=a-s);r.css({left:o+"px",width:s===a?"100vw":s+"px"});var i=window.innerHeight-(n.top+100)+"px";r.css({maxHeight:i})}()),10)).trigger("resize"),$(document).on("keydown",(function(t){return 27===t.keyCode&&"block"===r.css("display")&&r.fadeOut(100),70!==t.keyCode||!t.ctrlKey||(g(e).focus(),!1)})),$(document).on("click",(function(t){$(t.target).is(e)||0!==$(t.target).parents(".cin_ajaxsearch_display").length||"block"===r.css("display")&&r.fadeOut(100)}))},acquireHandlebarsInstance=()=>new Promise((e=>{window.AjaxSearchHandlebars=Handlebars.create(),e()})),registerHelpers=()=>new Promise((e=>{window.AjaxSearchHandlebars.registerHelper("ifCond",(function(e,t,r){return e===t?r.fn(this):r.inverse(this)})),window.AjaxSearchHandlebars.registerHelper("ifGT",(function(e,t,r){return e>t?r.fn(this):r.inverse(this)})),window.AjaxSearchHandlebars.registerHelper("pagination",(function(e,t,r,a){var n,s,o;3===arguments.length&&(a=r,r=5),n=e-Math.floor(r/2),s=e+Math.floor(r/2),n<=0&&(s-=n-1,n=1),s>t&&(n=(s=t)-r+1>0?s-r+1:1),o={startFromFirstPage:!1,pages:[],endAtLastPage:!1},1===n&&(o.startFromFirstPage=!0);for(var i=n;i<=s;i++)o.pages.push({page:i,isCurrent:i===e});return s===t&&(o.endAtLastPage=!0),a.fn(o)})),e()}));$("[data-searchurl]").length&&window.waitForObject("Handlebars").then(acquireHandlebarsInstance).then(registerHelpers).then(cin_ajax_search);