1import{j as e,r as C}from"./react-vendor-DuanA9jM.js";import{T as K,a as E,b as y,c as v,t as q,g as _,v as N,k as d,R as k,a5 as P,C as m,L as g,B as j,z as c,O as M,a8 as z,a9 as O,aa as H,ab as V,W as o,X as f,ad as U,aE as Y,aF as $,aG as W,s as T}from"./index-C5q0TaF9.js";import{S as F}from"./switch-TryNzk19.js";import{S as D,a as A,b as L,c as R,d as h}from"./select-Df3wbD-9.js";import{E as G}from"./external-link-CgCc-kHX.js";import"./pdf-vendor-Bjqeze7v.js";import"./ui-vendor-Bb6GvRc1.js";import"./chart-vendor-CP7R5S7C.js";import"./form-vendor-DsvdbqT8.js";import"./motion-vendor-B1Dv_HZR.js";import"./date-vendor-IjrnU_nu.js";import"./echnaPortalZIndex-DNgAjU3X.js";async function u(n,r={}){const{data:l,error:a}=await T.functions.invoke("admin-social-media-data",{body:{action:n,...r}});if(a)throw a;if(l&&l.error)throw new Error(l.error);return l}async function b(n,r){const l=n==="rss"?"curated-content-rss-fetch":n==="youtube"?"curated-content-youtube-fetch":"generate-daily-health-brief",{data:a,error:i}=await T.functions.invoke(l,{body:r?{source_id:r}:{}});if(i)throw i;return a}function X(){const n=q(),[r,l]=C.useState(!1),[a,i]=C.useState({name:"",source_type:"rss",url:"",channel_id:"",icon_url:"",fetch_frequency_hours:6,is_active:!0}),t=_({queryKey:["admin-social-sources"],queryFn:async()=>(await u("list_sources")).sources}),w=N({mutationFn:()=>u("create_source",a),onSuccess:()=>{c.success("Source added"),l(!1),i({name:"",source_type:"rss",url:"",channel_id:"",icon_url:"",fetch_frequency_hours:6,is_active:!0}),n.invalidateQueries({queryKey:["admin-social-sources"]})},onError:s=>c.error(s?.message||"Failed")}),B=N({mutationFn:({id:s,patch:x})=>u("update_source",{id:s,...x}),onSuccess:()=>n.invalidateQueries({queryKey:["admin-social-sources"]})}),I=N({mutationFn:s=>u("delete_source",{id:s}),onSuccess:()=>{c.success("Source deleted"),n.invalidateQueries({queryKey:["admin-social-sources"]})}}),Q=async()=>{c.info("Fetching all sourcesâ¦");try{const x=(await Promise.allSettled([b("rss"),b("youtube")])).filter(S=>S.status==="fulfilled").length;c.success(`Fetch complete (${x}/3 succeeded)`),n.invalidateQueries({queryKey:["admin-social-sources"]})}catch(s){c.error(s?.message||"Fetch failed")}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Content Sources"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage RSS feeds, YouTube channels, and the AI Daily Brief."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(d,{variant:"outline",onClick:Q,children:[e.jsx(k,{className:"mr-2 h-4 w-4"})," Fetch all now"]}),e.jsxs(d,{onClick:()=>l(!0),children:[e.jsx(P,{className:"mr-2 h-4 w-4"})," Add source"]})]})]}),e.jsx(m,{className:"p-0 overflow-hidden",children:t.isLoading?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(g,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"px-3 py-2 font-medium",children:"Name"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Type"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"URL / Channel"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Active"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Last fetched"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"px-3 py-2 font-medium text-right",children:"Actions"})]})}),e.jsx("tbody",{children:(t.data||[]).map(s=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:s.name}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(j,{variant:"secondary",children:s.source_type})}),e.jsx("td",{className:"px-3 py-2 max-w-[280px] truncate text-muted-foreground",children:s.channel_id||s.url||"â"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(F,{checked:!!s.is_active,onCheckedChange:x=>B.mutate({id:s.id,patch:{is_active:x}})})}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground",children:s.last_fetched_at?new Date(s.last_fetched_at).toLocaleStr
1ing():"â"}),e.jsx("td",{className:"px-3 py-2",children:s.last_error?e.jsx(j,{variant:"destructive",title:s.last_error,children:"error"}):e.jsx(j,{variant:"outline",children:"ok"})}),e.jsxs("td",{className:"px-3 py-2 text-right whitespace-nowrap",children:[e.jsx(d,{variant:"ghost",size:"sm",onClick:async()=>{c.info(`Fetching ${s.name}â¦`);const x=s.source_type==="youtube"?"youtube":s.source_type==="ai_brief"?"brief":"rss";try{await b(x,s.source_type==="ai_brief"?void 0:s.id),c.success("Fetched"),n.invalidateQueries({queryKey:["admin-social-sources"]})}catch(S){c.error(S?.message||"Failed")}},children:e.jsx(k,{className:"h-4 w-4"})}),e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>{confirm(`Delete source "${s.name}"?`)&&I.mutate(s.id)},children:e.jsx(M,{className:"h-4 w-4 text-destructive"})})]})]},s.id))})]})})}),e.jsx(z,{open:r,onOpenChange:l,children:e.jsxs(O,{children:[e.jsx(H,{children:e.jsx(V,{children:"Add content source"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(o,{children:"Name"}),e.jsx(f,{value:a.name,onChange:s=>i({...a,name:s.target.value}),placeholder:"WHO Health News"})]}),e.jsxs("div",{children:[e.jsx(o,{children:"Type"}),e.jsxs(D,{value:a.source_type,onValueChange:s=>i({...a,source_type:s}),children:[e.jsx(A,{children:e.jsx(L,{})}),e.jsxs(R,{children:[e.jsx(h,{value:"rss",children:"RSS"}),e.jsx(h,{value:"youtube",children:"YouTube"}),e.jsx(h,{value:"ai_brief",children:"AI Brief (prompt config)"})]})]})]}),a.source_type==="rss"&&e.jsxs("div",{children:[e.jsx(o,{children:"RSS URL"}),e.jsx(f,{value:a.url,onChange:s=>i({...a,url:s.target.value}),placeholder:"https://â¦/rss.xml"})]}),a.source_type==="youtube"&&e.jsxs("div",{children:[e.jsx(o,{children:"YouTube Channel ID"}),e.jsx(f,{value:a.channel_id,onChange:s=>i({...a,channel_id:s.target.value}),placeholder:"UCxxxxxxxx"})]}),a.source_type==="ai_brief"&&e.jsxs("div",{children:[e.jsx(o,{children:"System prompt (stored in url field)"}),e.jsx("textarea",{className:"w-full min-h-[120px] rounded-md border border-input bg-background px-3 py-2 text-sm",value:a.url,onChange:s=>i({...a,url:s.target.value}),placeholder:"Leave blank to use defaultâ¦"})]}),e.jsxs("div",{children:[e.jsx(o,{children:"Icon URL (optional)"}),e.jsx(f,{value:a.icon_url,onChange:s=>i({...a,icon_url:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(o,{children:"Fetch frequency (hours)"}),e.jsx(f,{type:"number",value:a.fetch_frequency_hours,onChange:s=>i({...a,fetch_frequency_hours:Number(s.target.value)})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{checked:a.is_active,onCheckedChange:s=>i({...a,is_active:s})}),e.jsx(o,{children:"Active"})]})]}),e.jsxs(U,{children:[e.jsx(d,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(d,{onClick:()=>w.mutate(),disabled:w.isPending,children:[w.isPending&&e.jsx(g,{className:"mr-2 h-4 w-4 animate-spin"}),"Add source"]})]})]})})]})}function J(){const n=q(),[r,l]=C.useState({}),a=_({queryKey:["admin-social-posts",r],queryFn:async()=>(await u("list_posts",{...r,limit:100})).posts}),i=N({mutationFn:t=>u("update_post",t),onSuccess:()=>n.invalidateQueries({queryKey:["admin-social-posts"]})});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(D,{value:r.source_type||"all",onValueChange:t=>l({...r,source_type:t==="all"?void 0:t}),children:[e.jsx(A,{className:"w-[180px]",children:e.jsx(L,{})}),e.jsxs(R,{children:[e.jsx(h,{value:"all",children:"All types"}),e.jsx(h,{value:"rss",children:"RSS articles"}),e.jsx(h,{value:"youtube",children:"YouTube videos"}),e.jsx(h,{value:"ai_brief",children:"AI briefs"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(F,{checked:r.hidden===!0,onCheckedChange:t=>l({...r,hidden:t?!0:void 0})}),e.jsx("span",{className:"text-muted-foreground",children:"Hidden only"})]})]}),e.jsx(m,{className:"p-0 overflow-hidden",children:a.isLoading?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(g,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"px-3 py-2 font-medium",children:"Title"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Source"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Published"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"px-3 py-2 font-medium text-right",children:"Actions"})]})}),e.jsx("tbody",{children:(a.data||[]).map(t=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsxs("td",{className:"px-3 py-2 max-w-[420px]",children:[e.jsx("div",{className:"font-medium truncate",children:t.title}),t.summary&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:t.summary})]}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx(j,{variant:"secondary",children:t.source_type}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:t.source_name})]}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground",children:new Date(t.published_at).toLocaleDateString()}),e.jsxs("td",{className:"px-3 py-2",children:[t.is_hidden&&e.jsx(j,{variant:"destructive",className:"mr-1",children:"hidden"}),t.is_featured&&e.jsx(j,{className:"bg-amber-500/20 text-amber-700 dark:text-amber-400",children:"featured"})]}),e.jsxs("td",{className:"px-3 py-2 text-right whitespace-nowrap",children:[e.jsx(d,{variant:"ghost",size:"sm",title:t.is_featured?"Unfeature":"Feature",onClick:()=>i.mutate({id:t.id,is_featured:!t.is_featured}),children:e.jsx(Y,{className:`h-4 w-4 ${t.is_featured?"fill-amber-500 text-amber-500":""}`})}),e.jsx(d,{variant:"ghost",size:"sm",title:t.is_hidden?"Show":"Hide",onClick:()=>i.mutate({id:t.id,is_hidden:!t.is_hidden}),children:t.is_hidden?e.jsx($,{className:"h-4 w-4"}):e.jsx(W,{className:"h-4 w-4"})}),t.permalink_url&&e.jsx(d,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx("a",{href:t.permalink_url,target:"_blank",rel:"noopener noreferrer",children:e.jsx(G,{className:"h-4 w-4"})})})]})]},t.id))})]})})})]})}function Z(){const n=q(),r=_({queryKey:["admin-social-briefs"],queryFn:async()=>(await u("list_posts",{source_type:"ai_brief",limit:30})).posts}),l=async()=>{c.info("Regenerating briefâ¦");try{const i=await b("brief");i?.ok===!1?c.error(i.reason||i.error||"Failed"):c.success("Brief generated"),n.invalidateQueries({queryKey:["admin-social-briefs"]})}catch(i){c.error(i?.message||"Failed")}},a=r.data?.[0];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"VHT Daily Brief"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"AI-generated daily summary of curated content."})]}),e.jsxs(d,{onClick:l,disabled:!0,title:"Disabled â pending refinement",children:[e.jsx(k,{className:"mr-2 h-4 w-4"})," Regenerate now"]})]}),e.jsxs(m,{className:"p-3 border-dashed bg-muted/30 text-sm text-muted-foreground",children:["AI Daily Brief is currently ",e.jsx("span",{className:"font-semibold text-foreground",children:"disabled"})," pending prompt refinement. No scheduled or manual generation will run. Existing briefs below are read-only."]}),a&&e.jsxs(m,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:new Date(a.published_at).toLocaleStr
1ing()}),e.jsx("h3",{className:"font-semibold mb-2",children:a.title}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-sans",children:a.body_html})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-2 text-muted-foreground",children:"Recent briefs"}),e.jsx(m,{className:"divide-y divide-border",children:(r.data||[]).map(i=>e.jsxs("div",{className:"px-3 py-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground mr-2",children:new Date(i.published_at).toLocaleDateString()}),i.title]},i.id))})]})]})}function ee(){const n=_({queryKey:["admin-social-analytics"],queryFn:async()=>await u("analytics")});if(n.isLoading)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(g,{className:"h-6 w-6 animate-spin text-muted-foreground"})});const r=n.data||{};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsx(p,{label:"Sources",value:r.totalSources}),e.jsx(p,{label:"Posts cached",value:r.totalPosts}),e.jsx(p,{label:"Views (lifetime)",value:r.views}),e.jsx(p,{label:"Saves",value:r.saves}
1),e.jsx(p,{label:"Invites (7d)",value:r.inviteTotal})]}),e.jsxs(m,{className:"p-4",children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Recent posts (last 7 days)"}),e.jsx("ul",{className:"text-sm divide-y divide-border",children:(r.topPosts||[]).map(l=>e.jsxs("li",{className:"py-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:new Date(l.published_at).toLocaleDateString()}),e.jsx("span",{className:"truncate",children:l.title}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:l.source_name})]},l.id))})]}),e.jsxs(m,{className:"p-4",children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Invites by channel (7 days)"}),e.jsxs("ul",{className:"text-sm",children:[Object.entries(r.inviteByChannel||{}).map(([l,a])=>e.jsxs("li",{className:"flex justify-between py-1",children:[e.jsx("span",{className:"capitalize",children:l.replace("_"," ")}),e.jsx("span",{className:"font-semibold",children:a})]},l)),Object.keys(r.inviteByChannel||{}).length===0&&e.jsx("li",{className:"text-muted-foreground",children:"No invites yet."})]})]})]})}function p({label:n,value:r}){return e.jsxs(m,{className:"p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:n}),e.jsx("div",{className:"text-2xl font-semibold",children:r??"â"})]})}function xe(){return e.jsxs("div",{className:"container mx-auto p-3 md:p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-xl md:text-3xl font-bold",children:"Social Media Control Center"}),e.jsx("p",{className:"text-sm md:text-base text-muted-foreground",children:"Manage curated RSS feeds, YouTube channels, AI Daily Briefs, and invite analytics."})]}),e.jsxs(K,{defaultValue:"sources",children:[e.jsxs(E,{children:[e.jsx(y,{value:"sources",children:"Sources"}),e.jsx(y,{value:"posts",children:"Posts"}),e.jsx(y,{value:"brief",children:"AI Brief"}),e.jsx(y,{value:"analytics",children:"Analytics"})]}),e.jsx(v,{value:"sources",className:"mt-4",children:e.jsx(X,{})}),e.jsx(v,{value:"posts",className:"mt-4",children:e.jsx(J,{})}),e.jsx(v,{value:"brief",className:"mt-4",children:e.jsx(Z,{})}),e.jsx(v,{value:"analytics",className:"mt-4",children:e.jsx(ee,{})})]})]})}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.