1import{r as l,j as e,I as b,L as _,C as B,aq as m,s as x}from"./index-PvriC7IB.js";import{A as H}from"./AdminLayout--iuuX7h1.js";import{B as j}from"./badge-Di2v8qh6.js";import{T as z}from"./textarea-CrOzCqRr.js";import{S as U,d as F,M as G}from"./AppRoutes-_SQgw96o.js";import{R as K}from"./refresh-cw-DnWtp8PJ.js";import{C as V}from"./circle-play-Bjb-3-35.js";import{C as X}from"./calendar-days-BW_BKwsl.js";import{S as Z}from"./shield-alert-Clnfn8ZY.js";import{H as J}from"./hash-DFC28CGS.js";import{L as Q}from"./linkedin-nIqsQo0g.js";const v={x:J,linkedin:Q,reddit:G},w={x:"X",linkedin:"LinkedIn",reddit:"Reddit"},Y={x:"Short-form posts, threads, launches, and rate-limited hooks.",linkedin:"Professional thought leadership, product proof, and founder updates.",reddit:"Community-safe posts, subreddit-specific questions, and founder learning loops."},ee=n=>["approved","scheduled","published"].includes(n)?"secondary":n==="needs_approval"?"outline":"destructive",se=n=>n==="published"?"border-accent/40 bg-accent/15 text-accent-foreground":n==="scheduled"?"border-primary/35 bg-primary/10 text-primary":n==="approved"?"border-secondary bg-secondary/60 text-secondary-foreground":n==="needs_approval"?"border-border bg-background text-muted-foreground":"border-destructive/30 bg-destructive/10 text-destructive",re=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],A=n=>{const o=new Date(n),h=(o.getDay()+6)%7;return o.setDate(o.getDate()-h),o.setHours(0,0,0,0),o},N=n=>n.toISOString().slice(0,10),u=n=>new Date(n.scheduled_at||n.created_at||Date.now()),xe=()=>{const[n,o]=l.useState([]),[h,y]=l.useState(!0),[L,k]=l.useState(null),[p,S]=l.useState(!1),M=async r=>{const{data:{session:t}}=await x.auth.getSession(),{data:s,error:a}=await x.functions.invoke("cmo-agent",{body:r,headers:t!=null&&t.access_token?{Authorization:`Bearer ${t.access_token}`}:void 0});if(a)throw a;if(s!=null&&s.error)throw new Error(s.error);return s},P=async r=>{const{data:{session:t}}=await x.auth.getSession(),{data:s,error:a}=await x.functions.invoke("smm-agent",{body:r,headers:t!=null&&t.access_token?{Authorization:`Bearer ${t.access_token}`}:void 0});if(a)throw a;if(s!=null&&s.error)throw new Error(s.error);return s},C=async()=>{y(!0);try{const r=await M({action:"listSmmPosts"});o(r.posts||[])}catch(r){m.error("SMM calendar failed to load",{description:r instanceof Error?r.message:"Unknown error"})}finally{y(!1)}};l.useEffect(()=>{C()},[]);const T=async r=>{k(r.id);try{const t=await M({action:"updateSmmPostStatus",postId:r.id,status:r.scheduled_at?"scheduled":"approved"});o(s=>s.map(a=>a.id===r.id?t.post:a)),m.success("Post approved for SMM execution")}catch(t){m.error("Approval failed",{description:t instanceof Error?t.message:"Unknown error"})}finally{k(null)}},I=async()=>{S(!0);try{const r=await P({action:"runDuePosts"});o(r.posts||[]),m.success("SMM campaign runner completed",{description:`${r.runner.published} published · ${r.runner.queued} waiting for platform connection`})}catch(r){m.error("SMM campaign failed",{description:r instanceof Error?r.message:"Unknown error"})}finally{S(!1)}},$=l.useMemo(()=>[...n].sort((r,t)=>new Date(r.scheduled_at||r.created_at||0).getTime()-new Date(t.scheduled_at||t.created_at||0).getTime()).reduce((r,t)=>{const s=new Date(t.scheduled_at||t.created_at||Date.now()).toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"});return r[s]=[...r[s]||[],t],r},{}),[n]),R=l.useMemo(()=>{const r=[...n].sort((d,i)=>u(d).getTime()-u(i).getTime()),t=A(r[0]?u(r[0]):new Date),s=A(r.at(-1)?u(r.at(-1)):new Date),a=Math.max(1,Math.ceil((s.getTime()-t.getTime())/(7*24*60*60*1e3))+1);return Array.from({length:a},(d,i)=>{const c=new Date(t);c.setDate(t.getDate()+i*7);const g=re.map((O,q)=>{const f=new Date(c);f.setDate(c.getDate()+q);const D=N(f);return{key:D,label:O,date:f,posts:r.filter(W=>N(u(W))===D)}});return{key:N(c),weekStart:c,days:g}})},[n]),E=r=>{const t=n.filter(d=>d.platform===r),s=t.some(d=>{var i;return d.error_message||((i=d.metadata)==null?void 0:i.connection_required)}),a=t.some(d=>["approved","scheduled","published"].includes(d.status));return s?"Connection required":a?"Ready when connected":"Awaiting approved posts"};return e.jsx(H,{children:e.jsxs("div",{className:"mx-auto max-w-7xl space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs(j,{variant:"secondary",className:"mb-3 gap-1.5",children:[e.jsx(U,{className:"h-3.5 w-3.5"})," cvZen SMM workflow"]}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"SMM Agent"}),e.jsx("p",{className:"text-muted-foreground",children:"Executes the approved calendar delegated by the CMO Agent across connected social platforms."})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs(b,{type:"button",variant:"outline",onClick:C,disabled:h,className:"gap-2",children:[e.jsx(K,{className:"h-4 w-4"})," Refresh calendar"]}),e.jsxs(b,{type:"button",onClick:I,disabled:p,className:"gap-2",children:[p?e.jsx(_,{className:"h-4 w-4 animate-spin"}):e.jsx(V,{className:"h-4 w-4"}),p?"Runningâ¦":"Run social media campaign"]})]})]}),e.jsx("section",{className:"grid gap-4 md:grid-cols-3",children:["linkedin","x","reddit"].map(r=>{const t=v[r],s=E(r);return e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5 shadow-card",children:[e.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t,{className:"h-5 w-5 text-primary"}),e.jsx("h2",{className:"font-semibold",children:w[r]})]}),e.jsx(j,{variant:s==="Connection required"?"destructive":"outline",children:s})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:Y[r]})]},r)})}),e.jsxs("section",{className:"rounded-xl border border-border bg-card p-5 shadow-card",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4 text-primary"}),e.jsx("h2",{className:"font-semibold",children:"CMO-approved calendar schedule"})]}),h?e.jsxs("div",{className:"py-12 text-center text-muted-foreground",children:[e.jsx(_,{className:"mx-auto mb-3 h-8 w-8 animate-spin text-primary"}
1),"Loading SMM calendarâ¦"]}):n.length?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4",children:R.map((r,t)=>e.jsxs("div",{className:"rounded-lg border border-border bg-background p-3",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("h3",{className:"font-semibold",children:["Week ",t+1]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Starts ",r.weekStart.toLocaleDateString(void 0,{month:"short",day:"numeric"})]})]}),e.jsx("div",{className:"grid min-w-[860px] grid-cols-7 gap-2 overflow-x-auto md:min-w-0",children:r.days.map(s=>e.jsxs("div",{className:"min-h-40 rounded-md border border-border bg-card p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase text-muted-foreground",children:s.label}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:s.date.getDate()})]}),e.jsx("div",{className:"space-y-2",children:s.posts.length?s.posts.map(a=>{const d=v[a.platform];return e.jsxs("div",{className:`rounded-md border p-2 text-xs ${se(a.status)}`,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1 font-semibold",children:[e.jsx(d,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:w[a.platform]})]}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase",children:a.status})]}),e.jsx("p",{className:"line-clamp-2 text-[11px] leading-snug",children:a.hook||a.body}),e.jsx("p",{className:"mt-1 text-[10px] opacity-80",children:a.scheduled_at?new Date(a.scheduled_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"No time"})]},a.id)}):e.jsx("div",{className:"rounded-md border border-dashed border-border p-3 text-center text-xs text-muted-foreground",children:"No posts"})})]},s.key))})]},r.key))}),Object.entries($).map(([r,t])=>e.jsxs("div",{className:"rounded-lg border border-border bg-background p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"font-semibold",children:r})]}),e.jsx("div",{className:"grid gap-3 xl:grid-cols-2",children:t.map(s=>{var c;const a=v[s.platform],d=["approved","scheduled","published"].includes(s.status),i=`${s.body}${s.cta?` 2 3CTA: ${s.cta}`:""}${(c=s.hashtags)!=null&&c.length?` 4${s.hashtags.map(g=>`#${g.replace(/^#/,"")}`).join(" ")}`:""}`;return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(a,{className:"h-4 w-4 text-primary"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"truncate font-semibold",children:s.hook||w[s.platform]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.scheduled_at?new Date(s.scheduled_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"No scheduled time"," · ",s.audience==="job_seeker"?"Candidate":s.audience==="both"?"Candidate + Recruiter":"Recruiter"]})]})]}),e.jsx(j,{variant:ee(s.status),children:s.status})]}),s.error_message?e.jsxs("div",{className:"mb-3 flex gap-2 rounded-md border border-destructive/20 bg-destructive/10 p-2 text-sm text-destructive",children:[e.jsx(Z,{className:"mt-0.5 h-4 w-4"})," ",s.error_message]}):null,e.jsx(z,{readOnly:!0,value:i,className:"min-h-32 text-sm"}),e.jsxs(b,{type:"button",size:"sm",className:"mt-3 w-full gap-2",disabled:d||L===s.id,onClick:()=>T(s),children:[e.jsx(B,{className:"h-4 w-4"})," ",d?"Approved for SMM":"Approve for schedule"]})]},s.id)})})]},r))]}):e.jsx("div",{className:"rounded-lg border border-border bg-background p-8 text-center text-muted-foreground",children:"Generate a CMO brief first. Its approved social calendar will appear here for SMM execution."})]})]})})};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.