import{s as a,j as e,L as l}from"./index-BH-cN4KT.js";import{a as c}from"./useQuery-C5OEng6p.js";import{A as v,F as d,I as N,R as y,M as w,a as k}from"./AdminShell-CWlEEeGv.js";import{C as o,a as u,b as m,c as x}from"./card-Doevctt3.js";import{E as q}from"./eye-DGHiGxQG.js";import"./use-auth-wvxHCDzg.js";import"./button-ChRro_zr.js";function r({label:n,value:i,icon:t,to:s}){return e.jsx(l,{to:s,className:"block",children:e.jsxs(o,{className:"hover:border-brand-accent transition-colors",children:[e.jsxs(u,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(m,{className:"text-xs uppercase tracking-widest text-muted-foreground",children:n}),e.jsx(t,{className:"w-4 h-4 text-brand-accent"})]}),e.jsx(x,{children:e.jsx("div",{className:"text-3xl font-serif font-black",children:i})})]})})}function R(){const n=c({queryKey:["admin","dashboard-stats"],queryFn:async()=>{const[s,b,f,h,p,j,g]=await Promise.all([a.from("articles").select("id",{count:"exact",head:!0}).eq("status","published"),a.from("articles").select("id",{count:"exact",head:!0}).eq("status","draft"),a.from("citizen_submissions").select("id",{count:"exact",head:!0}).eq("status","pending"),a.from("breaking_news").select("id",{count:"exact",head:!0}).eq("active",!0),a.from("ad_slots").select("id",{count:"exact",head:!0}).eq("active",!0),a.from("polls").select("id",{count:"exact",head:!0}).eq("active",!0),a.from("article_views").select("id",{count:"exact",head:!0})]);return{published:s.count??0,drafts:b.count??0,submissions:f.count??0,breaking:h.count??0,ads:p.count??0,polls:j.count??0,views:g.count??0}}}),i=c({queryKey:["admin","recent-articles"],queryFn:async()=>{const{data:s}=await a.from("articles").select("id, title, status, updated_at, author_name").order("updated_at",{ascending:!1}).limit(8);return s??[]}}),t=n.data;return e.jsxs(v,{title:"Newsroom Dashboard",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 mb-8",children:[e.jsx(r,{label:"Published",value:t?.published??"—",icon:d,to:"/admin/articles"}),e.jsx(r,{label:"Drafts",value:t?.drafts??"—",icon:d,to:"/admin/articles"}),e.jsx(r,{label:"Pending Submissions",value:t?.submissions??"—",icon:N,to:"/admin/submissions"}),e.jsx(r,{label:"Breaking",value:t?.breaking??"—",icon:y,to:"/admin/breaking"}),e.jsx(r,{label:"Active Polls",value:t?.polls??"—",icon:w,to:"/admin/polls"}),e.jsx(r,{label:"Active Ads",value:t?.ads??"—",icon:k,to:"/admin/ads"})]}),e.jsxs(o,{children:[e.jsxs(u,{className:"flex flex-row items-center justify-between",children:[e.jsx(m,{className:"font-serif",children:"Recent activity"}),e.jsx(q,{className:"w-4 h-4 text-muted-foreground"})]}),e.jsx(x,{children:i.data?.length?e.jsx("ul",{className:"divide-y divide-border",children:i.data.map(s=>e.jsxs("li",{className:"py-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold truncate",children:s.title}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.author_name??"Staff"," · ",new Date(s.updated_at).toLocaleString()]})]}),e.jsx("span",{className:`text-[10px] font-black uppercase px-2 py-0.5 rounded-sm ${s.status==="published"?"bg-brand-accent/10 text-brand-accent":"bg-muted text-muted-foreground"}`,children:s.status})]},s.id))}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No articles yet. ",e.jsx(l,{to:"/admin/articles",className:"text-brand-accent underline",children:"Create your first story"}),"."]})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-6",children:["Total recorded views across all articles: ",e.jsx("strong",{children:t?.views??0})]})]})}export{R as component};
