1import{j as e}from"./vendor-ui-HFWR8-3w.js";import{H as ee,B as z,u as F,s as x}from"./index-khXlasVk.js";import{T as we,a as fe,b as Y,c as Z}from"./tabs-6ee6ucII.js";import{p as te}from"./pageTitle-B7vsVqJ8.js";import{r as c}from"./vendor-react-TOmoy5F7.js";import{i as je}from"./invoke-DbClFP6z.js";import{z as Ne,a4 as _e,E as ye,c as ve,a8 as Se,Y as ke,F as Ce,$ as De,al as Ge,ak as Ee}from"./vendor-icons-DoRmp3nk.js";import"./vendor-charts-vYadQpzB.js";import"./vendor-supabase-BSJTZ0K-.js";function re({score:a}){if(a==null)return null;const C=Math.round(a*100),f=a>=.9?"bg-green-500/20 text-green-400":a>=.75?"bg-yellow-500/20 text-yellow-400":"bg-red-500/20 text-red-400";return e.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-mono font-bold ${f}`,children:["DNA ",C,"%"]})}function Ae(){const[a,C]=c.useState([]),[f,w]=c.useState([]),[h,y]=c.useState(null),[o,D]=c.useState(!1),[i,_]=c.useState(!1),[n,N]=c.useState(null),[j,P]=c.useState(""),[u,A]=c.useState(""),[R,O]=c.useState(""),[b,G]=c.useState(null),[U,I]=c.useState(""),[q,l]=c.useState(!1),[g,S]=c.useState(!1),[L,T]=c.useState(!1),[H,V]=c.useState(""),[s,d]=c.useState(!1),[p,M]=c.useState(!1),[J,Q]=c.useState(!1),[W,B]=c.useState(!1),[K,X]=c.useState(new Set),v=async()=>{const{data:t,error:r}=await x.from("articles").select("id, title, slug, status, source, published_at, created_at, scheduled_publish_at, view_count, tags, dna_match_score, geo_schema, og_image, target_keyword, keyword_volume").eq("human_rejected",!1).order("created_at",{ascending:!1});r&&console.error("[GEO Articles] fetch error:",r),t&&C(t);const{data:m,error:E}=await x.from("api_keys").select("*").order("created_at",{ascending:!1});E&&console.error("[GEO Articles] api_keys fetch error:",E),m&&w(m)};c.useEffect(()=>{v()},[]);const ce=async(t,r)=>{Q(!0);try{const m=t.name.split(".").pop(),E=`og/${r}-${Date.now()}.${m}`,{error:$}=await x.storage.from("post-media").upload(E,t,{upsert:!0});if($)throw $;const{data:k}=x.storage.from("post-media").getPublicUrl(E);await x.from("articles").update({og_image:k.publicUrl}).eq("id",r),N(se=>({...se,og_image:k.publicUrl})),M(!1),v()}catch(m){console.error("Image upload error:",m)}finally{Q(!1)}},oe=async t=>{B(!0);try{const r=(n==null?void 0:n.og_image)??null,{data:m}=await x.from("articles").select("title").eq("id",t).single();await x.from("articles").update({og_image:null}).eq("id",t),N(k=>({...k,og_image:null})),await x.from("image_generation_queue").insert({user_id:"09af746f-5d10-4870-9b8a-4a5ec0992bc1",article_id:t,post_id:null,post_content:`${(m==null?void 0:m.title)??"Prospel article"} â ${new Date().toLocaleDateString("en-GB",{month:"long",year:"numeric"})}`,platform:"x",status:"pending",requested_type:"auto"}),M(!1);let E=0;const $=setInterval(async()=>{E++;const{data:k}=await x.from("articles").select("og_image").eq("id",t).single();k!=null&&k.og_image&&k.og_image!==r&&(N(se=>({...se,og_image:k.og_image})),v(),clearInterval($),B(!1)),E>=24&&(clearInterval($),B(!1))},5e3)}catch(r){console.error("Image regeneration error:",r),B(!1)}},ae=t=>{if(t.status==="published"||t.source!=="perplexity")return null;const r=t.scheduled_publish_at?new Date(t.scheduled_publish_at):t.created_at?new Date(new Date(t.created_at).getTime()+48*60*60*1e3):null;return r?r<new Date?"Imminent":r.toLocaleDateString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}):null},de=async t=>{N(t),A(t.title??""),P("Loading..."),G(null),I("");const{data:r}=await x.from("articles").select("content, dna_match_score, geo_schema, og_image, scheduled_publish_at").eq("id",t.id).single();P((r==null?void 0:r.content)??""),O(r!=null&&r.geo_schema?JSON.stringify(r.geo_schema,null,2):""),N(m=>({...m,dna_match_score:(r==null?void 0:r.dna_match_score)??m.dna_match_score,geo_schema:(r==null?void 0:r.geo_schema)??m.geo_schema,og_image:(r==null?void 0:r.og_image)??m.og_image,scheduled_publish_at:(r==null?void 0:r.scheduled_publish_at)??m.scheduled_publish_at}))},le=async(t,r,m,E)=>{const{data:$}=await x.from("article_versions").select("version_number").eq("article_id",t).order("version_number",{ascending:!1}
1).limit(1).maybeSingle(),k=(($==null?void 0:$.version_number)??0)+1;await x.from("article_versions").insert({article_id:t,version_number:k,title:r,content:m,changed_by:E,snapshot:{title:r,content:m,changed_by:E}})},ie=()=>{if(!R.trim())return null;try{return JSON.parse(R)}catch{return(n==null?void 0:n.geo_schema)??null}},xe=async()=>{n&&(S(!0),await x.from("articles").update({title:u,content:j,geo_schema:ie()}).eq("id",n.id),await le(n.id,u,j,"[email protected]"),S(!1),v())},he=async()=>{if(!n||!H)return;d(!0);const t=new Date(H).toISOString();await x.from("articles").update({scheduled_publish_at:t}).eq("id",n.id),N(r=>({...r,scheduled_publish_at:t})),d(!1),T(!1),v()},me=async()=>{n&&(S(!0),await x.from("articles").update({title:u,content:j,geo_schema:ie(),status:"published",published_at:new Date().toISOString()}).eq("id",n.id),await le(n.id,u,j,"[email protected]"),S(!1),N(null),v())},pe=async()=>{if(!(!n||!b||!U.trim())){l(!0);try{const{error:t}=await x.functions.invoke("pc-process-rejection",{body:{article_id:n.id,rejection_mode:b,feedback:U}});if(t){console.error("[GEO Articles] pc-process-rejection error:",t),F.error("Failed to submit rejection");return}F.success(b==="fix"?"Rejection queued â Hermes will rewrite on next trigger":"Rejection queued â Hermes will research a new topic on next trigger"),G(null),I(""),N(null),v()}finally{l(!1)}}},ue=t=>{X(r=>{const m=new Set(r);return m.has(t)?m.delete(t):m.add(t),m})},ge=()=>{const t=a.filter(r=>r.status==="draft").map(r=>r.id);X(new Set(t))},be=async()=>{if(K.size===0)return;S(!0);const t=new Date().toISOString();await x.from("articles").update({status:"published",published_at:t}).in("id",Array.from(K)),X(new Set),S(!1),v()};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ee,{children:e.jsx("title",{children:te("Articles · GEO")})}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a.length," articles"]}),e.jsx("button",{onClick:ge,className:"px-3 py-1.5 rounded text-xs bg-white/5 hover:bg-white/10 text-white/60 hover:text-white transition-colors",children:"Select All Drafts"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(z,{size:"sm",variant:"outline",onClick:v,children:[e.jsx(Ne,{className:"h-3.5 w-3.5 mr-1"}),"Refresh"]}),e.jsx(z,{size:"sm",onClick:async()=>{const{data:t}=await je("generate-api-key",{name:"Articles API Key"});t!=null&&t.key?(y(t.key),D(!1),_(!1),F.success("API key generated!"),v()):F.error("Failed to generate key")},children:"Generate API Key"})]})]}),K.size>0&&e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-blue-600/10 border border-blue-500/20 rounded-lg",children:[e.jsxs("span",{className:"text-sm text-blue-400 font-medium",children:[K.size," article",K.size>1?"s":""," selected"]}),e.jsx("button",{onClick:be,disabled:g,className:"px-4 py-1.5 rounded text-sm bg-blue-600 hover:bg-blue-700 text-white font-semibold transition-colors disabled:opacity-50",children:g?"Publishing...":"Publish Selected"}),e.jsx("button",{onClick:()=>X(new Set),className:"px-3 py-1.5 rounded text-sm text-white/40 hover:text-white transition-colors",children:"Clear"})]}),a.length>0&&e.jsx("div",{className:"rounded-xl border border-border overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/30",children:[e.jsx("th",{className:"w-8 px-3 py-2"}),e.jsx("th",{className:"text-left px-4 py-2",children:"Title"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Image"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Source"}),e.jsx("th",{className:"text-left px-3 py-2",children:"DNA"}),e.jsx("th",{className:"text-left px-3 py-2 whitespace-nowrap",children:"Keyword"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Status"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Views"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Created"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Scheduled"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Published"}),e.jsx("th",{className:"text-right px-4 py-2",children:"Actions"})]})}),e.jsx("tbody",{children:a.map(t=>e.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/20",children:[e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("input",{type:"checkbox","aria-label":`Select ${t.title}`,checked:K.has(t.id),onChange:()=>ue(t.id),className:"rounded border-white/20 bg-white/5 text-blue-500 cursor-pointer"})}),e.jsx("td",{className:"px-4 py-2.5 max-w-[250px]",children:e.jsx("span",{className:"truncate block",children:t.title})}),e.jsx("td",{className:"px-3 py-2.5",children:t.og_image?e.jsx("img",{src:t.og_image,alt:"",className:"w-10 h-7 rounded object-cover border border-white/10 shrink-0",onError:r=>r.target.style.display="none"}):e.jsx("span",{className:"text-white/20 text-[10px]",children:"â"})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${t.source==="perplexity"?"bg-purple-500/20 text-purple-400":"bg-muted text-muted-foreground"}`,children:t.source})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx(re,{score:t.dna_match_score})}),e.jsx("td",{className:"px-3 py-2.5",children:t.target_keyword?e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"text-white/70 text-xs font-mono truncate block max-w-[160px]",title:t.target_keyword,
1children:t.target_keyword}),t.keyword_volume!=null&&e.jsxs("span",{className:"text-white/30 text-xs",children:[t.keyword_volume.toLocaleString(),"/mo"]})]}):e.jsx("span",{className:"text-white/20 text-xs",children:"â"})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${t.status==="published"?"bg-green-500/20 text-green-400":"bg-amber-500/20 text-amber-400"}`,children:t.status})}),e.jsx("td",{className:"px-3 py-2.5 text-right",children:t.view_count??0}),e.jsx("td",{className:"px-3 py-2.5",children:new Date(t.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-3 py-2.5",children:t.status==="draft"&&t.source==="perplexity"?e.jsx("span",{className:ae(t)==="Imminent"?"text-orange-400 font-semibold":"",children:ae(t)??"â"}):"â"}),e.jsx("td",{className:"px-3 py-2.5",children:t.published_at?e.jsx("span",{className:"text-green-400",children:new Date(t.published_at).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}):"â"}),e.jsxs("td",{className:"px-4 py-2.5 text-right flex gap-1 justify-end",children:[e.jsx("button",{onClick:()=>de(t),className:"px-3 py-1 rounded text-xs bg-purple-600 hover:bg-purple-700 text-white transition-colors",children:"Vibe Check"}),t.status==="draft"?e.jsx(z,{size:"sm",variant:"outline",onClick:async()=>{await x.from("articles").update({status:"published",published_at:new Date().toISOString()}).eq("id",t.id),v(),F.success("Published")},children:"Publish"}):e.jsx(z,{size:"sm",variant:"ghost",onClick:async()=>{await x.from("articles").update({status:"draft"}).eq("id",t.id),v(),F.success("Unpublished")},children:"Unpublish"}),e.jsx("a",{href:`/blog/${t.slug}`,target:"_blank",rel:"noopener noreferrer",children:e.jsx(z,{size:"sm",variant:"ghost",children:e.jsx(_e,{className:"h-3 w-3"})})}),e.jsx(z,{size:"sm",variant:"ghost",className:"text-destructive",onClick:async()=>{confirm("Delete this article?")&&(await x.from("articles").delete().eq("id",t.id),v(),F.success("Deleted"))},children:"Del"})]})]},t.id))})]})}),h&&e.jsxs("div",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 p-4 space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-amber-400",children:"Copy this key now. It won't be shown again."}),e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-2.5",children:[e.jsx("code",{className:"flex-1 text-xs font-mono truncate",children:o?h:h.substring(0,8)+"â¢".repeat(40)}),e.jsx("button",{type:"button",onClick:()=>D(t=>!t),className:"p-1 text-muted-foreground hover:text-foreground transition-colors shrink-0",title:o?"Hide":"Show",children:o?e.jsx(ye,{className:"w-4 h-4"}):e.jsx(ve,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:async()=>{await navigator.clipboard.writeText(h),_(!0),setTimeout(()=>_(!1),2e3)},className:`p-1 transition-colors shrink-0 ${i?"text-green-400":"text-muted-foreground hover:text-foreground"}`,title:"Copy",children:i?e.jsx(Se,{className:"w-4 h-4"}):e.jsx(ke,{className:"w-4 h-4"})})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Use as: Authorization: Bearer ",h.substring(0,12),"..."]})]}),f.length>0&&e.jsxs("div",{className:"space-y-2 mt-6",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"API Keys"}),e.jsx("div",{className:"rounded-xl border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/30",children:[e.jsx("th",{className:"text-left px-4 py-2",children:"Name"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Prefix"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Last used"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Status"}),e.jsx("th",{className:"text-right px-4 py-2",children:"Actions"})]})}),e.jsx("tbody",{children:f.map(t=>e.jsxs("tr",{className:"border-b border-border/50",children:[e.jsx("td",{className:"px-4 py-2.5",children:t.name}),e.jsxs("td",{className:"px-3 py-2.5 font-mono",children:[t.key_prefix,"..."]}),e.jsx("td",{className:"px-3 py-2.5",children:t.last_used_at?new Date(t.last_used_at).toLocaleDateString():"Never"}),e.jsx("td",{className:"px-3 py-2.5",children:t.is_active?e.jsx("span",{className:"text-green-400 text-[10px]",children:"Active"}):e.jsx("span",{className:"text-red-400 text-[10px]",children:"Revoked"})}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:e.jsx(z,{size:"sm",variant:"ghost",onClick:async()=>{await x.from("api_keys").update({is_active:!t.is_active}).eq("id",t.id),v()},children:t.is_active?"Revoke":"Restore"})})]},t.id))})]})})]}),n&&e.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-[#111118] border border-white/10 rounded-xl w-full max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-white font-semibold text-sm",children:"Vibe Check"}),e.jsx(re,{score:n.dna_match_score}),e.jsx("span",{className:"text-xs text-white/40 font-mono truncate max-w-xs",children:n.slug})]}),e.jsx("button",{type:"button",onClick:()=>N(null),className:"text-white/40 hover:text-white text-lg leading-none",children:"â"})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex-1 flex flex-col gap-3 p-4 overflow-y-auto border-r border-white/10",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-white/40",children:"OG Image"}),e.jsx("button",{type:"button",onClick:()=>M(!p),className:"text-xs text-blue-400 hover:text-blue-300 transition-colors",children:p?"Cancel":"Change image"})]}),!p&&(n!=null&&n.og_image?e.jsx("img",{src:n.og_image,alt:"OG Image",className:"w-full rounded-lg object-cover max-h-48 border border-white/10",onError:t=>t.target.style.display="none"}):W?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-blue-400 bg-blue-500/10 rounded-lg px-3 py-3 border border-blue-500/20",children:[e.jsx("span",{className:"animate-spin",children:"â³"}),e.jsx("span",{children:"Generating AI image â refreshing every 5s..."})]}):e.jsxs("div",{className:"flex items-center gap-2 text-xs text-white/30 bg-white/5 rounded-lg px-3 py-2",children:[e.jsx("span",{children:"â³"}),e.jsx("span",{children:"No image yet"})]})),p&&e.jsxs("div",{className:"flex flex-col gap-3 p-3 bg-white/5 rounded-lg border border-white/10",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-xs text-white/50",children:"Upload image"}),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp","aria-label":"Upload OG image",onCh
1ange:t=>{var m;const r=(m=t.target.files)==null?void 0:m[0];r&&(n!=null&&n.id)&&ce(r,n.id)},className:"text-xs text-white/50 file:mr-3 file:py-1.5 file:px-3 file:rounded file:border-0 file:text-xs file:bg-white/10 file:text-white hover:file:bg-white/20 cursor-pointer",disabled:J}),J&&e.jsx("p",{className:"text-xs text-blue-400",children:"Uploading..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-px bg-white/10"}),e.jsx("span",{className:"text-xs text-white/30",children:"or"}),e.jsx("div",{className:"flex-1 h-px bg-white/10"})]}),e.jsx("button",{type:"button",onClick:()=>{n!=null&&n.id&&oe(n.id)},disabled:W,className:"w-full px-4 py-2 rounded-lg text-sm bg-purple-600 hover:bg-purple-700 text-white font-semibold transition-colors disabled:opacity-50",children:W?"Generating...":"Generate new AI image"}),e.jsx("p",{className:"text-xs text-white/30 text-center",children:"Uses your article title to generate an on-brand image via Flux Schnell. Takes 15-30 seconds."})]})]}),e.jsx("input",{value:u,onChange:t=>A(t.target.value),className:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm placeholder-white/30",placeholder:"Title"}),e.jsx("textarea",{value:j,onChange:t=>P(t.target.value),className:"flex-1 w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm font-mono resize-none min-h-[380px]",placeholder:"Content (markdown)..."}),b&&e.jsxs("div",{className:"flex flex-col gap-3 p-3 bg-red-500/5 rounded-lg border border-red-500/20",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>G("fix"),className:`flex-1 px-3 py-2 rounded text-xs font-semibold transition-colors ${b==="fix"?"bg-orange-600 text-white":"bg-white/5 text-white/50 hover:bg-white/10"}`,children:"âï¸ Fix this article"}),e.jsx("button",{type:"button",onClick:()=>G("new_topic"),className:`flex-1 px-3 py-2 rounded text-xs font-semibold transition-colors ${b==="new_topic"?"bg-red-600 text-white":"bg-white/5 text-white/50 hover:bg-white/10"}`,children:"ð Research new topic"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-white/50 mb-1.5",children:b==="fix"?"What needs fixing? Be specific â Hermes will rewrite based on this.":"Why is this topic wrong? Hermes will research a different angle."}),e.jsx("textarea",{value:U,onChange:t=>I(t.target.value),className:"w-full bg-red-500/5 border border-red-500/20 rounded-lg px-3 py-2 text-white text-sm resize-none h-28 focus:outline-none focus:border-red-500/40",placeholder:b==="fix"?"e.g. SuperX is X-only, not LinkedIn. Rewrite the competitive angle to focus on founders switching from SuperX because they need LinkedIn support.":"e.g. The premise is wrong â SuperX does not support LinkedIn. Research a different Pillar 3 angle, e.g. Chrome Extension utility for multi-platform creators."})]}),e.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[e.jsx("button",{type:"button",onClick:()=>{G(null),I("")},className:"px-3 py-1.5 text-xs text-white/40 hover:text-white transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:pe,disabled:!U.trim()||q,className:`px-4 py-1.5 rounded text-xs font-semibold transition-colors disabled:opacity-50 ${b==="fix"?"bg-orange-600 hover:bg-orange-700 text-white":"bg-red-600 hover:bg-red-700 text-white"}`,children:q?"Submitting...":b==="fix"?"Send to Hermes for fixes":"Reject & research new topic"})]})]})]}),e.jsxs("div",{className:"w-72 flex flex-col p-4 overflow-y-auto shrink-0",children:[e.jsx("p",{className:"text-xs text-white/40 font-mono uppercase tracking-wider mb-2",children:"GEO Schema (editable)"}),e.jsx("textarea",{value:R,onChange:t=>O(t.target.value),className:"flex-1 text-xs text-green-400 bg-black/40 rounded-lg p-3 font-mono resize-none border border-white/10 focus:border-green-500/40 focus:outline-none min-h-[400px]",placeholder:'{"@context": "https://schema.org", ...}',spellCheck:!1,"aria-label":"GEO Schema JSON"})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-white/10",children:[e.jsx("button",{type:"button",onClick:()=>G(b?null:"new_topic"),className:"px-4 py-2 rounded-lg text-sm bg-red-500/10 hover:bg-red-500/20 text-red-400 transition-colors",children:b?"Cancel reject":"Reject"}),(n==null?void 0:n.status)==="draft"&&(n==null?void 0:n.source)==="perplexity"&&(L?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"datetime-local",value:H,onChange:t=>V(t.target.value),"aria-label":"Auto-publish schedule",className:"bg-white/5 border border-white/10 rounded px-2 py-1 text-white text-xs focus:outline-none focus:border-blue-500/50"}),e.jsx("button",{type:"button",onClick:he,disabled:s,className:"px-3 py-1.5 rounded text-xs bg-blue-600 hover:bg-blue-700 text-white transition-colors disabled:opacity-50",children:s?"Saving...":"Save"}),e.jsx("button",{type:"button",onClick:()=>T(!1),className:"text-xs text-white/30 hover:text-white transition-colors",children:"Cancel"})]}):e.jsxs("button",{type:"button",onClick:()=>{T(!0);const t=n.scheduled_publish_at??new Date(new Date(n.created_at).getTime()+48*60*60*1e3).toISOString();V(t.slice(0,16))},className:"px-3 py-1.5 rounded text-xs bg-white/5 hover:bg-white/10 text-white/50 hover:text-white transition-colors",children:["ð
Auto-publishes ",(()=>{const t=n.scheduled_publish_at??new Date(new Date(n.created_at).getTime()+1728e5),r=new Date(t);return r<new Date?"imminently":r.toLocaleDateString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})})()]})),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{type:"button",onClick:xe,disabled:g,className:"px-4 py-2 rounded-lg text-sm bg-white/10 hover:bg-white/15 text-white transition-colors disabled:opacity-50",children:"Save Draft"}),e.jsx("button",{type:"button",onClick:me,disabled:g,className:"px-4 py-2 rounded-lg text-sm bg-blue-600 hover:bg-blue-700 text-white font-semibold transition-colors disabled:opacity-50",children:g?"Publishing...":"PUBLISH"})]})]})]})})]})}function Oe(){var g,S,L,T,H,V;const[a,C]=c.useState([]),[f,w]=c.useState([]),[h,y]=c.useState(!1),[o,D]=c.useState(null),[i,_]=c.useState({}),[n,N]=c.useState(!1),[j,P]=c.useState(""),[u,A]=c.useState(""),[R,O]=c.useState(""),b=async()=>{y(!0);const{data:s}=await x.from("seo_pages").select("*").order("route"),{data:d}=await x.from("articles").select("id, title, slug, meta_title, meta_description, og_image, status, updated_at, geo_schema").eq("status","published").order("published_at",{ascending:!1}).limit(50);C(s??[]),w(d??[]),y(!1)};c.useEffect(()=>{b()},[]);const G=(s,d)=>{const p=d==="page"?s.page_title:s.meta_title??s.title,M=s.meta_description,J=d==="page"?s.og_image_url:s.og_image,Q=d==="page"?s.json_ld:s.geo_schema,B=[!!p&&p.length<=70,
1!!M&&M.length<=170,!!J,!!Q].filter(Boolean).length;return B===4?{label:"Great",colour:"bg-green-500/20 text-green-400"}:B>=2?{label:"OK",colour:"bg-yellow-500/20 text-yellow-400"}:{label:"Poor",colour:"bg-red-500/20 text-red-400"}},U=async()=>{O("Pinging...");try{await fetch("https://www.google.com/ping?sitemap=https://www.prospel.app/sitemap.xml",{mode:"no-cors"}),O("Pinged â"),setTimeout(()=>O(""),3e3)}catch{O("Done (no-cors â check GSC)"),setTimeout(()=>O(""),4e3)}},I=async()=>{try{const[s,d]=await Promise.all([fetch("/sitemap.xml").then(p=>p.text()),fetch("/sitemap-ai.xml").then(p=>p.text())]);P(s),A(d)}catch(s){console.error("Sitemap fetch error",s)}},q=(s,d)=>{D({...s,_type:d}),_(d==="page"?{page_title:s.page_title??"",meta_description:s.meta_description??"",og_image_url:s.og_image_url??"",canonical_url:s.canonical_url??"",twitter_card_type:s.twitter_card_type??"summary_large_image",json_ld:s.json_ld?JSON.stringify(s.json_ld,null,2):"",is_indexed:s.is_indexed??!0}:{meta_title:s.meta_title??s.title??"",meta_description:s.meta_description??"",og_image:s.og_image??"",json_ld:s.geo_schema?JSON.stringify(s.geo_schema,null,2):""})},l=async()=>{var s,d;if(o){N(!0);try{if(o._type==="page"){let p=null;if((s=i.json_ld)!=null&&s.trim())try{p=JSON.parse(i.json_ld)}catch{}await x.from("seo_pages").update({page_title:i.page_title,meta_description:i.meta_description,og_image_url:i.og_image_url,canonical_url:i.canonical_url,twitter_card_type:i.twitter_card_type,json_ld:p,is_indexed:i.is_indexed,updated_at:new Date().toISOString()}).eq("id",o.id)}else{let p=null;if((d=i.json_ld)!=null&&d.trim())try{p=JSON.parse(i.json_ld)}catch{}await x.from("articles").update({meta_title:i.meta_title,meta_description:i.meta_description,og_image:i.og_image,geo_schema:p}).eq("id",o.id)}}finally{N(!1),D(null),b()}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ee,{children:e.jsx("title",{children:te("SEO Manager · GEO")})}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Public Pages",value:a.length+f.length,colour:"text-white"},{label:"Missing Description",value:[...a.filter(s=>!s.meta_description),...f.filter(s=>!s.meta_description)].length,colour:"text-yellow-400"},{label:"Missing OG Image",value:[...a.filter(s=>!s.og_image_url),...f.filter(s=>!s.og_image)].length,colour:"text-yellow-400"},{label:"Missing JSON-LD",value:[...a.filter(s=>!s.json_ld),...f.filter(s=>!s.geo_schema)].length,colour:"text-orange-400"}].map(s=>e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs text-white/40 mb-1",children:s.label}),e.jsx("p",{className:`text-2xl font-bold ${s.colour}`,children:s.value})]},s.label))}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("button",{type:"button",onClick:U,className:"px-4 py-2 rounded-lg text-sm bg-blue-600 hover:bg-blue-700 text-white transition-colors",children:R||"Ping Google"}),e.jsx("button",{type:"button",onClick:I,className:"px-4 py-2 rounded-lg text-sm bg-white/10 hover:bg-white/15 text-white transition-colors",children:"Load Sitemaps"}),e.jsx("a",{href:"https://search.google.com/search-console",target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 rounded-lg text-sm bg-white/5 hover:bg-white/10 text-white/70 hover:text-white transition-colors",children:"Open GSC â"})]}),h?e.jsx("div",{className:"text-white/40 text-sm py-8 text-center",children:"Loading..."}):e.jsx("div",{className:"bg-white/5 border border-white/10 rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/10",children:[e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"Page"}),e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"Type"}),e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"Title"}),e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"Desc"}),e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"OG"}),e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"JSON-LD"}),e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"Score"}),e.jsx("th",{className:"text-left p-3 text-white/50 font-medium",children:"Actions"})]})}),e.jsxs("tbody",{children:[a.map(s=>{const d=G(s,"page");return e.jsxs("tr",{className:"border-b border-white/5 hover:bg-white/5 transition-colors",children:[e.jsx("td",{className:"p-3 text-white/70 font-mono text-xs",children:s.route}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-blue-500/20 text-blue-400",children:"Static"})}),e.jsx("td",{className:"p-3 text-white/70 text-xs max-w-[160px] truncate",children:s.page_title}),e.jsx("td",{className:"p-3",children:s.meta_description?e.jsx("span",{className:"text-green-400",children:"â"}):e.jsx("span",{className:"text-red-400",children:"â"})}),e.jsx("td",{className:"p-3",children:s.og_image_url?e.jsx("span",{className:"text-green-400",children:"â"}):e.jsx("span",{className:"text-red-400",children:"â"})}),e.jsx("td",{className:"p-3",children:s.json_ld?e.jsx("span",{className:"text-green-400",children:"â"}):e.jsx("span",{className:"text-red-400",children:"â"})}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-semibold ${d.colour}`,children:d.label})}),e.jsx("td",{className:"p-3",children:e.jsx("button",{type:"button",onClick:()=>q(s,"page"),className:"px-3 py-1 rounded text-xs bg-white/10 hover:bg-white/20 text-white transition-colors",children:"Edit"})})]},s.id)}),f.map(s=>{const d=G(s,"article");return e.jsxs("tr",{className:"border-b border-white/5 hover:bg-white/5 transition-colors",children:[e.jsxs("td",{className:"p-3 text-white/70 font-mono text-xs",children:["/blog/",s.slug]}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-purple-500/20 text-purple-400",children:"Article"})}),e.jsx("td",{className:"p-3 text-white/70 text-xs max-w-[160px] truncate",children:s.meta_title??s.title}),e.jsx("td",{className:"p-3",children:s.meta_description?e.jsx("span",{className:"text-green-400",children:"â"}):e.jsx("span",{className:"text-red-400",children:"â"})}),e.jsx("td",{className:"p-3",children:s.og_image?e.jsx("span",{className:"text-green-400",children:"â"}):e.jsx("span",{className:"text-red-400",children:"â"})}),e.jsx("td",{className:"p-3",children:s.geo_schema?e.jsx("span",{className:"text-green-400",children:"â"}):e.jsx("span",{className:"text-red-400",children:"â"})}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-semibold ${d.colour}`,children:d.label})}),e.jsx("td",{className:"p-3",children:e.jsx("button",{type:"button",onClick:()=>q(s,"article"),className:"px-3 py-1 rounded text-xs bg-white/10 hover:bg-white/20 text-white transition-colors",children:"Edit"})})]},s.id)})]})]})}),(j||u)&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[j&&e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"sitemap.xml"}),e.jsx("button",{type:"button",onClick:()=>{const s=new Blob([j],{type:"application/xml"}),d=URL.createObjectURL(s),p=document.createElement("a");p.href=d,p.download="sitemap.xml",p.click()},className:"px-3 py-1 rounded text-xs bg-white/10 hover:bg-white/20 text-white transition-colors",children:"Download"})]}),e.jsx("pre",{className:"text-xs text-white/50 overflow-x-auto max-h-48 whitespace-pre-wrap",children:j})]}),u&&e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"sitemap-ai.xml"}),e.jsx("button",{type:"button",onClick:()=>{const s=new Blob([u],{type:"application/xml"}),d=URL.createObjectURL(s),p=document.createElement("a");p.href=d,p.download="sitemap-ai.xml",p.click()},className:"px-3 py-1 rounded text-xs bg-white/10 hover:bg-white/20 text-white transition-colors",children:"Download"})]}),e.jsx("pre",{className:"text-xs text-white/50 overflow-x-auto max-h-48 whitespace-pre-wrap",children:u})]})]}),e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm text-white/70 font-medium mb-3",children:"robots.txt"}),e.jsx("pre",{className:"text-xs text-white/50 font-mono whitespace-pre-wrap",children:`User-agent: * 2Allow: / 3Disallow: /dashboard/ 4Disallow: /admin/ 5Disallow: /api/ 6 7User-agent: GPTBot 8Allow: / 9 10User-agent: OAI-SearchBot 11Allow: / 12 13User-agent: PerplexityBot 14Allow: / 15 16User-agent: Google-Extended 17Allow: / 18 19User-agent: anthropic-ai 20Allow: / 21 22User-agent: Claude-Web 23Allow: / 24 25User-agent: Gemini 26Allow: / 27 28Sitemap: https://prospel.app/sitemap.xml 29Sitemap: https://prospel.app/sitemap-ai.xml`})]}),o&&e.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-[#111118] border border-white/10 rounded-xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-white font-semibold text-sm",children:"Edit SEO"}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${o._type==="page"?"bg-blue-500/20 text-blue-400":"bg-purple-500/20 text-purple-400"}`,children:o._type==="page"?o.route:`/blog/${o.slug}`})]}),e.jsx("button",{type:"button",onClick:()=>D(null),className:"text-white/40 hover:text-white text-lg",children:"â"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-xs text-white/50",children:o._type==="page"?"Page Title":"Meta Title"}),e.jsxs("span",{className:`text-xs font-mono ${((g=o._type==="page"?i.page_title:i.meta_title)==null?void 0:g.length)>70?"text-red-400":((S=o._type==="page"?i.page_title:i.meta_title)==null?void 0:S.length)>60?"text-yellow-400":"text-white/30"}`,children:[((L=o._type==="page"?i.page_title:i.meta_title)==null?void 0:L.length)??0,"/70"]})]}),e.jsx("input",{"aria-label":"Page title",value:o._type==="page"?i.page_title??"":i.meta_title??"",onChange:s=>_(d=>({...d,[o._type==="page"?"page_title":"meta_title"]:s.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-xs text-white/50",children:"Meta Description"}),e.jsxs("span",{className:`text-xs font-mono ${((T=i.meta_description)==null?void 0:T.length)>170?"text-red-400":((H=i.meta_description)==null?void 0:H.length)>155?"text-yellow-400":"text-white/30"}`,children:[((V=i.meta_description)==null?void 0:V.length)??0,"/170"]})]}),e.jsx("textarea",{"aria-label":"Meta description",value:i.meta_description??"",onChange:s=>_(d=>({...d,meta_description:s.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm resize-none h-24"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-white/50 block mb-1",children:"OG Image URL"}),e.jsx("input",{"aria-label":"OG image URL",value:o._type==="page"?i.og_image_url??"":i.og_image??"",onChange:s=>_(d=>({...d,[o._type==="page"?"og_image_url":"og_image"]:s.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm font-mono",placeholder:"https://..."}),(o._type==="page"?i.og_image_url:i.og_image)&&e.jsx("img",{src:o._type==="page"?i.og_image_url:i.og_image,alt:"OG preview",className:"mt-2 rounded-lg w-full max-h-32 object-cover border border-white/10",onError:s=>s.target.style.display="none"})]}),o._type==="page"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-white/50 block mb-1",children:"Canonical URL"}),e.jsx("input",{"aria-label":"Canonical URL",value:i.canonical_url??"",onChange:s=>_(d=>({...d,canonical_url:s.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm font-mono",placeholder:"https://www.prospel.app/..."})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-white/50 mb-2",children:"SERP Preview"}),e.jsxs("div",{className:"bg-white rounded-lg p-3",children:[e.jsx("p",{className:"text-blue-700 text-sm font-medium truncate",children:o._type==="page"?i.canonical_url:`https://www.prospel.app/blog/${o.slug}`}),e.jsx("p",{className:"text-green-700 text-xs mb-1 truncate",children:o._type==="page"?i.canonical_url:`www.prospel.app ⺠blog ⺠${o.slug}`}),e.jsx("p",{className:"text-gray-900 text-sm font-medium leading-tight",children:(o._type==="page"?i.page_title:i.meta_title)||"
29No title set"}),e.jsx("p",{className:"text-gray-600 text-xs mt-0.5 line-clamp-2",children:i.meta_description||"No description set"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-white/50 block mb-1",children:"JSON-LD Schema"}),e.jsx("textarea",{"aria-label":"JSON-LD schema",value:i.json_ld??"",onChange:s=>_(d=>({...d,json_ld:s.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-xs font-mono resize-none h-32",placeholder:'{"@context": "https://schema.org", "@type": "..."}'})]}),o._type==="page"&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",id:"is_indexed",checked:i.is_indexed??!0,onChange:s=>_(d=>({...d,is_indexed:s.target.checked})),className:"rounded border-white/20"}),e.jsx("label",{htmlFor:"is_indexed",className:"text-sm text-white/70",children:"Include in sitemap (indexed)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-white/10",children:[e.jsx("button",{type:"button",onClick:()=>D(null),className:"text-sm text-white/40 hover:text-white transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:l,disabled:n,className:"px-4 py-2 rounded-lg text-sm bg-blue-600 hover:bg-blue-700 text-white font-semibold transition-colors disabled:opacity-50",children:n?"Saving...":"Save"})]})]})})]})}const ne=[{id:1,label:"Voice & Content Generation"},{id:2,label:"Consistency & Publishing"},{id:3,label:"Engagement Intelligence"},{id:4,label:"Performance & Growth"},{id:5,label:"LinkedIn B2B Authority"}];function Re(){var I,q;const[a,C]=c.useState(null),[f,w]=c.useState([]),[h,y]=c.useState([]),[o,D]=c.useState([]),[i,_]=c.useState([]),[n,N]=c.useState(!1),[j,P]=c.useState(!1),[u,A]=c.useState(null),R=async()=>{N(!0);const[l,g,S,L,T]=await Promise.all([x.from("pc_phase_state").select("*").single(),x.from("pc_session_runs").select("*").order("started_at",{ascending:!1}).limit(20),x.from("pc_failed_drafts").select("*").eq("human_review_required",!0).eq("reviewed",!1).order("created_at",{ascending:!1}),x.from("pc_topic_rejections").select("*").gt("cooldown_until",new Date().toISOString()).eq("reactivated",!1).order("cooldown_until"),x.from("pc_retry_queue").select("*").eq("status","pending").order("next_retry_at")]);C(l.data),w(g.data??[]),y(S.data??[]),D(L.data??[]),_(T.data??[]),N(!1)};c.useEffect(()=>{R()},[]);const O=async()=>{if(!a)return;P(!0);const l=!a.kill_switch_active;await x.from("pc_phase_state").update({kill_switch_active:l,kill_switch_reason:l?"Manually activated by admin":null,consecutive_failures:l?a.consecutive_failures:0}).eq("id",a.id),await x.from("pc_scheduler_events").insert({event_type:l?"kill_switch_activated":"kill_switch_deactivated",notes:l?"Manually activated by admin":"Manually deactivated by admin"}),P(!1),R()},b=async(l,g)=>{await x.from("pc_failed_drafts").update({reviewed:!0,reviewer_action:g,reviewed_at:new Date().toISOString()}).eq("id",l),R()},G=()=>{window.alert(`To trigger Hermes immediately, SSH to Hetzner and run: 30 31`+"docker exec hermes-vm-engine hermes cron run a2018a6d7a1b"+` 32 33Otherwise the next scheduled run is 09:00 UTC.`)},U=((I=ne.find(l=>l.id===(a==null?void 0:a.next_pillar)))==null?void 0:I.label)??`Pillar ${a==null?void 0:a.next_pillar}`;return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ee,{children:e.jsx("title",{children:te("GEO Bot · GEO")})}),n?e.jsx("div",{className:"text-white/40 text-sm py-8 text-center",children:"Loading..."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"Engine State"}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-bold ${(a==null?void 0:a.phase)==="ongoing"?"bg-green-500/20 text-green-400":"bg-blue-500/20 text-blue-400"}`,children:((q=a==null?void 0:a.phase)==null?void 0:q.toUpperCase())??"SEED"})]}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-white/40",children:"Articles submitted"}),e.jsx("span",{className:"text-white",children:(a==null?void 0:a.seed_articles_count)??0})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-white/40",children:"Days running"}),e.jsx("span",{className:"text-white",children:(a==null?void 0:a.days_since_start)??0})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-white/40",children:"Next pillar"}),e.jsxs("span",{className:"text-white",children:["Pillar ",a==null?void 0:a.next_pillar," â ",U]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-white/40",children:"Consecutive failures"}),e.jsx("span",{className:((a==null?void 0:a.consecutive_failures)??0)>=2?"text-red-400":"text-white",children:(a==null?void 0:a.consecutive_failures)??0})]})]}),e.jsxs("div",{className:"space-y-1.5 pt-2",children:[e.jsx("p",{className:"text-xs text-white/40 mb-2",children:"Pillar coverage"}),ne.map(l=>{var L;const g=((L=a==null?void 0:a.pillar_coverage)==null?void 0:L[String(l.id)])??0,S=Math.max(...Object.values((a==null?void 0:a.pillar_coverage)??{}).map(Number),1);return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-xs text-white/50 w-6 shrink-0",children:["P",l.id]}),e.jsx("div",{className:"flex-1 bg-white/5 rounded-full h-1.5",children:e.jsx("div",{className:"bg-blue-500 h-1.5 rounded-full transition-all",style:{width:`${g/S*100}%`}})}),e.jsx("span",{className:"text-xs text-white/40 w-4 text-right shrink-0",children:g}),e.jsx("span",{className:"text-xs text-white/30 truncate max-w-[160px]",children:l.label})]},l.id)})]})]}),e.jsxs("div",{className:`border rounded-xl p-4 space-y-3 ${a!=null&&a.kill_switch_active?"bg-red-500/10 border-red-500/30":"bg-white/5 border-white/10"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"Kill Switch"}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-bold ${a!=null&&a.kill_switch_active?"bg-red-500/20 text-red-400":"bg-green-500/20 text-green-400"}`,children:a!=null&&a.kill_switch_active?"ACTIVE":"INACTIVE"})]}),(a==null?void 0:a.kill_switch_active)&&e.jsx("p",{className:"text-xs text-red-400/80",children:a.kill_switch_reason}),e.jsx("button",{type:"button",onClick:O,disabled:j,className:`w-full px-4 py-2 rounded-lg text-sm font-semibold transition-colors disabled:opacity-50 ${a!=null&&a.kill_switch_active?"bg-green-600 hover:bg-green-700 text-white":"bg-red-600/80 hover:bg-red-600 text-white"}`,children:j?"Updating...":a!=null&&a.kill_switch_active?"Deactivate Kill Switch":"Activate Kill Switch"}),e.jsx("p",{className:"text-xs text-white/30",children:"Auto-activates after 3 consecutive hard failures. You will be notified by email."}),e.jsx("button",{type:"button",onClick:G,className:"w-full px-4 py-2 rounded-lg text-sm bg-purple-600 hover:bg-purple-700 text-white font-semibold transition-colors",children:"â¡ Trigger Hermes Session Now"})]})]}),h.length>0&&e.jsxs("div",{className:"bg-orange-500/5 border border-orange-500/20 rounded-xl p-4",children:[e.jsxs("p",{className:"text-sm text-orange-400 font-medium mb-3",children:[h.length," Failed Draft",h.length>
331?"s":""," â Human Review Required"]}),e.jsx("div",{className:"space-y-2",children:h.map(l=>{var g;return e.jsxs("div",{className:"flex items-center justify-between bg-white/5 rounded-lg p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-white",children:l.topic}),e.jsxs("p",{className:"text-xs text-white/40 mt-0.5",children:["Pillar ",l.pillar," · DNA ",((g=l.dna_match_score)==null?void 0:g.toFixed(2))??"?"," · ",l.rewrite_attempts," rewrites · ",l.failure_reason]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>A(l),className:"px-3 py-1 rounded text-xs bg-white/10 hover:bg-white/20 text-white transition-colors",children:"Review"}),e.jsx("button",{type:"button",onClick:()=>b(l.id,"approved"),className:"px-3 py-1 rounded text-xs bg-green-600 hover:bg-green-700 text-white transition-colors",children:"Approve"}),e.jsx("button",{type:"button",onClick:()=>b(l.id,"rejected"),className:"px-3 py-1 rounded text-xs bg-red-600/80 hover:bg-red-600 text-white transition-colors",children:"Reject"})]})]},l.id)})})]}),e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl overflow-hidden",children:[e.jsx("div",{className:"p-3 border-b border-white/10",children:e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"Session Run Log"})}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/10",children:[e.jsx("th",{className:"text-left p-3 text-white/40 font-medium text-xs",children:"Run ID"}),e.jsx("th",{className:"text-left p-3 text-white/40 font-medium text-xs",children:"Session Result"}),e.jsx("th",{className:"text-left p-3 text-white/40 font-medium text-xs",children:"Phase"}),e.jsx("th",{className:"text-left p-3 text-white/40 font-medium text-xs",children:"Pillar"}),e.jsx("th",{className:"text-left p-3 text-white/40 font-medium text-xs",children:"Topic"}),e.jsx("th",{className:"text-left p-3 text-white/40 font-medium text-xs",children:"DNA"}),e.jsx("th",{className:"text-left p-3 text-white/40 font-medium text-xs",children:"Started"})]})}),e.jsx("tbody",{children:f.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-6 text-center text-white/30 text-xs",children:"No sessions yet. GEO Bot has not run."})}):f.map(l=>{var g;return e.jsxs("tr",{className:"border-b border-white/5 hover:bg-white/5 transition-colors",children:[e.jsx("td",{className:"p-3 text-white/40 font-mono text-xs max-w-[100px] truncate",children:l.run_id}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-semibold ${l.status==="published"?"bg-green-500/20 text-green-400":l.status==="failed"||l.status==="aborted"?"bg-red-500/20 text-red-400":l.status==="running"?"bg-blue-500/20 text-blue-400":l.status==="deferred"?"bg-yellow-500/20 text-yellow-400":"bg-white/10 text-white/50"}`,children:{published:"Submitted â",deferred:"Retry Queued",failed:"Failed",running:"Running...",no_publish:"No Topic",aborted:"Aborted"}[l.status]??l.status})}),e.jsx("td",{className:"p-3 text-white/50 text-xs",children:l.phase}),e.jsx("td",{className:"p-3 text-white/50 text-xs",children:l.pillar??"â"}),e.jsx("td",{className:"p-3 text-white/70 text-xs max-w-[200px] truncate",children:l.topic??"â"}),e.jsx("td",{className:"p-3 text-white/50 text-xs",children:((g=l.dna_match_score)==null?void 0:g.toFixed(2))??"â"}),e.jsx("td",{className:"p-3 text-white/40 text-xs",children:new Date(l.started_at).toLocaleDateString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})})]},l.id)})})]})]}),e.jsx("p",{className:"text-xs text-white/30 mt-2",children:'"Submitted" means the article was successfully sent to the Articles tab as a draft. Publication happens after your Vibe Check or the 48hr auto-publish.'}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsxs("p",{className:"text-sm text-white/70 font-medium mb-3",children:["Topic Cooldowns (",o.length,")"]}),o.length===0?e.jsx("p",{className:"text-xs text-white/30",children:"No active cooldowns"}
33):e.jsx("div",{className:"space-y-2",children:o.map(l=>e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-white/70 truncate max-w-[160px]",children:l.topic}),e.jsxs("p",{className:"text-white/30",children:["Pillar ",l.pillar," · ",l.rejection_type]})]}),e.jsxs("p",{className:"text-white/40",children:["Until ",new Date(l.cooldown_until).toLocaleDateString("en-GB",{day:"numeric",month:"short"})]})]},l.id))})]}),e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsxs("p",{className:"text-sm text-white/70 font-medium mb-3",children:["Retry Queue (",i.length,")"]}),i.length===0?e.jsx("p",{className:"text-xs text-white/30",children:"No pending retries"}):e.jsx("div",{className:"space-y-2",children:i.map(l=>e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-white/70 font-mono truncate max-w-[160px]",children:l.topic_fingerprint}),e.jsxs("p",{className:"text-white/30",children:["Attempt ",l.attempt_count,"/",l.max_attempts]})]}),e.jsx("p",{className:"text-white/40",children:new Date(l.next_retry_at).toLocaleDateString("en-GB",{day:"numeric",month:"short"})})]},l.id))})]})]})]}),u&&e.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-[#111118] border border-white/10 rounded-xl w-full max-w-3xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-white font-semibold text-sm",children:"Failed Draft Review"}),e.jsxs("span",{className:"px-2 py-0.5 rounded text-xs bg-orange-500/20 text-orange-400",children:["Pillar ",u.pillar]}),u.dna_match_score&&e.jsxs("span",{className:"px-2 py-0.5 rounded text-xs bg-red-500/20 text-red-400 font-mono",children:["DNA ",(u.dna_match_score*100).toFixed(0),"%"]})]}),e.jsx("button",{type:"button",onClick:()=>A(null),className:"text-white/40 hover:text-white text-lg",children:"â"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-white/40 mb-1",children:"Topic"}),e.jsx("p",{className:"text-sm text-white",children:u.topic})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-white/40 mb-1",children:"Failure reason"}),e.jsx("p",{className:"text-sm text-red-400",children:u.failure_reason})]}),e.jsx("div",{children:e.jsxs("p",{className:"text-xs text-white/40 mb-1",children:["Rewrites attempted: ",u.rewrite_attempts]})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-white/40 mb-1",children:"Content"}),e.jsx("pre",{className:"text-xs text-white/70 bg-black/40 rounded-lg p-3 overflow-x-auto whitespace-pre-wrap max-h-[400px]",children:u.content_markdown})]}),u.geo_schema&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-white/40 mb-1",children:"GEO Schema"}),e.jsx("pre",{className:"text-xs text-green-400 bg-black/40 rounded-lg p-3 overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(u.geo_schema,null,2)})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-white/10",children:[e.jsx("button",{type:"button",onClick:()=>{b(u.id,"rejected"),A(null)},className:"px-4 py-2 rounded-lg text-sm bg-red-600/80 hover:bg-red-600 text-white transition-colors",children:"Reject"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{type:"button",onClick:()=>A(null),className:"text-sm text-white/40 hover:text-white transition-colors",children:"Close"}),e.jsx("button",{type:"button",onClick:()=>{b(u.id,"approved"),A(null)},className:"px-4 py-2 rounded-lg text-sm bg-green-600 hover:bg-green-700 text-white font-semibold transition-colors",children:"Approve"})]})]})]})})]})}function Ie(){const[a,C]=c.useState([]);if(c.useEffect(()=>{(async()=>{const{data:h}=await x.from("articles").select("id, title, status, scheduled_publish_at, published_at, dna_match_score, source, human_rejected").eq("source","perplexity").eq("human_rejected",!1).in("status",["draft","published"]).order("scheduled_publish_at",{ascending:!0,nullsFirst:!1}).limit(10);C(h??[])})()},[]),a.length===0)return e.jsx("p",{className:"text-xs text-white/30",children:"No articles in queue"});const f=new Date;return e.jsx("div",{className:"space-y-2",children:a.map(w=>{const h=w.scheduled_publish_at?new Date(w.scheduled_publish_at):null,y=!!h&&h<f&&w.status==="draft",o=w.status==="published";return e.jsxs("div",{className:`flex items-center gap-3 p-3 rounded-lg border text-xs ${o?"bg-green-500/5 border-green-500/10":y?"bg-orange-500/10 border-orange-500/20":"bg-white/5 border-white/10"}`,children:[e.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${o?"bg-green-400":y?"bg-orange-400 animate-pulse":"bg-blue-400"}`}),e.jsx("p",{className:"flex-1 text-white/70 truncate",children:w.title}),w.dna_match_score!=null&&e.jsxs("span",{className:"text-white/30 font-mono",children:[Math.round(w.dna_match_score*100),"%"]}),e.jsx("span",{className:`shrink-0 ${o?"text-green-400":y?"text-orange-400 font-semibold":"text-white/40"}`,children:o?`Published ${new Date(w.published_at).toLocaleDateString("en-GB",{day:"numeric",month:"short"})}`:y?"Publishes imminently":h?h.toLocaleDateString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}):"Unscheduled"})]},w.id)})})}function Le(){const[a,C]=c.useState(null),[f,w]=c.useState(!1),[h,y]=c.useState(7),o=async()=>{const{data:i}=await x.from("geo_schedule").select("*").eq("active",!0).maybeSingle();i&&(C(i),y(i.articles_per_week))};c.useEffect(()=>{o()},[]);const D=async()=>{a&&(w(!0),await x.from("geo_schedule").update({articles_per_week:h,updated_at:new Date().toISOString()}).eq("id",a.id),w(!1),o())};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm text-white font-semibold",children:"Publishing Schedule"}),e.jsx("p",{className:"text-xs text-white/40 mt-0.5",children:"Controls how often Hermes drafts and articles publish"})]}),e.jsx("button",{type:"button",onClick:D,disabled:f||h===(a==null?void 0:a.articles_per_week),className:"px-4 py-1.5 rounded-lg text-xs bg-blue-600 hover:bg-blue-700 text-white font-semibold transition-colors disabled:opacity-40",children:f?"
33Saving...":"Save"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs text-white/50",children:"Articles per week"}),e.jsx("span",{className:"text-sm font-bold text-white",children:h===7?"1 per day":h===1?"1 per week":`${h} per week`})]}),e.jsx("input",{type:"range",min:1,max:7,step:1,value:h,onChange:i=>y(Number(i.target.value)),"aria-label":"Articles per week",className:"w-full accent-blue-500"}),e.jsxs("div",{className:"flex justify-between text-xs text-white/30",children:[e.jsx("span",{children:"1/wk"}),e.jsx("span",{children:"2"}),e.jsx("span",{children:"3"}),e.jsx("span",{children:"4"}),e.jsx("span",{children:"5"}),e.jsx("span",{children:"6"}),e.jsx("span",{children:"1/day"})]})]}),(()=>{const i=Math.round(168/h),_=(a==null?void 0:a.draft_buffer)??2,n=i*_,N=[{label:"Hermes drafts every",value:`${i} hrs`,colour:"text-blue-400"},{label:"Articles publish every",value:`${i} hrs`,colour:"text-green-400"},{label:"Review window",value:`${n} hrs`,colour:"text-purple-400"},{label:"Draft buffer",value:`${_} articles`,colour:"text-white/60"}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mt-4",children:N.map(j=>e.jsxs("div",{className:"bg-black/20 rounded-lg p-3 text-center",children:[e.jsx("p",{className:"text-xs text-white/40 mb-1",children:j.label}),e.jsx("p",{className:`text-lg font-bold ${j.colour}`,children:j.value})]},j.label))})})()]}),e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm text-white font-semibold mb-3",children:"Publishing Queue"}),e.jsx(Ie,{})]})]})}function Me(){return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ee,{children:e.jsx("title",{children:te("GEO")})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-white",children:"GEO Content Engine"}),e.jsx("p",{className:"text-sm text-white/40 mt-1",children:"Articles, SEO, autonomous content bot and publishing schedule"})]}),e.jsxs(we,{defaultValue:"articles",children:[e.jsxs(fe,{children:[e.jsxs(Y,{value:"articles",className:"gap-1",children:[e.jsx(Ce,{className:"h-3.5 w-3.5"}),"Articles"]}),e.jsxs(Y,{value:"seo",className:"gap-1",children:[e.jsx(De,{className:"h-3.5 w-3.5"}),"SEO Manager"]}),e.jsxs(Y,{value:"bot",className:"gap-1",children:[e.jsx(Ge,{className:"h-3.5 w-3.5"}),"GEO Bot"]}),e.jsxs(Y,{value:"schedule",className:"gap-1",children:[e.jsx(Ee,{className:"h-3.5 w-3.5"}),"Schedule"]})]}),e.jsx(Z,{value:"articles",className:"mt-4",children:e.jsx(Ae,{})}),e.jsx(Z,{value:"seo",className:"mt-4",children:e.jsx(Oe,{})}),e.jsx(Z,{value:"bot",className:"mt-4",children:e.jsx(Re,{})}),e.jsx(Z,{value:"schedule",className:"mt-4",children:e.jsx(Le,{})})]})]})}export{Me 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.