const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./chunks/theme-integration-CgzpZgJ4.js","./chunks/preload-helper-Du-ZIQLl.js"])))=>i.map(i=>d[i]);
import{_ as m}from"./chunks/preload-helper-Du-ZIQLl.js";const d=typeof window<"u"&&window.FindAstraConfig||{},_=!!(d.provider&&d.provider.is_server_side),h=typeof d.language=="string"?d.language:"",E=()=>d.rest&&d.rest.root?d.rest.root.replace(/\/$/,""):"";function f(t){return h?{...t,language:h}:t}function S(){return _}async function l(t,e){const a=await fetch(E()+t,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!a.ok)throw new Error(`${a.status}: ${await a.text()}`);return a.json()}async function y(t,e=6,a={}){if(!t||!t.trim())return{results:[],fallback:[]};const n={query:t,limit:e};if(a.log===!1&&(n.log=!1),_)return l("/search",f(n));const{embed:r}=await m(async()=>{const{embed:c}=await import("./chunks/embedder-CEK0uOnA.js");return{embed:c}},[],import.meta.url),[i]=await r([t]);return l("/search",f({...n,vector:i}))}async function k(t,e=6){if(!t||!t.trim())return{results:[],fallback:[]};if(_)return l("/search/autocomplete",f({query:t,limit:e}));const{embed:a}=await m(async()=>{const{embed:r}=await import("./chunks/embedder-CEK0uOnA.js");return{embed:r}},[],import.meta.url),[n]=await a([t]);return l("/search/autocomplete",f({query:t,vector:n,limit:e}))}async function C(t){if(!Array.isArray(t)||t.length===0)return null;try{const e=await l("/search/stash",{ids:t});return e&&e.token?e.token:null}catch(e){return console.warn("[FindAstra] stashIds failed:",e),null}}const g=window.FindAstraConfig||{},p=g.i18n||{},b=S(),A=!(g.theme&&g.theme.autocomplete===!1),L=(t,e=300)=>{let a;return(...n)=>{clearTimeout(a),a=setTimeout(()=>t(...n),e)}},u=(t,e)=>{t&&(t.textContent=e)},w=(t,e,a)=>{const n=document.createElement("li");n.className="findastra-widget__result"+(a?" findastra-widget__result--fallback":"");const r=document.createElement("a");if(r.href=e.permalink,r.className="findastra-widget__result-link",e.image){const o=document.createElement("img");o.src=e.image,o.alt="",o.loading="lazy",o.className="findastra-widget__result-image",r.appendChild(o)}const i=document.createElement("div");i.className="findastra-widget__result-meta";const c=document.createElement("div");c.className="findastra-widget__result-title",c.textContent=e.title,i.appendChild(c);const s=document.createElement("div");s.className="findastra-widget__result-price",s.innerHTML=e.price_html,i.appendChild(s),r.appendChild(i),n.appendChild(r),n.dataset.productId=String(e.product_id),n.dataset.score=e.score.toFixed(4),a&&(n.dataset.fallback="1"),t.appendChild(n)},I=(t,e,a)=>{if(t.innerHTML="",e&&e.length){for(const r of e)w(t,r,!1);return}if(a&&a.length){const r=document.createElement("li");r.className="findastra-widget__fallback-header",r.setAttribute("role","presentation"),r.textContent=p.no_results_fallback||"No exact matches — here are some popular products:",t.appendChild(r);for(const i of a)w(t,i,!0);return}const n=document.createElement("li");n.className="findastra-widget__empty",n.textContent=p.no_results||"No matching products.",t.appendChild(n)},N=t=>{const e=t.querySelector("[data-findastra-input]"),a=t.querySelector("[data-findastra-status]"),n=t.querySelector("[data-findastra-results]"),r=t.querySelector("form"),i=parseInt(t.dataset.limit||"12",10),c=async s=>{if(!s||s.length<2){n.innerHTML="",u(a,"");return}u(a,p.searching||"Searching…");try{const o=await y(s,i);u(a,""),I(n,o.results||[],o.fallback||[])}catch(o){console.error(o),u(a,p.error||"Search failed.")}};r?.addEventListener("submit",s=>{s.preventDefault(),c(e.value.trim())}),e?.addEventListener("input",L(s=>{c(s.target.value.trim())},350))},v=()=>{document.querySelectorAll("[data-findastra-widget]").forEach(N),A&&m(()=>import("./chunks/theme-integration-CgzpZgJ4.js"),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{}),b||m(()=>import("./chunks/embedder-CEK0uOnA.js"),[],import.meta.url).then(e=>e.prewarm&&e.prewarm()).catch(()=>{})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",v):v();window.FindAstra=window.FindAstra||{};window.FindAstra.stashIds=C;export{y as a,C as b,S as g,k as s};
//# sourceMappingURL=frontend.js.map
