PageSourceSearch

https://smartmanageai.ai/assets/social-media-CsJ3Ov8F.js

js smartmanageai.ai collected 2026-10-05 15:07:40 UTC 54,933 bytes, 5 lines download raw bytes

1import{j as e,r as j}from"./vendor-react-DKbe1Umz.js";import{u as B,a as D}from"./vendor-data-CjSe2wkl.js";import{dt as Ve,du as He,dv as We,dw as Xe,dx as Je,dy as Ze,aG as J,C as U,v as Q,s as ue,t as me,l as M,u as le,q as v,o as R,ba as es,w as ss,M as ce,N as oe,B as g,Q as de,K as fe,L as E,I as L,S as se,g as ae,h as te,i as ne,j as S,T as be,D as Re,c as Me,d as Le,e as Oe,f as Fe,n as Ke,U as as,V as ts,W as ns,X as _,Y as Te,cM as is,dz as ls,au as rs,av as cs,aw as os}from"./index-DZ74KeH3.js";import{bI as he,ay as pe,cd as $e,cV as Ne,cD as ve,i as ye,az as ds,$ as qe,gm as us,cR as ms,fw as hs,dl as _e,Y as xs,c0 as K,j as Ue,gn as Pe,J as Qe,av as Ee,E as ze,cr as ps,n as gs,dv as js,cZ as Ge,b5 as fs,dc as vs,b3 as ge,au as xe,Z as bs,o as Ns,b8 as Ye,dB as ys,fc as ws,d4 as Ae,d9 as Cs,bT as ks,bA as Ss,aS as Ts,k as Ps,a8 as Es,dd as As}from"./vendor-ui-DMaW9-Ov.js";import{g as Is,h as Ds,s as Rs,e as Ms,y as Ls,n as Os,a as ee,o as Fs,q as Ks,i as $s}from"./vendor-dates-5UNeOyFW.js";import"./vendor-charts-DWX9qznF.js";import"./vendor-forms-C2vWC2ab.js";const ie=[{value:"FACEBOOK",label:"Facebook",icon:Ve,color:"#1877F2"},{value:"INSTAGRAM",label:"Instagram",icon:He,color:"#E4405F"},{value:"LINKEDIN",label:"LinkedIn",icon:We,color:"#0A66C2"},{value:"TWITTER",label:"X (Twitter)",icon:()=>e.jsx("span",{className:"font-bold text-sm",children:"𝕏"}),color:"#000000"},{value:"TIKTOK",label:"TikTok",icon:Xe,color:"#000000"},{value:"YOUTUBE",label:"YouTube",icon:Je,color:"#FF0000"},{value:"PINTEREST",label:"Pinterest",icon:Ze,color:"#BD081C"}],Be={TWITTER:280,LINKEDIN:1300,INSTAGRAM:2200,FACEBOOK:63206,TIKTOK:2200,YOUTUBE:5e3,PINTEREST:500},qs={DRAFT:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300",PENDING_APPROVAL:"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300",APPROVED:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300",SCHEDULED:"bg-purple-100 text-purple-700 dark:bg-purple-900 dark:text-purple-300",QUEUED:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900 dark:text-indigo-300",POSTED:"bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300",FAILED:"bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-300"};function F(s){return ie.find(p=>p.value===s)||ie[0]}function _s(){const{data:s,isLoading:p}=B({queryKey:["/api/social/stats"]});if(p)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[1,2,3,4].map(i=>e.jsx(J,{className:"h-28"},i))});const r=[{label:"Total Posts",value:(s==null?void 0:s.total)||0,icon:he,color:"text-blue-600"},{label:"Scheduled",value:(s==null?void 0:s.scheduled)||0,icon:pe,color:"text-purple-600"},{label:"Published This Month",value:(s==null?void 0:s.publishedThisMonth)||0,icon:$e,color:"text-green-600"},{label:"Drafts",value:(s==null?void 0:s.drafts)||0,icon:Ne,color:"text-gray-600"},{label:"Pending Approval",value:(s==null?void 0:s.pendingApproval)||0,icon:ve,color:"text-amber-600"},{label:"Failed",value:(s==null?void 0:s.failed)||0,icon:ye,color:"text-red-600"},{label:"Published This Week",value:(s==null?void 0:s.publishedThisWeek)||0,icon:ds,color:"text-emerald-600"},{label:"Connected Accounts",value:(s==null?void 0:s.connectedAccounts)||0,icon:qe,color:"text-indigo-600"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:r.map((i,u)=>e.jsx(U,{children:e.jsx(Q,{className:"pt-4 pb-3 px-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:i.label}),e.jsx("p",{className:"text-2xl font-bold mt-1","data-testid":`stat-${i.label.toLowerCase().replace(/\s/g,"-")}`,children:i.value})]}),e.jsx(i.icon,{className:`h-5 w-5 ${i.color}`})]})})},u))}),(s==null?void 0:s.totalEngagement)&&(s.totalEngagement.likes>0||s.totalEngagement.comments>0||s.totalEngagement.shares>0||s.totalEngagement.reach>0)&&e.jsxs(U,{children:[e.jsx(ue,{className:"pb-3",children:e.jsx(me,{className:"text-base",children:"Engagement"})}),e.jsx(Q,{children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Total Likes",value:s.totalEngagement.likes,icon:us,color:"text-rose-500"},{label:"Total Comments",value:s.totalEngagement.comments,icon:ms,color:"text-blue-500"},{label:"Total Shares",value:s.totalEngagement.shares,icon:hs,color:"text-green-500"},{label:"Total Reach",value:s.totalEngagement.reach,icon:ve,color:"text-purple-500"}].map(i=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border","data-testid":`engagement-${i.label.toLowerCase().replace(/\s/g,"-")}`,children:[e.jsx(i.icon,{className:`h-5 w-5 ${i.color}`}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:i.label}),e.jsx("p",{className:"text-lg font-bold",children:i.value.toLocaleStr
1ing()})]})]},i.label))})})]}),(s==null?void 0:s.byPlatform)&&Object.keys(s.byPlatform).length>0&&e.jsxs(U,{children:[e.jsx(ue,{className:"pb-3",children:e.jsx(me,{className:"text-base",children:"Posts by Platform"})}),e.jsx(Q,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:Object.entries(s.byPlatform).map(([i,u])=>{const x=F(i),h=x.icon;return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border","data-testid":`platform-count-${i.toLowerCase()}`,children:[e.jsx(h,{className:"h-4 w-4",style:{color:x.color}}),e.jsx("span",{className:"text-sm font-medium",children:x.label}),e.jsx(M,{variant:"secondary",className:"text-xs",children:u})]},i)})})})]})]})}function Ie(){const{toast:s}=le(),{data:p,isLoading:r}=B({queryKey:["/api/social/accounts"]}),{data:i}=B({queryKey:["/api/social/auth/platform-status"]});j.useEffect(()=>{const n=new URLSearchParams(window.location.search),o=n.get("connected"),k=n.get("error");if(o){const w=F(o);s({title:`${w.label} Connected`,description:`Your ${w.label} account was successfully connected.`}),v.invalidateQueries({queryKey:["/api/social/accounts"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),window.history.replaceState({},"","/social-media")}k&&(s({title:"Connection Failed",description:{facebook_denied:"Facebook connection was cancelled.",facebook_failed:"Facebook connection failed. Please try again.",facebook_not_configured:"Facebook app credentials are not configured yet.",linkedin_denied:"LinkedIn connection was cancelled.",linkedin_failed:"LinkedIn connection failed. Please try again.",linkedin_not_configured:"LinkedIn app credentials are not configured yet.",twitter_denied:"Twitter/X connection was cancelled.",twitter_failed:"Twitter/X connection failed. Please try again.",twitter_not_configured:"Twitter/X app credentials are not configured yet.",tiktok_denied:"TikTok connection was cancelled.",tiktok_failed:"TikTok connection failed. Please try again.",tiktok_not_configured:"TikTok app credentials are not configured. Contact your admin to set up TikTok integration.",youtube_denied:"YouTube connection was cancelled.",youtube_failed:"YouTube connection failed. Please try again.",youtube_not_configured:"YouTube/Google API credentials are not configured. Contact your admin to set up YouTube integration.",pinterest_denied:"Pinterest connection was cancelled.",pinterest_failed:"Pinterest connection failed. Please try again.",pinterest_not_configured:"Pinterest app credentials are not configured. Contact your admin to set up Pinterest integration."}[k]||"Social account connection failed.",variant:"destructive"}),window.history.replaceState({},"","/social-media"))},[s]);const u=D({mutationFn:async n=>R("DELETE",`/api/social/accounts/${n}`),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/social/accounts"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),s({title:"Account disconnected"})},onError:n=>s({title:"Error",description:n.message,variant:"destructive"})}),x=D({mutationFn:async n=>(await R("POST",`/api/social/accounts/${n}/refresh`)).json(),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/social/accounts"]}),s({title:"Token refreshed",description:"Account token has been renewed."})},onError:n=>s({title:"Refresh failed",description:n.message,variant:"destructive"})}),h=n=>p==null?void 0:p.find(o=>o.platform===n),t=n=>{switch(n){case"FACEBOOK":return"/api/social/auth/facebook";case"INSTAGRAM":return"/api/social/auth/facebook";case"LINKEDIN":return"/api/social/auth/linkedin";case"TWITTER":return"/api/social/auth/twitter";case"TIKTOK":return"/api/social/auth/tiktok";case"YOUTUBE":return"/api/social/auth/youtube";case"PINTEREST":return"/api/social/auth/pinterest";default:return null}},d=n=>i?i[n]??!1:!1;return e.jsx(es,{children:e.jsxs(U,{children:[e.jsxs(ue,{className:"pb-3",children:[e.jsxs(me,{className:"text-base flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),"Connected Accounts"]}),e.jsx(ss,{children:"Connect your social media accounts to enable publishing"})]}),e.jsxs(Q,{children:[r?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[1,2,3,4].map(n=>e.jsx(J,{className:"h-24"},n))}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-3",children:ie.map(n=>{const o=h(n.value),k=n.icon,w=(o==null?void 0:o.status)==="CONNECTED",C=(o==null?void 0:o.status)==="EXPIRED",m=t(n.value),f=d(n.value),y=!m;return e.jsxs("div",{className:`flex flex-col items-center gap-2 p-3 rounded-lg border transition-colors ${w?"border-green-200 bg-green-50/50 dark:border-green-900 dark:bg-green-950/30":C?"border-amber-200 bg-amber-50/50 dark:border-amber-900 dark:bg-amber-950/30":"border-dashed"}`,"data-testid":`account-${n.value.toLowerCase()}`,children:[e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("div",{style:{color:w?n.color:void 0},className:w?"":"text-muted-foreground",children:e.jsx(k,{className:"h-6 w-6"})}),e.jsx("span",{className:"text-xs font-medium text-center leading-tight",children:n.label})]}),w?e.jsxs("div",{className:"flex flex-col items-center gap-1.5 w-full",children:[e.jsxs(M,{variant:"outline",className:"text-xs text-green-600 border-green-300 gap-1 px-1.5 py-0",children:[e.jsx(xs,{className:"h-3 w-3"}),"Connected"]}),(o==null?void 0:o.accountName)&&e.jsx("span",{className:"text-xs text-muted-foreground truncate w-full text-center",title:o.accountName,children:o.accountName}),e.jsxs("div",{className:"flex gap-1 w-full",children:[e.jsxs(ce,{children:[e.jsx(oe,{asChild:!0,children:e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 px-1.5 flex-1 text-xs",onClick:()=>x.mutate(o.id),disabled:x.isPending,"data-testid":`button-refresh-${n.value.toLowerCase()}`,children:x.isPending?e.jsx(K,{className:"h-3 w-3 animate-spin"}):e.jsx(Ue,{className:"h-3 w-3"})})}),e.jsx(de,{children:e.jsx("p",{children:"Refresh token"})})]}),e.jsxs(ce,{children:[e.jsx(oe,{asChild:!0,children:e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 px-1.5 flex-1 text-xs text-red-500 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-950",onClick:()=>u.mutate(o.id),disabled:u.isPending,"data-testid":`button-disconnect-${n.value.toLowerCase()}`,children:u.isPending?e.jsx(K,{className:"h-3 w-3 animate-spin"}):e.jsx(Pe,{className:"h-3 w-3"})})}),e.jsx(de,{children:e.jsx("p",{children:"Disconnect"})})]})]})]}):C?e.jsxs("div",{className:"flex flex-col items-center gap-1.5 w-full",children:[e.jsxs(M,{variant:"outline",className:"text-xs text-amber-600 border-amber-300 gap-1 px-1.5 py-0",children:[e.jsx(Qe,{className:"h-3 w-3"}),"Expired"]}),e.jsxs("div",{className:"flex gap-1 w-full",children:[m&&e.jsx(g,{variant:"outline",size:"sm",className:"h-6 px-1.5 flex-1 text-xs",onClick:()=>{window.location.href=m},"data-testid":`button-reconnect-${n.value.toLowerCase()}`,children:"Reconnect"}),e.jsxs(ce,{children:[e.jsx(oe,{asChild:!0,children:e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-xs text-red-500 hover:text-red-600",onClick:()=>u.mutate(o.id),disabled:u.isPending,"data-testid":`button-remove-${n.value.toLowerCase()}`,children:e.jsx(Pe,{className:"h-3 w-3"})})}),e.jsx(de,{children:e.jsx("p",{children:"Remove"})})]})]})]}):y?e.jsxs(M,{variant:"outline",className:"text-xs text-muted-foreground gap-1 px-1.5 py-0 cursor-default",children:[e.jsx(Ee,{className:"h-3 w-3"}),"Not supported"]}):f?e.jsxs(g,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs w-full gap-1",onClick:()=>{window.location.href=m},"data-testid":`button-connect-${n.value.toLowerCase()}`,children:[e.jsx(ze,{className:"h-3 w-3"}),"Connect"]}):e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsxs(M,{variant:"outline",className:"text-xs text-amber-600 border-amber-300 gap-1 px-1.5 py-0 cursor-default",children:[e.jsx(Ee,{className:"h-3 w-3"}),"Setup Needed"]})}),e.jsx(de,{side:"bottom",className:"max-w-[200px]",children:e.jsxs("p",{children:[n.label," API credentials not configured. Add them in environment settings to enable OAuth."]})})]})]},n.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Clicking Connect redirects you to the platform's authorization page. All tokens are stored encrypted."})]})]})})}function Us({posts:s,currentDate:p,onDateChange:r,onEdit:i,onCreateForDate:u}
1){const x=Is(p),h=Ds(p),t=Rs(x),d=Ms(h),n=Ls({start:t,end:d});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:()=>r(Os(p,1)),"data-testid":"cal-prev-month",children:e.jsx(ps,{className:"h-4 w-4"})}),e.jsx("h3",{className:"text-lg font-semibold","data-testid":"cal-current-month",children:ee(p,"MMMM yyyy")}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>r(Fs(p,1)),"data-testid":"cal-next-month",children:e.jsx(gs,{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(o=>e.jsx("div",{className:"bg-muted py-2 text-center text-xs font-medium text-muted-foreground",children:o},o)),n.map((o,k)=>{const w=ee(o,"yyyy-MM-dd"),C=s[w]||[],m=Ks(o,p),f=$s(o);return e.jsxs("div",{className:`bg-background min-h-[100px] p-1.5 cursor-pointer hover:bg-muted/50 transition-colors ${m?"":"opacity-40"} ${f?"ring-2 ring-primary ring-inset":""}`,onClick:()=>u==null?void 0:u(o),"data-testid":`cal-day-${w}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:`text-xs font-medium ${f?"text-primary":"text-muted-foreground"}`,children:ee(o,"d")}),C.length>0&&e.jsx(M,{variant:"secondary",className:"text-[10px] h-4 px-1",children:C.length})]}),e.jsxs("div",{className:"space-y-0.5",children:[C.slice(0,3).map(y=>{const T=F(y.platform||"FACEBOOK"),A=T.icon;return e.jsxs("div",{className:"flex items-center gap-1 px-1 py-0.5 rounded text-[10px] truncate cursor-pointer hover:bg-muted",style:{backgroundColor:T.color+"15",color:T.color},onClick:b=>{b.stopPropagation(),i(y)},"data-testid":`cal-post-${y.id}`,children:[e.jsx(A,{className:"h-2.5 w-2.5 shrink-0"}),e.jsx("span",{className:"truncate",children:y.title||y.content.substring(0,20)})]},y.id)}),C.length>3&&e.jsxs("div",{className:"text-[10px] text-muted-foreground text-center",children:["+",C.length-3," more"]})]})]},k)})]})]})}function Qs({platform:s,content:p,hashtags:r,mediaUrls:i}){const u=F(s),x=u.icon,h=p+(r.length>0?`
2
3`+r.map(n=>`#${n}`).join(" "):""),t=Be[s]||5e3,d=h.length>t;return s==="TWITTER"?e.jsxs("div",{className:"rounded-xl border p-4 max-w-sm bg-background",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center shrink-0",children:e.jsx(x,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm font-bold",children:"Your Company"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"@company · now"})]}),e.jsx("p",{className:`text-sm mt-1 whitespace-pre-wrap ${d?"text-destructive":""}`,children:h||"Your tweet will appear here..."}),i.length>0&&e.jsx("div",{className:`mt-2 grid gap-1 ${i.length===1?"grid-cols-1":"grid-cols-2"} rounded-xl overflow-hidden`,children:i.slice(0,4).map((n,o)=>e.jsx("img",{src:n,alt:"",className:"w-full h-32 object-cover"},o))}),e.jsx("div",{className:"flex justify-between mt-3 text-muted-foreground max-w-[250px]",children:["💬","🔁","❤️","📤"].map((n,o)=>e.jsx("span",{className:"text-xs",children:n},o))})]})]}),e.jsxs("p",{className:`text-xs mt-2 ${d?"text-destructive font-medium":"text-muted-foreground"}`,children:[h.length,"/",t]})]}):s==="INSTAGRAM"?e.jsxs("div",{className:"rounded-xl border max-w-sm bg-background overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-tr from-yellow-400 via-pink-500 to-purple-600 p-0.5",children:e.jsx("div",{className:"w-full h-full rounded-full bg-background flex items-center justify-center",children:e.jsx(x,{className:"h-3.5 w-3.5",style:{color:u.color}})})}),e.jsx("span",{className:"text-xs font-semibold",children:"your_company"})]}),e.jsx("div",{className:"aspect-square bg-muted flex items-center justify-center",children:i.length>0?e.jsx("img",{src:i[0],alt:"",className:"w-full h-full object-cover"}
3):e.jsx(js,{className:"h-12 w-12 text-muted-foreground/30"})}),e.jsxs("div",{className:"px-3 py-2",children:[e.jsx("div",{className:"flex gap-3 mb-2 text-lg",children:"❤️ 💬 📤"}),e.jsxs("p",{className:"text-xs",children:[e.jsx("strong",{children:"your_company"})," ",p||"Caption..."]}),r.length>0&&e.jsx("p",{className:"text-xs text-blue-500 mt-1",children:r.map(n=>`#${n}`).join(" ")})]})]}):s==="LINKEDIN"?e.jsxs("div",{className:"rounded-xl border max-w-md bg-background p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-muted flex items-center justify-center",children:e.jsx(x,{className:"h-6 w-6",style:{color:u.color}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Your Company"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Construction · Just now"})]})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:h||"Your post will appear here..."}),i.length>0&&e.jsx("div",{className:"mt-3 rounded-lg overflow-hidden border",children:e.jsx("img",{src:i[0],alt:"",className:"w-full h-48 object-cover"})}),e.jsx(fe,{className:"my-3"}),e.jsx("div",{className:"flex justify-around text-xs text-muted-foreground",children:["👍 Like","💬 Comment","🔁 Repost","📤 Send"].map(n=>e.jsx("span",{children:n},n))})]}):e.jsxs("div",{className:"rounded-xl border max-w-md bg-background p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center",children:e.jsx(x,{className:"h-5 w-5",style:{color:u.color}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Your Company"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Just now · 🌐"})]})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:h||"Your post will appear here..."}),i.length>0&&e.jsx("div",{className:`mt-3 grid gap-1 ${i.length===1?"grid-cols-1":"grid-cols-2"} rounded-lg overflow-hidden`,children:i.slice(0,4).map((n,o)=>e.jsx("img",{src:n,alt:"",className:"w-full h-40 object-cover"},o))}),e.jsx(fe,{className:"my-3"}),e.jsx("div",{className:"flex justify-around text-xs text-muted-foreground",children:["👍 Like","💬 Comment","↗ Share"].map(n=>e.jsx("span",{children:n},n))}),d&&e.jsxs("p",{className:"text-xs text-destructive mt-2",children:[h.length,"/",t," characters"]})]})}function zs({mediaUrls:s,onMediaUrlsChange:p}){const{toast:r}=le(),[i,u]=j.useState(""),[x,h]=j.useState("none"),[t,d]=j.useState(""),[n,o]=j.useState(!1),k=j.useRef(null),w=D({mutationFn:async m=>(await R("POST","/api/social/posts/generate-image",{prompt:m})).json(),onSuccess:m=>{m.imageUrl&&(p([...s,m.imageUrl]),d(""),h("none"),v.invalidateQueries({queryKey:["/api/website/media"]}),r({title:"Image generated"}))},onError:m=>r({title:"Image generation failed",description:m.message,variant:"destructive"})}),C=async m=>{if(!m.type.startsWith("image/")){r({title:"Invalid file type",description:"Only image files are supported.",variant:"destructive"});return}if(m.size>10*1024*1024){r({title:"File too large",description:"Maximum file size is 10MB.",variant:"destructive"});return}o(!0);try{const f=new FormData;f.append("file",m);const y=await fetch("/api/social/upload-media",{method:"POST",body:f,credentials:"include"});if(!y.ok){const A=await y.json().catch(()=>({error:"Upload failed"}));r({title:"Upload failed",description:A.error,variant:"destructive"});return}const T=await y.json();T.url&&(p([...s,T.url]),v.invalidateQueries({queryKey:["/api/website/media"]}),r({title:"Image uploaded"}))}catch{r({title:"Upload failed",variant:"destructive"})}finally{o(!1)}};return e.jsxs("div",{children:[e.jsxs(E,{children:["Media (",s.length,"/4)"]}),s.length>0&&e.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:s.map((m,f)=>e.jsxs("div",{className:"relative w-16 h-16 rounded-lg border overflow-hidden group",children:[e.jsx("img",{src:m,alt:"",className:"w-full h-full object-cover"}),e.jsx("button",{className:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center",onClick:()=>p(s.filter((y,T)=>T!==f)),"data-testid":`remove-media-${f}`,children:e.jsx(Ge,{className:"h-4 w-4 text-white"})})]},f))}),s.length<4&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:k,type:"file",accept:"image/*",className:"hidden",onChange:m=>{var y;const f=(y=m.target.files)==null?void 0:y[0];f&&C(f),m.target.value=""},"data-testid":"input-social-upload-file"}),e.jsxs(g,{variant:"outline",size:"sm",type:"button",className:"gap-1.5",onClick:()=>{var m;return(m=k.current)==null?void 0:m.click()},disabled:n,"data-testid":"button-upload-media",children:[n?e.jsx(K,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(fs,{className:"h-3.5 w-3.5"}),"Upload"]}),e.jsxs(g,{variant:x==="url"?"secondary":"outline",size:"sm",type:"button",className:"gap-1.5",onClick:()=>h(x==="url"?"none":"url"),"data-testid":"button-media-url-toggle",children:[e.jsx(_e,{className:"h-3.5 w-3.5"}),"URL"]}),e.jsxs(g,{variant:x==="ai"?"secondary":"outline",size:"sm",type:"button",className:"gap-1.5",onClick:()=>h(x==="ai"?"none":"ai"),"data-testid":"button-media-ai-toggle",children:[e.jsx(vs,{className:"h-3.5 w-3.5"}),"Generate"]})]}),x==="url"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{placeholder:"Paste an image URL...",value:i,onChange:m=>u(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),i.trim()&&(p([...s,i.trim()]),u("")))},"data-testid":"input-media-url"}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>{i.trim()&&(p([...s,i.trim()]),u(""))},disabled:!i.trim(),"data-testid":"button-add-media-url",children:e.jsx(ge,{className:"h-4 w-4"})})]}),x==="ai"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{placeholder:"Describe the image you want...",value:t,onChange:m=>d(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),t.trim().length>=3&&w.mutate(t.trim()))},"data-testid":"input-ai-image-prompt"}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>w.mutate(t.trim()),disabled:w.isPending||t.trim().length<3,"data-testid":"button-generate-image",children:w.isPending?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(xe,{className:"h-4 w-4"})})]})]})]})}function Gs({scheduleMode:s,scheduledAt:p,isRecurring:r,recurringFrequency:i,recurringInterval:u,notes:x,hashtags:h,hashtagInput:t,campaignTag:d,onScheduleModeChange:n,onScheduledAtChange:o,onIsRecurringChange:k,onRecurringFrequencyChange:w,onRecurringIntervalChange:C,onNotesChange:m,onHashtagsChange:f,onHashtagInputChange:y,onCampaignTagChange:T}){const A=()=>{const b=t.trim().replace(/^#/,"");b&&!h.includes(b)&&(f([...h,b]),y(""))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(E,{children:"Hashtags"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(L,{placeholder:"Add hashtag...",value:t,onChange:b=>y(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),A())},"data-testid":"input-hashtag"}),e.jsx(g,{variant:"outline",size:"sm",onClick:A,"data-testid":"button-add-hashtag",children:e.jsx(ge,{className:"h-4 w-4"})})]}),h.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:h.map((b,I)=>e.jsxs(M,{variant:"secondary",className:"text-xs cursor-pointer",onClick:()=>f(h.filter((V,z)=>z!==I)),children:["#",b," ×"]},I))})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Campaign Tag"}),e.jsx(L,{placeholder:"e.g. Spring 2026 Campaign",value:d,onChange:b=>T(b.target.value),"data-testid":"input-campaign"})]}),e.jsx(fe,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{className:"font-medium",children:"Scheduling"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{variant:s==="now"?"default":"outline",size:"sm",onClick:()=>n("now"),"data-testid":"btn-schedule-now",children:"Save as Draft"}),e.jsxs(g,{variant:s==="schedule"?"default":"outline",size:"sm",onClick:()=>n("schedule"),"data-testid":"btn-schedule-later",children:[e.jsx(pe,{className:"h-4 w-4 mr-1"}),"Schedule"]})]}),s==="schedule"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(E,{children:"Schedule Date & Time"}),e.jsx(L,{type:"datetime-local",value:p,onChange:b=>o(b.target.value),"data-testid":"input-schedule-date"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"recurring",checked:r,onChange:b=>k(b.target.checked),className:"rounded","data-testid":"checkbox-recurring"}),e.jsx(E,{htmlFor:"recurring",className:"text-sm cursor-pointer",children:"Recurring post"})]}),r&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(se,{value:i,onValueChange:w,children:[e.jsx(ae,{className:"w-32","data-testid":"select-recurring-freq",children:e.jsx(te,{})}),e.jsxs(ne,{children:[e.jsx(S,{value:"daily",children:"Daily"}),e.jsx(S,{value:"weekly",children:"Weekly"}),e.jsx(S,{value:"monthly",children:"Monthly"})]})]}),e.jsx("span",{className:"text-sm text-muted-foreground self-center",children:"every"}),e.jsx(L,{type:"number",min:1,max:30,value:u,onChange:b=>C(parseInt(b.target.value)||1),className:"w-16","data-testid":"input-recurring-interval"}),e.jsx("span",{className:"text-sm text-muted-foreground self-center",children:i==="daily"?"day(s)":i==="weekly"?"week(s)":"month(s)"})]})]})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Internal Notes"}),e.jsx(be,{placeholder:"Any internal notes about this post...",value:x,onChange:b=>
3m(b.target.value),className:"min-h-[60px]","data-testid":"input-post-notes"})]})]})}function Ys({platform:s,tone:p,onContentGenerated:r}){const{toast:i}=le(),[u,x]=j.useState(""),[h,t]=j.useState(null),d=D({mutationFn:async()=>(await R("POST","/api/social/posts/generate",{platform:s,topic:u,tone:p})).json(),onSuccess:n=>{t(n),r(n),i({title:"AI content generated"})},onError:n=>i({title:"Generation failed",description:n.message,variant:"destructive"})});return e.jsxs("div",{className:"p-3 rounded-lg border bg-muted/30 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4 text-amber-500"}),e.jsx("span",{className:"text-sm font-medium",children:"AI Content Generator"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{placeholder:"Enter a topic for AI to generate content...",value:u,onChange:n=>x(n.target.value),"data-testid":"input-ai-topic"}),e.jsx(g,{variant:"outline",onClick:()=>d.mutate(),disabled:d.isPending||!u.trim(),"data-testid":"button-generate-ai",children:d.isPending?e.jsx(K,{className:"h-4 w-4 animate-spin"}):e.jsx(xe,{className:"h-4 w-4"})})]}),h&&e.jsxs("div",{className:"space-y-2 text-xs",children:[h.bestTimeToPost&&e.jsxs("p",{children:[e.jsx("strong",{children:"Best time:"})," ",h.bestTimeToPost]}),h.engagementTips&&e.jsxs("p",{children:[e.jsx("strong",{children:"Tips:"})," ",h.engagementTips]})]})]})}function Bs({open:s,onClose:p,editingPost:r,prefilledDate:i}){const{toast:u}=le(),{data:x}=B({queryKey:["/api/social/auth/platform-status"]}),h=()=>({title:"",content:"",platforms:["FACEBOOK"],status:"DRAFT",hashtags:[],hashtagInput:"",scheduledAt:"",campaignTag:"",tone:"professional",notes:"",isRecurring:!1,recurringFrequency:"weekly",recurringInterval:1,utmSource:"",utmMedium:"social",utmCampaign:"",scheduleMode:"now",mediaUrls:[],socialAccountId:""}),[t,d]=j.useState(h()),[n,o]=j.useState(!1),[k,w]=j.useState(!1),[C,m]=j.useState(!1),f=j.useRef(null);j.useEffect(()=>{if(!C)return;const a=l=>{f.current&&!f.current.contains(l.target)&&m(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[C]);const{data:y}=B({queryKey:["/api/social/accounts"],enabled:s}),T=j.useMemo(()=>y?y.filter(a=>t.platforms.includes(a.platform)&&a.status==="CONNECTED"):[],[y,t.platforms]),A=!!r,b=s?((r==null?void 0:r.id)||"new")+((i==null?void 0:i.toISOString())||""):"";j.useEffect(()=>{var a,l;if(s){if(r)d({title:r.title||"",content:r.content||"",platforms:r.platforms&&r.platforms.length>0?r.platforms:r.platform?[r.platform]:["FACEBOOK"],status:r.status,hashtags:r.hashtags||[],hashtagInput:"",scheduledAt:r.scheduledAt?new Date(r.scheduledAt).toISOString().slice(0,16):"",campaignTag:r.campaignTag||"",tone:r.tone||"professional",notes:r.notes||"",isRecurring:r.isRecurring||!1,recurringFrequency:((a=r.recurringPattern)==null?void 0:a.frequency)||"weekly",recurringInterval:((l=r.recurringPattern)==null?void 0:l.interval)||1,utmSource:"",utmMedium:"social",utmCampaign:"",scheduleMode:r.scheduledAt?"schedule":"now",mediaUrls:r.mediaUrls||[],socialAccountId:r.socialAccountId||""});else if(i){const P=new Date(i.getFullYear(),i.getMonth(),i.getDate(),9,0).toISOString().slice(0,16);d({...h(),scheduledAt:P,scheduleMode:"schedule"})}else d(h());o(!1),w(!1),m(!1)}},[b]);const I=j.useMemo(()=>x?t.platforms.filter(a=>!(x[a]??!1)):[],[t.platforms,x]),V=t.platforms.length>0?Math.min(...t.platforms.map(a=>Be[a]||5e3)):5e3,z=t.content.length,G=z>V,H=D({mutationFn:async a=>(await R("POST","/api/social/posts",a)).json(),onSuccess:a=>{v.invalidateQueries({queryKey:["/api/social/posts"]}),v.invalidateQueries({queryKey:["/api/social/calendar"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),u({title:"Post created"}),a!=null&&a.warning&&u({title:"Note",description:a.warning}),p()},onError:a=>u({title:"Error",description:a.message,variant:"destructive"})}),Y=D({mutationFn:async a=>R("PATCH",`/api/social/posts/${r.id}`,a),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/social/posts"]}),v.invalidateQueries({queryKey:["/api/social/calendar"]}
3),v.invalidateQueries({queryKey:["/api/social/stats"]}),u({title:"Post updated"}),p()},onError:a=>u({title:"Error",description:a.message,variant:"destructive"})}),W=a=>{if(t.platforms.length===0){u({title:"Select at least one platform",variant:"destructive"});return}if(a==="SCHEDULED"&&!t.socialAccountId&&T.length>0){u({title:"Please select an account",description:"Select which connected account to publish to before scheduling.",variant:"destructive"});return}const l={title:t.title||null,content:t.content,platform:t.platforms[0]||null,platforms:t.platforms,status:a,hashtags:t.hashtags.length>0?t.hashtags:null,campaignTag:t.campaignTag||null,tone:t.tone,notes:t.notes||null,isRecurring:t.isRecurring,utmSource:t.utmSource||null,utmMedium:t.utmMedium||null,utmCampaign:t.utmCampaign||null,mediaUrls:t.mediaUrls.length>0?t.mediaUrls:null,socialAccountId:t.socialAccountId||null};t.scheduleMode==="schedule"&&t.scheduledAt&&(l.scheduledAt=new Date(t.scheduledAt).toISOString(),a==="DRAFT"&&(l.status="SCHEDULED")),t.isRecurring&&(l.recurringPattern={frequency:t.recurringFrequency,interval:t.recurringInterval}),A?Y.mutate(l):(l.aiGenerated=n,l.aiPrompt=null,H.mutate(l))},Z=()=>{const a=t.hashtagInput.trim().replace(/^#/,"");a&&!t.hashtags.includes(a)&&d(l=>({...l,hashtags:[...l.hashtags,a],hashtagInput:""}))},O=H.isPending||Y.isPending;return e.jsx(Re,{open:s,onOpenChange:a=>{a||p()},children:e.jsxs(Me,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Le,{children:[e.jsx(Oe,{children:A?"Edit Post":"Create New Post"}),e.jsx(Fe,{children:A?"Update your social media post":"Create and schedule a social media post"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(E,{children:"Platforms"}),e.jsxs("div",{className:"relative",ref:f,children:[e.jsxs("button",{type:"button",className:"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm r
3ing-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onClick:()=>m(!C),"data-testid":"select-platform",children:[e.jsxs("span",{className:"flex items-center gap-1 overflow-hidden",children:[t.platforms.length===0?e.jsx("span",{className:"text-muted-foreground",children:"Select platforms..."}):t.platforms.slice(0,3).map(a=>{const l=F(a),P=l.icon;return e.jsx(P,{className:"h-4 w-4 shrink-0",style:{color:l.color}},a)}),t.platforms.length>3&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-1",children:["+",t.platforms.length-3]})]}),e.jsx(bs,{className:"h-4 w-4 shrink-0 opacity-50"})]}),C&&e.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-md border bg-popover p-1 shadow-md",children:ie.map(a=>{const l=a.icon,P=t.platforms.includes(a.value),$=x?x[a.value]??!1:!0;return e.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent hover:text-accent-foreground",onClick:()=>{d(q=>{const X=P?q.platforms.filter(re=>re!==a.value):[...q.platforms,a.value];return{...q,platforms:X.length===0?q.platforms:X}})},"data-testid":`platform-option-${a.value.toLowerCase()}`,children:[e.jsx("div",{className:`flex h-4 w-4 items-center justify-center rounded-sm border ${P?"bg-primary border-primary":"border-muted-foreground/30"}`,children:P&&e.jsx(Ns,{className:"h-3 w-3 text-primary-foreground"})}),e.jsx(l,{className:"h-3.5 w-3.5",style:{color:a.color}}),e.jsx("span",{className:$?"":"text-muted-foreground",children:a.label}),!$&&e.jsx("span",{className:"ml-auto text-xs text-amber-500",children:"Not configured"})]},a.value)})})]}),I.length>0&&e.jsxs("div",{className:"flex items-start gap-2 mt-2 p-2 rounded-md bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800","data-testid":"platform-config-warning",children:[e.jsx(Qe,{className:"h-4 w-4 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:I.length===1?`${F(I[0]).label} API credentials are not configured. Posts to this platform will fail to publish.`:`${I.map(a=>F(a).label).join(", ")} API credentials are not configured. Posts to these platforms will fail to publish.`})]})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Tone"}),e.jsxs(se,{value:t.tone,onValueChange:a=>d(l=>({...l,tone:a})),children:[e.jsx(ae,{"data-testid":"select-tone",children:e.jsx(te,{})}),e.jsxs(ne,{children:[e.jsx(S,{value:"professional",children:"Professional"}),e.jsx(S,{value:"casual",children:"Casual"}),e.jsx(S,{value:"marketing",children:"Marketing"}),e.jsx(S,{value:"humorous",children:"Humorous"}),e.jsx(S,{value:"educational",children:"Educational"}),e.jsx(S,{value:"inspirational",children:"Inspirational"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Title (internal label)"}),e.jsx(L,{placeholder:"Give your post a name for easy reference",value:t.title,onChange:a=>d(l=>({...l,title:a.target.value})),"data-testid":"input-post-title"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{children:"Content"}),e.jsxs(g,{variant:"ghost",size:"sm",className:"h-6 text-xs",onClick:()=>w(!k),"data-testid":"toggle-preview",children:[e.jsx(ve,{className:"h-3 w-3 mr-1"}),k?"Edit":"Preview"]})]}),e.jsxs("span",{className:`text-xs ${G?"text-destructive font-medium":"text-muted-foreground"}`,children:[z,"/",V]})]}),k?e.jsx("div",{className:"flex justify-center p-4 bg-muted/30 rounded-lg min-h-[200px]",children:e.jsxs("div",{className:"w-full space-y-2",children:[t.platforms.length>1&&e.jsx("div",{className:"flex gap-1 justify-center mb-2",children:t.platforms.map(a=>{const l=F(a),P=l.icon;return e.jsxs(M,{variant:"outline",className:"text-xs",children:[e.jsx(P,{className:"h-3 w-3 mr-1",style:{color:l.color}}),l.label]},a)})}),e.jsx(Qs,{platform:t.platforms[0]||"FACEBOOK",content:t.content,hashtags:t.hashtags,mediaUrls:t.mediaUrls})]})}):e.jsx(be,{placeholder:"Write your post content...",value:t.content,onChange:a=>d(l=>({...l,content:a.target.value})),className:"min-h-[120px]","data-testid":"input-post-content"})]}),T.length>0&&e.jsxs("div",{children:[e.jsx(E,{children:"Post to Account"}),e.jsxs(se,{value:t.socialAccountId,onValueChange:a=>d(l=>({...l,socialAccountId:a})),children:[e.jsx(ae,{"data-testid":"select-account",children:e.jsx(te,{placeholder:"Select an account..."})}),e.jsxs(ne,{children:[e.jsx(S,{value:"",children:"No account selected"}),T.map(a=>e.jsx(S,{value:a.id,children:a.accountName||a.platform},a.id))]})]}),t.scheduleMode==="schedule"&&!t.socialAccountId&&e.jsx("p",{className:"text-xs text-amber-600 mt-1",children:"Select an account to enable publishing when scheduled"})]}),e.jsx(zs,{mediaUrls:t.mediaUrls,onMediaUrlsChange:a=>d(l=>({...l,mediaUrls:a}))}),e.jsx(Ys,{platform:t.platforms[0]||"FACEBOOK",tone:t.tone,onContentGenerated:a=>{o(!0),d(l=>({...l,content:a.content||l.content,hashtags:a.hashtags||l.hashtags,title:a.title||l.title}))}}),e.jsxs("div",{children:[e.jsx(E,{children:"Hashtags"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(L,{placeholder:"Add hashtag...",value:t.hashtagInput,onChange:a=>d(l=>({...l,hashtagInput:a.target.value})),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),Z())},"data-testid":"input-hashtag"}),e.jsx(g,{variant:"outline",size:"sm",onClick:Z,"data-testid":"button-add-hashtag",children:e.jsx(ge,{className:"h-4 w-4"})})]}),t.hashtags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:t.hashtags.map((a,l)=>e.jsxs(M,{variant:"secondary",className:"text-xs cursor-pointer",onClick:()=>d(P=>({...P,hashtags:P.hashtags.filter(($,q)=>q!==l)})),children:["#",a," ×"]},l))})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Campaign Tag"}),e.jsx(L,{placeholder:"e.g. Spring 2026 Campaign",value:t.campaignTag,onChange:a=>d(l=>({...l,campaignTag:a.target.value})),"data-testid":"input-campaign"})]}),e.jsx(Gs,{scheduleMode:t.scheduleMode,scheduledAt:t.scheduledAt,isRecurring:t.isRecurring,recurringFrequency:t.recurringFrequency,recurringInterval:t.recurringInterval,notes:t.notes,onScheduleModeChange:a=>d(l=>({...l,scheduleMode:a})),onScheduledAtChange:a=>d(l=>({...l,scheduledAt:a})),onIsRecurringChange:a=>d(l=>({...l,isRecurring:a})),onRecurringFrequencyChange:a=>d(l=>({...l,recurringFrequency:a})),onRecurringIntervalChange:a=>d(l=>({...l,recurringInterval:a})),onNotesChange:a=>d(l=>({...l,notes:a})),hashtags:t.hashtags,hashtagInput:t.hashtagInput,campaignTag:t.campaignTag,onHashtagsChange:a=>d(l=>({...l,hashtags:a})),onHashtagInputChange:a=>d(l=>({...l,hashtagInput:a})),onCampaignTagChange:a=>d(l=>({...l,campaignTag:a}))})]}),e.jsxs(Ke,{className:"gap-2 sm:gap-0",children:[e.jsx(g,{variant:"outline",onClick:p,children:"Cancel"}),e.jsxs(g,{variant:"outline",onClick:()=>W("DRAFT"),disabled:O||!t.content.trim()||G,"data-testid":"button-save-draft",children:[O?e.jsx(K,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Save as Draft"]}),e.jsxs(g,{variant:"outline",onClick:()=>W("PENDING_APPROVAL"),disabled:O||!t.content.trim()||G,"data-testid":"button-submit-for-approval",className:"border-amber-500 text-amber-600 hover:bg-amber-50 hover:text-amber-700 dark:border-amber-400 dark:text-amber-400 dark:hover:bg-amber-950",children:[O?e.jsx(K,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ye,{className:"h-4 w-4 mr-2"}),"Submit for Approval"]}),t.scheduleMode==="schedule"&&t.scheduledAt&&e.jsxs(g,{onClick:()=>W("SCHEDULED"),disabled:O||!t.content.trim()||G,"data-testid":"button-schedule-post",children:[O?e.jsx(K,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(pe,{className:"h-4 w-4 mr-2"}),"Schedule Post"]})]})]})})}function De({post:s,onEdit:p,onDelete:r,onPublish:i,onDuplicate:u,onReject:x,onApprove:h}){const t=F(s.platform||"FACEBOOK"),d=t.icon;return e.jsx(U,{className:"hover:shadow-md transition-shadow","data-testid":`post-card-${s.id}`,children:e.jsx(Q,{className:"pt-4 pb-3 px-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-2 rounded-lg border shrink-0",style:{borderColor:t.color+"40"},children:e.jsx(d,{className:"h-4 w-4",style:{color:t.color}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[s.title&&e.jsx("p",{className:"text-sm font-medium truncate",children:s.title}),e.jsx(M,{className:`text-xs shrink-0 ${qs[s.status]||""}`,variant:"secondary",children:s.status.replace(/_/g," ")}),s.aiGenerated&&e.jsxs(M,{variant:"outline",className:"text-xs shrink-0",children:[e.jsx(xe,{className:"h-3 w-3 mr-1"}),"AI"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:s.content}),s.mediaUrls&&s.mediaUrls.length>0&&e.jsxs("div",{className:"flex gap-1 mt-2",children:[s.mediaUrls.slice(0,4).map((n,o)=>e.jsx("div",{className:"w-10 h-10 rounded border overflow-hidden shrink-0",children:e.jsx("img",{src:n,alt:"",className:"w-full h-full object-cover"})},o)),s.mediaUrls.length>4&&e.jsxs("div",{className:"w-10 h-10 rounded border flex items-center justify-center text-xs text-muted-foreground",children:["+",s.mediaUrls.length-4]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-muted-foreground",children:[s.scheduledAt&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(pe,{className:"h-3 w-3"}),ee(new Date(s.scheduledAt),"MMM d, h:mm a")]}),s.publishedAt&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($e,{className:"h-3 w-3"}),ee(new Date(s.publishedAt),"MMM d, h:mm a")]}),s.campaignTag&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(he,{className:"h-3 w-3"}),s.campaignTag]}),s.hashtags&&s.hashtags.length>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ys,{className:"h-3 w-3"}),s.hashtags.length," tags"]}),s.externalPostUrl&&e.jsxs("a",{href:s.externalPostUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-primary hover:underline",onClick:n=>n.stopPropagation(),children:[e.jsx(ze,{className:"h-3 w-3"}),"View Post"]})]}),s.rejectionReason&&s.approvalStatus==="rejected"&&e.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-900 text-xs text-red-700 dark:text-red-400","data-testid":`rejection-reason-${s.id}`,children:[e.jsx("strong",{children:"Rejected:"})," ",s.rejectionReason]}),s.status==="FAILED"&&s.lastError&&e.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-900 text-xs text-red-700 dark:text-red-400",children:[e.jsx("strong",{children:"Error:"})," ",s.lastError]})]})]}),e.jsxs(as,{children:[e.jsx(ts,{asChild:!0,children:e.jsx(g,{variant:"ghost",size:"sm",className:"shrink-0","data-testid":`post-actions-${s.id}`,children:e.jsx(ws,{className:"h-4 w-4"})})}),e.jsxs(ns,{align:"end",children:[s.status!=="POSTED"&&e.jsxs(_,{onClick:()=>p(s),"data-testid":`edit-post-${s.id}`,children:[e.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Edit"]}),u&&e.jsxs(_,{onClick:()=>u(s.id),"data-testid":`duplicate-post-${s.id}`,children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Duplicate"]}),e.jsx(Te,{}),s.status==="PENDING_APPROVAL"&&h&&e.jsxs(_,{onClick:()=>h(s.id),className:"text-green-600 focus:text-green-600","data-testid":`approve-post-${s.id}`,children:[e.jsx(Cs,{className:"h-4 w-4 mr-2"}),"Approve"]}),s.status==="PENDING_APPROVAL"&&x&&e.jsxs(_,{onClick:()=>x(s.id),className:"text-amber-600 focus:text-amber-600","data-testid":`reject-post-${s.id}`,children:[e.jsx(ye,{className:"h-4 w-4 mr-2"}),"Reject"]}),s.status==="FAILED"&&i&&e.jsxs(_,{onClick:()=>i(s.id),className:"text-blue-600 focus:text-blue-600","data-testid":`publish-post-${s.id}`,children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"}),"Retry Publish"]}),s.status!=="POSTED"&&s.status!=="PENDING_APPROVAL"&&s.status!=="FAILED"&&i&&e.jsxs(_,{onClick:()=>i(s.id),"data-testid":`publish-post-${s.id}`,children:[e.jsx(Ye,{className:"h-4 w-4 mr-2"}),"Publish Now"]}),e.jsx(Te,{}),e.jsxs(_,{onClick:()=>{var n;navigator.clipboard.writeText(s.content+((n=s.hashtags)!=null&&n.length?`
4
5`+s.hashtags.map(o=>"#"+o).join(" "):""))},"data-testid":`copy-content-${s.id}`,children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Copy Content"]}),e.jsxs(_,{onClick:()=>r(s.id),className:"text-destructive focus:text-destructive","data-testid":`delete-post-${s.id}`,children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Delete"]})]})]})]})})})}function sa(){var we;const{toast:s}=le(),{status:p}=is(),r=ls(p),[i,u]=j.useState("dashboard"),[x,h]=j.useState(!1),[t,d]=j.useState(null),[n,o]=j.useState(new Date),[k,w]=j.useState("all"),[C,m]=j.useState("all"),[f,y]=j.useState(""),[T,A]=j.useState(null),[b,I]=j.useState(!1),[V,z]=j.useState(null),[G,H]=j.useState(""),Y=B({queryKey:["/api/social/posts",k,C],queryFn:async()=>{const c=new URLSearchParams;k!=="all"&&c.set("status",k),C!=="all"&&c.set("platform",C),c.set("limit","100");const N=await fetch(`/api/social/posts?${c}`,{credentials:"include"});if(!N.ok)throw new Error("Failed to fetch posts");return N.json()}}),W=B({queryKey:["/api/social/calendar",n.getMonth()+1,n.getFullYear()],queryFn:async()=>{const c=await fetch(`/api/social/calendar?month=${n.getMonth()+1}&year=${n.getFullYear()}`,{credentials:"include"});if(!c.ok)throw new Error("Failed to fetch calendar");return c.json()},enabled:i==="calendar"}),Z=D({mutationFn:async c=>R("DELETE",`/api/social/posts/${c}`),onSuccess:()=>
5{v.invalidateQueries({queryKey:["/api/social/posts"]}),v.invalidateQueries({queryKey:["/api/social/calendar"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),s({title:"Post deleted"})},onError:c=>s({title:"Error",description:c.message,variant:"destructive"})}),O=D({mutationFn:async c=>(await R("POST",`/api/social/posts/${c}/publish`)).json(),onSuccess:c=>{v.invalidateQueries({queryKey:["/api/social/posts"]}),v.invalidateQueries({queryKey:["/api/social/calendar"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),c!=null&&c.warning?s({title:"Published (with notice)",description:c.warning}):c!=null&&c.externalPostUrl?s({title:"Published successfully",description:"Post is now live on the platform."}):s({title:"Post published",description:"Status updated to Published."})},onError:c=>s({title:"Publish failed",description:c.message,variant:"destructive"})}),a=D({mutationFn:async c=>(await R("POST",`/api/social/posts/${c}/approve`)).json(),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/social/posts"]}),v.invalidateQueries({queryKey:["/api/social/calendar"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),s({title:"Post approved",description:"The post has been approved and is ready to publish."})},onError:c=>s({title:"Approval failed",description:c.message,variant:"destructive"})}),l=D({mutationFn:async c=>R("POST",`/api/social/posts/${c}/duplicate`),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/social/posts"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),s({title:"Post duplicated"})},onError:c=>s({title:"Error",description:c.message,variant:"destructive"})}),P=D({mutationFn:async({id:c,reason:N})=>R("POST",`/api/social/posts/${c}/reject`,{reason:N}),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/social/posts"]}),v.invalidateQueries({queryKey:["/api/social/calendar"]}),v.invalidateQueries({queryKey:["/api/social/stats"]}),s({title:"Post rejected"}),I(!1),z(null),H("")},onError:c=>s({title:"Error",description:c.message,variant:"destructive"})}),$=j.useMemo(()=>{var Ce;const c=((Ce=Y.data)==null?void 0:Ce.data)||[];if(!f)return c;const N=f.toLowerCase();return c.filter(je=>{var ke,Se;return((ke=je.title)==null?void 0:ke.toLowerCase().includes(N))||je.content.toLowerCase().includes(N)||((Se=je.campaignTag)==null?void 0:Se.toLowerCase().includes(N))})},[Y.data,f]),q=c=>{A(c),d(null),h(!0)},X=c=>{d(c),h(!0)},re=c=>{z(c),H(""),I(!0)};return e.jsxs("div",{className:"px-3 sm:px-6 py-4 sm:py-6 space-y-6","data-testid":"page-social-media",children:[!r&&e.jsxs(rs,{variant:"default","data-testid":"alert-social-not-configured",children:[e.jsx(ks,{className:"h-4 w-4"}),e.jsx(cs,{children:"Social Media Not Configured"}),e.jsx(os,{children:"No social media platforms have been connected yet. Go to the Accounts tab to connect your Facebook, LinkedIn, Twitter, or other social accounts before creating posts."})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-page-title",children:"Social Media Manager"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Create, schedule, and manage your social media content"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center rounded-lg border p-0.5",children:[e.jsx(g,{variant:i==="dashboard"?"default":"ghost",size:"sm",onClick:()=>u("dashboard"),"data-testid":"view-dashboard",children:e.jsx(Ss,{className:"h-4 w-4"})}),e.jsx(g,{variant:i==="list"?"default":"ghost",size:"sm",onClick:()=>u("list"),"data-testid":"view-list",children:e.jsx(Ts,{className:"h-4 w-4"})}
5),e.jsx(g,{variant:i==="calendar"?"default":"ghost",size:"sm",onClick:()=>u("calendar"),"data-testid":"view-calendar",children:e.jsx(Ps,{className:"h-4 w-4"})}),e.jsx(g,{variant:i==="accounts"?"default":"ghost",size:"sm",onClick:()=>u("accounts"),"data-testid":"view-accounts",children:e.jsx(qe,{className:"h-4 w-4"})})]}),e.jsxs(g,{onClick:()=>{d(null),A(null),h(!0)},disabled:!r,title:r?void 0:"Connect a social media account first","data-testid":"button-new-post",children:[e.jsx(ge,{className:"h-4 w-4 mr-2"}),"New Post"]})]})]}),i==="dashboard"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(_s,{}),e.jsx(Ie,{}),e.jsxs(U,{children:[e.jsx(ue,{className:"pb-3",children:e.jsx(me,{className:"text-base",children:"Recent Posts"})}),e.jsx(Q,{className:"space-y-2",children:Y.isLoading?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(c=>e.jsx(J,{className:"h-20"},c))}):$.length>0?$.slice(0,5).map(c=>e.jsx(De,{post:c,onEdit:X,onDelete:N=>Z.mutate(N),onPublish:r?N=>O.mutate(N):void 0,onDuplicate:r?N=>l.mutate(N):void 0,onReject:re,onApprove:r?N=>a.mutate(N):void 0},c.id)):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(he,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No posts yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Create your first social media post to get started"})]})})]})]}),i==="list"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[e.jsx(Es,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(L,{placeholder:"Search posts...",value:f,onChange:c=>y(c.target.value),className:"pl-9","data-testid":"input-search-posts"})]}),e.jsxs(se,{value:k,onValueChange:w,children:[e.jsxs(ae,{className:"w-[150px]","data-testid":"filter-status",children:[e.jsx(As,{className:"h-3.5 w-3.5 mr-2"}),e.jsx(te,{placeholder:"Status"})]}),e.jsxs(ne,{children:[e.jsx(S,{value:"all",children:"All Status"}),e.jsx(S,{value:"DRAFT",children:"Draft"}),e.jsx(S,{value:"PENDING_APPROVAL",children:"Pending Approval"}),e.jsx(S,{value:"APPROVED",children:"Approved"}),e.jsx(S,{value:"SCHEDULED",children:"Scheduled"}),e.jsx(S,{value:"POSTED",children:"Posted"}),e.jsx(S,{value:"FAILED",children:"Failed"})]})]}),e.jsxs(se,{value:C,onValueChange:m,children:[e.jsx(ae,{className:"w-[150px]","data-testid":"filter-platform",children:e.jsx(te,{placeholder:"Platform"})}),e.jsxs(ne,{children:[e.jsx(S,{value:"all",children:"All Platforms"}),ie.map(c=>e.jsx(S,{value:c.value,children:c.label},c.value))]})]})]}),Y.isLoading?e.jsx("div",{className:"space-y-2",children:[1,2,3,4,5].map(c=>e.jsx(J,{className:"h-20"},c))}):$.length>0?e.jsx("div",{className:"space-y-2",children:$.map(c=>e.jsx(De,{post:c,onEdit:X,onDelete:N=>Z.mutate(N),onPublish:r?N=>O.mutate(N):void 0,onDuplicate:r?N=>l.mutate(N):void 0,onReject:re,onApprove:r?N=>a.mutate(N):void 0},c.id))}):e.jsx(U,{children:e.jsxs(Q,{className:"py-12 text-center",children:[e.jsx(he,{className:"h-12 w-12 mx-auto mb-3 opacity-30 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"No posts match your filters"})]})})]}),i==="calendar"&&e.jsx(U,{children:e.jsx(Q,{className:"pt-6",children:W.isLoading?e.jsxs("div",{className:"space-y-4",children:[e.jsx(J,{className:"h-8 w-48 mx-auto"}),e.jsx(J,{className:"h-[500px]"})]}):e.jsx(Us,{posts:((we=W.data)==null?void 0:we.posts)||{},currentDate:n,onDateChange:o,onEdit:X,onCreateForDate:r?q:void 0})})}),i==="accounts"&&e.jsx(Ie,{}),x&&e.jsx(Bs,{open:x,onClose:()=>{h(!1),d(null),A(null)},editingPost:t,prefilledDate:T}),e.jsx(Re,{open:b,onOpenChange:I,children:e.jsxs(Me,{className:"sm:max-w-md",children:[e.jsxs(Le,{children:[e.jsx(Oe,{children:"Reject Post"}),e.jsx(Fe,{children:"Provide a reason for rejecting this post. The creator will see this feedback."})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Rejection Reason"}),e.jsx(be,{placeholder:"Explain why this post is being rejected...",value:G,onChange:c=>H(c.target.value),className:"min-h-[80px]","data-testid":"input-reject-reason"})]}),e.jsxs(Ke,{children:[e.jsx(g,{variant:"outline",onClick:()=>I(!1),children:"Cancel"}),e.jsxs(g,{variant:"destructive",onClick:()=>{V&&P.mutate({id:V,reason:G})},disabled:P.isPending,"data-testid":"button-confirm-reject",children:[P.isPending?e.jsx(K,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ye,{className:"h-4 w-4 mr-2"}),"Reject Post"]})]})]})})]})}export{sa 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.