1import{c as se,r as a,j as e,L as y,o as m,n as _,aq as L}from"./index-1OI8ZhN3.js";import{H as re}from"./Helmet-DXZH_4gP.js";import{A as ae}from"./admin-header-DrFvWCLk.js";import{A as ie}from"./admin-footer-Cbtn1Pp3.js";import{M as ne}from"./mobile-bottom-nav-Bq2IchjJ.js";import{C as D,a as R,b as q,c as B,d as M}from"./card-CXajSqfT.js";import{I as C}from"./input-BrhtNOz5.js";import{P as oe}from"./progress-CR9DY50h.js";import{F as O}from"./file-text-D8QacB-H.js";import{L as le}from"./list-todo-CIrp8_n8.js";import{S as k}from"./sparkles-4sdPY3DQ.js";import{C as $}from"./circle-check-big-711QmPcB.js";import{C as de}from"./circle-x-BItIiI8w.js";import"./index-Dh5t3qfJ.js";import"./index-DHR8KBxT.js";import"./sheet-kHi76Aux.js";import"./index-B95X6yZN.js";import"./index-13CpEvTD.js";import"./chevron-right-Bg1Ue0xO.js";import"./check-ah1m94T2.js";import"./moon-CGWF3PoQ.js";import"./product-tour-BnYa2Pa1.js";import"./circle-help-CBJYSWhJ.js";import"./proxy-CY8bL92s.js";import"./layers-CahpRybE.js";import"./message-square-DorWBFwU.js";import"./chart-column-DWfvtkQc.js";import"./megaphone-CN-WyBTy.js";import"./ellipsis-lGeWIebH.js";function Be(){const{toast:b}=se(),[x,Q]=a.useState(""),[A,W]=a.useState(""),[v,H]=a.useState(""),[h,K]=a.useState(1500),[f,U]=a.useState(!1),[r,S]=a.useState(!1),[j,N]=a.useState(null),[l,G]=a.useState(null),[u,I]=a.useState([{id:"content",label:"Generate Article Content (4000+ words)",status:"pending"},{id:"image",label:"Create Featured Image",status:"pending"},{id:"save",label:"Save to Database",status:"pending"}]),p=a.useRef(null),F=()=>h===1500?"1500+ words":h===2500?"2500+ words":"4000+ words",z=()=>{I([{id:"content",label:`Generate Article Content (${F()})`,status:"pending"},{id:"image",label:"Create Featured Image",status:"pending"},{id:"save",label:"Save to Database",status:"pending"}])},i=(t,n,o)=>{I(g=>g.map(d=>d.id===t?{...d,status:n,message:o}:d))},E=()=>{const t=u.filter(o=>o.status==="completed").length,n=u.filter(o=>o.status==="in_progress").length;return Math.round((t+n*.5)/u.length*100)},J=async()=>{var t;if(!x.trim()){b({title:"Topic required",description:"Please enter a topic for the article.",variant:"destructive"});return}S(!0),N(null),G(null),z(),p.current=new AbortController;try{i("content","in_progress",`AI is writing a ${F()} article with charts and graphs...`);const g=(await(await fetch("/api/admin/auth/session",{credentials:"include"})).json()).csrfToken||"",d=await fetch("/api/admin/blog/generate-with-progress",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-Token":g},credentials:"include",body:JSON.stringify({topic:x.trim(),industry:A.trim(),keywords:v?v.split(",").map(c=>c.trim()).filter(Boolean):[],autoPublish:f,targetWordCount:h}),signal:p.current.signal});if(!d.ok){const c=await d.json();throw new Error(c.message||c.error||"Failed to generate article")}const P=(t=d.body)==null?void 0:t.getReader(),Y=new TextDecoder;if(!P)throw new Error("Unable to read response stream");let Z="";for(;;){const{done:c,value:ee}=await P.read();if(c)break;const T=Y.decode(ee,{stream:!0});Z+=T;const te=T.split(` 2`).filter(w=>w.startsWith("data: "));for(const w of te)try{const s=JSON.parse(w.substring(6));if(s.step&&(s.step==="content"?s.status==="completed"?i("content","completed","Article content generated successfully"):s.status==="in_progress"&&i("content","in_progress",s.message||"Generating article content..."):s.step==="image"?s.status==="completed"?i("image","completed","Featured image created"):s.status==="in_progress"?i("image","in_progress",s.message||"Creating featured image..."):s.status==="skipped"&&i("image","completed","Using fallback image"):s.step==="save"&&(s.status==="completed"?i("save","completed",f?"Article published!":"Article saved as draft"):s.status==="in_progress"&&i("save","in_progress",s.message||"Saving to database..."))),s.complete&&s.post&&(G(s.post),L.invalidateQueries({queryKey:["/api/admin/blog/summaries"]}),L.invalidateQueries({queryKey:["/api/blog/summaries"]}),b({title:"Article Generated!",description:f?"Your article has been published.":"Your article has been saved as a draft."})),s.error)throw new Error(s.error)}catch{}}}catch(n){if(n.name==="AbortError")N("Generation cancelled");else{N(n.message||"An unexpected error occurred");const o=u.find(g=>g.status==="in_progress");o&&i(o.id,"error",n.message)}b({title:"Generation Failed",description:n.message,variant:"destructive"})}finally{S(!1),p.current=null}},V=()=>{p.current&&p.current.abort()},X=t=>{switch(t){case"completed":return e.jsx($,{className:"h-5 w-5 text-green-500"});case"error":return e.jsx(de,{className:"h-5 w-5 text-red-500"});case"in_progress":return e.jsx(_,{className:"h-5 w-5 animate-spin text-primary"});default:return e.jsx("div",{className:"h-5 w-5 rounded-full border-2 border-muted-foreground
2/30"})}};return e.jsxs(e.Fragment,{children:[e.jsx(re,{children:e.jsx("meta",{name:"robots",content:"noindex, nofollow"})}),e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(ae,{}),e.jsx("main",{className:"pt-6",children:e.jsxs("div",{className:"container mx-auto px-4 lg:px-6 py-16",children:[e.jsxs("div",{className:"flex flex-wrap justify-between items-center gap-4 mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl md:text-5xl font-bold mb-2",style:{fontFamily:"Space Grotesk, sans-serif"},"data-testid":"text-admin-title",children:"AI Article Generator"}),e.jsx("p",{className:"text-muted-foreground",children:"Generate complete blog articles with AI including charts and visuals"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{href:"/admin/blog",children:e.jsxs(m,{variant:"outline",className:"gap-2","data-testid":"button-blog-management",children:[e.jsx(O,{className:"h-4 w-4"}),"Blog Management"]})}),e.jsx(y,{href:"/admin/article-queue",children:e.jsxs(m,{variant:"outline",className:"gap-2","data-testid":"button-article-queue",children:[e.jsx(le,{className:"h-4 w-4"}),"Article Queue"]})})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-8",children:[e.jsxs(D,{children:[e.jsxs(R,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(k,{className:"h-5 w-5"}),"Generate Article"]}),e.jsx(B,{children:"Enter a topic and let AI create a complete article with charts, graphs, FAQs, and SEO optimization. Choose your preferred article length."})]}),e.jsxs(M,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Topic *"}),e.jsx(C,{value:x,onChange:t=>Q(t.target.value),placeholder:"e.g., Top 10 Digital Marketing Trends for 2025",disabled:r,"data-testid":"input-topic"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Category (optional)"}),e.jsx(C,{value:A,onChange:t=>W(t.target.value),placeholder:"Leave blank for AI auto-detection",disabled:r,"data-testid":"input-category"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"AI will detect the category from your topic if left blank"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Keywords (comma-separated, optional)"}),e.jsx(C,{value:v,onChange:t=>H(t.target.value),placeholder:"Leave blank for AI auto-detection",disabled:r,"data-testid":"input-keywords"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"AI will generate optimal SEO keywords from your topic if left blank"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Article Length"}),e.jsxs("select",{value:h,onChange:t=>K(Number(t.target.value)),disabled:r,className:"w-full h-9 px-3 py-2 rounded-md border border-input bg-background text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"select-word-count",children:[e.jsx("option",{value:1500,children:"Short (~1,500 words) - Quick reads, focused topics"}),e.jsx("option",{value:2500,children:"Medium (~2,500 words) - Balanced depth"}),e.jsx("option",{value:4e3,children:"Long (~4,000 words) - Comprehensive SEO powerhouse"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Longer articles typically rank better for competitive keywords"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"autoPublish",checked:f,onChange:t=>U(t.target.checked),disabled:r,className:"rounded"}),e.jsx("label",{htmlFor:"autoPublish",className:"text-sm",children:"Publish immediately (otherwise save as draft)"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(m,{onClick:J,disabled:r||!x.trim(),className:"flex-1 gap-2","data-testid":"button-generate",children:r?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"h-4 w-4 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4"}),"Generate Article"]})}),r&&e.jsx(m,{variant:"outline",onClick:V,"data-testid":"button-cancel",children:"Cancel"})]})]})]}),e.jsxs(D,{children:[e.jsxs(R,{children:[e.jsx(q,{children:"Generation Progress"}),e.jsx(B,{children:r?"Watch as AI creates your article step by step...":"Progress will appear here when you start generating."})]}),e.jsxs(M,{className:"space-y-6",children:[(r||l||j)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"Overall Progress"}),e.jsxs("span",{children:[E(),"%"]})]}),e.jsx(oe,{value:E(),className:"h-3"})]}),e.jsx("div",{className:"space-y-4",children:u.map(t=>e.jsxs("div",{className:`flex items-start gap-3 p-3 rounded-lg transition-all duration-300 ${t.status==="in_progress"?"bg-primary/10 border border-primary/20":t.status==="completed"?"bg-green-500/10 border border-green-500/20":t.status==="error"?"bg-red-500/10 border border-red-500/20":"bg-muted/30"}`,children:[X(t.status),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:`font-medium ${t.status==="pending"?"text-muted-foreground":""}`,children:t.label}),t.message&&e.jsxs("p",{className:`text-sm mt-1 ${t.status==="error"?"text-red-500":t.status==="in_progress"?"text-primary font-medium animate-pulse":"text-muted-foreground"}`,children:[t.status==="in_progress"&&"â ",t.message]})]})]},t.id))}),j&&e.jsxs("div",{className:"p-4 bg-destructive/10 border border-destructive/20 rounded-lg",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:"Generation Error"}),e.jsx("p",{className:"text-sm text-destructive/80 mt-1",children:j}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Please try again or adju
2st your topic."})]}),l&&e.jsxs("div",{className:"p-4 bg-green-500/10 border border-green-500/20 rounded-lg space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{className:"h-5 w-5 text-green-500"}),e.jsx("p",{className:"font-medium text-green-700 dark:text-green-400",children:"Article Generated Successfully!"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:l.title}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Status: ",l.status]})]}),l.featuredImageUrl&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Featured Image:"}),e.jsx("img",{src:l.featuredImageUrl,alt:"Featured",className:"w-full h-32 object-cover rounded-lg border"})]}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(y,{href:"/admin/blog",children:e.jsxs(m,{size:"sm",variant:"outline",className:"gap-2",children:[e.jsx(O,{className:"h-4 w-4"}),"View in Blog Manager"]})}),e.jsx(m,{size:"sm",variant:"outline",className:"gap-2",onClick:()=>window.open(`/blog/${l.slug}`,"_blank"),children:"View Article"})]})]})]}),!r&&!l&&!j&&e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(k,{className:"h-12 w-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:'Enter a topic and click "Generate Article" to get started.'}),e.jsx("p",{className:"text-sm mt-2",children:"Generation takes about 30-60 seconds."})]})]})]})]})]})}),e.jsx(ie,{}),e.jsx(ne,{}),e.jsx("div",{className:"h-16 lg:hidden"})]})]})}export{Be as default}; 3//# sourceMappingURL=admin-ai-generator-BDoRH6ou.js.map
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.