import{r}from"./index.DIfZGIpv.js";import{c as b}from"./client.D72tZIIN.js";import{j as t}from"./jsx-runtime.D_zvdyIk.js";import"./index.XeJbqeyU.js";function N(){const[a,l]=r.useState([]),[h,x]=r.useState(null),[p,u]=r.useState(!0),[m,i]=r.useState(null),[c,o]=r.useState("");r.useEffect(()=>{Promise.all([fetch("/api/auth/session").then(e=>e.json()),fetch("/api/watchlist").then(e=>e.json()).catch(()=>({items:[]}))]).then(([e,s])=>{x(e.user),l(s.items||[]),u(!1)})},[]);const g=async e=>{await fetch("/api/watchlist",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({product_id:e})}),l(a.filter(s=>s.product_id!==e))},w=async e=>{const s=c?parseFloat(c):null;await fetch("/api/watchlist",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({product_id:e,target_price:s})}),l(a.map(n=>n.product_id===e?{...n,target_price:s}:n)),i(null),o("")};return p?t.jsx("div",{className:"text-center text-white/40 py-12",children:"Laden..."}):h?a.length===0?t.jsxs("div",{className:"text-center py-12",children:[t.jsx("p",{className:"text-4xl mb-4",children:"👟"}),t.jsx("p",{className:"text-white/60 mb-4",children:"Je watchlist is nog leeg"}),t.jsx("a",{href:"/",className:"inline-block rounded-lg bg-[#00FF6A] px-6 py-2.5 font-bold text-black",children:"Ontdek sneakers"})]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("p",{className:"text-sm text-white/40",children:[a.length," sneaker",a.length!==1?"s":""," op je watchlist"]}),a.map(e=>{const s=e.cutout_image_url||e.image_url,n=e.original_price&&e.lowest_price&&e.lowest_price<e.original_price;return t.jsxs("div",{className:"flex gap-4 rounded-xl border border-white/10 bg-white/5 p-4",children:[t.jsx("a",{href:`/sneakers/${e.slug}`,className:"shrink-0",children:t.jsx("img",{src:s,alt:e.name,className:"h-24 w-24 rounded-lg object-contain bg-white/5"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-[11px] font-bold uppercase tracking-widest text-white/40",children:e.brand}),t.jsx("a",{href:`/sneakers/${e.slug}`,className:"font-semibold text-white hover:text-[#00FF6A] transition-colors",children:e.name}),e.colorway&&t.jsx("p",{className:"text-xs text-white/40",children:e.colorway}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-3",children:[e.lowest_price?t.jsxs("span",{className:"text-lg font-black text-[#00FF6A]",children:["€",Number(e.lowest_price).toFixed(2).replace(".",",")]}):t.jsx("span",{className:"text-sm text-white/40",children:"Niet beschikbaar"}),n&&t.jsxs("span",{className:"text-sm text-white/40 line-through",children:["€",Number(e.original_price).toFixed(2).replace(".",",")]}),t.jsxs("span",{className:"text-xs text-white/30",children:[e.shop_count," shop",Number(e.shop_count)!==1?"s":""]})]}),t.jsx("div",{className:"mt-2 flex items-center gap-2",children:m===e.product_id?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-xs text-white/40",children:"Alert onder €"}),t.jsx("input",{type:"number",value:c,onChange:j=>o(j.target.value),step:"0.01",min:"0",className:"w-20 rounded border border-white/10 bg-white/5 px-2 py-1 text-sm text-white focus:border-[#00FF6A]/50 focus:outline-none",autoFocus:!0}),t.jsx("button",{onClick:()=>w(e.product_id),className:"text-xs text-[#00FF6A] hover:underline",children:"Opslaan"}),t.jsx("button",{onClick:()=>i(null),className:"text-xs text-white/30 hover:text-white/60",children:"×"})]}):t.jsx("button",{onClick:()=>{i(e.product_id),o(e.target_price?.toString()||"")},className:"text-xs text-white/40 hover:text-[#00FF6A] transition-colors",children:e.target_price?`🎯 Alert onder €${Number(e.target_price).toFixed(2).replace(".",",")} — wijzig`:"+ Prijsalert instellen"})})]}),t.jsx("button",{onClick:()=>g(e.product_id),className:"shrink-0 self-start rounded-full p-2 text-white/30 hover:bg-red-500/10 hover:text-red-400 transition-colors",title:"Verwijderen",children:t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"w-4 h-4",children:t.jsx("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})})})]},e.id)})]}):t.jsxs("div",{className:"text-center py-12",children:[t.jsx("p",{className:"text-white/60 mb-4",children:"Log in om je watchlist te bekijken"}),t.jsx("a",{href:"/",className:"inline-block rounded-lg bg-[#00FF6A] px-6 py-2.5 font-bold text-black",children:"Naar home"})]})}const d=document.getElementById("watchlist-app");d&&b.createRoot(d).render(r.createElement(N));
