import{j as e}from"./jsx-runtime.D_zvdyIk.js";import{r as a}from"./index.DIfZGIpv.js";import{A as N,a as f,u as v}from"./AdminAuth.CbzFS552.js";import{A as o}from"./AdminLayout.CKC2eNsX.js";import{R as b,X as _,Y as y,T as B}from"./CartesianChart.zfG3JjV4.js";import{B as A,a as d}from"./BarChart.Dgp66h7A.js";import"./index.cthNB-FE.js";import"./index.XeJbqeyU.js";function k(){const{token:x}=v(),[i,h]=a.useState([]),[r,m]=a.useState(null),[l,u]=a.useState([]),[p,F]=a.useState(!0),c={Authorization:`Bearer ${x}`};a.useEffect(()=>{fetch("/api/admin/feeds/health",{headers:c}).then(s=>s.json()).then(s=>h(s.feeds||[])).finally(()=>F(!1))},[]),a.useEffect(()=>{r&&fetch(`/api/admin/feeds/health?feed_id=${r}`,{headers:c}).then(s=>s.json()).then(s=>u(s.history||[]))},[r]);const j=s=>{if(!s)return"-";const n=s.minutes||0,t=s.seconds||0;return n>0?`${n}m ${t}s`:`${t}s`},g=s=>{if(!s)return"Nooit";const n=Date.now()-new Date(s).getTime(),t=Math.floor(n/36e5);return t<1?`${Math.floor(n/6e4)}m geleden`:t<24?`${t}u geleden`:`${Math.floor(t/24)}d geleden`};return p?e.jsx(o,{title:"Feed Health",children: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"})})}):e.jsx(o,{title:"Feed Health",children:e.jsxs("div",{className:"space-y-4",children:[i.map(s=>e.jsxs("div",{className:`bg-[#141414] border rounded-xl p-5 cursor-pointer transition-colors
            ${s.stale?"border-[#FF3B3B]/50":s.high_errors?"border-[#FFD700]/50":"border-[#333]"}
            ${r===s.id?"ring-1 ring-[#00FF6A]":""}`,onClick:()=>m(r===s.id?null:s.id),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${s.is_enabled?s.stale?"bg-[#FF3B3B]":"bg-[#00FF6A]":"bg-[#666]"}`}),e.jsx("span",{className:"text-[#F5F5F5] font-medium",children:s.name}),s.stale&&e.jsx("span",{className:"text-xs bg-[#FF3B3B]/20 text-[#FF3B3B] px-2 py-0.5 rounded",children:"Stale (>24h)"}),s.high_errors&&e.jsx("span",{className:"text-xs bg-[#FFD700]/20 text-[#FFD700] px-2 py-0.5 rounded",children:"High Errors"})]}),e.jsxs("div",{className:"flex items-center gap-6 text-sm text-[#999]",children:[e.jsxs("span",{title:"Products",children:[s.product_count||0," prod."]}),e.jsxs("span",{title:"Sneaker ratio",children:[s.sneaker_ratio,"% sneakers"]}),e.jsx("span",{title:"Last sync",children:g(s.last_sync_at)}),e.jsx("span",{title:"Duration",children:j(s.duration)}),e.jsx("span",{className:s.last_sync_status==="success"?"text-[#00FF6A]":"text-[#FF3B3B]",children:s.last_sync_status||"-"})]})]}),r===s.id&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-[#222]",children:[e.jsxs("div",{className:"grid grid-cols-5 gap-4 text-sm mb-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[#666]",children:"Fetched:"})," ",e.jsx("span",{className:"text-[#F5F5F5]",children:s.products_fetched??"-"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#666]",children:"New:"})," ",e.jsx("span",{className:"text-[#00FF6A]",children:s.products_new??"-"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#666]",children:"Updated:"})," ",e.jsx("span",{className:"text-[#F5F5F5]",children:s.products_updated??"-"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#666]",children:"Removed:"})," ",e.jsx("span",{className:"text-[#FF3B3B]",children:s.products_removed??"-"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#666]",children:"Errors:"})," ",e.jsx("span",{className:s.errors_count>0?"text-[#FFD700]":"text-[#F5F5F5]",children:s.errors_count??"-"})]})]}),s.last_error&&e.jsx("div",{className:"text-xs text-[#FF3B3B] bg-[#FF3B3B]/10 p-2 rounded mb-4 max-h-20 overflow-auto",children:s.last_error}),l.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm text-[#999] mb-2",children:"Sync History"}),e.jsx(b,{width:"100%",height:150,children:e.jsxs(A,{data:[...l].reverse(),children:[e.jsx(_,{dataKey:"started_at",tick:!1}),e.jsx(y,{tick:{fill:"#999",fontSize:11}}),e.jsx(B,{contentStyle:{background:"#1A1A1A",border:"1px solid #333",borderRadius:8,fontSize:12}}),e.jsx(d,{dataKey:"products_new",stackId:"a",fill:"#00FF6A",name:"New"}),e.jsx(d,{dataKey:"products_updated",stackId:"a",fill:"#FFD700",name:"Updated"}),e.jsx(d,{dataKey:"products_removed",stackId:"a",fill:"#FF3B3B",name:"Removed"})]})})]})]})]},s.id)),i.length===0&&e.jsx("div",{className:"text-[#666] text-center py-20",children:"Geen feeds geconfigureerd"})]})})}function K(){return e.jsx(N,{children:e.jsx(f,{children:e.jsx(k,{})})})}export{K as default};
