1import{f as Z,e as P,a as ee,r as m,j as e,L as _,B as a,s as te}from"./index-CK3vutSl.js";import{S as se}from"./SEOHead-CON3zavc.js";import{C as S,a as k}from"./card-DZ0L_26S.js";import{B as g}from"./badge-DSpRzzed.js";import{T as ae}from"./textarea-CymhbYJ8.js";import{D as B,a as T,b as R,c as F,d as L,e as O}from"./dialog-CaAso78V.js";import{T as re,a as ie,b as z,c,d as ne,e as d}from"./table-PtNWaZC5.js";import{N as E}from"./Navbar-BUpDNnzb.js";import{F as G}from"./Footer-FFVJjLyw.js";import{c as oe,d as le,e as ce}from"./useBlogSubmissions-BmnwYOyP.js";import{u as de}from"./useIsAdmin-BuXYVmKR.js";import{u as me,A as xe}from"./useAIGenerate-Cm_fIzvW.js";import{L as f}from"./loader-circle-XW1Y8Qce.js";import{A as he}from"./arrow-left-BUIXgTrn.js";import{F as pe}from"./index-0mbE7Hqp.js";import{E as ue}from"./eye-Bn8L-HjB.js";import{C as je}from"./circle-check-C6IuHH5E.js";import{C as ge}from"./circle-x-768GWCHb.js";import{T as fe}from"./trash-2-BxXxfsBm.js";import"./index-DbsHWzTR.js";import"./Combination-CMXmbd7n.js";import"./useProfile-B5IlLGJw.js";import"./avatar-C3uy22Nn.js";import"./index-BsnkaMDn.js";import"./chevron-right-CWRhAgdX.js";import"./settings-CZ-FKz03.js";import"./log-out-BwoLdbKR.js";import"./user-COEoZknB.js";import"./house-DvWMWEH7.js";import"./message-square-bZ_BbvsG.js";import"./users-yySNN4BJ.js";import"./plus-D178_5fr.js";import"./calendar-days-Bm2AhvK-.js";import"./sparkles-ubwtpnfR.js";import"./heart-CV_CSns9.js";import"./star-DA5biP6Q.js";import"./zap-BjYdfLPn.js";import"./map-pin-BOiT9jNc.js";import"./building-2-tZ3PgJs7.js";import"./external-link-Iw7g49f4.js";import"./useQuery-Cmekee7_.js";import"./useMutation-CVx1DYW2.js";const ot=()=>{const{isAdmin:I,loading:H}=de(),{user:p}=Z(),{data:r,isLoading:$}=oe(),i=le(),v=ce(),{generate:q,isGenerating:M}=me(),{toast:b}=P(),Q=ee(),[s,u]=m.useState(null),[V,x]=m.useState(!1),[J,h]=m.useState(!1),[N,w]=m.useState(""),[j,K]=m.useState("all"),U=async()=>{const t=await q({type:"blog",mode:"full_draft"});if(t)try{let o=t.trim();o.startsWith("```")&&(o=o.replace(/^```(?:json)?\n?/,"").replace(/\n?```$/,""));const l=JSON.parse(o),{error:D}=await te.from("blog_submissions").insert({title:l.title,slug:l.slug||l.title.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),excerpt:l.excerpt,content:l.content,author_name:"Coliving Revolution",author_email:"[email protected]",user_id:(p==null?void 0:p.id)||null,status:"pending"});if(D)throw D;Q.invalidateQueries({queryKey:["blog-submissions-all"]}),b({title:"AI Draft Created",description:`"${l.title}" saved as pending.`})}catch(o){console.error("Failed to save AI draft:",o),b({title:"Parse Error",description:"Could not parse AI response. Try again.",variant:"destructive"})}},C=async t=>{await i.mutateAsync({id:t,status:"approved"})},W=async()=>{s&&(await i.mutateAsync({id:s.id,status:"rejected",rejection_reason:N}),h(!1),w(""),u(null))},X=async t=>{confirm("Are you sure you want to delete this submission?")&&await v.mutateAsync(t)},y=t=>{u(t),h(!0)},Y=t=>{u(t),x(!0)},n=r==null?void 0:r.filter(t=>j==="all"?!0:t.status===j),A=(r==null?void 0:r.filter(t=>t.status==="pending").length)||0;return H?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(f,{className:"w-8 h-8 animate-spin text-primary"})}):I?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(se,{title:"Admin â Blog",description:"Review and manage blog post submissions.",noindex:!0}),e.jsx(E,{}),e.jsx("section",{className:"pt-32 pb-16 px-4",children:e.jsxs("div",{className:"container mx-auto",children:[e.jsx(_,{to:"/blog",children:e.jsxs(a,{variant:"ghost",className:"mb-6",children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),"Back to Blog"]})}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4 mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-heading text-3xl font-bold text-foreground mb-2",children:"Blog Submissions"}),e.jsx("p",{className:"text-muted-foreground",children:"Review and manage blog post submissions"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[A>0&&e.jsxs(g,{className:"bg-amber-500/20 text-amber-600 border-amber-500/30 w-fit",children:[A," pending review"]}),e.jsx(xe,{onClick:U,isLoading:M,label:"Generate Blog Draft"})]})]}),e.jsx("div",{className:"flex gap-2 mb-6",children:["all","pending","approved","rejected"].map(t=>e.jsx(a,{variant:j===t?"default":"outline",size:"sm",onClick:()=>K(t),className:"capitalize",children:t},t))}),$?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(f,{className:"w-8 h-8 animate-spin text-primary"})}):(n==null?void 0:n.length)===0?e.jsx(S,{children:e.jsxs(k,{className:"py-12 text-center",children:[e.jsx(pe,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"No submissions foun
1d"})]})}):e.jsx(S,{children:e.jsx(k,{className:"p-0",children:e.jsxs(re,{children:[e.jsx(ie,{children:e.jsxs(z,{children:[e.jsx(c,{children:"Title"}),e.jsx(c,{children:"Author"}),e.jsx(c,{children:"Topic"}),e.jsx(c,{children:"Status"}),e.jsx(c,{children:"Submitted"}),e.jsx(c,{className:"text-right",children:"Actions"})]})}),e.jsx(ne,{children:n==null?void 0:n.map(t=>e.jsxs(z,{children:[e.jsx(d,{className:"font-medium max-w-xs truncate",children:t.title}),e.jsx(d,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t.author_name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.author_email})]})}),e.jsx(d,{children:t.blog_topics?e.jsx(g,{style:{backgroundColor:`${t.blog_topics.color}20`,color:t.blog_topics.color||void 0,borderColor:`${t.blog_topics.color}50`},children:t.blog_topics.name}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(d,{children:e.jsx(g,{variant:t.status==="approved"?"default":t.status==="rejected"?"destructive":"secondary",children:t.status})}),e.jsx(d,{className:"text-muted-foreground",children:new Date(t.created_at).toLocaleDateString()}),e.jsx(d,{children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a,{variant:"ghost",size:"icon",onClick:()=>Y(t),children:e.jsx(ue,{className:"w-4 h-4"})}),t.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx(a,{variant:"ghost",size:"icon",onClick:()=>C(t.id),disabled:i.isPending,className:"text-green-600 hover:text-green-700 hover:bg-green-50",children:e.jsx(je,{className:"w-4 h-4"})}),e.jsx(a,{variant:"ghost",size:"icon",onClick:()=>y(t),disabled:i.isPending,className:"text-red-600 hover:text-red-700 hover:bg-red-50",children:e.jsx(ge,{className:"w-4 h-4"})})]}),e.jsx(a,{variant:"ghost",size:"icon",onClick:()=>X(t.id),disabled:v.isPending,className:"text-muted-foreground hover:text-destructive",children:e.jsx(fe,{className:"w-4 h-4"})})]})})]},t.id))})]})})})]})}),e.jsx(B,{open:V,onOpenChange:x,children:e.jsxs(T,{className:"max-w-3xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(R,{children:[e.jsx(F,{className:"font-heading text-xl",children:s==null?void 0:s.title}),e.jsxs(L,{children:["By ",s==null?void 0:s.author_name," (",s==null?void 0:s.author_email,")"]})]}),e.jsxs("div",{className:"space-y-4",children:[(s==null?void 0:s.featured_image_url)&&e.jsx("img",{src:s.featured_image_url,alt:s.title,className:"w-full h-48 object-cover rounded-lg"}),(s==null?void 0:s.excerpt)&&e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground mb-1",children:"Excerpt"}),e.jsx("p",{className:"text-foreground",children:s.excerpt})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm text-muted-foreground mb-1",children:"Content"}),e.jsx("div",{className:"prose prose-sm max-w-none text-foreground whitespace-pre-wrap",children:s==null?void 0:s.content})]}),(s==null?void 0:s.rejection_reason)&&e.jsxs("div",{className:"bg-destructive/10 p-4 rounded-lg",children:[e.jsx("h4",{className:"font-semibold text-sm text-destructive mb-1",children:"Rejection Reason"}),e.jsx("p",{className:"text-destructive",children:s.rejection_reason})]})]}),e.jsx(O,{children:(s==null?void 0:s.status)==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx(a,{variant:"outline",onClick:()=>{x(!1),y(s)},children:"Reject"}),e.jsx(a,{onClick:()=>{C(s.id),x(!1)},children:"Approve & Publish"})]})})]})}),e.jsx(B,{open:J,onOpenChange:h,children:e.jsxs(T,{children:[e.jsxs(R,{children:[e.jsx(F,{children:"Reject Submission"}),e.jsxs(L,{children:['Provide a reason for rejecting "',s==null?void 0:s.title,'"']})]}),e.jsx(ae,{value:N,onChange:t=>w(t.target.value),placeholder:"Please explain why this submission is being rejected...",rows:4}),e.jsxs(O,{children:[e.jsx(a,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),e.jsxs(a,{variant:"destructive",onClick:W,disabled:i.isPending,children:[i.isPending?e.jsx(f,{className:"w-4 h-4 animate-spin mr-2"}):null,"Reject Submission"]})]})]})}),e.jsx(G,{})]}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(E,{}),e.jsxs("div",{className:"container mx-auto px-4 pt-32 pb-16 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground mb-4",children:"Access Denied"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"You need admin privileges to access this page."}),e.jsx(_,{to:"/",children:e.jsx(a,{children:"Go Home"})})]}),e.jsx(G,{})]})};export{ot as default};
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.