import{j as e}from"./jsx-runtime.D_zvdyIk.js";import{r as a}from"./index.DIfZGIpv.js";import{A as R,a as E,u as L}from"./AdminAuth.CbzFS552.js";import{A as $}from"./AdminLayout.CKC2eNsX.js";function _(){const{token:u}=L(),[c,b]=a.useState(30),[n,j]=a.useState(""),[l,v]=a.useState("score"),[o,h]=a.useState("desc"),[d,f]=a.useState([]),[N,g]=a.useState(0),[i,x]=a.useState(1),[A,p]=a.useState(!0),F={Authorization:`Bearer ${u}`};a.useEffect(()=>{p(!0);const t=new URLSearchParams({days:String(c),sort:l,order:o,page:String(i),limit:"50"});n&&t.set("brand",n),fetch(`/api/admin/performance?${t}`,{headers:F}).then(s=>s.json()).then(s=>{f(s.data||[]),g(s.total||0)}).finally(()=>p(!1))},[c,n,l,o,i]);const y=t=>{l===t?h(o==="desc"?"asc":"desc"):(v(t),h("desc"))},w=()=>{const t=["name","brand","pageviews","clicks","watchlist_adds","active_alerts","ctr","conversions","revenue","score"],s=[t.join(","),...d.map(C=>t.map(P=>`"${C[P]??""}"`).join(","))].join(`
`),S=new Blob([s],{type:"text/csv"}),k=URL.createObjectURL(S),m=document.createElement("a");m.href=k,m.download=`performance-${c}d.csv`,m.click()},r=({col:t,label:s})=>e.jsxs("th",{className:"pb-2 cursor-pointer hover:text-[#00FF6A] select-none",onClick:()=>y(t),children:[s," ",l===t&&(o==="desc"?"↓":"↑")]});return e.jsxs($,{title:"Product Performance",children:[e.jsxs("div",{className:"flex flex-wrap gap-3 mb-6 items-center",children:[[7,30,90].map(t=>e.jsxs("button",{onClick:()=>{b(t),x(1)},className:`px-4 py-1.5 rounded-lg text-sm ${c===t?"bg-[#00FF6A] text-black font-medium":"bg-[#1A1A1A] text-[#999] hover:text-white"}`,children:[t,"d"]},t)),e.jsx("input",{type:"text",placeholder:"Filter merk...",value:n,onChange:t=>{j(t.target.value),x(1)},className:"bg-[#1A1A1A] border border-[#333] rounded-lg px-3 py-1.5 text-sm text-[#F5F5F5] w-48"}),e.jsx("button",{onClick:w,className:"ml-auto px-4 py-1.5 rounded-lg text-sm bg-[#1A1A1A] text-[#999] hover:text-white border border-[#333]",children:"📥 Export CSV"})]}),e.jsxs("div",{className:"bg-[#141414] border border-[#333] rounded-xl overflow-hidden",children:[A?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("div",{className:"w-8 h-8 border-2 border-[#00FF6A] border-t-transparent rounded-full animate-spin"})}):d.length===0?e.jsx("div",{className:"text-[#666] text-center py-20",children:"Geen producten gevonden"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-[#999] text-left bg-[#0F0F0F]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Product"}),e.jsx(r,{col:"pageviews",label:"Views"}),e.jsx(r,{col:"clicks",label:"Clicks"}),e.jsx(r,{col:"watchlist",label:"Watchlist"}),e.jsx("th",{className:"pb-2",children:"Alerts"}),e.jsx(r,{col:"ctr",label:"CTR"}),e.jsx(r,{col:"conversions",label:"Conv."}),e.jsx(r,{col:"revenue",label:"Revenue"}),e.jsx(r,{col:"score",label:"Score"})]})}),e.jsx("tbody",{children:d.map((t,s)=>e.jsxs("tr",{className:"border-t border-[#222] hover:bg-[#1A1A1A]",children:[e.jsxs("td",{className:"p-3",children:[e.jsx("div",{className:"text-[#F5F5F5] max-w-[250px] truncate",children:t.name}),e.jsx("div",{className:"text-xs text-[#666]",children:t.brand})]}),e.jsx("td",{className:"p-3 text-[#999]",children:t.pageviews}),e.jsx("td",{className:"p-3 text-[#999]",children:t.clicks}),e.jsx("td",{className:"p-3 text-[#999]",children:t.watchlist_adds}),e.jsx("td",{className:"p-3 text-[#999]",children:t.active_alerts}),e.jsxs("td",{className:"p-3 text-[#999]",children:[t.ctr,"%"]}),e.jsx("td",{className:"p-3 text-[#999]",children:t.conversions}),e.jsxs("td",{className:"p-3 text-[#00FF6A]",children:["€",Number(t.revenue).toFixed(2)]}),e.jsx("td",{className:"p-3 font-medium text-[#F5F5F5]",children:Math.round(Number(t.score))})]},s))})]})}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-[#222] text-sm text-[#999]",children:[e.jsxs("span",{children:[N," producten"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>x(t=>Math.max(1,t-1)),disabled:i===1,className:"px-3 py-1 rounded bg-[#1A1A1A] disabled:opacity-30",children:"←"}),e.jsxs("span",{className:"px-3 py-1",children:["Pagina ",i]}),e.jsx("button",{onClick:()=>x(t=>t+1),disabled:d.length<50,className:"px-3 py-1 rounded bg-[#1A1A1A] disabled:opacity-30",children:"→"})]})]})]})]})}function G(){return e.jsx(R,{children:e.jsx(E,{children:e.jsx(_,{})})})}export{G as default};
