import{j as e}from"./jsx-runtime.D_zvdyIk.js";import{r as s}from"./index.DIfZGIpv.js";import{r as C}from"./index.cthNB-FE.js";import"./index.XeJbqeyU.js";function P({productId:n,size:g="sm"}){const[o,d]=s.useState(!1),[r,l]=s.useState(!1),[x,f]=s.useState(null),[w,h]=s.useState(!1),[u,b]=s.useState(""),[m,i]=s.useState(""),[p,j]=s.useState("");s.useEffect(()=>{fetch("/api/auth/session").then(t=>t.json()).then(t=>{t.user&&(f(t.user),fetch("/api/watchlist").then(c=>c.json()).then(c=>{c.items?.some(a=>a.product_id===n)&&d(!0)}).catch(()=>{}))}).catch(()=>{})},[n]);const y=async t=>{if(t.preventDefault(),t.stopPropagation(),!x){h(!0);return}l(!0);try{o?(await fetch("/api/watchlist",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({product_id:n})}),d(!1)):(await fetch("/api/watchlist",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({product_id:n,target_price:p?parseFloat(p):null})}),d(!0))}catch{}l(!1)},v=async t=>{t.preventDefault(),l(!0),i("");try{const a=await(await fetch("/api/auth/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:u})})).json();if(a.ok)i("Check je email! 📧");else if(a.error?.includes("al geregistreerd")){const k=await(await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:u})})).json();i(k.message||"Check je email voor de inloglink!")}else i(a.error||"Er ging iets mis")}catch{i("Er ging iets mis")}l(!1)},N=g==="sm"?"w-5 h-5":"w-6 h-6",S=g==="sm"?"p-1.5":"p-2";return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:y,disabled:r,className:`${S} rounded-full transition-all duration-200 ${o?"bg-[#00FF6A]/20 text-[#00FF6A]":"bg-white/10 text-white/60 hover:bg-white/20 hover:text-white"} ${r?"opacity-50":""}`,title:o?"Verwijder van watchlist":"Voeg toe aan watchlist",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:o?"currentColor":"none",stroke:"currentColor",strokeWidth:2,className:N,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 8.25c0-2.485-2.099-4.5-4.688-4.5-1.935 0-3.597 1.126-4.312 2.733-.715-1.607-2.377-2.733-4.313-2.733C5.1 3.75 3 5.765 3 8.25c0 7.22 9 12 9 12s9-4.78 9-12z"})})}),w&&typeof document<"u"&&C.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/70 p-4",onClick:t=>{t.target===t.currentTarget&&h(!1)},children:e.jsxs("div",{className:"w-full max-w-sm rounded-2xl border border-white/10 bg-[#141414] p-6 shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{className:"mb-2 text-lg font-bold text-white",children:"Sneaker volgen"}),e.jsx("p",{className:"mb-4 text-sm text-white/60",children:"Voer je email in om deze sneaker op je watchlist te zetten en prijsalerts te ontvangen."}),e.jsxs("form",{onSubmit:v,children:[e.jsx("input",{type:"email",value:u,onChange:t=>b(t.target.value),placeholder:"je@email.nl",required:!0,className:"mb-3 w-full rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-white placeholder-white/30 focus:border-[#00FF6A]/50 focus:outline-none"}),e.jsxs("div",{className:"mb-3 rounded-lg border border-white/10 bg-white/5 p-3",children:[e.jsx("p",{className:"text-xs font-medium text-white/50 mb-1.5",children:"Prijsalert (optioneel)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-white/60",children:"Mail mij onder €"}),e.jsx("input",{type:"number",value:p,onChange:t=>j(t.target.value),placeholder:"0,00",step:"0.01",min:"0",className:"w-24 rounded-lg border border-white/10 bg-white/5 px-3 py-1.5 text-white placeholder-white/30 focus:border-[#00FF6A]/50 focus:outline-none"})]})]}),m&&e.jsx("p",{className:`mb-3 text-sm ${m.includes("Check")?"text-[#00FF6A]":"text-red-400"}`,children:m}),e.jsx("button",{type:"submit",disabled:r,className:"w-full rounded-lg bg-[#00FF6A] px-4 py-2.5 font-bold text-black transition-colors hover:bg-[#00FF6A]/90 disabled:opacity-50",children:r?"Even geduld...":"Watchlist & Alerts activeren"})]}),e.jsx("button",{onClick:()=>h(!1),className:"mt-3 w-full text-center text-sm text-white/40 hover:text-white/60",children:"Annuleren"})]})}),document.body)]})}export{P as default};
