import{j as e}from"./jsx-runtime.D_zvdyIk.js";import{r as l}from"./index.2yJIXLcc.js";import{G as i}from"./iconBase.Blz05Vck.js";function m(a){return i({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"m289.94 256 95-95A24 24 0 0 0 351 127l-95 95-95-95a24 24 0 0 0-34 34l95 95-95 95a24 24 0 1 0 34 34l95-95 95 95a24 24 0 0 0 34-34z"},child:[]}]})(a)}function f(a){return i({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M456.69 421.39 362.6 327.3a173.81 173.81 0 0 0 34.84-104.58C397.44 126.38 319.06 48 222.72 48S48 126.38 48 222.72s78.38 174.72 174.72 174.72A173.81 173.81 0 0 0 327.3 362.6l94.09 94.09a25 25 0 0 0 35.3-35.3zM97.92 222.72a124.8 124.8 0 1 1 124.8 124.8 124.95 124.95 0 0 1-124.8-124.8z"},child:[]}]})(a)}const w=()=>{const[a,s]=l.useState(!1),[u,n]=l.useState("");l.useEffect(()=>{const r=new URLSearchParams(window.location.search).get("q");r&&(n(r),s(!0));const c=document.getElementById("searchInput");(a||r)&&c.focus()},[a]);const o=t=>{const r=t?`/products?q=${encodeURIComponent(t)}`:"/products";window.location.href=r.toString()},d=t=>{s(!0),n(t.target.value),o(t.target.value)},p=()=>{n(""),s(!1),o("")},h=t=>{t.preventDefault();const c=t.target.search;o(c.value)};return e.jsxs("form",{onSubmit:h,className:"border border-border dark:border-darkmode-border rounded-full flex bg-light/10 pl-4 relative",children:[e.jsx("input",{type:"text",name:"search",placeholder:"Search for products",autoComplete:"off",value:u,onChange:d,id:"searchInput",className:"bg-transparent border-none search-input focus:ring-transparent p-2 w-full"}),e.jsxs("div",{className:"absolute right-0 top-0 flex h-full items-center",children:[u&&e.jsx("button",{type:"button",onClick:p,className:"p-2 m-1 rounded-full",children:e.jsx(m,{className:"h-4 w-4"})}),e.jsx("button",{type:"submit",className:"search-icon p-2 m-1 rounded-full",children:e.jsx(f,{className:"h-5 w-5"})})]})]})};export{w as default};
