1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Dq2zLArw.js","assets/query-_koPiPsI.js","assets/react-vendor-h1rQ_Bae.js","assets/ui-radix-CKwvnS8F.js","assets/supabase-DL6nu9mS.js","assets/charts-Xu79y1bN.js","assets/motion-nVmI7L5T.js","assets/index-DKBqfRLs.css"])))=>i.map(i=>d[i]); 2import{d as ht}from"./supabase-DL6nu9mS.js";import{b as Fe,u as Ne,j as e}from"./query-_koPiPsI.js";import{f as Ke,h as mt,r as g}from"./react-vendor-h1rQ_Bae.js";import{c as Oe,f as pt,s as b,ak as ft,b3 as Be,C as O,B as p,S as pe,L as te,ah as se,X as Le,k as S,T as xt,a as gt,b as Z,d as ee,g as u,m as bt,l as vt,M as wt,z as xe,V as Ue,w as jt,N as Ie,E as yt}from"./index-Dq2zLArw.js";import{L as _t,D as Nt,a as At,b as kt,d as It,e as qt,c as Ae,C as St}from"./dropdown-menu-BvquEsnV.js";import{S as Ct,a as Tt,b as zt,c as $t,d as H}from"./select-S0HS5dUY.js";import{C as Dt,a as Rt,b as Pt}from"./collapsible-BqfEIKWx.js";import{S as Me}from"./SchedulePostDialog-C-xwY00d.js";import{F as Et,P as Qt}from"./PublishedEditConfirmDialog-D-G19WOA.js";import{W as Lt}from"./wand-sparkles-DjjB0AGR.js";import{T as ge}from"./trash-2-DwNrObEE.js";import{E as Mt}from"./ellipsis-B1RSoOWp.js";import{A as Ft}from"./at-sign-tnMzNgxu.js";import{Q as Kt}from"./quote-Cc7kmDa5.js";import{P as Ve}from"./pencil-Bx-7KBdi.js";import{C as Ot}from"./chevron-right-N8QrdNsP.js";import{C as Bt}from"./copy-BJMOZJfL.js";import{f as qe}from"./format-Bq4KMpNp.js";import"./ui-radix-CKwvnS8F.js";import"./charts-Xu79y1bN.js";import"./motion-nVmI7L5T.js";import"./circle-CflMNCk5.js";import"./chevron-up-Dbq7Df3-.js";import"./notifyError-B5A7t736.js";import"./image-B61r9cSd.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const Ut=Oe("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/** 8 * @license lucide-react v0.462.0 - ISC 9 * 10 * This source code is licensed under the ISC license. 11 * See the LICENSE file in the root directory of this source tree. 12 */const X=Oe("Archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]),K={all:"All platforms",linkedin:"LinkedIn",twitter:"X",threads:"Threads",newsletter:"Newsletter",quote:"Pull quotes"};function Ge(m){const o={};for(const v of m)o[v.platform]=(o[v.platform]||0)+1;return o}function Se({items:m,compact:o=!1}){const v=Ge(m),_=["linkedin","twitter","threads","newsletter","quote"].filter(h=>(v[h]||0)>0);return _.length===0?null:e.jsx("span",{className:"inline-flex items-center gap-1.5 flex-wrap",children:_.map(h=>{const w=He[h],C=w.icon;return e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-md border border-border bg-background/60 ${o?"px-1.5 py-0.5 text-[10px]":"px-2 py-0.5 text-xs"} text-muted-foreground`,title:`${v[h]} ${w.label}`,children:[e.jsx(C,{className:`h-3 w-3 ${w.tone}`}),e.jsx("span",{className:"tabular-nums font-medium text-foreground/80",children:v[h]})]},h)})})}const He={linkedin:{label:"LinkedIn",icon:bt,tone:"text-[#0A66C2]"},twitter:{label:"X",icon:vt,tone:"text-foreground"},threads:{label:"Threads",icon:Ft,tone:"text-foreground"},quote:{label:"Pull quote",icon:Kt,tone:"text-muted-foreground"},newsletter:{label:"Newsletter",icon:wt,tone:"text-foreground"}};function Xe({p:m}){const o=He[m],v=o.icon;return e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(v,{className:`h-3.5 w-3.5 ${o.tone}`}),o.label]})}function vs(){const{user:m}=pt(),o=Ke(),[v,P]=mt(),_=v.get("recent"),h=Fe(),[w,C]=g.useState("ready"),[f,F]=g.useState("all"),[T,J]=g.useState(()=>{if(typeof window>"u")return!1;try{return localStorage.getItem("distribute_group_by_article")==="1"}catch{return!1}});g.useEffect(()=>{try{localStorage.setItem("distribute_group_by_article",T?"1":"0")}catch{}},[T]);const[E,$]=g.useState(!!_),[N,B]=g.useState(new Set),[q,a]=g.useState(null),[A,Q]=g.useState(null);g.useState(!1);const[z,be]=g.useState([]),[Je,ae]=g.useState(0);g.useEffect(()=>{let t=()=>{};return ht(async()=>{const{subscribePublishSuccess:r}=await import("./index-Dq2zLArw.js").then(i=>i.bl);return{subscribePublishSuccess:r}},__vite__mapDeps([0,1,2,3,4,5,6,7])).then(({subscribePublishSuccess:r})=>{t=r(()=>{h.invalidateQueries({queryKey:["active-schedules"]}),h.invalidateQueries({queryKey:["distribute"]}),h.invalidateQueries({queryKey:["linkedin-variations"]}),h.invalidateQueries({queryKey:["twitter-variations"]}),h.invalidateQueries({queryKey:["threads-drafts"]})})}),()=>t()},[h]);const[Ce,We]=g.useState(!1),[re,Te]=g.useState(null);g.useState(null),g.useState(""),g.useState(!1);const[L,ve]=g.useState(null),[M,W]=g.useState({running:!1,done:0,total:0});g.useEffect(()=>{_&&(C("ready"),$(!0))},[_]);const Ye=()=>{$(!1),v.has("recent")&&(v.delete("recent"),v.delete("t"),P(v,{replace:!0}))},{data:I,isLoading:ie}=Ne({queryKey:["distribute-inbox",m?.id],enabled:!!m,queryFn:async()=>{const t=m.id,[r,i,l,d,n,c,k]=await Promise.all([b.from("linkedin_post_variations").select("id, post_id, content, status, created_at, published_at, linkedin_post_url, source, archived_at, fidelity_score, fabricated_claims").eq("user_id",t).order("created_at",{ascending:!1}).limit(200),b.from("twitter_threads").select("id, post_id, content, status, created_at, published_at, twitter_post_url, source, archived_at, fidelity_score, fabricated_claims").eq("user_id",t).order("created_at",{ascending:!1}).limit(200),b.from("threads_drafts").select("id, post_id, content, status, created_at, published_at, threads_post_url, source, archived_at, fidelity_score, fabricated_claims").eq("user_id",t).order("created_at",{ascending:!1}).limit(200),b.from("pull_quotes").select("id, post_id, quote_text, used_in, created_at").eq("user_id",t).order("created_at",{ascending:!1}).limit(200),b.from("newsletter_templates").select("id, post_id, name, subject, content, source, created_at, category, fidelity_score, fabricated_claims").eq("user_id",t).eq("source","atomized").order("created_at",{ascending:!1}).limit(200),b.from("posts").select("id, title, slug").eq("author_id",t),b.from("scheduled_posts").select("id, post_id, standalone_post_id, platform, content, published_at, platform_post_url, variation_id").eq("user_id",t).eq("status","published").in("platform",["linkedin","twitter","threads"]).order("published_at",{ascending:!1}).limit(200)]),y=new Map;
12(c.data||[]).forEach(s=>y.set(s.id,{title:s.title,slug:s.slug}));const R=[];(r.data||[]).forEach(s=>{const x=s.post_id?y.get(s.post_id):null;R.push({id:`li-${s.id}`,rawId:s.id,postId:s.post_id,platform:"linkedin",preview:s.content,articleTitle:x?.title||"Standalone post",articleSlug:x?.slug||null,createdAt:s.created_at,publishedAt:s.published_at,externalUrl:s.linkedin_post_url,variationTable:"linkedin_post_variations",source:s.source,archivedAt:s.archived_at,fidelityScore:s.fidelity_score??null,fabricatedClaims:Array.isArray(s.fabricated_claims)?s.fabricated_claims:null})}),(i.data||[]).forEach(s=>{const x=s.post_id?y.get(s.post_id):null;R.push({id:`tw-${s.id}`,rawId:s.id,postId:s.post_id,platform:"twitter",preview:s.content,articleTitle:x?.title||"Standalone thread",articleSlug:x?.slug||null,createdAt:s.created_at,publishedAt:s.published_at,externalUrl:s.twitter_post_url,variationTable:"twitter_threads",source:s.source,archivedAt:s.archived_at,fidelityScore:s.fidelity_score??null,fabricatedClaims:Array.isArray(s.fabricated_claims)?s.fabricated_claims:null})}),(l.data||[]).forEach(s=>{const x=s.post_id?y.get(s.post_id):null;R.push({id:`th-${s.id}`,rawId:s.id,postId:s.post_id,platform:"threads",preview:s.content,articleTitle:x?.title||"Standalone post",articleSlug:x?.slug||null,createdAt:s.created_at,publishedAt:s.published_at,externalUrl:s.threads_post_url,variationTable:"threads_drafts",source:s.source,archivedAt:s.archived_at,fidelityScore:s.fidelity_score??null,fabricatedClaims:Array.isArray(s.fabricated_claims)?s.fabricated_claims:null})}),(n.data||[]).forEach(s=>{R.push({id:`nl-${s.id}`,rawId:s.id,postId:s.post_id??null,platform:"newsletter",preview:s.content,subject:s.subject,articleTitle:s.name||"Newsletter draft",articleSlug:null,createdAt:s.created_at,publishedAt:null,variationTable:"newsletter_templates",source:s.source||"atomized",fidelityScore:s.fidelity_score??null,fabricatedClaims:Array.isArray(s.fabricated_claims)?s.fabricated_claims:null})}),(d.data||[]).forEach(s=>{const x=s.post_id?y.get(s.post_id):null,G=Array.isArray(s.used_in)&&s.used_in.length>0;R.push({id:`pq-${s.id}`,rawId:s.id,postId:s.post_id,platform:"quote",preview:s.quote_text,articleTitle:x?.title||"Article quote",articleSlug:x?.slug||null,createdAt:s.created_at,publishedAt:G?s.created_at:null,variationTable:"pull_quotes",source:"atomized"})});const me=new Set([...(r.data||[]).map(s=>s.id),...(i.data||[]).map(s=>s.id),...(l.data||[]).map(s=>s.id)]);return(k.data||[]).forEach(s=>{if(s.variation_id&&me.has(s.variation_id))return;const x=s.platform,G=s.post_id?y.get(s.post_id):null,ct=x==="linkedin"?"li":x==="twitter"?"tw":"th",ut=x==="linkedin"?"linkedin_post_variations":x==="twitter"?"twitter_threads":"threads_drafts";R.push({id:`sp-${ct}-${s.id}`,rawId:s.id,postId:s.post_id,platform:x,preview:s.content||"",articleTitle:G?.title||"Standalone post",articleSlug:G?.slug||null,createdAt:s.published_at,publishedAt:s.published_at,externalUrl:s.platform_post_url,variationTable:ut,source:"scheduled"})}),{items:R,reach:{impressions:0,reactions:0},posts:c.data||[]}},staleTime:3e4}),{data:le,isLoading:Ze}=Ne({queryKey:["distribute-scheduled",m?.id],enabled:!!m,queryFn:async()=>{const t=m.id,{data:r,error:i}=await b.from("scheduled_posts").select("id, post_id, platform, scheduled_for, content, status, variation_id, variation_table").eq("user_id",t).in("status",["pending","queued","scheduled"]).order("scheduled_for",{ascending:!0}).limit(200);if(i)throw i;if(!r||r.length===0)return[];const l=Array.from(new Set(r.map(n=>n.post_id).filter(Boolean)));let d={};if(l.length>0){const{data:n}=await b.from("posts").select("id, title").in("id",l);(n||[]).forEach(c=>d[c.id]=c.title)}return r.map(n=>({id:n.id,postId:n.post_id,platform:n.platform||"linkedin",scheduledFor:n.scheduled_for,content:n.content||"",articleTitle:d[n.post_id]||"Standalone post",status:n.status,variationId:n.variation_id||null,variationTable:n.variation_table||null}))},staleTime:3e4}),{data:we}=Ne({queryKey:["distribute-failed",m?.id],enabled:!!m,queryFn:async()=>{const{count:t}=await b.from("scheduled_posts").select("id",{count:"exact",head:!0}).eq("user_id",m.id).eq("status","failed");return t||0},staleTime:3e4}),D=g.useMemo(()=>
12{if(!I)return[];const t=new Set(I.items.filter(r=>r.platform!=="quote"&&r.postId).map(r=>r.postId));return I.posts.filter(r=>!t.has(r.id)).map(r=>({postId:r.id,title:r.title,publishedAt:r.created_at||""}))},[I]),Y=g.useMemo(()=>{if(!I)return[];const t=new Map;for(const i of I.items){if(!i.postId||i.platform==="quote"||i.publishedAt||i.archivedAt)continue;const l=t.get(i.postId);l?l.items.push(i):t.set(i.postId,{title:i.articleTitle,items:[i]})}const r=[];for(const[i,{title:l,items:d}]of t.entries()){const n=Ge(d);(!n.linkedin||!n.twitter||!n.threads)&&r.push({postId:i,title:l,matrix:n})}return r},[I]),{data:ze}=ft(),j=g.useMemo(()=>{const t=I?.items||[],r=l=>!!(l.variationTable&&l.rawId&&ze?.has(`${l.variationTable}:${l.rawId}`)),i=t.filter(l=>!l.archivedAt);return{ready:i.filter(l=>!l.publishedAt&&l.platform!=="quote"&&!r(l)),published:i.filter(l=>!!l.publishedAt&&l.platform!=="quote"),quotes:i.filter(l=>l.platform==="quote"&&!l.publishedAt),archived:t.filter(l=>!!l.archivedAt)}},[I,ze]),je={ready:j.ready.length,scheduled:le?.length||0,published7d:j.published.filter(t=>t.publishedAt&&new Date(t.publishedAt).getTime()>Date.now()-7*24*60*60*1e3).length};I?.reach;const $e=w==="published"?j.published:w==="quotes"?j.quotes:w==="archive"?j.archived:j.ready,et=10*60*1e3,ye=t=>t.source!=="atomized"?!1:!!(t.postId===_||t.platform==="newsletter"&&!t.postId&&t.createdAt&&Date.now()-new Date(t.createdAt).getTime()<et),De=_?j.ready.filter(ye).length:0,Re=_?j.ready.filter(ye):[];let U=E&&_&&w==="ready"?$e.filter(ye):$e;f!=="all"&&(U=U.filter(t=>t.platform===f));const Pe=g.useMemo(()=>{const t=Date.now()-2592e6;return j.ready.filter(r=>r.variationTable&&r.platform!=="newsletter"&&r.platform!=="quote"&&r.createdAt&&new Date(r.createdAt).getTime()<t).length},[j.ready]),ne=t=>{B(r=>{const i=new Set(r);return i.has(t)?i.delete(t):i.add(t),i})},V=()=>B(new Set),de=async t=>{if(!t.variationTable&&t.platform!=="quote"||!confirm("Delete this draft?"))return;const r=t.platform==="quote"?"pull_quotes":t.variationTable;let i=b.from(r).delete().eq("id",t.rawId);m?.id&&(i=i.eq("user_id",m.id));const{data:l,error:d}=await i.select("id");if(d){console.error("[distribute] delete error",{table:r,id:t.rawId,error:d}),u.error("Couldn't delete draft",{description:d.message});return}if(!l||l.length===0){console.warn("[distribute] delete returned 0 rows",{table:r,id:t.rawId}),u.error("Couldn't delete draft",{description:"Row not found or blocked by permissions. Refresh and try again."});return}u.success("Draft removed"),h.invalidateQueries({queryKey:["distribute-inbox"]})},oe=["linkedin_post_variations","twitter_threads","threads_drafts"],ce=async t=>{if(!t.variationTable||!oe.includes(t.variationTable)){u.info("Archive isn't supported for this draft type â use Delete");return}const{error:r}=await b.from(t.variationTable).update({archived_at:new Date().toISOString()}).eq("id",t.rawId);if(r){u.error("Couldn't archive");return}u.success("Archived",{description:"Find it under the Archive tab to restore."}),h.invalidateQueries({queryKey:["distribute-inbox"]})},tt=async t=>{if(!t.variationTable||!oe.includes(t.variationTable))return;const{error:r}=await b.from(t.variationTable).update({archived_at:null}).eq("id",t.rawId);if(r){u.error("Couldn't restore");return}u.success("Restored to Ready"),h.invalidateQueries({queryKey:["distribute-inbox"]})},st=async()=>{if(N.size===0)return;const t=(I?.items||[]).filter(d=>N.has(d.id)&&d.variationTable&&oe.includes(d.variationTable)&&!d.archivedAt);if(t.length===0){u.info("Select social drafts (LI / X / Threads) to archive.");return}if(!confirm(`Archive ${t.length} draft(s)? You can restore them from the Archive tab.`))return;const r={};t.forEach(d=>{var n;(r[n=d.variationTable]||(r[n]=[])).push(d.rawId)});let i=0;const l=new Date().toISOString();for(const[d,n]of Object.entries(r)){const{error:c}=await b.from(d).update({archived_at:l}).in("id",n);c||(i+=n.length)}u.success(`Archived ${i} draft${i===1?"":"s"}`),V(),h.invalidateQueries({queryKey:["distribute-inbox"]})},_e=async t=>{const r=Date.now()-t*24*60*60*1e3,i=j.ready.filter(c=>c.variationTable&&oe.includes(c.variationTable)&&c.createdAt&&new Date(c.createdAt).getTime()<r);if(i.length===0){u.info(`No Ready drafts older than ${t} days.`);return}if(!confirm(`Archive ${i.length} Ready draft${i.length===1?"":"s"} older than ${t} days? 13 14They'll move to the Archive tab where you can restore or delete them.`))return;const l={};
14i.forEach(c=>{var k;(l[k=c.variationTable]||(l[k]=[])).push(c.rawId)});let d=0;const n=new Date().toISOString();for(const[c,k]of Object.entries(l)){const{error:y}=await b.from(c).update({archived_at:n}).in("id",k);y||(d+=k.length)}u.success(`Archived ${d} stale draft${d===1?"":"s"}`),h.invalidateQueries({queryKey:["distribute-inbox"]})},at=async()=>{if(N.size===0||!confirm(`Delete ${N.size} draft(s)?`))return;const t=(I?.items||[]).filter(d=>N.has(d.id));let r=0,i=0;const l=[];for(const d of t){const n=d.platform==="quote"?"pull_quotes":d.variationTable;if(!n){i++;continue}let c=b.from(n).delete().eq("id",d.rawId);m?.id&&(c=c.eq("user_id",m.id));const{data:k,error:y}=await c.select("id");y?(i++,l.push(y.message),console.error("[distribute] bulk delete error",{table:n,id:d.rawId,error:y})):!k||k.length===0?i++:r++}r>0&&u.success(`Removed ${r} draft(s)`),i>0&&u.error(`${i} draft(s) couldn't be deleted`,{description:l[0]||"Refresh and try again."}),V(),h.invalidateQueries({queryKey:["distribute-inbox"]})},rt=async()=>{const t=(I?.items||[]).filter(r=>N.has(r.id)&&r.platform!=="quote"&&r.postId);if(t.length===0){u.error("Pick at least one draft tied to an article to schedule.");return}be(t),ae(0),a(t[0])},it=()=>{const t=Je+1;if(z.length>0&&t<z.length)ae(t),setTimeout(()=>a(z[t]),150),u.success(`Scheduled ${t} of ${z.length}`);else{const r=z.length||1;be([]),ae(0),a(null),V(),u.success(`Scheduled ${r} post${r===1?"":"s"}`)}},lt=async()=>{if(N.size===0)return;const t=(I?.items||[]).filter(c=>N.has(c.id)&&c.postId),r=Array.from(new Set(t.map(c=>c.postId).filter(Boolean)));if(r.length===0){u.error("Select drafts tied to a published article.");return}if(!confirm(`Run AI-Ready upgrade on ${r.length} article(s)? You'll get a toast when done.`))return;W({running:!0,done:0,total:r.length});const{data:i}=await b.from("posts").select("id, title, content, meta_description, status").in("id",r),l=(i||[]).filter(c=>c.status==="published"&&c.content);if(l.length===0){W({running:!1,done:0,total:0}),u.error("None of the selected articles are published yet.");return}W({running:!0,done:0,total:l.length});let d=0,n=0;for(let c=0;c<l.length;c++){const k=l[c];try{const{data:y,error:R}=await b.functions.invoke("geo-optimize-content",{body:{title:k.title,content:k.content,metaDescription:k.meta_description||"",failingChecks:[]}});if(R||!y?.rewrittenContent)n++;else{if(await b.from("posts").update({content:y.rewrittenContent,meta_description:y.rewrittenMeta||k.meta_description,updated_at:new Date().toISOString()}).eq("id",k.id),Array.isArray(y.faqs)&&y.faqs.length>0){const{data:me}=await b.from("article_faqs").select("question").eq("post_id",k.id),Qe=new Set((me||[]).map(x=>x.question.toLowerCase().trim())),s=y.faqs.filter(x=>x?.question&&!Qe.has(x.question.toLowerCase().trim()));s.length>0&&await b.from("article_faqs").insert(s.map((x,G)=>({post_id:k.id,question:x.question,answer:x.answer,position:(me?.length||0)+G})))}d++}}catch{n++}W({running:!0,done:c+1,total:l.length})}W({running:!1,done:0,total:0}),V(),d>0?u.success("AI-Ready upgrade complete",{description:`${d} article${d===1?"":"s"} optimized${n>0?`, ${n} failed`:""}.`}):u.error("Bulk upgrade failed",{description:"Try the per-article button on the Dashboard."}),h.invalidateQueries({queryKey:["distribute-inbox"]})},ue=t=>{if(t.platform==="newsletter"){o("/newsletter"),u.info("Find your atomized newsletter under Templates");return}if(t.publishedAt&&(t.platform==="linkedin"||t.platform==="twitter"||t.platform==="threads")){ve(t);return}if(t.postId&&t.platform==="linkedin"){o(`/editor/${t.postId}?panel=linkedin&variation=${t.rawId}`);return}if(t.postId&&(t.platform==="twitter"||t.platform==="threads")){o(`/editor/${t.postId}?panel=${t.platform}&variation=${t.rawId}`);return}t.postId?o(`/editor/${t.postId}`):(u.info("Standalone drafts open in the AI Assistant"),o("/agent"))},nt=t=>{if(!t.postId){u.info("Standalone published posts can't seed a new draft yet");return}t.platform==="linkedin"?o(`/editor/${t.postId}?panel=linkedin&seed=${encodeURIComponent(t.preview||"")}`):o(`/editor/${t.postId}?panel=${t.platform}`),u.info("Drafting a new version â the published post is untouched")},he=t=>{t.postId?o(`/editor/${t.postId}?panel=linkedin&seed=${encodeURIComponent(t.preview)}`):o(`/agent?seed=${encodeURIComponent(t.preview)}`)},Ee=async t=>{Te(t);try{const{error:r}=await b.functions.invoke("atomize-content",{body:{postId:t,platforms:["linkedin","twitter","threads","quotes"]}});if(r)throw r;u.success("Atomized â drafts will appear in your inbox"),h.invalidateQueries({queryKey:["distribute-inbox"]})}catch(r){u.error(r?.message||"Atomization failed")}finally{Te(null)}},dt=async t=>{if(!confirm("Cancel this scheduled post?"))return;const{error:r}=await b.from("scheduled_posts").delete().eq("id",t);if(r){u.error("Couldn't cancel â try again");return}u.success("Scheduled post cancelled"),h.invalidateQueries({queryKey:["distribute-scheduled"]}),h.invalidateQueries({queryKey:["active-schedules"]}),h.invalidateQueries({queryKey:["scheduled-posts"]})},ot=t=>{if(!t.postId){u.info("This scheduled post has no source article");return}if((t.platform==="linkedin"||t.platform==="twitter"||t.platform==="threads")&&t.variationId){o(`/editor/${t.postId}?panel=${t.platform}&variation=${t.variationId}`);return}if(t.platform==="linkedin"||t.platform==="twitter"||t.platform==="threads"){o(`/editor/${t.postId}?panel=${t.platform}`);return}o(`/editor/${t.postId}`)};return e.jsxs("div",{className:"container mx-auto max-w-6xl px-4 md:px-6 py-8",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Be,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("h1",{className:"text-3xl font-light tracking-tight",children:"Distribution"})]}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-2xl mb-5",children:"Ship the work you already wrote. Every atomized draft, scheduled post, and pull quote â in one place."}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(ke,{label:"Ready",value:je.ready,hint:"drafts to ship"}),e.jsx(ke,{label:"Scheduled",value:je.scheduled,hint:"queued in calendar"}),e.jsx(ke,{label:"Published (7d)",value:je.published7d,hint:"posts in last 7 days"})]})]}),(we||0)>0&&e.jsxs(O,{className:"p-3 mb-4 border-destructive/40 bg-destructive/5 flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-sm",children:[e.jsx("strong",{children:we})," scheduled post",we===1?"":"s"," failed to publish."]}),e.jsx(p,{size:"sm",variant:"outline",onClick:()=>o("/schedule"),children:"Fix on calendar â"})]}),(D.length>0||Y.length>0)&&e.jsx(O,{className:"p-4 mb-6 border-dashed bg-muted/30",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(pe,{className:"h-4 w-4 text-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[D.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("h3",{className:"text-sm font-medium mb-1",children:[D.length," article",D.length===1?"":"s"," not atomized yet"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"One click turns each into 3 LinkedIn posts, 2 X threads, a Threads post, and 5 pull quotes."}),e.jsx("div",{className:"space-y-1.5",children:(Ce?D:D.slice(0,3)).map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 p-2 rounded-md bg-background border border-border",children:[e.jsx("span",{className:"text-sm truncate flex-1",children:t.title}),e.jsx(p,{size:"sm",variant:"default",onClick:()=>Ee(t.postId),disabled:re===t.postId,children:re===t.postId?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),"Atomizingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-3.5 w-3.5 mr-1.5"}),"Atomize"]})})]},t.postId))}),D.length>3&&e.jsx(p,{variant:"ghost",size:"sm",className:"mt-2 h-7 text-xs",onClick:()=>We(t=>!t),children:Ce?"Show less":`View all (${D.length})`})]}),Y.length>0&&e.jsxs("div",{className:D.length>0?"mt-4 pt-4 border-t border-border":"",children:[e.jsxs("h3",{className:"text-sm font-medium mb-1",children:[Y.length," article",Y.length===1?"":"s"," with partial coverage"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"These have some drafts but are missing a platform. Re-atomize to fill the gaps."}),e.jsx("div",{className:"space-y-1.5",children:Y.slice(0,4).map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 p-2 rounded-md bg-background border border-border",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm truncate",children:t.title}),e.jsx("div",{className:"mt-1",children:e.jsx(Se,{items:Object.entries(t.matrix).flatMap(([r,i])=>
14Array.from({length:i||0},()=>({platform:r}))),compact:!0})})]}),e.jsx(p,{size:"sm",variant:"outline",onClick:()=>Ee(t.postId),disabled:re===t.postId,children:re===t.postId?e.jsx(te,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(pe,{className:"h-3.5 w-3.5"})})]},t.postId))})]})]})]})}),N.size>0&&e.jsxs("div",{className:"sticky top-2 z-10 mb-4 flex items-center justify-between gap-3 rounded-md border border-border bg-background/95 backdrop-blur p-3 shadow-sm",children:[e.jsxs("span",{className:"text-sm",children:[e.jsx("strong",{children:N.size})," selected"]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-end",children:[e.jsxs(p,{size:"sm",variant:"default",onClick:rt,disabled:M.running,children:[e.jsx(se,{className:"h-3.5 w-3.5 mr-1.5"}),"Schedule"]}),e.jsx(p,{size:"sm",variant:"outline",onClick:lt,disabled:M.running,title:"Optimize the linked articles for AI engines (ChatGPT, Perplexity, Google AI Overviews)",children:M.running?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),M.done,"/",M.total]}):e.jsxs(e.Fragment,{children:[e.jsx(Lt,{className:"h-3.5 w-3.5 mr-1.5"}),"Make AI-Ready"]})}),e.jsxs(p,{size:"sm",variant:"ghost",onClick:st,disabled:M.running,title:"Move selected drafts to the Archive tab",children:[e.jsx(X,{className:"h-3.5 w-3.5 mr-1.5"}),"Archive"]}),e.jsxs(p,{size:"sm",variant:"destructive",onClick:at,disabled:M.running,children:[e.jsx(ge,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete (",N.size,")"]}),e.jsx(p,{size:"sm",variant:"ghost",onClick:V,disabled:M.running,children:e.jsx(Le,{className:"h-3.5 w-3.5"})})]})]}),E&&_&&w==="ready"&&e.jsxs("div",{className:"mb-4 flex items-center gap-2 flex-wrap",children:[e.jsxs(S,{variant:"default",className:"gap-1.5 py-1 pl-2.5 pr-1",children:[e.jsx(pe,{className:"h-3 w-3"}),"Just atomized · ",De," draft",De===1?"":"s",e.jsx("button",{onClick:Ye,className:"ml-1 rounded-full hover:bg-background/20 p-0.5","aria-label":"Show all drafts",children:e.jsx(Le,{className:"h-3 w-3"})})]}),Re.length>0&&e.jsx(Se,{items:Re,compact:!0}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Filtered to the drafts you just created."})]}),e.jsxs(xt,{value:w,onValueChange:t=>C(t),children:[e.jsxs(gt,{children:[e.jsxs(Z,{value:"ready",children:["Ready",j.ready.length>0&&e.jsx(S,{variant:"secondary",className:"ml-2 h-5 px-1.5 text-xs",children:j.ready.length})]}),e.jsxs(Z,{value:"scheduled",children:["Scheduled",(le?.length||0)>0&&e.jsx(S,{variant:"secondary",className:"ml-2 h-5 px-1.5 text-xs",children:le.length})]}),e.jsxs(Z,{value:"published",children:["Published",j.published.length>0&&e.jsx(S,{variant:"outline",className:"ml-2 h-5 px-1.5 text-xs",children:j.published.length})]}),e.jsxs(Z,{value:"quotes",children:["Pull quotes",j.quotes.length>0&&e.jsx(S,{variant:"outline",className:"ml-2 h-5 px-1.5 text-xs",children:j.quotes.length})]}),e.jsxs(Z,{value:"archive",children:["Archive",j.archived.length>0&&e.jsx(S,{variant:"outline",className:"ml-2 h-5 px-1.5 text-xs",children:j.archived.length})]})]}),w!=="scheduled"&&e.jsxs("div",{className:"mt-4 mb-2 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Et,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Platform"})]}),e.jsxs(Ct,{value:f,onValueChange:t=>F(t),children:[e.jsx(Tt,{className:"h-8 w-[150px] text-xs",children:e.jsx(zt,{})}),e.jsxs($t,{children:[e.jsx(H,{value:"all",children:K.all}),e.jsx(H,{value:"linkedin",children:K.linkedin}),e.jsx(H,{value:"twitter",children:K.twitter}),e.jsx(H,{value:"threads",children:K.threads}),e.jsx(H,{value:"newsletter",children:K.newsletter}),e.jsx(H,{value:"quote",children:K.quote})]})]}),(w==="ready"||w==="published")&&e.jsxs(p,{variant:T?"secondary":"ghost",size:"sm",className:"h-8 gap-1.5 text-xs",onClick:()=>J(t=>!t),title:"Group drafts by source article",children:[e.jsx(_t,{className:"h-3.5 w-3.5"}),T?"Grouped by article":"Group by article"]})]}),w==="ready"&&e.jsxs(Nt,{children:[e.jsx(At,{asChild:!0,children:e.jsxs(p,{variant:"outline",size:"sm",className:"h-8 gap-1.5 text-xs",children:[e.jsx(Mt,{className:"h-3.5 w-3.5"}),"Cleanup"]})}),e.jsxs(kt,{align:"end",className:"w-64",children:[e.jsx(It,{className:"text-xs",children:"Bulk cleanup"}),e.jsx(qt,{}),e.jsxs(Ae,{onClick:()=>_e(30),disabled:Pe===0,children:[e.jsx(X,{className:"h-3.5 w-3.5 mr-2"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm",children:"Archive Ready drafts older than 30d"}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[Pe," match"]})]})]}),e.jsxs(Ae,{onClick:()=>_e(14),children:[e.jsx(X,{className:"h-3.5 w-3.5 mr-2"}),e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:"text-sm",children:"Archive older than 14d"})})]}),e.jsxs(Ae,{onClick:()=>_e(7),children:[e.jsx(X,{className:"h-3.5 w-3.5 mr-2"}),e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:"text-sm",children:"Archive older than 7d"})})]})]})]})]}),e.jsx(ee,{value:"ready",className:"mt-4",children:e.jsx(fe,{items:U,isLoading:ie,emptyTitle:f==="all"?"Inbox zero.":`No ${K[f]} drafts.`,emptyHint:"Atomize an article above or from the Editor to fill this list.",onSchedule:t=>a(t),onEdit:ue,onDelete:de,onArchive:ce,onQuoteUse:he,selected:N,onToggle:ne,groupByArticle:T,mode:"ready"})}),e.jsx(ee,{value:"scheduled",className:"mt-6",children:e.jsx(Vt,{items:le||[],isLoading:Ze,onCancel:dt,onEdit:ot,onReschedule:t=>Q(t),onView:()=>o("/schedule")})}),e.jsx(ee,{value:"published",className:"mt-4",children:e.jsx(fe,{items:U,isLoading:ie,emptyTitle:"Nothing published yet.",emptyHint:"Once a draft goes live, it appears here for one-click reshare.",onSchedule:t=>a(t),onEdit:ue,onDelete:de,onArchive:ce,onQuoteUse:he,selected:N,onToggle:ne,groupByArticle:T,mode:"published"})}),e.jsx(ee,{value:"quotes",className:"mt-4",children:e.jsx(fe,{items:U,isLoading:ie,emptyTitle:"No pull quotes saved.",emptyHint:"Atomize an article and ThoughtForge will surface its sharpest lines here.",onSchedule:t=>a(t),onEdit:ue,onDelete:de,onArchive:ce,onQuoteUse:he,selected:N,onToggle:ne,groupByArticle:!1,mode:"quotes"})}),e.jsx(ee,{value:"archive",className:"mt-4",children:e.jsx(fe,{items:U,isLoading:ie,emptyTitle:"Archive empty.",emptyHint:"Drafts you archive land here. Restore anytime.",onSchedule:t=>a(t),onEdit:ue,onDelete:de,onArchive:ce,onRestore:tt,onQuoteUse:he,selected:N,onToggle:ne,groupByArticle:T,mode:"archive"})})]}),q&&q.postId&&(q.platform==="linkedin"||q.platform==="twitter"||q.platform==="threads")&&e.jsx(Me,{open:!!q,onOpenChange:t=>{t||(be([]),ae(0),a(null))},postId:q.postId,content:q.preview,platform:q.platform,variationId:q.rawId,variationTable:q.variationTable,onScheduled:()=>{h.invalidateQueries({queryKey:["distribute-inbox"]}),h.invalidateQueries({queryKey:["distribute-scheduled"]}),z.length>0?it():(a(null),V(),u.success("Scheduled â see the calendar in /schedule"))}}),A&&A.postId&&(A.platform==="linkedin"||A.platform==="twitter"||A.platform==="threads")&&e.jsx(Me,{open:!!A,onOpenChange:t=>{t||Q(null)},postId:A.postId,content:A.content,platform:A.platform,variationId:A.variationId||void 0,variationTable:A.variationTable||void 0,existingScheduleId:A.id,onScheduled:()=>Q(null)}),L&&(L.platform==="linkedin"||L.platform==="twitter"||L.platform==="threads")&&e.jsx(Qt,{open:!!L,onOpenChange:t=>{t||ve(null)},platform:L.platform,liveUrl:L.externalUrl,onEditAsNew:()=>{const t=L;ve(null),nt(t)}})]})}function ke({label:m,value:o,hint:v}){return e.jsxs("div",{className:"rounded-md border border-border bg-card/50 p-3",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-wider text-muted-foreground",children:m}),e.jsx("div",{className:"text-2xl font-light mt-1 leading-none",children:o}),e.jsx("div",{className:"text-[10px] text-muted-foreground mt-1.5",children:v})]})}function Vt({items:m,isLoading:o,onCancel:v,onEdit:P,onReschedule:_,onView:h}){const w=Ke(),C=Fe();return o?e.jsx("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:e.jsx(te,{className:"h-5 w-5 animate-spin"})}):m.length===0?e.jsxs(O,{className:"p-12 text-center border-dashed",children:[e.jsx(se,{className:"h-8 w-8 mx-auto text-muted-foreground mb-3"}),e.jsx("h3",{className:"text-base font-medium mb-1",children:"Nothing scheduled."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Hit Schedule on any draft above to queue it for the right moment."})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(p,{variant:"ghost",size:"sm",onClick:h,children:"Open calendar â"})}),m.map(f=>{const F=new Date(f.scheduledFor),T=F.getTime()>Date.now(),J=!!f.postId&&(f.platform==="linkedin"||f.platform==="twitter"||f.platform==="threads");return e.jsx(O,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1.5 flex-wrap",children:[e.jsx(Xe,{p:f.platform}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:f.articleTitle}),e.jsx(S,{variant:"secondary",className:"h-5 text-[10px]",children:T?`in ${xe(F)}`:"publishing now"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:qe(F,"PPp")})]}
14),e.jsx("p",{className:"text-sm text-foreground/90 line-clamp-2 whitespace-pre-wrap",children:f.content})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[J&&e.jsxs(p,{variant:"ghost",size:"sm",onClick:()=>P(f),children:[e.jsx(Ve,{className:"h-3.5 w-3.5 mr-1.5"}),"Edit"]}),e.jsxs(p,{variant:"default",size:"sm",onClick:async()=>{if(!confirm(`Publish this ${f.platform} post now?`))return;const{data:E,error:$}=await b.functions.invoke("publish-scheduled-now",{body:{scheduledPostId:f.id}});if($||E?.success===!1){u.error("Couldn't publish now",{description:E?.error||$?.message});return}u.success("Publishing now â refreshing in a few seconds"),setTimeout(()=>{C.invalidateQueries({queryKey:["distribute-scheduled"]}),C.invalidateQueries({queryKey:["distribute-inbox"]}),C.invalidateQueries({queryKey:["active-schedules"]})},4e3)},children:[e.jsx(Ue,{className:"h-3.5 w-3.5 mr-1.5"}),"Publish now"]}),f.postId&&e.jsxs(p,{variant:"ghost",size:"sm",onClick:()=>w(`/schedule?postId=${f.postId}`),title:"See this post in the master calendar",children:[e.jsx(se,{className:"h-3.5 w-3.5 mr-1.5"}),"View in calendar"]}),e.jsxs(p,{variant:"ghost",size:"sm",onClick:()=>_(f),children:[e.jsx(se,{className:"h-3.5 w-3.5 mr-1.5"}),"Reschedule"]}),e.jsxs(p,{variant:"ghost",size:"sm",onClick:()=>v(f.id),className:"text-muted-foreground hover:text-destructive",children:[e.jsx(ge,{className:"h-3.5 w-3.5 mr-1.5"}),"Cancel"]})]})]})},f.id)})]})}function fe({items:m,isLoading:o,emptyTitle:v,emptyHint:P,onSchedule:_,onEdit:h,onDelete:w,onArchive:C,onRestore:f,onQuoteUse:F,selected:T,onToggle:J,groupByArticle:E=!1,mode:$="ready"}){if(o)return e.jsx("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:e.jsx(te,{className:"h-5 w-5 animate-spin"})});if(m.length===0)return e.jsxs(O,{className:"p-12 text-center border-dashed",children:[e.jsx(Be,{className:"h-8 w-8 mx-auto text-muted-foreground mb-3"}),e.jsx("h3",{className:"text-base font-medium mb-1",children:v}),e.jsx("p",{className:"text-sm text-muted-foreground",children:P})]});const N=a=>
14e.jsx(O,{className:"p-4 hover:border-foreground/20 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(St,{checked:T.has(a.id),onCheckedChange:()=>J(a.id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1.5 flex-wrap",children:[e.jsx(Xe,{p:a.platform}),!E&&e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:a.articleTitle}),a.publishedAt&&e.jsxs(S,{variant:"outline",className:"h-5 text-[10px] gap-1",children:[e.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-foreground"}),"Live"]}),a.archivedAt&&e.jsxs(S,{variant:"outline",className:"h-5 text-[10px] gap-1 text-muted-foreground",children:[e.jsx(X,{className:"h-3 w-3"}),"Archived"]}),a.fabricatedClaims&&a.fabricatedClaims.length>0&&e.jsxs(S,{variant:"outline",className:"h-5 text-[10px] gap-1 border-amber-500/40 text-amber-600 dark:text-amber-400 bg-amber-500/5",title:`Fact-checker flagged ${a.fabricatedClaims.length} claim(s) not found in your article: 15 16⢠${a.fabricatedClaims.join(` 17⢠`)} 18 19Review before publishing.`,children:["â Review ",a.fabricatedClaims.length," claim",a.fabricatedClaims.length>1?"s":""]}),typeof a.fidelityScore=="number"&&a.fidelityScore>=9&&(!a.fabricatedClaims||a.fabricatedClaims.length===0)&&e.jsx(S,{variant:"outline",className:"h-5 text-[10px] gap-1 border-emerald-500/40 text-emerald-600 dark:text-emerald-400 bg-emerald-500/5",title:`Fidelity score ${a.fidelityScore}/10 â every concrete claim is grounded in your article.`,children:"â Fact-checked"}),a.publishedAt&&(()=>{try{return e.jsxs("span",{className:"text-[10px] text-muted-foreground inline-flex items-center gap-1",title:qe(new Date(a.publishedAt),"PPpp"),children:[e.jsx(Ie,{className:"h-3 w-3"}),"Published ",xe(new Date(a.publishedAt),{addSuffix:!0})]})}catch{return null}})(),!a.publishedAt&&a.createdAt&&(()=>{try{return e.jsxs("span",{className:"text-[10px] text-muted-foreground inline-flex items-center gap-1",title:`Generated ${qe(new Date(a.createdAt),"PPpp")}`,children:[e.jsx(Ie,{className:"h-3 w-3"}),"Generated ",xe(new Date(a.createdAt),{addSuffix:!0})]})}catch{return null}})(),!a.publishedAt&&!a.archivedAt&&a.platform!=="quote"&&a.createdAt&&Date.now()-new Date(a.createdAt).getTime()>30*24*60*60*1e3&&e.jsx(S,{variant:"outline",className:"h-5 text-[10px] text-muted-foreground",title:"In Ready for 30+ days. Schedule, publish, or archive to clean up.",children:"Stale"})]}),a.subject&&e.jsxs("p",{className:"text-xs font-medium text-foreground/80 mb-1 truncate",children:["Subject: ",a.subject]}),e.jsx("p",{className:"text-sm text-foreground/90 line-clamp-3 whitespace-pre-wrap",children:a.preview})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[a.publishedAt&&a.externalUrl&&e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"ghost",size:"sm",onClick:async()=>{try{await navigator.clipboard.writeText(a.externalUrl),u.success("Link copied")}catch{u.error("Couldn't copy link")}},title:"Copy live link",children:e.jsx(Bt,{className:"h-3.5 w-3.5"})}),e.jsx(p,{variant:"ghost",size:"sm",asChild:!0,title:"Open live post",children:e.jsx("a",{href:a.externalUrl,target:"_blank",rel:"noreferrer",children:e.jsx(yt,{className:"h-3.5 w-3.5"})})})]}),$==="archive"?e.jsxs(e.Fragment,{children:[f&&e.jsxs(p,{variant:"default",size:"sm",onClick:()=>f(a),title:"Restore to Ready",children:[e.jsx(Ut,{className:"h-3.5 w-3.5 mr-1.5"}),"Restore"]}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>w(a),className:"text-muted-foreground hover:text-destructive",title:"Delete permanently",children:e.jsx(ge,{className:"h-3.5 w-3.5"})})]}):a.platform==="quote"?e.jsxs(p,{variant:"default",size:"sm",onClick:()=>F(a),children:[e.jsx(Ue,{className:"h-3.5 w-3.5 mr-1.5"}),"Use as post"]}):a.publishedAt?null:e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>h(a),title:"Edit",children:e.jsx(Ve,{className:"h-3.5 w-3.5"})}),e.jsxs(p,{variant:"default",size:"sm",onClick:()=>_(a),children:[e.jsx(se,{className:"h-3.5 w-3.5 mr-1.5"}),"Schedule"]})]}),$!=="archive"&&!a.publishedAt&&C&&a.variationTable&&a.variationTable!=="newsletter_templates"&&a.variationTable!=="pull_quotes"&&e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>C(a),className:"text-muted-foreground",title:"Archive (soft-delete, restorable)",children:e.jsx(X,{className:"h-3.5 w-3.5"})}),$!=="archive"&&!a.publishedAt&&e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>w(a),className:"text-muted-foreground hover:text-destructive",title:"Delete permanently",children:e.jsx(ge,{className:"h-3.5 w-3.5"})})]})]})},a.id);if(!E)return e.jsx("div",{className:"space-y-2",children:m.map(N)});const B=new Map;for(const a of m){const A=a.postId||`__standalone-${a.id}`,Q=B.get(A),z=a.createdAt?new Date(a.createdAt).getTime():0;Q?(Q.items.push(a),z>Q.latest&&(Q.latest=z)):B.set(A,{key:A,title:a.articleTitle,items:[a],latest:z})}const q=Array.from(B.values()).sort((a,A)=>A.latest-a.latest);return e.jsx("div",{className:"space-y-2",children:q.map(a=>e.jsx(Gt,{title:a.title,items:a.items,latest:a.latest,renderCard:N},a.key))})}function Gt({title:m,items:o,latest:v,renderCard:P}){const[_,h]=g.useState(!0);return e.jsx(Dt,{open:_,onOpenChange:h,children:e.jsxs(O,{className:"overflow-hidden",children:[e.jsx(Rt,{asChild:!0,children:e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 hover:bg-muted/40 text-left",children:[_?e.jsx(jt,{className:"h-4 w-4 text-muted-foreground shrink-0"}):e.jsx(Ot,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:m}),e.jsxs(S,{variant:"secondary",className:"h-5 text-[10px]",children:[o.length," draft",o.length===1?"":"s"]}),e.jsx(Se,{items:o,compact:!0}),v>0&&e.jsxs("span",{className:"text-[10px] text-muted-foreground inline-flex items-center gap-1",children:[e.jsx(Ie,{className:"h-3 w-3"}),"Latest ",xe(new Date(v),{addSuffix:!0})]})]})})]})}),e.jsx(Pt,{children:e.jsx("div",{className:"p-3 pt-0 space-y-2 border-t border-border bg-muted/10",children:o.map(P)})})]})})}export{vs 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.