1import{r as a,j as s}from"./react-RN8z7mqm.js";import{s as p}from"./supabase-D7bm-uKx.js";import{toast as c}from"./sonner-CSA395gJ.js";import{q as g,ad as w,am as j,ae as y,ap as N}from"./icons-CFy5kY0-.js";function S(){const[m,h]=a.useState([]),[f,b]=a.useState(!0),[i,u]=a.useState(null),n=a.useCallback(async e=>{const{data:{session:t}}=await p.auth.getSession();if(!t?.access_token)throw new Error("Not signed in");const r=await fetch("/api/blog/admin",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.access_token}`},body:JSON.stringify(e)}),x=await r.json();if(!r.ok)throw new Error(x.error??"Request failed");return x},[]),l=a.useCallback(async()=>{try{const e=await n({action:"list"});h(e.posts??[])}catch(e){c.error(e instanceof Error?e.message:"Load failed")}finally{b(!1)}},[n]);a.useEffect(()=>{l()},[l]);const d=async(e,t)=>{if(!(e==="delete"&&t&&!confirm(`Delete "${t.title}" permanently?`))){u(t?.id??e);try{await n({action:e,id:t?.id}),c.success(e==="publish"?"Published + IndexNow pinged":e==="draft-now"?"Draft generated â review below":"Done"),await l()}catch(r){c.error(r instanceof Error?r.message:"Failed")}finally{u(null)}}},o=m.filter(e=>!e.published);return f?s.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"Loadingâ¦"}):s.jsxs("div",{className:"mx-auto max-w-5xl p-6",children:[s.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"font-serif text-2xl",children:"Blog"}),s.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["The cron drafts one post every Tuesday 08:00 UTC (house DeepSeek, ~$0.001). Nothing goes live without your click â publish pings IndexNow automatically.",o.length>0&&s.jsxs("span",{className:"ml-1 font-medium text-foreground",children:[o.length," draft",o.length>1?"s":""," awaiting review."]})]})]}),s.jsxs("button",{onClick:()=>d("draft-now"),disabled:i==="draft-now",className:"inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs hover:bg-accent disabled:opacity-50",children:[s.jsx(g,{className:"h-3.5 w-3.5"})," ",i==="draft-now"?"Draftingâ¦":"Draft next topic now"]})]}),s.jsx("div",{className:"mt-6 space-y-3",children:m.map(e=>s.jsx("div",{className:`rounded-xl border p-4 ${e.published?"bg-card":"border-primary/40 bg-primary/5"}`,children:s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"font-medium",children:e.title}),s.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-semibold ${e.published?"bg-green-500/10 text-green-600":"bg-primary/10 text-primary"}`,children:e.published?"live":"draft"})]}),s.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:e.description}),s.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["/blog/",e.slug," · ",new Date(e.created_at).toLocaleDateString()]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.published&&s.jsx("a",{href:`/blog/${e.slug}`,target:"_blank",rel:"noreferrer",className:"rounded-md border p-1.5 hover:bg-accent",title:"View live",children:s.jsx(w,{className:"h-3.5 w-3.5"})}),s.jsxs("button",{onClick:()=>d(e.published?"unpublish":"publish",e),disabled:i===e.id,className:"inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs hover:bg-accent disabled:opacity-50",title:e.published?"Unpublish":"Publish + ping IndexNow",children:[e.published?s.jsx(j,{className:"h-3.5 w-3.5"}):s.jsx(y,{className:"h-3.5 w-3.5"}),e.published?"Unpublish":"Publish"]}),s.jsx("button",{onClick:()=>d("delete",e),disabled:i===e.id,className:"rounded-md border p-1.5 hover:bg-accent hover:text-destructive disabled:opacity-50",title:"Delete",children:s.jsx(N,{className:"h-3.5 w-3.5"})})]})]})},e.id))})]})}export{S as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.