import{j as t}from"./jsx-runtime.D_zvdyIk.js";import{r as n}from"./index.DIfZGIpv.js";function b({large:i=!1}){const[r,l]=n.useState(""),[c,d]=n.useState([]),[u,o]=n.useState(!1),a=n.useRef(null),s=n.useRef();n.useEffect(()=>{if(r.length<2){d([]);return}return clearTimeout(s.current),s.current=setTimeout(async()=>{try{const e=await fetch(`/api/search?q=${encodeURIComponent(r)}`);e.ok&&d(await e.json())}catch{}},200),()=>clearTimeout(s.current)},[r]),n.useEffect(()=>{const e=w=>{a.current&&!a.current.contains(w.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);const m=e=>{e.key==="Enter"&&r.trim().length>=2&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:"search",search_term:r.trim()}),o(!1),window.location.href=`/zoeken?q=${encodeURIComponent(r.trim())}`)},h=`/zoeken?q=${encodeURIComponent(r.trim())}`,x=()=>{window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:"search",search_term:r.trim()})};return t.jsxs("div",{ref:a,className:"relative z-[60] w-full",children:[t.jsxs("div",{className:`relative flex items-center rounded-2xl border border-border/50 bg-bg-card transition-all focus-within:border-accent/50 focus-within:shadow-lg focus-within:shadow-accent/5 ${i?"px-5 py-4":"px-4 py-2.5"}`,children:[t.jsx("svg",{className:"mr-3 h-5 w-5 shrink-0 text-text-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),t.jsx("input",{type:"text",value:r,onChange:e=>{l(e.target.value),o(!0)},onFocus:()=>o(!0),onKeyDown:m,placeholder:"Zoek sneakers...",className:`w-full bg-transparent text-text placeholder-text-muted outline-none ${i?"text-lg":"text-sm"}`,"aria-label":"Zoek sneakers"}),r&&t.jsx("button",{onClick:()=>{l(""),o(!1)},className:"ml-2 text-text-muted hover:text-text","aria-label":"Zoekopdracht wissen",children:t.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),u&&c.length>0&&t.jsxs("div",{className:"absolute left-0 right-0 top-full z-[100] mt-2 overflow-hidden rounded-2xl border border-border/50 bg-bg-card shadow-2xl",children:[c.map(e=>t.jsxs("a",{href:`/sneakers/${e.slug}`,className:"flex items-center gap-4 px-4 py-3 transition-colors hover:bg-bg-hover",onClick:()=>{window.dataLayer=window.dataLayer||[],window.dataLayer.push({ecommerce:null}),window.dataLayer.push({event:"select_item",ecommerce:{items:[{item_id:e.id,item_name:`${e.brand} ${e.name}`,item_brand:e.brand,price:e.lowestPrice}]}})},children:[t.jsx("img",{src:e.image,alt:"",className:"h-12 w-12 rounded-lg bg-bg-elevated object-contain"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"truncate text-sm font-semibold text-text",children:[e.brand," ",e.name]}),t.jsxs("div",{className:"text-xs text-text-muted",children:[e.colorway,e.shopCount>0&&` · ${e.shopCount} ${e.shopCount===1?"winkel":"winkels"}`]})]}),t.jsxs("div",{className:"text-sm font-bold text-accent",children:["€",e.lowestPrice.toFixed(2).replace(".",",")]})]},e.id)),t.jsxs("a",{href:h,onClick:x,className:"flex items-center justify-center gap-2 border-t border-border/30 px-4 py-3 text-sm font-semibold text-accent transition-colors hover:bg-bg-hover",children:["Bekijk alle resultaten",t.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})]})]})]})}export{b as default};
