PageSourceSearch

https://blueroots-production.up.railway.app/assets/social-media-page-UC5eJc4Z.js

js blueroots-production.up.railway.app collected 2026-10-03 12:12:01 UTC 48,976 bytes, 2 lines download raw bytes

1import{d as R,j as e,b as $}from"./tanstack-raftEBQU.js";import{r as h}from"./react-vendor-DG9jHnNQ.js";import{b4 as K,bk as $e,aH as E,i as j,aN as Ee,aP as qe,aQ as G,a5 as oe,aO as I,y as Me,b3 as T,p as se,s as Oe,t as Fe,q as te,d as B,bm as Q,bh as L,b0 as A,aF as ee,v as Ne,ah as D,w as ze,aX as ve,af as U,O as me,Q as xe,T as he,U as ue,ag as q,bj as Ue,a_ as Re,aM as le,ao as M,a8 as ye}from"./index-CwEfLZlp.js";import{T as Ke}from"./textarea-u-nF7bwL.js";import{S as we}from"./scroll-area-3boIVyA5.js";import{T as _e}from"./triangle-alert-CxdbLZNa.js";import{S as ke}from"./settings-DYB6eI4d.js";import{P as pe}from"./plus-B2Qz2fhA.js";import{C as He}from"./calendar-B8tRS6Pn.js";import{I as ge}from"./image-nEbDIYlL.js";import{L as ie}from"./link-2-CYZaaWG9.js";import{C as Be}from"./chevron-left-BdMoxC7t.js";import{C as fe}from"./clock-BBumLuNC.js";import{T as ne}from"./trash-2-D8NernoQ.js";import{C as Qe}from"./copy-DS2sWNpy.js";import{U as Ve}from"./unlink-DQmiyVfQ.js";import{S as X}from"./send-QQ2CR8ls.js";import{E as ce}from"./eye-Dgt_VxJ0.js";import{F as Ce}from"./facebook-wScnw2LL.js";import{P as de}from"./play-CpYKipzd.js";import{E as Ye}from"./ellipsis-C9z0sgWx.js";import{B as Je}from"./bookmark-Bko2QcuU.js";import"./radix-B0zOOFBK.js";import"./charts-ycOWY838.js";import"./dnd-IADusAtS.js";const W=K("Heart",[["path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",key:"c3ymky"}]]);const Se=K("Instagram",[["rect",{width:"20",height:"20",x:"2",y:"2",rx:"5",ry:"5",key:"2e1cvw"}],["path",{d:"M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z",key:"9exkf1"}],["line",{x1:"17.5",x2:"17.51",y1:"6.5",y2:"6.5",key:"r4j83e"}]]);const Te=K("Linkedin",[["path",{d:"M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z",key:"c2jq9f"}],["rect",{width:"4",height:"12",x:"2",y:"9",key:"mk3on5"}],["circle",{cx:"4",cy:"4",r:"2",key:"bt5ra8"}]]);const Xe=K("Music",[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]);const ae=K("Repeat2",[["path",{d:"m2 9 3-3 3 3",key:"1ltn5i"}],["path",{d:"M13 18H7a2 2 0 0 1-2-2V6",key:"1r6tfw"}],["path",{d:"m22 15-3 3-3-3",key:"4rnwn2"}],["path",{d:"M11 6h6a2 2 0 0 1 2 2v10",key:"2f72bc"}]]);const We=K("ThumbsUp",[["path",{d:"M7 10v12",key:"1qc93n"}],["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",key:"emmmcr"}]]);const Ze=K("Youtube",[["path",{d:"M2.5 17a24.12 24.12 0 0 1 0-10 2 2 0 0 1 1.4-1.4 49.56 49.56 0 0 1 16.2 0A2 2 0 0 1 21.5 7a24.12 24.12 0 0 1 0 10 2 2 0 0 1-1.4 1.4 49.55 49.55 0 0 1-16.2 0A2 2 0 0 1 2.5 17",key:"1q2vi4"}],["path",{d:"m10 15 5-3-5-3z",key:"1jp15x"}]]),k=[{key:"facebook",label:"Facebook",color:"bg-blue-600 text-white",charLimit:63206},{key:"instagram",label:"Instagram",color:"bg-gradient-to-r from-sky-500 to-pink-500 text-white",charLimit:2200},{key:"threads",label:"Threads",color:"bg-zinc-800 text-white",charLimit:500},{key:"linkedin",label:"LinkedIn",color:"bg-blue-700 text-white",charLimit:3e3},{key:"x",label:"X",color:"bg-zinc-900 text-white",charLimit:280},{key:"tiktok",label:"TikTok",color:"bg-gradient-to-r from-cyan-500 to-pink-500 text-white",charLimit:2200,note:"Video required"},{key:"youtube",label:"YouTube",color:"bg-red-600 text-white",charLimit:5e3,note:"Video required"},{key:"bluesky",label:"Bluesky",color:"bg-sky-500 text-white",charLimit:300}];function Le({platform:s,className:t}){switch(s){case"facebook":return e.jsx(Ce,{className:t});case"instagram":return e.jsx(Se,{className:t});case"linkedin":return e.jsx(Te,{className:t});default:return e.jsx(E,{className:t})}}function Pe({platform:s}){const t=k.find(c=>c.key===s);return e.jsx(B,{className:T("text-[10px] px-1.5 py-0",t?.color||"bg-gray-600 text-white"),"data-testid":`badge-platform-${s}`,children:t?.label||s})}const Ae={draft:"bg-gray-500/15 text-gray-400 border-gray-500/30",scheduled:"bg-blue-500/15 text-blue-400 border-blue-500/30",pending_approval:"bg-yellow-500/15 text-yellow-400 border-yellow-500/30",approved:"bg-green-500/15 text-green-400 border-green-500/30",published:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30",failed:"bg-red-500/15 text-red-400 border-red-500/30",paused:"bg-orange-500/15 text-orange-400 border-orange-500/30"};function J(s,t){try{return JSON.parse(s)}catch{return t}}function Us(){const{selectedCampaign:s}=$e(),t=s?.id,[c,l]=h.useState("posts"),[n,u]=h.useState(!1),[m,p]=h.useState(null),[o,b]=h.useState(!1),{data:N}=R({queryKey:[`/api/campaigns/${t}/social/settings`],enabled:!!t}),y=N?.pauseAllOutgoing===!0;if(!s)return e.jsxs("div",{className:"h-full flex flex-col","data-testid":"social-media-page",children:[e.jsxs("div",{className:"p-4 border-b border-border/50 flex items-center gap-3",children:[e.jsx(E,{className:"h-5 w-5 text-sky-400"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Social Media"})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a campaign to manage social media"})]});const d=v=>{p(v||null),u(!0)};return e.jsxs("div",{className:"h-full flex flex-col","data-testid":"social-media-page",children:[y&&e.jsxs("div",{className:"px-4 py-2 bg-red-500/10 border-b border-red-500/30 flex items-center gap-2","data-testid":"pause-banner",children:[e.jsx(_e,{className:"h-4 w-4 text-red-400"}),e.jsx("span",{className:"text-sm text-red-400 font-medium",children:"All outgoing posts are paused"})]}),e.jsxs("div",{className:"p-4 border-b border-border/50 flex items-center gap-3",children:[e.jsx(E,{className:"h-5 w-5 text-sky-400"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Social Media"}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(j,{variant:"outline",size:"sm",onClick:()=>b(!0),"data-testid":"button-social-settings",children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsxs(j,{size:"sm",onClick:()=>d(),"data-testid":"button-new-post",children:[e.jsx(pe,{className:"h-4 w-4 mr-1"})," New Post"]})]})]}),e.jsxs(Ee,{value:c,onValueChange:l,className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs(qe,{className:"mx-4 mt-2 w-fit",children:[e.jsxs(G,{value:"calendar","data-testid":"tab-calendar",children:[e.jsx(He,{className:"h-3.5 w-3.5 mr-1"})," Calendar"]}),e.jsxs(G,{value:"posts","data-testid":"tab-posts",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"})," Posts"]}),e.jsxs(G,{value:"media","data-testid":"tab-media",children:[e.jsx(ge,{className:"h-3.5 w-3.5 mr-1"})," Media Library"]}),e.jsxs(G,{value:"accounts","data-testid":"tab-accounts",children:[e.jsx(ie,{className:"h-3.5 w-3.5 mr-1"})," Accounts"]})]}),e.jsx(I,{value:"calendar",className:"flex-1 overflow-auto",children:e.jsx(Ge,{campaignId:t,onOpenPost:d,isPaused:y})}),e.jsx(I,{value:"posts",className:"flex-1 overflow-auto",children:e.jsx(Ie,{campaignId:t,onEditPost:d,isPaused:y})}),e.jsx(I,{value:"media",className:"flex-1 overflow-auto",children:e.jsx(es,{campaignId:t})}),e.jsx(I,{value:"accounts",className:"flex-1 overflow-auto",children:e.jsx(ss,{campaignId:t})})]}),e.jsx(ms,{campaignId:t,open:n,onOpenChange:u,editingPost:m}),e.jsx(hs,{campaignId:t,open:o,onOpenChange:b})]})}
1function Ge({campaignId:s,onOpenPost:t,isPaused:c}){const[l,n]=h.useState(new Date),[u,m]=h.useState(null),{data:p=[]}=R({queryKey:[`/api/campaigns/${s}/social/posts`],enabled:!!s}),o=l.getFullYear(),b=l.getMonth(),N=new Date(o,b,1).getDay(),y=new Date(o,b+1,0).getDate(),d=l.toLocaleString("default",{month:"long",year:"numeric"}),v=h.useMemo(()=>{const x={};return p.forEach(g=>{if(!g.scheduledAt)return;const r=new Date(g.scheduledAt);if(r.getFullYear()===o&&r.getMonth()===b){const f=r.getDate();x[f]||(x[f]=[]),x[f].push(g)}}),x},[p,o,b]),C=()=>n(new Date(o,b-1,1)),P=()=>n(new Date(o,b+1,1)),a=u?v[u]||[]:[];return e.jsxs("div",{className:"flex flex-col lg:flex-row flex-1 gap-4 p-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(j,{variant:"outline",size:"sm",onClick:C,"data-testid":"button-prev-month",children:e.jsx(Be,{className:"h-4 w-4"})}),e.jsx("h2",{className:"text-lg font-semibold",children:d}),e.jsx(j,{variant:"outline",size:"sm",onClick:P,"data-testid":"button-next-month",children:e.jsx(Me,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-px bg-border rounded-lg overflow-hidden",children:[["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(x=>e.jsx("div",{className:"bg-muted/50 p-2 text-center text-xs font-medium text-muted-foreground",children:x},x)),Array.from({length:N}).map((x,g)=>e.jsx("div",{className:"bg-background/50 p-2 min-h-[80px]"},`empty-${g}`)),Array.from({length:y}).map((x,g)=>{const r=g+1,f=v[r]||[],_=u===r,O=new Date().getDate()===r&&new Date().getMonth()===b&&new Date().getFullYear()===o;return e.jsxs("button",{onClick:()=>m(r),className:T("bg-background/50 p-2 min-h-[80px] text-left hover:bg-muted/50 transition-colors cursor-pointer",_&&"ring-2 ring-sky-500 bg-sky-500/5"),"data-testid":`calendar-day-${r}`,children:[e.jsx("span",{className:T("text-xs font-medium",O&&"bg-sky-500 text-white rounded-full w-6 h-6 flex items-center justify-center"),children:r}),f.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[f.slice(0,3).map(F=>{const re=J(F.platforms,[]);return e.jsx("div",{className:"flex gap-0.5",children:re.map(V=>{const Z=k.find(Y=>Y.key===V);return e.jsx("div",{className:T("w-2 h-2 rounded-full",Z?.color?.split(" ")[0]||"bg-gray-500"),title:Z?.label||V},V)})},F.id)}),f.length>3&&e.jsxs("span",{className:"text-[9px] text-muted-foreground",children:["+",f.length-3]})]})]},r)})]})]}),e.jsx("div",{className:"lg:w-80 shrink-0",children:e.jsxs(se,{className:"cc-card",children:[e.jsx(Oe,{className:"pb-2",children:e.jsx(Fe,{className:"text-sm",children:u?`${d.split(" ")[0]} ${u}`:"Select a day"})}),e.jsx(te,{children:u===null?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click a day to see scheduled posts."}):a.length===0?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"No posts scheduled"}),e.jsxs(j,{size:"sm",variant:"outline",onClick:()=>t(),"data-testid":"button-schedule-new",children:[e.jsx(pe,{className:"h-3.5 w-3.5 mr-1"})," Schedule Post"]})]}):e.jsx("div",{className:"space-y-2",children:a.map(x=>{const g=J(x.platforms,[]),r=c&&x.status==="scheduled"?"paused":x.status;return e.jsxs("button",{onClick:()=>t(x),className:"w-full text-left p-2 rounded-md hover:bg-muted/50 transition-colors","data-testid":`day-post-${x.id}`,children:[e.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[g.map(f=>e.jsx(Pe,{platform:f},f)),e.jsx(B,{variant:"outline",className:T("text-[10px] ml-auto",Ae[r]),children:r})]}),e.jsx("p",{className:"text-xs line-clamp-2",children:x.content}),x.scheduledAt&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1",children:[e.jsx(fe,{className:"inline h-2.5 w-2.5 mr-0.5"}),new Date(x.scheduledAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]},x.id)})})})]})})]})}function Ie({campaignId:s,onEditPost:t,isPaused:c}){const{toast:l}=Q(),[n,u]=h.useState("all"),[m,p]=h.useState(new Set),{data:o=[],isLoading:b}=R({queryKey:[`/api/campaigns/${s}/social/posts`],enabled:!!s}),N=$({mutationFn:async a=>{await A("DELETE",`/api/campaigns/${s}/social/posts/${a}`)},onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/posts`]}),l({title:"Post deleted"})},onError:a=>l({title:"Error",description:a.message,variant:"destructive"})}),y=$({mutationFn:async a=>{await A("POST",`/api/campaigns/${s}/social/posts/${a}/approve`)},onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/posts`]}),l({title:"Post approved"})},onError:a=>l({title:"Error",description:a.message,variant:"destructive"})}),d=n==="all"?o:o.filter(a=>a.status===n),v=a=>{p(x=>{const g=new Set(x);return g.has(a)?g.delete(a):g.add(a),g})},C=async()=>{for(const a of m)await N.mutateAsync(a);p(new Set)},P=async()=>{for(const a of m)await y.mutateAsync(a);p(new Set)};return e.jsxs("div",{className:"flex flex-col flex-1 px-4 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 py-3 flex-wrap",children:[["all","draft","scheduled","pending_approval","published"].map(a=>e.jsx(j,{size:"sm",variant:n===a?"default":"outline",onClick:()=>u(a),className:"text-xs","data-testid":`filter-${a}`,children:a==="all"?"All":a==="pending_approval"?"Pending":a.charAt(0).toUpperCase()+a.slice(1)},a)),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[d.length," posts"]}),m.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{orientation:"vertical",className:"h-6"}),e.jsxs(j,{size:"sm",variant:"outline",className:"text-xs text-green-400",onClick:P,"data-testid":"button-bulk-approve",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 mr-1"})," Approve (",m.size,")"]}),e.jsxs(j,{size:"sm",variant:"outline",className:"text-xs text-red-400",onClick:C,"data-testid":"button-bulk-delete",children:[e.jsx(ne,{className:"h-3.5 w-3.5 mr-1"})," Delete (",m.size,")"]})]})]}),e.jsx(we,{className:"flex-1",children:b?e.jsx("div",{className:"flex items-center justify-center p-12",children:e.jsx(D,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):d.length===0?e.jsxs("div",{className:"text-center text-muted-foreground p-12",children:[e.jsx(oe,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No posts yet."})]}):e.jsx("div",{className:"space-y-2",children:d.map(a=>{const x=J(a.platforms,[]),g=c&&a.status==="scheduled"?"paused":a.status;return e.jsx(se,{className:"cc-card cursor-pointer hover:border-sky-500/30 transition-colors","data-testid":`post-card-${a.id}`,children:e.jsxs(te,{className:"p-3 flex items-start gap-3",children:[e.jsx(ze,{checked:m.has(a.id),onCheckedChange:()=>v(a.id),className:"mt-1","data-testid":`checkbox-post-${a.id}`}),e.jsxs("div",{className:"flex-1 min-w-0",onClick:()=>t(a),children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 flex-wrap",children:[x.map(r=>e.jsx(Pe,{platform:r},r)),e.jsx(B,{variant:"outline",className:T("text-[10px]",Ae[g]),children:g}),a.approvalRequired&&a.status!=="approved"&&a.status!=="published"&&e.jsx(B,{variant:"outline",className:"text-[10px] bg-yellow-500/10 text-yellow-400 border-yellow-500/20",children:"Needs Approval"})]}),e.jsx("p",{className:"text-sm line-clamp-2",children:a.content}),e.jsxs("div",{className:"flex items-center gap-3 mt-1.5 text-xs text-muted-foreground",children:[a.scheduledAt&&e.jsxs("span",{children:[e.jsx(fe,{className:"inline h-3 w-3 mr-0.5"}),new Date(a.scheduledAt).toLocaleDateString()," ",new Date(a.scheduledAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]}),a.campaignTag&&e.jsx(B,{variant:"outline",className:"text-[10px]",children:a.campaignTag})]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[a.status==="pending_approval"&&e.jsx(j,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-green-400",onClick:r=>{r.stopPropagation(),y.mutate(a.id)},"data-testid":`button-approve-${a.id}`,children:e.jsx(Ne,{className:"h-3.5 w-3.5"})}),e.jsx(j,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive",onClick:r=>{r.stopPropagation(),N.mutate(a.id)},"data-testid":`button-delete-${a.id}`,children:e.jsx(ne,{className:"h-3.5 w-3.5"})})]})]})},a.id)})})})]})}function es({campaignId:s}){const{toast:t}=Q(),[c,l]=h.useState(!1),[n,u]=h.useState(""),[m,p]=h.useState(""),[o,b]=h.useState(!1),[N,y]=h.useState(!1),d=h.useRef(null),{data:v=[],isLoading:C}=R({queryKey:[`/api/campaigns/${s}/social/media`],enabled:!!s}),P=async r=>{if(!(!r||r.length===0)){b(!0);try{for(const f of Array.from(r)){const _=new FormData;_.append("file",f);const O=await fetch(`/api/campaigns/${s}/social/media/upload`,{method:"POST",body:_,credentials:"include"});if(!O.ok){const F=await O.json();throw new Error(F.message||"Upload failed")}}L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/media`]}),t({title:`${r.length} file${r.length>
11?"s":""} uploaded`})}catch(f){t({title:"Upload failed",description:f.message,variant:"destructive"})}finally{b(!1),y(!1),d.current&&(d.current.value="")}}},a=$({mutationFn:async()=>(await A("POST",`/api/campaigns/${s}/social/media`,{url:n.trim(),filename:m.trim()||n.split("/").pop()||"media"})).json(),onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/media`]}),t({title:"Media added"}),u(""),p(""),l(!1)},onError:r=>t({title:"Error",description:r.message,variant:"destructive"})}),x=$({mutationFn:async r=>{await A("DELETE",`/api/campaigns/${s}/social/media/${r}`)},onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/media`]}),t({title:"Media deleted"})},onError:r=>t({title:"Error",description:r.message,variant:"destructive"})}),g=r=>{navigator.clipboard.writeText(r),t({title:"URL copied to clipboard"})};return e.jsxs("div",{className:"flex flex-col flex-1 px-4 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 py-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Media Library"}),e.jsx(B,{variant:"outline",className:"text-xs",children:v.length}),e.jsxs(j,{size:"sm",variant:"outline",className:"ml-auto",onClick:()=>l(!c),"data-testid":"button-add-media",children:[e.jsx(pe,{className:"h-4 w-4 mr-1"})," Add Media"]})]}),c&&e.jsxs("div",{className:"mb-3 space-y-3",children:[e.jsxs("div",{className:`border-2 border-dashed rounded-xl p-6 text-center transition-colors cursor-pointer ${N?"border-sky-400 bg-sky-500/10":"border-border hover:border-muted-foreground"}`,onDragOver:r=>{r.preventDefault(),y(!0)},onDragLeave:()=>y(!1),onDrop:r=>{r.preventDefault(),P(r.dataTransfer.files)},onClick:()=>d.current?.click(),"data-testid":"media-dropzone",children:[e.jsx("input",{ref:d,type:"file",multiple:!0,accept:"image/*,video/*,.pdf",className:"hidden",onChange:r=>P(r.target.files)}),o?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(D,{className:"h-8 w-8 animate-spin text-sky-400"}),e.jsx("p",{className:"text-sm text-sky-300",children:"Uploading..."})]}):e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(ve,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-foreground",children:"Drag & drop files here, or click to browse"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Images, videos, PDFs up to 50MB"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("div",{className:"flex-1 border-t border-border"}),e.jsx("span",{children:"or add by URL"}),e.jsx("div",{className:"flex-1 border-t border-border"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{placeholder:"Paste image/video URL",value:n,onChange:r=>u(r.target.value),className:"text-sm flex-1","data-testid":"input-media-url"}),e.jsx(j,{size:"sm",onClick:()=>a.mutate(),disabled:!n.trim()||a.isPending,"data-testid":"button-upload-media",children:a.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):"Add"})]})]}),e.jsx(we,{className:"flex-1",children:C?e.jsx("div",{className:"flex items-center justify-center p-12",children:e.jsx(D,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):v.length===0?e.jsxs("div",{className:"text-center text-muted-foreground p-12",children:[e.jsx(ge,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No media uploaded yet."})]}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3",children:v.map(r=>{const f=r.mimeType?.startsWith("image")||/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(r.url);return e.jsxs(se,{className:"cc-card overflow-hidden group","data-testid":`media-item-${r.id}`,children:[e.jsxs("div",{className:"aspect-square bg-muted/50 flex items-center justify-center relative overflow-hidden",children:[f?e.jsx("img",{src:r.url,alt:r.filename,className:"w-full h-full object-cover"}):e.jsx(oe,{className:"h-8 w-8 text-muted-foreground"}),e.jsxs("div",{className:"absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[e.jsxs(j,{size:"sm",variant:"secondary",className:"h-7 text-xs",onClick:()=>g(r.url),"data-testid":`button-copy-url-${r.id}`,children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"})," Copy URL"]}),e.jsx(j,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>x.mutate(r.id),"data-testid":`button-delete-media-${r.id}`,children:e.jsx(ne,{className:"h-3 w-3"})})]})]}),e.jsxs(te,{className:"p-2",children:[e.jsx("p",{className:"text-xs truncate",children:r.filename}),r.sizeBytes>0&&e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[(r.sizeBytes/1024).toFixed(1)," KB"]}
1)]})]},r.id)})})})]})}function ss({campaignId:s}){const{toast:t}=Q(),[c,l]=h.useState(null),[n,u]=h.useState(""),[m,p]=h.useState(""),{data:o=[],isLoading:b}=R({queryKey:[`/api/campaigns/${s}/social/accounts`],enabled:!!s}),N=$({mutationFn:async()=>(await A("POST",`/api/campaigns/${s}/social/accounts`,{platform:c,accountName:m.trim()||n.trim(),accountHandle:n.trim()})).json(),onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/accounts`]}),t({title:"Account connected"}),l(null),u(""),p("")},onError:d=>t({title:"Error",description:d.message,variant:"destructive"})}),y=$({mutationFn:async d=>{await A("DELETE",`/api/campaigns/${s}/social/accounts/${d}`)},onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/accounts`]}),t({title:"Account disconnected"})}});return e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-foreground",children:"Connected Accounts"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Connect your social media accounts to publish posts directly from Blueroots"})]}),b?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(D,{className:"h-6 w-6 animate-spin text-sky-400"})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:k.map(d=>{const v=o.find(C=>C.platform===d.key);return e.jsxs("div",{className:"bg-card/80 border border-border rounded-xl p-4 flex items-center gap-3",children:[e.jsx("div",{className:`shrink-0 w-10 h-10 rounded-lg flex items-center justify-center text-xs font-bold ${d.color}`,children:e.jsx(Le,{platform:d.key,className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:d.label}),v?e.jsxs("p",{className:"text-xs text-emerald-400 flex items-center gap-1 truncate",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400 inline-block"}),"Connected",v.accountHandle?` as @${v.accountHandle}`:""]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Not connected"})]}),v?e.jsxs(j,{size:"sm",variant:"ghost",className:"text-xs text-red-400 hover:text-red-300 hover:bg-red-500/10",onClick:()=>y.mutate(v.id),disabled:y.isPending,children:[e.jsx(Ve,{className:"h-3 w-3 mr-1"})," Disconnect"]}):e.jsxs(j,{size:"sm",className:"text-xs bg-sky-600 hover:bg-sky-700",onClick:()=>{l(d.key),u(""),p("")},children:[e.jsx(ie,{className:"h-3 w-3 mr-1"})," Connect"]})]},d.key)})}),e.jsx(me,{open:!!c,onOpenChange:d=>{d||l(null)},children:e.jsxs(xe,{className:"bg-background border-border max-w-sm",children:[e.jsx(he,{children:e.jsxs(ue,{className:"text-foreground",children:["Connect ",k.find(d=>d.key===c)?.label]})}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("div",{className:"rounded-lg bg-sky-500/10 border border-sky-500/20 p-3",children:e.jsx("p",{className:"text-xs text-sky-300",children:"Full OAuth login is coming in the next update. For now, enter your account details to link for content planning and scheduling."})}),e.jsxs("div",{children:[e.jsx(q,{className:"text-xs text-muted-foreground mb-1 block",children:"Account / Page Name"}),e.jsx(U,{value:m,onChange:d=>p(d.target.value),placeholder:"e.g. Rob Cooper For Congress",className:"text-sm bg-card border-border"})]}),e.jsxs("div",{children:[e.jsx(q,{className:"text-xs text-muted-foreground mb-1 block",children:"Handle / Username"}),e.jsx(U,{value:n,onChange:d=>u(d.target.value),placeholder:"e.g. @robcooper2026",className:"text-sm bg-card border-border"})]}),e.jsxs(j,{className:"w-full bg-sky-600 hover:bg-sky-700",onClick:()=>N.mutate(),disabled:!n.trim()&&!m.trim()||N.isPending,children:[N.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(ie,{className:"h-4 w-4 mr-1"}),"Connect Account"]})]})]})})]})}function ts({content:s,mediaUrl:t}){const c=k.find(l=>l.key==="facebook");return e.jsxs("div",{className:"rounded-xl bg-white text-black overflow-hidden border border-gray-200","data-testid":"preview-facebook",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-blue-600",children:"Facebook Preview"})}),e.jsxs("div",{className:"px-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-blue-100 flex items-center justify-center shrink-0",children:e.jsx(Ce,{className:"h-4 w-4 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[13px] font-semibold leading-tight",children:"Campaign Name"}),e.jsxs("p",{className:"text-[11px] text-gray-500",children:["Just now · ",e.jsx(ye,{className:"inline h-2.5 w-2.5"})]})]})]}),e.jsx("p",{className:"text-[13px] leading-snug whitespace-pre-wrap break-words mb-2",children:s||" "})]}),t&&e.jsx("img",{src:t,alt:"",className:"w-full max-h-64 object-cover border-t border-gray-100",onError:l=>{l.target.style.display="none"}}),e.jsxs("div",{className:"px-3 py-2 border-t border-gray-100 flex items-center justify-around text-gray-500 text-[12px]",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(We,{className:"h-3.5 w-3.5"})," Like"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(M,{className:"h-3.5 w-3.5"})," Comment"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(E,{className:"h-3.5 w-3.5"})," Share"]})]}),s.length>c.charLimit&&e.jsxs("div",{className:"px-3 pb-1.5 text-[10px] text-red-500 font-medium",children:[s.length,"/",c.charLimit," characters"]})]})}function as({content:s,mediaUrl:t}){const c=k.find(n=>n.key==="instagram"),l=s.length>125?s.slice(0,125)+"... more":s;return e.jsxs("div",{className:"rounded-xl bg-white text-black overflow-hidden border border-gray-200","data-testid":"preview-instagram",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-pink-600",children:"Instagram Preview"})}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-sky-500 to-pink-500 flex items-center justify-center",children:e.jsx(Se,{className:"h-3.5 w-3.5 text-foreground"})}),e.jsx("span",{className:"text-[13px] font-semibold",children:"campaign_handle"})]}),e.jsx(Ye,{className:"h-4 w-4 text-gray-600"})]}),e.jsx("div",{className:"aspect-square bg-gray-100 flex items-center justify-center overflow-hidden",children:t?e.jsx("img",{src:t,alt:"",className:"w-full h-full object-cover",onError:n=>{n.target.src="",n.target.className="hidden"}}):e.jsx(ge,{className:"h-12 w-12 text-gray-300"})}),e.jsxs("div",{className:"px-3 py-2 flex items-center gap-4",children:[e.jsx(W,{className:"h-5 w-5 text-gray-800"}),e.jsx(M,{className:"h-5 w-5 text-gray-800"}),e.jsx(X,{className:"h-5 w-5 text-gray-800"}),e.jsx(Je,{className:"h-5 w-5 text-gray-800 ml-auto"})]}),e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("p",{className:"text-[13px] leading-snug",children:[e.jsx("span",{className:"font-semibold",children:"campaign_handle"})," ",l||" "]})}),s.length>c.charLimit&&e.jsxs("div",{className:"px-3 pb-1.5 text-[10px] text-red-500 font-medium",children:[s.length,"/",c.charLimit," characters"]})]})}function rs({content:s,mediaUrl:t}){const c=k.find(n=>n.key==="threads"),l=s.length>c.charLimit;return e.jsxs("div",{className:"rounded-xl bg-white text-black overflow-hidden border border-gray-200","data-testid":"preview-threads",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-gray-600",children:"Threads Preview"})}),e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-gray-900 flex items-center justify-center shrink-0 mt-0.5",children:e.jsx(E,{className:"h-4 w-4 text-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[13px] font-semibold",children:"campaign_handle"}),e.jsx("span",{className:"text-[11px] text-gray-400",children:"2m"})]}),e.jsx("p",{className:"text-[13px] leading-snug whitespace-pre-wrap break-words mt-0.5",children:s||" "}),t&&e.jsx("img",{src:t,alt:"",className:"mt-2 rounded-lg w-full max-h-48 object-cover",onError:n=>{n.target.style.display="none"}}),e.jsxs("div",{className:"flex items-center gap-5 mt-2 text-gray-400",children:[e.jsx(W,{className:"h-4 w-4"}),e.jsx(M,{className:"h-4 w-4"}),e.jsx(ae,{className:"h-4 w-4"}),e.jsx(X,{className:"h-4 w-4"})]})]})]})}),l&&e.jsxs("div",{className:"px-3 pb-1.5 text-[10px] text-red-500 font-medium",children:[s.length,"/",c.charLimit," characters"]})]})}function ls({content:s,mediaUrl:t}){const c=k.find(l=>l.key==="linkedin");return e.jsxs("div",{className:"rounded-xl bg-white text-black overflow-hidden border border-gray-200","data-testid":"preview-linkedin",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-blue-700",children:"LinkedIn Preview"})}),e.jsxs("div",{className:"px-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center shrink-0",children:e.jsx(Te,{className:"h-4 w-4 text-blue-700"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[13px] font-semibold leading-tight",children:"Campaign Name"}),e.jsx("p",{className:"text-[11px] text-gray-500",children:"Campaign · Just now"})]})]}),e.jsx("p",{className:"text-[13px] leading-snug whitespace-pre-wrap break-words",children:s||" "})]}),t&&e.jsx("img",{src:t,alt:"",className:"w-full max-h-64 object-cover",onError:l=>{l.target.style.display="none"}}),e.jsxs("div",{className:"px-3 py-2 border-t border-gray-100 flex items-center justify-around text-gray-500 text-[12px]",children:[e.jsx("span",{className:"flex items-center gap-1",children:"👍 Like"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(M,{className:"h-3.5 w-3.5"})," Comment"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ae,{className:"h-3.5 w-3.5"})," Repost"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(X,{className:"h-3.5 w-3.5"})," Send"]})]}),s.length>c.charLimit&&e.jsxs("div",{className:"px-3 pb-1.5 text-[10px] text-red-500 font-medium",children:[s.length,"/",c.charLimit," characters"]})]})}function is({content:s,mediaUrl:t}){const c=k.find(n=>n.key==="x"),l=s.length>c.charLimit;return e.jsxs("div",{className:"rounded-xl bg-black text-white overflow-hidden border border-gray-800","data-testid":"preview-x",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-gray-500",children:"X Preview"})}),e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-gray-800 flex items-center justify-center shrink-0 mt-0.5",children:e.jsx(E,{className:"h-4 w-4 text-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[13px] font-bold",children:"Campaign"}),e.jsx("span",{className:"text-[12px] text-gray-500",children:"@campaign_handle"}),e.jsx("span",{className:"text-[12px] text-gray-500",children:"· now"})]}),e.jsx("p",{className:T("text-[14px] leading-snug whitespace-pre-wrap break-words mt-0.5",l&&"text-red-400"),children:s||" "}),t&&e.jsx("img",{src:t,alt:"",className:"mt-2 rounded-2xl w-full max-h-52 object-cover border border-gray-800",onError:n=>{n.target.style.display="none"}}),e.jsxs("div",{className:"flex items-center justify-between mt-2.5 text-gray-500 max-w-[280px]",children:[e.jsx(M,{className:"h-4 w-4"}),e.jsx(ae,{className:"h-4 w-4"}),e.jsx(W,{className:"h-4 w-4"}),e.jsx(ce,{className:"h-4 w-4"}),e.jsx(E,{className:"h-4 w-4"})]})]})]})}),e.jsx("div",{className:"px-3 pb-1.5",children:e.jsxs("span",{className:T("text-[10px] font-medium",l?"text-red-500":"text-gray-600"),children:[s.length,"/",c.charLimit]})})]})}function ns({content:s}){const t=k.find(c=>c.key==="tiktok");return e.jsxs("div",{className:"rounded-xl bg-black text-white overflow-hidden border border-gray-800","data-testid":"preview-tiktok",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-gray-500",children:"TikTok Preview"})}),e.jsxs("div",{className:"relative aspect-[9/14] max-h-[320px] bg-gray-900 flex items-center justify-center mx-3 rounded-xl overflow-hidden mb-3",children:[e.jsxs("div",{className:"text-center",children:[e.jsx(de,{className:"h-12 w-12 text-foreground
1/40 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-foreground/50 font-medium",children:"Video Required"})]}),e.jsxs("div",{className:"absolute right-2 bottom-16 flex flex-col items-center gap-4",children:[e.jsx(W,{className:"h-6 w-6 text-foreground/80"}),e.jsx(M,{className:"h-6 w-6 text-foreground/80"}),e.jsx(E,{className:"h-6 w-6 text-foreground/80"}),e.jsx(Xe,{className:"h-6 w-6 text-foreground/80"})]}),e.jsxs("div",{className:"absolute bottom-2 left-2 right-12",children:[e.jsx("p",{className:"text-[11px] font-semibold mb-0.5",children:"@campaign_handle"}),e.jsx("p",{className:"text-[11px] leading-snug line-clamp-3",children:s||"Caption here..."})]})]}),s.length>t.charLimit&&e.jsxs("div",{className:"px-3 pb-1.5 text-[10px] text-red-500 font-medium",children:[s.length,"/",t.charLimit," characters"]})]})}function cs({content:s,mediaUrl:t}){const c=k.find(n=>n.key==="youtube"),l=s.split(`
2`)[0]?.slice(0,100)||"Video Title";return e.jsxs("div",{className:"rounded-xl bg-white text-black overflow-hidden border border-gray-200","data-testid":"preview-youtube",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-red-600",children:"YouTube Preview"})}),e.jsxs("div",{className:"aspect-video bg-gray-900 flex items-center justify-center relative overflow-hidden mx-3 rounded-lg",children:[t?e.jsx("img",{src:t,alt:"",className:"w-full h-full object-cover",onError:n=>{n.target.style.display="none"}}):e.jsx(de,{className:"h-14 w-14 text-foreground/30"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-14 h-10 bg-red-600/90 rounded-xl flex items-center justify-center",children:e.jsx(de,{className:"h-5 w-5 text-foreground fill-white"})})})]}),e.jsxs("div",{className:"px-3 py-2.5 flex items-start gap-2.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-red-100 flex items-center justify-center shrink-0",children:e.jsx(Ze,{className:"h-4 w-4 text-red-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-semibold leading-snug line-clamp-2",children:l}),e.jsx("p",{className:"text-[11px] text-gray-500 mt-0.5",children:"Campaign Name · 0 views · Just now"})]})]}),s.length>c.charLimit&&e.jsxs("div",{className:"px-3 pb-1.5 text-[10px] text-red-500 font-medium",children:[s.length,"/",c.charLimit," characters"]})]})}function ds({content:s,mediaUrl:t}){const c=k.find(n=>n.key==="bluesky"),l=s.length>c.charLimit;return e.jsxs("div",{className:"rounded-xl bg-white text-black overflow-hidden border border-gray-200","data-testid":"preview-bluesky",children:[e.jsx("div",{className:"px-3 pt-1.5 pb-1",children:e.jsx("span",{className:"text-[10px] font-medium text-sky-500",children:"Bluesky Preview"})}),e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-sky-100 flex items-center justify-center shrink-0 mt-0.5",children:e.jsx(ye,{className:"h-4 w-4 text-sky-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[13px] font-semibold",children:"Campaign"}),e.jsx("span",{className:"text-[12px] text-gray-400",children:"@campaign.bsky.social"})]}),e.jsx("p",{className:T("text-[13px] leading-snug whitespace-pre-wrap break-words mt-0.5",l&&"text-red-500"),children:s||" "}),t&&e.jsx("img",{src:t,alt:"",className:"mt-2 rounded-lg w-full max-h-48 object-cover",onError:n=>{n.target.style.display="none"}}),e.jsxs("div",{className:"flex items-center gap-5 mt-2 text-gray-400",children:[e.jsx(M,{className:"h-4 w-4"}),e.jsx(ae,{className:"h-4 w-4"}),e.jsx(W,{className:"h-4 w-4"}),e.jsx(E,{className:"h-4 w-4"})]})]})]})}),e.jsx("div",{className:"px-3 pb-1.5",children:e.jsxs("span",{className:T("text-[10px] font-medium",l?"text-red-500":"text-gray-400"),children:[s.length,"/",c.charLimit]})})]})}const os={facebook:ts,instagram:as,threads:rs,linkedin:ls,x:is,tiktok:ns,youtube:cs,bluesky:ds};function ms({campaignId:s,open:t,onOpenChange:c,editingPost:l}){const{toast:n}=Q(),{user:u}=Ue(),[m,p]=h.useState(""),[o,b]=h.useState(new Set),[N,y]=h.useState(""),[d,v]=h.useState(""),[C,P]=h.useState(!1),[a,x]=h.useState(""),[g,r]=h.useState(!1),f=h.useRef(null),[_,O]=h.useState(!1),F=async i=>{if(!(!i||i.length===0||!s)){O(!0);try{const S=i[0],w=new FormData;w.append("file",S);const H=await fetch(`/api/campaigns/${s}/social/media/upload`,{method:"POST",body:w,credentials:"include"});if(!H.ok)throw new Error("Upload failed");const De=await H.json();x(De.url),L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/media`]})}catch(S){n({title:"Upload failed",description:S.message,variant:"destructive"})}finally{O(!1),f.current&&(f.current.value="")}}},re=()=>{if(l){p(l.content),b(new Set(J(l.platforms,[]))),y(l.scheduledAt?l.scheduledAt.slice(0,16):""),v(l.campaignTag),P(l.approvalRequired);const i=J(l.mediaUrls,[]);x(i[0]||"")}else p(""),b(new Set),y(""),v(""),P(!1),x("");r(!1)},V=i=>{i&&re(),c(i)},Z=i=>
2{b(S=>{const w=new Set(S);return w.has(i)?w.delete(i):w.add(i),w})},Y=h.useMemo(()=>{let i=1/0;return o.forEach(S=>{const w=k.find(H=>H.key===S);w&&w.charLimit<i&&(i=w.charLimit)}),i===1/0?2200:i},[o]),z=$({mutationFn:async i=>{const S=a.trim()?JSON.stringify([a.trim()]):"[]",w=JSON.stringify(Array.from(o));return l?(await A("PATCH",`/api/campaigns/${s}/social/posts/${l.id}`,{content:m,platforms:w,mediaUrls:S,scheduledAt:N?new Date(N).toISOString():"",status:i,campaignTag:d,approvalRequired:C})).json():(await A("POST",`/api/campaigns/${s}/social/posts`,{content:m,platforms:w,mediaUrls:S,scheduledAt:N?new Date(N).toISOString():"",status:i,campaignTag:d,approvalRequired:C,metadata:"{}"})).json()},onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/posts`]}),n({title:l?"Post updated":"Post created"}),c(!1)},onError:i=>n({title:"Error",description:i.message,variant:"destructive"})}),je=m.trim()&&o.size>0&&m.length<=Y,be=Array.from(o);return e.jsx(me,{open:t,onOpenChange:V,children:e.jsx(xe,{className:"max-w-6xl max-h-[90vh] overflow-hidden bg-background border-border p-0","data-testid":"post-composer-dialog",children:e.jsxs("div",{className:"flex flex-col h-full max-h-[90vh]",children:[e.jsx(he,{className:"px-6 pt-5 pb-3 border-b border-border/50 shrink-0",children:e.jsx(ue,{className:"text-lg",children:l?"Edit Post":"New Post"})}),e.jsxs("div",{className:"flex flex-1 min-h-0",children:[e.jsxs("div",{className:"w-[55%] border-r border-border/50 overflow-y-auto p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx(q,{className:"text-xs text-muted-foreground mb-2 block",children:"Platforms"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:k.map(i=>e.jsxs("button",{onClick:()=>Z(i.key),className:T("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-all border",o.has(i.key)?T(i.color,"border-transparent"):"bg-card text-muted-foreground border-border hover:border-sky-500/40"),"data-testid":`platform-toggle-${i.key}`,children:[e.jsx(Le,{platform:i.key,className:"h-3.5 w-3.5"}),i.label,i.note&&o.has(i.key)&&e.jsxs("span",{className:"text-[9px] opacity-70 ml-0.5",children:["(",i.note,")"]})]},i.key))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx(q,{className:"text-xs text-muted-foreground",children:"Content"}),e.jsxs("span",{className:T("text-xs",m.length>Y?"text-red-400":"text-muted-foreground"),children:[m.length,"/",Y]})]}),e.jsx(Ke,{value:m,onChange:i=>p(i.target.value),placeholder:"What's on your mind?",rows:7,className:"resize-none bg-card border-border","data-testid":"textarea-post-content"})]}),e.jsxs("div",{children:[e.jsx(q,{className:"text-xs text-muted-foreground mb-1 block",children:"Attach Media"}),a?e.jsxs("div",{className:"relative rounded-lg overflow-hidden border border-border bg-card",children:[e.jsx("img",{src:a,alt:"",className:"w-full max-h-32 object-cover",onError:i=>{i.target.style.display="none"}}),e.jsx("button",{type:"button",onClick:()=>x(""),className:"absolute top-1 right-1 h-6 w-6 rounded-full bg-black/70 hover:bg-black flex items-center justify-center text-white",children:e.jsx(Re,{className:"h-3 w-3"})})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"border-2 border-dashed border-border hover:border-sky-500/50 rounded-lg p-3 text-center cursor-pointer transition-colors",onClick:()=>f.current?.click(),onDragOver:i=>{i.preventDefault(),i.currentTarget.classList.add("border-sky-400")},onDragLeave:i=>{i.currentTarget.classList.remove("border-sky-400")},onDrop:i=>{i.preventDefault(),i.currentTarget.classList.remove("border-sky-400"),F(i.dataTransfer.files)},children:[e.jsx("input",{ref:f,type:"file",accept:"image/*,video/*",className:"hidden",onChange:i=>F(i.target.files)}),_?e.jsx(D,{className:"h-5 w-5 animate-spin text-sky-400 mx-auto"}):e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"h-5 w-5 text-muted-foreground mx-auto mb-1"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Drop image/video or click to upload"})]})]}),e.jsx(U,{value:a,onChange:i=>x(i.target.value),placeholder:"Or paste a URL...",className:"text-xs bg-card border-border","data-testid":"input-media-url-composer"})]})]}),e.jsxs("div",{children:[e.jsx(q,{className:"text-xs text-muted-foreground mb-1 block",children:"Schedule (optional)"}),e.jsx(U,{type:"datetime-local",value:N,onChange:i=>y(i.target.value),className:"text-sm w-fit bg-card border-border","data-testid":"input-scheduled-at"})]}),e.jsxs("div",{children:[e.jsx(q,{className:"text-xs text-muted-foreground mb-1 block",children:"Campaign Tag (optional)"}),e.jsx(U,{value:d,onChange:i=>
2v(i.target.value),placeholder:"e.g. launch-week, gotv",className:"text-sm bg-card border-border","data-testid":"input-campaign-tag"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{checked:C,onCheckedChange:P,id:"approval-required","data-testid":"switch-approval-required"}),e.jsx(q,{htmlFor:"approval-required",className:"text-sm cursor-pointer",children:"Require approval before posting"})]}),l&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"border-border"}),e.jsxs(j,{variant:"ghost",size:"sm",className:"text-xs",onClick:()=>r(!g),"data-testid":"button-toggle-comments",children:[e.jsx(M,{className:"h-3.5 w-3.5 mr-1"})," ",g?"Hide":"Show"," Comments"]}),g&&e.jsx(xs,{campaignId:s,postId:l.id})]}),e.jsx(ee,{className:"border-border"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(j,{variant:"outline",onClick:()=>z.mutate("draft"),disabled:!m.trim()||o.size===0||z.isPending,className:"border-border","data-testid":"button-save-draft",children:[z.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin mr-1"}):null,"Save as Draft"]}),N&&e.jsxs(j,{onClick:()=>z.mutate(C?"pending_approval":"scheduled"),disabled:!je||z.isPending,"data-testid":"button-schedule-post",children:[e.jsx(fe,{className:"h-4 w-4 mr-1"})," Schedule"]}),!N&&e.jsxs(j,{onClick:()=>z.mutate(C?"pending_approval":"published"),disabled:!je||z.isPending,"data-testid":"button-post-now",children:[e.jsx(X,{className:"h-4 w-4 mr-1"})," Post Now"]})]})]}),e.jsxs("div",{className:"w-[45%] overflow-y-auto bg-card/50 p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(ce,{className:"h-4 w-4 text-sky-400"}),e.jsx("span",{className:"text-sm font-medium text-sky-400",children:"Live Previews"})]}),be.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx(ce,{className:"h-10 w-10 text-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select platforms to see live previews"})]}):e.jsx("div",{className:"space-y-4",children:be.map(i=>{const S=os[i];return S?e.jsx(S,{content:m,mediaUrl:a},i):null})})]})]})]})})})}function xs({campaignId:s,postId:t}){const{toast:c}=Q(),[l,n]=h.useState(""),{data:u=[],isLoading:m}=R({queryKey:[`/api/campaigns/${s}/social/posts/${t}/comments`],enabled:!!t}),p=$({mutationFn:async()=>(await A("POST",`/api/campaigns/${s}/social/posts/${t}/comments`,{content:l.trim()})).json(),onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/posts/${t}/comments`]}),n("")},onError:o=>c({title:"Error",description:o.message,variant:"destructive"})});return e.jsx(se,{className:"cc-card",children:e.jsxs(te,{className:"p-3 space-y-2",children:[m?e.jsx(D,{className:"h-4 w-4 animate-spin text-muted-foreground"}):u.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No comments yet."}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:u.map(o=>e.jsxs("div",{className:"text-xs p-2 bg-muted/50 rounded","data-testid":`comment-${o.id}`,children:[e.jsx("p",{children:o.content}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:new Date(o.createdAt).toLocaleString()})]},o.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{value:l,onChange:o=>n(o.target.value),placeholder:"Add a comment...",className:"text-sm h-8",onKeyDown:o=>{o.key==="Enter"&&l.trim()&&(o.preventDefault(),p.mutate())},"data-testid":"input-comment"}),e.jsx(j,{size:"sm",className:"h-8",onClick:()=>p.mutate(),disabled:!l.trim()||p.isPending,"data-testid":"button-add-comment",children:e.jsx(X,{className:"h-3 w-3"})})]})]})})}function hs({campaignId:s,open:t,onOpenChange:c}){const{toast:l}=Q(),{data:n}=R({queryKey:[`/api/campaigns/${s}/social/settings`],enabled:!!s}),u=$({mutationFn:async m=>(await A("PATCH",`/api/campaigns/${s}/social/settings`,m)).json(),onSuccess:()=>{L.invalidateQueries({queryKey:[`/api/campaigns/${s}/social/settings`]}),l({title:"Settings updated"})},onError:m=>l({title:"Error",description:m.message,variant:"destructive"})});return e.jsx(me,{open:t,onOpenChange:c,children:e.jsxs(xe,{className:"max-w-sm","data-testid":"social-settings-dialog",children:[e.jsx(he,{children:e.jsxs(ue,{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4"})," Social Settings"]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Pause All Outgoing"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Stop all scheduled posts from being published"})]}),e.jsx(le,{checked:n?.pauseAllOutgoing||!1,onCheckedChange:m=>u.mutate({pauseAllOutgoing:m}),"data-testid":"switch-pause-all"})]}),e.jsx(ee,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Require Approval by Default"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"New posts will require approval before posting"})]}),e.jsx(le,{checked:n?.defaultApprovalRequired||!1,onCheckedChange:m=>u.mutate({defaultApprovalRequired:m}),"data-testid":"switch-default-approval"})]})]})]})})}export{Us 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.