var q=s=>{throw TypeError(s)};var E=(s,i,e)=>i.has(s)||q("Cannot "+e);var t=(s,i,e)=>(E(s,i,"read from private field"),e?e.call(s):i.get(s)),h=(s,i,e)=>i.has(s)?q("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(s):i.set(s,e),o=(s,i,e,r)=>(E(s,i,"write to private field"),r?r.call(s,e):i.set(s,e),e),L=(s,i,e)=>(E(s,i,"access private method"),e);import{U as M}from"./Utils-DWmIjEEK.js";import"./Translator-Bios5QX5.js";import"./vue.esm-bundler-DZdE0M9V.js";import"./Arr-MwYQQ3qa.js";import"./dayjs.min-2rai63wT.js";import"./timezone-C2U15obx.js";document.addEventListener("DOMContentLoaded",()=>{var e,r,p,a,c,f,d,m,A,y,k;class s{constructor(n){h(this,y);h(this,e);h(this,r);h(this,p);h(this,a);h(this,c);h(this,f,"new-tab");h(this,d,!1);h(this,m,n=>{var w;n.preventDefault();const u=t(this,r),U=(w=t(this,c))==null?void 0:w.value,v=u.value;t(this,A).call(this,U,v)});h(this,A,(n,u)=>{t(this,r).classList.add("is-active"),t(this,d)?t(this,a).parentElement.style.display="none":t(this,a).parentElement.style.display="block";const v=`${window.fluentcart_search_bar_vars.rest.url}/public/product-search/`;if(this.isLinkedWithShopApp()){const l={};u?l.wildcard=u:l.wildcard="",n&&(l["product-categories"]=n),window.fluentCartShopApps[0].applyFilters(l);return}let w=new URL(v);const g={post_title:u,url_mode:t(this,f),termId:n||""};if(Object.keys(g).length>0)for(let[l,S]of Object.entries(g))w.searchParams.append(l,S);const B=w.href;if(u)fetch(B).then(l=>l.json()).then(l=>{const S=l.htmlView;t(this,a).innerHTML=S;const b=t(this,a).parentElement.querySelector("h5");b&&(b.style.display="block"),S.trim()===""&&(t(this,a).innerHTML='<li class="is-empty">No results found.</li>',b&&(b.style.display="none"))}).catch(l=>{console.error("Error fetching data:",l)});else{L(this,y,k).call(this);return}});o(this,e,n),o(this,c,t(this,e).querySelector("[data-fluent-cart-search-bar-app-taxonomy]")),o(this,r,t(this,e).querySelector("[data-fluent-cart-search-bar]")),o(this,p,t(this,e).querySelector("[data-fluent-cart-search-clear]")),o(this,a,t(this,e).querySelector("[data-fluent-cart-search-bar-lists-wrapper]")),o(this,f,t(this,e).dataset.urlMode||"new-tab"),this.init(),o(this,d,t(this,e).dataset.linkWithShopApp||!1)}isLinkedWithShopApp(){const n=Array.isArray(window.fluentCartShopApps)&&window.fluentCartShopApps.length>0;return t(this,d)&&n}init(){const n=M.debounce(t(this,m),300);t(this,r).addEventListener("keyup",n),t(this,c)&&t(this,c).addEventListener("change",n),t(this,a).parentElement.style.display="none",t(this,r).addEventListener("input",()=>{t(this,r).value.trim()!==""?t(this,p).style.display="block":t(this,p).style.display="none"}),t(this,p).addEventListener("click",()=>{t(this,r).value="",t(this,p).style.display="none",L(this,y,k).call(this)})}}e=new WeakMap,r=new WeakMap,p=new WeakMap,a=new WeakMap,c=new WeakMap,f=new WeakMap,d=new WeakMap,m=new WeakMap,A=new WeakMap,y=new WeakSet,k=function(){t(this,r).classList.remove("is-active"),t(this,a).parentElement.style.display="none",t(this,a).innerHTML="",t(this,d)&&typeof window.fluentCartShopApps<"u"&&window.fluentCartShopApps.length>0&&window.fluentCartShopApps[0].applyFilters({wildcard:"","product-categories":""})},document.querySelectorAll("[data-fluent-cart-search-bar-app-wrapper]").forEach(C=>{new s(C)})});
