1import{a9 as ue,b as G,u as xe,r as N,e as A,g as v,j as e,E as w,V as S,Z as _,J as Y,B as c,a1 as Z,S as z,s as C,D as he,aX as pe,P as U,w as ge,x as je,y as fe,L as h,A as y,aK as ve,X as Q,aC as be,aD as ye,aE as Ne,aF as we,aG as $,$ as P,ay as Se,q as p,a3 as f,cv as Ce,bq as ee,C as Te}from"./index-D8npRbe8.js";import{T as D}from"./textarea-BHey_zcY.js";import{T as ke,a as Ae,b as K,c as R}from"./tabs-BRbvJiqb.js";import{S as te}from"./shield-x-Cc8ocB8_.js";import{M as ae}from"./message-circle-CPzGcVZS.js";import{U as se}from"./upload-CIoDO--D.js";import{E as Pe}from"./eye-M72yFs_F.js";import{S as De}from"./square-pen-2QDxPDqs.js";import{T as Fe}from"./trash-2-BO2ImyhD.js";import{P as Ie}from"./pause-DZZbauxZ.js";import{f as F}from"./format-p6_WXlQP.js";import"./index-BCbkSr9d.js";const Ee=ue("Trash",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}]]);function Xe(){const{toast:l}=G(),{user:a,isLoading:T}=xe(),[b,g]=N.useState(!1),[x,j]=N.useState(null),[i,r]=N.useState(!1),u=N.useRef(null),[s,d]=N.useState({title:"",slug:"",content:"",excerpt:"",metaDescription:"",metaTitle:"",canonicalUrl:"",ogTitle:"",ogDescription:"",schemaBlocks:[],featuredImage:"",featuredImageAlt:"",status:"draft",scheduledAt:"",categories:[]}),[k,I]=N.useState(!1),{data:E,isLoading:ie}=A({queryKey:["/api/admin/check"],enabled:!!a}),{data:B,isLoading:ne,error:Oe}=A({queryKey:["/api/admin/blog/posts"],enabled:E?.isAdmin===!0}),{data:le}=A({queryKey:["/api/admin/blog/comments","pending"],queryFn:async()=>{const t=await fetch("/api/admin/blog/comments?status=pending",{credentials:"include"});if(!t.ok)throw new Error("Failed to load pending comments");return t.json()},enabled:E?.isAdmin===!0,refetchInterval:6e4}),H=le?.length||0,J=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),L=()=>{d({title:"",slug:"",content:"",excerpt:"",metaDescription:"",metaTitle:"",canonicalUrl:"",ogTitle:"",ogDescription:"",schemaBlocks:[],featuredImage:"",featuredImageAlt:"",status:"draft",scheduledAt:"",categories:[]}),j(null),I(!1)},V=v({mutationFn:async t=>f("POST","/api/admin/blog/posts",{...t,publishedAt:t.status==="published"?new Date().toISOString():null,scheduledAt:t.status==="scheduled"&&t.scheduledAt?new Date(t.scheduledAt).toISOString():null}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/blog/posts"]}),p.invalidateQueries({queryKey:["/api/blog/posts"]}),l({title:"Post created successfully"}),L(),g(!1)},onError:()=>{l({title:"Failed to create post",variant:"destructive"})}}),W=v({mutationFn:async({id:t,data:n})=>f("PATCH",`/api/admin/blog/posts/${t}`,{...n,publishedAt:n.status==="published"&&!x?.publishedAt?new Date().toISOString():x?.publishedAt,scheduledAt:n.status==="scheduled"&&n.scheduledAt?new Date(n.scheduledAt).toISOString():null}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/blog/posts"]}),p.invalidateQueries({queryKey:["/api/blog/posts"]}),l({title:"Post updated successfully"}),L(),g(!1)},onError:()=>{l({title:"Failed to update post",variant:"destructive"})}}),re=v({mutationFn:async t=>f("DELETE",`/api/admin/blog/posts/${t}`),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/blog/posts"]}),p.invalidateQueries({queryKey:["/api/blog/posts"]}),l({title:"Post deleted successfully"})},onError:()=>{l({title:"Failed to delete post",variant:"destructive"})}}),[qe,O]=N.useState(new Set);v({mutationFn:async t=>(O(o=>new Set(o).add(t)),(await f("POST",`/api/admin/blog/push-to-prod/${t}`,{})).json()),onSuccess:(t,n)=>{O(o=>{const m=new Set(o);return m.delete(n),m}),t.imported?l({title:"Post pushed to production!",description:"It's now live on getspiced.ai"}):l({title:"Already on production",description:"This post already exists there."})},onError:(t,n)=>{O(o=>{const m=new Set(o);return m.delete(n),m}),l({title:"Push failed",description:"Could not reach production server.",variant:"destructive"})}});const de=async t=>{if(!t.type.startsWith("image/")){l({title:"Please select an image file",variant:"destructive"});return}if(t.size>10*1024*1024){l({title:"Image must be under 10MB",variant:"destructive"});return}r(!0);try{const n=await f("POST","/api/uploads/request-url",{name:t.name,size:t.size,contentType:t.type}),{uploadURL:o,objectPath:m}=await n.json();await fetch(o,{method:"PUT",body:t,headers:{"Content-Type":t.type}}),d({...s,featuredImage:m}),l({title:"Image uploaded successfully"})}catch{l({title:"Failed to upload image",variant:"destructive"})}finally{r(!1)}};if(T||ie)return e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",children:e.jsx(w,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!a)return e.jsx("div",{className:"container max-w-2xl mx-auto py-16 px-4 text-center",children:e.jsxs(S,{className:"p-8",children:[e.jsx(te,{className:"h-16 w-16 mx-auto text-muted-foreground mb-4"}),e.jsx(_,{className:"text-2xl mb-4",children:"Login Required"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Please log in with an admin account to access the blog manager."}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx(Y,{href:"/blog",children:e.jsx(c,{variant:"outline","data-testid":"button-back-to-blog",children:"Back to Blog"})}),e.jsx("a",{href:"/api/login?returnTo=/admin/blog",children:e.jsx(c,{"data-testid":"button-login",children:"Log In"})})]})]})});if(E?.isAdmin!==!0)return e.jsx("div",{className:"container max-w-2xl mx-auto py-16 px-4 text-center",children:e.jsxs(S,{className:"p-8",children:[e.jsx(te,{className:"h-16 w-16 mx-auto text-muted-foreground mb-4"}),e.jsx(_,{className:"text-2xl mb-4",children:"Access Denied"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"You don't have permission to access the blog admin panel. Only authorized administrators can manage blog content."}),e.jsx(Y,{href:"/blog",children:e.jsx(c,{"data-testid":"button-back-to-blog",children:"Back to Blog"})})]})});const ce=t=>{j(t),d({title:t.title,slug:t.slug,content:t.content,excerpt:t.excerpt||"",metaDescription:t.metaDescription||"",metaTitle:t.metaTitle||"",canonicalUrl:t.canonicalUrl||"",ogTitle:t.ogTitle||"",ogDescription:t.ogDescription||"",schemaBlocks:t.schemaBlocks||[],featuredImage:t.featuredImage||"",featuredImageAlt:t.featuredImageAlt||"",status:t.status,scheduledAt:t.scheduledAt?F(new Date(t.scheduledAt),"yyyy-MM-dd'T'HH:mm"):"",categories:t.categories||[]});const n=!!t.metaTitle||!!t.canonicalUrl||!!t.ogTitle||!!t.ogDescription||t.schemaBlocks?.length>0;I(n),g(!0)},X=s.schemaBlocks.some(t=>{const n=t.trim();if(!n)return!1;try{return JSON.parse(n),!1}catch{return!0}}),oe=t=>{if(t.preventDefault(),X){l({title:"Fix invalid JSON in schema blocks before saving",variant:"destructive"});return}const n=s.schemaBlocks.map(m=>m.trim()).filter(m=>m.length>0),o={...s,slug:s.slug||J(s.title),schemaBlocks:n};x?W.mutate({id:x.id,data:o}):V.mutate(o)};return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-black tracking-tight",children:"Blog Manager"}),e.jsx("p",{className:"text-muted-foreground",children:"Create and manage blog posts, automation, and comments"})]}),e.jsxs(ke,{defaultValue:"posts",className:"space-y-6",children:[e.jsxs(Ae,{"data-testid":"tabs-blog-admin",children:[e.jsxs(K,{value:"posts","data-testid":"tab-posts",children:[e.jsx(Z,{className:"w-4 h-4 mr-2"}),"Posts"]}),e.jsxs(K,{value:"automation","data-testid":"tab-automation",children:[e.jsx(z,{className:"w-4 h-4 mr-2"}),"Auto-Blog"]}),e.jsxs(K,{value:"comments","data-testid":"tab-comments",children:[e.jsx(ae,{className:"w-4 h-4 mr-2"}),"Comments",H>0&&e.jsx(C,{variant:"destructive",className:"ml-2 px-1.5 py-0 h-5 min-w-5 text-xs justify-center","data-testid":"badge-pending-comments",children:H})]})]}),e.jsxs(R,{value:"posts",className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-end mb-4",children:e.jsxs(he,{open:b,onOpenChange:t=>{g(t),t||L()},children:[e.jsx(pe,{asChild:!0,children:e.jsxs(c,{"data-testid":"button-new-post",children:[e.jsx(U,{className:"w-4 h-4 mr-2"}),"New Post"]})}),e.jsxs(ge,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsx(je,{children:e.jsx(fe,{children:x?"Edit Post":"Create New Post"})}),e.jsxs("form",{onSubmit:oe,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"title",children:"Title"}),e.jsx(y,{id:"title",value:s.title,onChange:t=>{const n=t.target.value;d({...s,title:n,slug:x?s.slug:J(n)})},placeholder:"Post title","data-testid":"input-title"}),s.slug&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["URL: /blog/",s.slug]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Featured Image"}),e.jsx("input",{ref:u,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const n=t.target.files?.[0];n&&de(n)},"data-testid":"input-image-file"}),s.featuredImage?e.jsxs("div",{className:"relative space-y-2",children:[e.jsxs("div",{className:"border rounded-md p-3 flex items-center gap-3",children:[e.jsx(ve,{className:"w-5 h-5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-sm truncate flex-1",children:s.featuredImage.startsWith("/objects/")?"Uploaded image":s.featuredImage}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(c,{type:"button",variant:"ghost",size:"icon",onClick:()=>u.current?.click(),disabled:i,"data-testid":"button-change-image",children:e.jsx(se,{className:"w-4 h-4"})}),e.jsx(c,{type:"button",variant:"ghost",size:"icon",onClick:()=>d({...s,featuredImage:"",featuredImageAlt:""}),"data-testid":"button-remove-image",children:e.jsx(Q,{className:"w-4 h-4"})})]})]}),e.jsx(y,{value:s.featuredImageAlt,onChange:t=>d({...s,featuredImageAlt:t.target.value}),placeholder:"Alt text (describe the image for accessibility & SEO)",maxLength:250,"data-testid":"input-image-alt"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex gap-2",children:e.jsx(c,{type:"button",variant:"outline",className:"flex-1 justify-center gap-2",onClick:()=>u.current?.click(),disabled:i,"data-testid":"button-upload-image",children:i?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"w-4 h-4 animate-spin"}),"Uploading..."]}):e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-4 h-4"}),"Upload Image"]})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"or paste URL:"}),e.jsx(y,{value:s.featuredImage,onChange:t=>d({...s,featuredImage:t.target.value}),placeholder:"https://...",className:"flex-1","data-testid":"input-image-url"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"content",children:"Content (HTML)"}),e.jsx(D,{id:"content",value:s.content,onChange:t=>d({...s,content:t.target.value}),placeholder:"Paste or write your blog post HTML content here",rows:12,className:"font-mono text-sm","data-testid":"input-content"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"excerpt",children:"Excerpt"}),e.jsx(D,{id:"excerpt",value:s.excerpt,onChange:t=>d({...s,excerpt:t.target.value}),placeholder:"Auto-generated by AI â or write your own summary",rows:2,"data-testid":"input-excerpt"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"metaDescription",children:"Meta Description (SEO)"}),e.jsx(D,{id:"metaDescription",value:s.metaDescription,onChange:t=>d({...s,metaDescription:t.target.value}),placeholder:"Auto-generated by AI â or write your own SEO description",rows:2,"data-testid":"input-meta"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.metaDescription.length,"/160 characters"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors",onClick:()=>I(!k),"data-testid":"button-toggle-seo",children:[e.jsx("span",{className:`transition-transform ${k?"rotate-90":""}`,children:"â¶"}),"Advanced SEO Settings",(s.metaTitle||s.canonicalUrl||s.ogTitle||s.ogDescription||s.schemaBlocks.length>0)&&e.jsx(C,{variant:"secondary",className:"text-xs",children:"configured"})]}),k&&e.jsxs("div",{className:"space-y-4 pl-4 border-l-2 border-muted",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"metaTitle",children:"Meta Title"}),e.jsx(y,{id:"metaTitle",value:s.metaTitle,onChange:t=>d({...s,metaTitle:t.target.value}),placeholder:"Custom title tag (defaults to post title)","data-testid":"input-meta-title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"canonicalUrl",children:"Canonical URL"}),e.jsx(y,{id:"canonicalUrl",value:s.canonicalUrl,onChange:t=>d({...s,canonicalUrl:t.target.value}),placeholder:"https://getspiced.ai/blog/... (auto-generated if blank)","data-testid":"input-canonical-url"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"ogTitle",children:"OG Title"}),e.jsx(y,{id:"ogTitle",value:s.ogTitle,onChange:t=>d({...s,ogTitle:t.target.value}),placeholder:"Open Graph title override","data-testid":"input-og-title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"ogDescription",children:"OG Description"}),e.jsx(y,{id:"ogDescription",value:s.ogDescription,onChange:t=>d({...s,ogDescription:t.target.value}),placeholder:"Open Graph description override","data-testid":"input-og-description"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{children:"Schema Blocks (JSON-LD)"}),e.jsxs(c,{type:"button",variant:"outline",size:"sm",onClick:()=>d({...s,schemaBlocks:[...s.schemaBlocks,""]}),"data-testid":"button-add-schema",children:[e.jsx(U,{className:"w-3 h-3 mr-1"}),"Add Schema Block"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Paste raw JSON only, without <script> tags."}),s.schemaBlocks.map((t,n)=>{const o=t.trim();let m=!0;if(o)try{JSON.parse(o)}catch{m=!1}return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Block ",n+1]}),e.jsx(c,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>{const q=s.schemaBlocks.filter((M,me)=>me!==n);d({...s,schemaBlocks:q})},"data-testid":`button-remove-schema-${n}`,children:e.jsx(Q,{className:"w-3 h-3"})})]}),e.jsx(D,{value:t,onChange:q=>
1{const M=[...s.schemaBlocks];M[n]=q.target.value,d({...s,schemaBlocks:M})},placeholder:'{"@context":"https://schema.org","@type":"Article",...}',rows:6,className:`font-mono text-xs ${o&&!m?"border-destructive":""}`,"data-testid":`input-schema-${n}`}),o&&!m&&e.jsx("p",{className:"text-xs text-destructive","data-testid":`error-schema-${n}`,children:"Invalid JSON â fix before saving"}),o&&m&&e.jsx("p",{className:"text-xs text-green-600 dark:text-green-400",children:"Valid JSON"})]},n)}),s.schemaBlocks.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No schema blocks. A default BlogPosting schema is auto-generated if none are added."})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"status",children:"Status"}),e.jsxs(be,{value:s.status,onValueChange:t=>d({...s,status:t}),children:[e.jsx(ye,{"data-testid":"select-status",children:e.jsx(Ne,{})}),e.jsxs(we,{children:[e.jsx($,{value:"draft",children:"Draft"}),e.jsx($,{value:"scheduled",children:"Scheduled"}),e.jsx($,{value:"published",children:"Published"})]})]})]}),s.status==="scheduled"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"scheduledAt",children:"Schedule Date & Time"}),e.jsx(y,{id:"scheduledAt",type:"datetime-local",value:s.scheduledAt,onChange:t=>d({...s,scheduledAt:t.target.value}),"data-testid":"input-scheduled"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Categories"}),e.jsx("div",{className:"flex gap-4 flex-wrap",children:[{value:"main",label:"Main"},{value:"creator",label:"Creator"},{value:"entrepreneurs",label:"Entrepreneurs"}].map(t=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer","data-testid":`checkbox-category-${t.value}`,children:[e.jsx("input",{type:"checkbox",checked:s.categories.includes(t.value),onChange:n=>{n.target.checked?d({...s,categories:[...s.categories,t.value]}):d({...s,categories:s.categories.filter(o=>o!==t.value)})},className:"rounded border-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:t.label})]},t.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select which landing page blogs this post appears on"})]}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx(c,{type:"button",variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsx(c,{type:"submit",disabled:V.isPending||W.isPending||X,"data-testid":"button-save-post",children:x?"Update Post":"Create Post"})]})]})]})]})}),ne?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Loading posts..."}):!B||B.length===0?e.jsx(S,{className:"border-dashed",children:e.jsxs(P,{className:"p-12 text-center",children:[e.jsx(Z,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-bold mb-2",children:"No blog posts yet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Create your first blog post to improve SEO and drive organic traffic."}),e.jsxs(c,{onClick:()=>g(!0),"data-testid":"button-empty-create",children:[e.jsx(U,{className:"w-4 h-4 mr-2"}),"Create First Post"]})]})}):e.jsx("div",{className:"space-y-4",children:B.map(t=>e.jsx(S,{className:"hover-elevate",children:e.jsx(P,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-bold truncate",children:t.title}),e.jsx(C,{variant:t.status==="published"?"default":"secondary",children:t.status})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-2 truncate",children:["/blog/",t.slug]}),t.publishedAt&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(Se,{className:"w-3 h-3"}),"Published ",F(new Date(t.publishedAt),"MMM d, yyyy")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.status==="published"&&e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>window.open(`/blog/${t.slug}`,"_blank"),"data-testid":`button-view-${t.id}`,children:e.jsx(Pe,{className:"w-4 h-4"})}),!1,e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>ce(t),"data-testid":`button-edit-${t.id}`,children:e.jsx(De,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>{confirm("Are you sure you want to delete this post?")&&re.mutate(t.id)},"data-testid":`button-delete-${t.id}`,children:e.jsx(Fe,{className:"w-4 h-4 text-destructive"})})]})]})})},t.id))})]}),e.jsx(R,{value:"automation",className:"space-y-4",children:e.jsx(Be,{})}),e.jsx(R,{value:"comments",className:"space-y-4",children:e.jsx(Le,{})})]})]})}function Be(){const{toast:l}=G(),{data:a,isLoading:T}=A({queryKey:["/api/admin/blog/auto-config"]}),b=v({mutationFn:async r=>f("PATCH","/api/admin/blog/auto-config",{paused:r}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/blog/auto-config"]}),l({title:"Auto-blog updated"})},onError:()=>l({title:"Failed to update",variant:"destructive"})}),g=v({mutationFn:async()=>f("POST","/api/admin/blog/auto-generate",{}),onSuccess:async r=>{const u=await r.json();l({title:"Post generated!",description:u.slug?`/blog/${u.slug}`:"See posts tab"}),p.invalidateQueries({queryKey:["/api/admin/blog/auto-config"]}),p.invalidateQueries({queryKey:["/api/admin/blog/posts"]}),p.invalidateQueries({queryKey:["/api/blog/posts"]})},onError:r=>l({title:"Generation failed",description:r?.message||"See server logs",variant:"destructive"})}),x=v({mutationFn:async r=>f("PATCH","/api/admin/blog/auto-config",{lastTopicIndex:r}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/blog/auto-config"]}),l({title:"Topic rotation updated"})},onError:()=>l({title:"Failed to update topic",variant:"destructive"})}),j=v({mutationFn:async r=>f("POST","/api/admin/blog/test-summary-email",{failure:r}),onSuccess:async r=>{const u=await r.json();u.sent?l({title:"Test email sent",description:`${u.variant} variant â ${(u.recipients||[]).join(", ")}`}):l({title:"Not sent",description:u.reason||"No recipients configured",variant:"destructive"})},onError:r=>l({title:"Test email failed",description:r?.message||"See server logs",variant:"destructive"})});if(T||!a)return e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:e.jsx(w,{className:"w-6 h-6 animate-spin mx-auto"})});const i=a.lastTopicIndex!==null&&a.lastTopicIndex>=0?a.topics[a.lastTopicIndex]?.label:"â";return e.jsx(S,{children:e.jsxs(P,{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black mb-1",children:"Daily Auto-Blog"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generates 9 fresh posts per day with Claude + Gemini â 3 always cover the business of subscription creators (SFW industry journalism for adult-industry operators: AI workflows, online safety, business growth, industry trends, ethics, education), the other 6 rotate through 12 topic categories (content, business, AI tools, trending topics, tutorials, prompting tips). Every post is SEO + GEO optimized with 3-6 internal links back to GetSpiced. Featured images never include men. Hard cap of 10 posts/day."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{variant:a.paused?"default":"outline",onClick:()=>b.mutate(!a.paused),disabled:b.isPending,"data-testid":"button-toggle-pause",children:a.paused?e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"w-4 h-4 mr-2"}),"Resume"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"w-4 h-4 mr-2"}),"Pause"]})}),e.jsx(c,{onClick:()=>g.mutate(),disabled:g.isPending,"data-testid":"button-generate-now",children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"w-4 h-4 mr-2 animate-spin"}),"Generatingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2"}),"Generate Now"]})}),e.jsx(c,{variant:"outline",onClick:()=>j.mutate(!1),disabled:j.isPending,"data-testid":"button-test-summary-email",children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"w-4 h-4 mr-2 animate-spin"}),"Sendingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-4 h-4 mr-2"}),"Test Email"]})}),e.jsx(c,{variant:"outline",onClick:()=>j.mutate(!0),disabled:j.isPending,"data-testid":"button-test-alert-email",children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"w-4 h-4 mr-2 animate-spin"}),"Sendingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-4 h-4 mr-2"}),"Test Alert"]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"border rounded-md p-4",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Status"}),e.jsx(C,{variant:a.paused?"secondary":"default","data-testid":"badge-auto-status",children:a.paused?"Paused":"Active"})]}),e.jsxs("div",{className:"border rounded-md p-4",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Total generated"}),e.jsx("p",{className:"font-bold text-lg","data-testid":"text-total-generated",children:a.totalGenerated})]}),e.jsxs("div",{className:"border rounded-md p-4",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Last topic"}),e.jsx("p",{className:"font-medium",children:i})]}),e.jsxs("div",{className:"border rounded-md p-4",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Next topic"}),e.jsx("p",{className:"font-medium","data-testid":"text-next-topic",children:a.nextTopic.label})]}),e.jsxs("div",{className:"border rounded-md p-4",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Last run"}),e.jsxs("p",{className:"text-sm",children:[a.lastRunAt?F(new Date(a.lastRunAt),"MMM d, yyyy h:mm a"):"Never",a.lastRunStatus&&e.jsx(C,{variant:a.lastRunStatus==="success"?"default":"destructive",className:"ml-2 text-xs",children:a.lastRunStatus})]}),a.lastRunError&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:a.lastRunError})]}),e.jsxs("div",{className:"border rounded-md p-4",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Schedule"}),e.jsxs("p",{className:"text-sm",children:["Daily â ",a.postsPerBatch," posts every 24 hours"]})]}),e.jsxs("div",{className:"border rounded-md p-4",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Today's usage"}),e.jsxs("p",{className:"text-sm","data-testid":"text-daily-cap",children:[e.jsxs("span",{className:a.dailyCountToday>=a.maxPostsPerDay?"font-bold text-destructive":"font-medium",children:[a.dailyCountToday," / ",a.maxPostsPerDay]}),e.jsx("span",{className:"text-muted-foreground",children:" posts published today (UTC)"})]}),a.dailyCountToday>=a.maxPostsPerDay&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:"Daily cap reached â further runs will be refused until UTC midnight."})]}),a.runLockActive&&e.jsxs("div",{className:"border border-amber-500/50 bg-amber-500/10 rounded-md p-4 sm:col-span-2","data-testid":"banner-run-lock-active",children:[e.jsx("p",{className:"text-xs uppercase text-amber-600 dar
1k:text-amber-400 mb-1",children:"Batch in progress"}),e.jsx("p",{className:"text-sm",children:"A blog generation batch is currently running. New runs are blocked until it finishes (lock auto-expires after 30 minutes)."})]})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground",children:"Topic rotation"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click a topic to set it as the next one"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.topics.map((r,u)=>{const s=((a.lastTopicIndex??-1)+1)%a.topics.length,d=u===s;return e.jsxs(c,{type:"button",size:"sm",variant:d?"default":"outline",onClick:()=>{const k=(u-1+a.topics.length)%a.topics.length;x.mutate(k)},disabled:x.isPending,"data-testid":`button-topic-${r.slug}`,children:[d&&e.jsx(z,{className:"w-3 h-3 mr-1"}),r.label]},r.slug)})})]})]})})}function Le(){const{toast:l}=G(),[a,T]=N.useState("pending"),{data:b,isLoading:g}=A({queryKey:["/api/admin/blog/comments",a],queryFn:async()=>{const r=await fetch(`/api/admin/blog/comments?status=${a==="all"?"":a}`,{credentials:"include"});if(!r.ok)throw new Error("Failed to load comments");return r.json()}}),x=v({mutationFn:async({id:i,status:r})=>f("PATCH",`/api/admin/blog/comments/${i}`,{status:r}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/blog/comments"]}),l({title:"Comment updated"})},onError:()=>l({title:"Failed to update",variant:"destructive"})}),j=v({mutationFn:async i=>f("DELETE",`/api/admin/blog/comments/${i}`),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/blog/comments"]}),l({title:"Comment deleted"})},onError:()=>l({title:"Failed to delete",variant:"destructive"})});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-2 flex-wrap",children:["pending","approved","rejected","all"].map(i=>e.jsx(c,{variant:a===i?"default":"outline",size:"sm",onClick:()=>T(i),"data-testid":`filter-${i}`,children:i.charAt(0).toUpperCase()+i.slice(1)},i))}),g?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:e.jsx(w,{className:"w-6 h-6 animate-spin mx-auto"})}):!b||b.length===0?e.jsx(S,{className:"border-dashed",children:e.jsxs(P,{className:"p-8 text-center text-muted-foreground",children:[e.jsx(ae,{className:"w-10 h-10 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No comments to show."})]})}):e.jsx("div",{className:"space-y-3",children:b.map(i=>e.jsx(S,{"data-testid":`admin-comment-${i.id}`,children:e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-bold",children:i.name}),i.email&&e.jsx("span",{className:"text-muted-foreground text-xs ml-2",children:i.email}),e.jsx(C,{variant:i.status==="approved"?"default":i.status==="rejected"?"destructive":"secondary",className:"ml-2 text-xs",children:i.status})]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Post #",i.postId," · ",F(new Date(i.createdAt),"MMM d, yyyy h:mm a")]})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap mb-3",children:i.content}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[i.status!=="approved"&&e.jsxs(c,{size:"sm",onClick:()=>x.mutate({id:i.id,status:"approved"}),"data-testid":`button-approve-${i.id}`,children:[e.jsx(Te,{className:"w-3 h-3 mr-1"}),"Approve"]}),i.status!=="rejected"&&e.jsxs(c,{size:"sm",variant:"outline",onClick:()=>x.mutate({id:i.id,status:"rejected"}),"data-testid":`button-reject-${i.id}`,children:[e.jsx(Q,{className:"w-3 h-3 mr-1"}),"Reject"]}),e.jsxs(c,{size:"sm",variant:"ghost",onClick:()=>{confirm("Delete this comment permanently?")&&j.mutate(i.id)},"data-testid":`button-delete-${i.id}`,children:[e.jsx(Ee,{className:"w-3 h-3 mr-1 text-destructive"}),"Delete"]})]})]})},i.id))})]})}export{Xe 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.