1import{r as g,aa as Ke,ag as Ye,d as U,s as z,ai as de,j as t,B as X,x as Be,am as ze,an as Ue,ao as qe,y as Ve,S as pe}from"./index-Cke0-Kmn.js";import{B as te}from"./badge-CY5IFNd5.js";import{C as Ge}from"./calendar-DhO0e2AN.js";import{S as Qe,a as Ze,b as Je,c as Xe,d as et}from"./select-BbZoQNLm.js";import{g as tt}from"./error-message-Cyy_cL3V.js";import{C as rt}from"./calendar-days-B7kApTp1.js";import{C as st}from"./calendar-xjWEMz-f.js";import{E as Se}from"./earth-lzamsJIB.js";import{Y as Te}from"./youtube-AZhxUnaK.js";import{L as q}from"./linkedin-CKWfDE0N.js";import{L as Ne}from"./loader-circle-DDUvwZEy.js";import{T as De}from"./triangle-alert-BKZKf0e4.js";import"./endOfMonth-D_i57ikB.js";import"./chevron-down-Bo5P4eIV.js";const nt=[{key:"w0",label:"W0 Carousels",short:"W0",dotClass:"bg-emerald-500"},{key:"w1",label:"W1 Press Releases",short:"W1",dotClass:"bg-accent"},{key:"w2",label:"W2 Thought Leadership",short:"W2",dotClass:"bg-purple-600"},{key:"w3",label:"W3 Videos",short:"W3",dotClass:"bg-sky-500"},{key:"portrait",label:"W3.1 Vertical Videos",short:"W3.1",dotClass:"bg-orange-500"}],$e="admin-social-calendar-type-filters-v1",ce={w0:!0,w1:!0,w2:!0,w3:!0,portrait:!0},at=()=>{try{const e=localStorage.getItem($e);if(!e)return{...ce};const s=JSON.parse(e);return{...ce,...s}}catch{return{...ce}}},Ce=g.createContext(new Map),Ie=e=>g.useContext(Ce).get(e)??[],me=({names:e,dense:s=!1})=>{if(e.length===0)return null;const a=e.join(", ");if(s){const b=e.length-1;return t.jsxs("div",{className:"text-[10px] text-muted-foreground truncate",title:a,children:[e[0],b>0&&t.jsxs("span",{className:"opacity-70",children:[" +",b," more"]})]})}if(e.length<=2)return t.jsx("div",{className:"text-[10px] text-muted-foreground truncate",title:a,children:e.join(", ")});const i=e.length-2;return t.jsxs("div",{className:"text-[10px] text-muted-foreground truncate",title:a,children:[e.slice(0,2).join(", "),t.jsxs("span",{className:"opacity-70",children:[" +",i," more"]})]})},he={insurtech:{key:"insurtech",name:"Insurtech Eye",short:"IE",swatch:"bg-green-600",bar:"border-l-green-600",bg:"bg-green-50 dark:bg-green-950/30",border:"border-green-400 dark:border-green-700",text:"text-green-950 dark:text-green-100",ring:"ring-green-400/40"},merchants:{key:"merchants",name:"Merchants Eye",short:"ME",swatch:"bg-purple-600",bar:"border-l-purple-600",bg:"bg-purple-50 dark:bg-purple-950/30",border:"border-purple-400 dark:border-purple-700",text:"text-purple-950 dark:text-purple-100",ring:"ring-purple-400/40"},tradetech:{key:"tradetech",name:"TradeTech Eye",short:"TT",swatch:"bg-orange-500",bar:"border-l-orange-500",bg:"bg-orange-50 dark:bg-orange-950/30",border:"border-orange-400 dark:border-orange-700",text:"text-orange-950 dar
1k:text-orange-100",ring:"ring-orange-400/40"},ffnews:{key:"ffnews",name:"FF News",short:"FF",swatch:"bg-accent",bar:"border-l-accent",bg:"bg-accent/10 dark:bg-accent/15",border:"border-accent/50",text:"text-foreground",ring:"ring-accent/40"},_blue:{key:"_blue",name:"YouTube only",short:"YT",swatch:"bg-sky-500",bar:"border-l-sky-500",bg:"bg-sky-50 dark:bg-sky-950/30",border:"border-sky-400 dark:border-sky-700",text:"text-sky-950 dark:text-sky-100",ring:"ring-sky-400/40"}},ot=e=>!!e&&(e==="insurtech"||e==="merchants"||e==="tradetech"||e==="ffnews"),Ee=e=>ot(e.target_page)?he[e.target_page]:he._blue,Y=[{key:"yt",label:"YouTube",short:"YT",icon:Te,targetPage:null},{key:"li-ffnews",label:"LinkedIn · FF News",short:"LI-FF",icon:q,targetPage:"ffnews"},{key:"li-insurtech",label:"LinkedIn · Insurtech Eye",short:"LI-IE",icon:q,targetPage:"insurtech"},{key:"li-merchants",label:"LinkedIn · Merchants Eye",short:"LI-ME",icon:q,targetPage:"merchants"},{key:"li-tradetech",label:"LinkedIn · TradeTech Eye",short:"LI-TT",icon:q,targetPage:"tradetech"}],ue=[{value:"Europe/London",label:"London (BST/GMT)",short:"BST"},{value:"UTC",label:"UTC",short:"UTC"},{value:"Europe/Paris",label:"Paris (CET/CEST)",short:"CET"},{value:"America/New_York",label:"New York (EST/EDT)",short:"EST"},{value:"America/Chicago",label:"Chicago (CST/CDT)",short:"CST"},{value:"America/Los_Angeles",label:"Los Angeles (PST/PDT)",short:"PST"},{value:"Asia/Dubai",label:"Dubai (GST)",short:"GST"},{value:"Asia/Kolkata",label:"Mumbai (IST)",short:"IST"},{value:"Asia/Singapore",label:"Singapore (SGT)",short:"SGT"},{value:"Asia/Hong_Kong",label:"Hong Kong (HKT)",short:"HKT"},{value:"Asia/Tokyo",label:"Tokyo (JST)",short:"JST"},{value:"Australia/Sydney",label:"Sydney (AEST/AEDT)",short:"AEST"}],R=(e,s)=>{const a=new Intl.DateTimeFormat("en-GB",{timeZone:s,hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(e),i=y=>{var c;return Number(((c=a.find($=>$.type===y))==null?void 0:c.value)??"0")};let b=i("hour");return b===24&&(b=0),{y:i("year"),mo:i("month"),d:i("day"),h:b,mi:i("minute"),s:i("second")}},re=(e,s,a,i,b,y)=>{let c=Date.UTC(e,s-1,a,i,b);for(let $=0;$<4;$++){const k=R(new Date(c),y),d=Date.UTC(k.y,k.mo-1,k.d,k.h,k.mi),u=Date.UTC(e,s-1,a,i,b)-d;if(u===0)break;c+=u}return new Date(c)},xe=(e,s)=>new Intl.DateTimeFormat("en-GB",{timeZone:s,hour12:!1,hour:"2-digit",minute:"2-digit"}).format(e),I=e=>{const s=new Date(e);return s.setHours(0,0,0,0),s},H=(e,s)=>{const a=new Date(e);return a.setDate(a.getDate()+s),a},V=e=>{const s=I(e),a=(s.getDay()+6)%7;return H(s,-a)},ge=e=>{const s=new Date(e.getFullYear(),e.getMonth(),1);return s.setHours(0,0,0,0),s},Me=e=>V(ge(e)),ee=(()=>{const e=[];for(let s=7;s<19;s++)for(const a of[0,20,40])e.push({h:s,m:a,key:`${s}:${a}`,isHour:a===0});return e})(),Q=(e,s)=>{const a=s==="yt"?e.yt_short_status:e.li_post_status;return a==="posted"?"posted":a==="posting"||a==="uploading"?"posting":a==="failed"||a==="error"?"failed":"idle"},lt=(e,s,a)=>{const b=!a||s==="failed"?"border-dashed":"border-solid",y=s==="idle"?"opacity-80":"";return`${e.bg} ${e.border} ${e.text} ${e.ring} ${b} ${y}`},it=(e,s)=>{const a=R(new Date(e),s);return`${a.h}:${Math.floor(a.mi/20)*20}`},B=e=>!e.source||e.source==="portrait",dt=e=>e==="insurtech"||e==="merchants"||e==="tradetech",be=e=>B(e)&&e.yt_short_status!=="skipped",_e=e=>B(e)&&dt(e.target_page)&&e.li_post_status!=="skipped",ct={w0:{label:"W0",className:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300 border-emerald-500/40"},w1:{label:"W1",className:"bg-accent/15 text-accent border-accent/40"},w2:{label:"W2",className:"bg-purple-500/15 text-purple-700 dark:text-purple-300 border-purple-500/40"},w3:{label:"W3",className:"bg-sky-500/15 text-sky-700 dark:text-sky-300 border-sky-500/40"},portrait:{label:"W3.1",className:"bg-orange-500/15 text-orange-700 dark:text-orange-300 border-orange-500/40"}},fe=({clip:e})=>{const s=e.source??"portrait",a=ct[s];return t.jsx("span",{className:`inline-flex items-center rounded-sm border px-1 py-0 text-[9px] font-bold leading-none tracking-wider up
1percase ${a.className}`,title:`Content type: ${a.label}`,children:a.label})},ut=e=>e.li_post_status==="posted"||e.source==="w0"||e.source==="w3"?!0:B(e)?be(e)||_e(e):e.source==="w1"?e.target_page==="insurtech"||e.target_page==="merchants"||e.target_page==="tradetech":!1,mt=e=>{if(!B(e))return["li"];const s=[];return be(e)&&s.push("yt"),_e(e)&&s.push("li"),s},ht=(e,s)=>{if(s==="yt")return"yt";const a=Y.find(i=>i.targetPage&&i.targetPage===e.target_page);return(a==null?void 0:a.key)??"yt"},ye=(e,s)=>Q(e,ht(e,s)),gt=(e,s)=>s==="yt"?e.yt_short_url:e.li_post_url||(e.li_post_urn?`https://www.linkedin.com/feed/update/${encodeURIComponent(e.li_post_urn)}/`:null),se=e=>{const s=mt(e),a=s.map(c=>ye(e,c)),i=a.every(c=>c==="posted"),b=a.some(c=>c==="failed"),y=e.status==="scheduled";return{channels:s,statuses:a,allPosted:i,anyFailed:b,committed:y}},ft=(e,s)=>s==="yt"?e.yt_short_url:e.li_post_url||(e.li_post_urn?`https://www.linkedin.com/feed/update/${encodeURIComponent(e.li_post_urn)}/`:null),pt=e=>e.getTime()<Date.now(),ne=e=>!!e&&new Date(e).getTime()>Date.now(),we=e=>e?e==="ff-news"||e==="ffnews"||e==="spotlight"?"ffnews":e==="insurtech-eye"?"insurtech":e==="merchants-eye"?"merchants":e==="tradetech-eye"?"tradetech":"_blue":"_blue",xt=e=>{const s=Date.now();return e.scheduled_for&&new Date(e.scheduled_for).getTime()>s?e.scheduled_for:e.published_at?e.published_at:e.scheduled_for},bt=(e,s,a)=>{const i=xt(e);return i?{id:`${s}:${e.id}`,title:e.title,ai_title:null,scheduled_for:i,target_page:we(e.ff_destination_site),status:e.status,yt_short_status:null,yt_short_url:null,li_post_status:e.li_post_status,li_post_url:e.li_post_url,li_post_urn:null,error_message:e.li_post_error,source:s,edit_href:a}:null},Le={posted:"posted",due:"posting",processing:"posting",error:"error",scheduled:null},_t=e=>{if(!e.calendar_at)return null;const s=e.li_calendar_state??"scheduled";return{id:`w0:${e.id}`,title:e.title,ai_title:null,scheduled_for:e.calendar_at,target_page:we(e.ff_destination_site),status:s==="scheduled"?"scheduled":s,yt_short_status:null,yt_short_url:null,li_post_status:Le[s]??null,li_post_url:e.li_post_url,li_post_urn:null,error_message:e.status_reason,li_calendar_state:s,source:"w0",edit_href:"/admin/carousels",story_titles:e.story_titles,pdf_url:e.pdf_url,status_reason:e.status_reason}},yt=e=>{if(!e.calendar_at)return null;const s=e.li_calendar_state??"scheduled";return{id:`w3:${e.id}`,title:e.title,ai_title:null,scheduled_for:e.calendar_at,target_page:we(e.ff_destination_site),status:e.video_status,yt_short_status:null,yt_short_url:null,li_post_status:Le[s]??e.li_post_status,li_post_url:e.published_linkedin_post||e.li_post_url,li_post_urn:null,error_message:null,li_calendar_state:s,source:"w3",edit_href:`/admin/videos/${e.id}`}},Wt=()=>{const e=Ke(),s=Ye(),[a,i]=g.useState(()=>new Date),[b,y]=g.useState(!1),[c,$]=g.useState(()=>localStorage.getItem("cal-social-tz")||"Europe/London"),k=ue.find(r=>r.value===c)??ue[0],[d,C]=g.useState(()=>localStorage.getItem("cal-social-view")||"day"),[u,N]=g.useState(()=>I(new Date)),[j,o]=g.useState(null),[m,S]=g.useState(null),[h,L]=g.useState(()=>at());g.useEffect(()=>{try{localStorage.setItem($e,JSON.stringify(h))}catch{}},[h]);const P=r=>L(n=>({...n,[r]:!n[r]}));g.useEffect(()=>{localStorage.setItem("cal-social-tz",c)},[c]),g.useEffect(()=>{localStorage.setItem("cal-social-view",d)},[d]),g.useEffect(()=>{const r=setInterval(()=>i(new Date),15e3);return()=>clearInterval(r)},[]);const x=g.useMemo(()=>{if(d==="day"){const n=I(u);return{start:n,end:H(n,1)}}if(d==="week"){const n=V(u);return{start:n,end:H(n,7)}}const r=Me(u);return{start:r,end:H(r,42)}},[u,d]),{data:T,isLoading:O,refetch:l}=U({queryKey:["admin-calendar-social",d,x.start.toISOString(),x.end.toISOString()],refetchInterval:6e4,queryFn:async()=>{const{data:r,error:n}=await z.from("w3.1_portrait_videos").select("id, title, ai_title, scheduled_for, target_page, status, yt_short_status, yt_short_url, li_post_status, li_post_url, li_post_urn, error_message").not("scheduled_for","is",null).gte("scheduled_for",x.start.toISOString()).lt("scheduled_for",x.end.toISOString());if(n)throw n;return r??[]}}),p="id, title, scheduled_for, published_at, status, ff_destination_site, li_post_status, li_post_url, li_posted_at, li_post_error",f=r=>r.or(`and(scheduled_for.gte.${x.start.toISOString()},scheduled_for.lt.${x.end.toISOString()}),and(published_at.gte.${x.start.toISOString()},published_at.lt.${x.end.toISOString()})`),D=U({queryKey:["admin-calendar-social-w1",x.start.toISOString(),x.end.toISOString()],refetchInterval:6e4,queryFn:async()=>{const{data:r,error:n}=await f(z.from("w1_press_releases").select(p));if(n)throw n;return r??[]}}),v=U({queryKey:["admin-calendar-social-w2",x.start.toISOString(),x.end.toISOString()],refetchInterval:6e4,queryFn:async()=>{const{data:r,error:n}=await f(z.from("w2_thought_leadership").select(p));if(n)throw n;return r??[]}}),W=U({queryKey:["admin-calendar-social-w3",x.start.toISOString(),x.end.toISOString()],refetchInterval:6e4,queryFn:async()=>{const{data:r,error:n}=await z.from("v_w3_linkedin_calendar").select("id, title, ff_destination_site, video_status, li_post_status, li_post_url, published_linkedin_post, li_posted_at, calendar_at, li_calendar_state").not("calendar_at","is",null).gte("calendar_at",x.start.toISOString()).lt("calendar_at",x.end.toISOString());if(n)throw n;return r??[]}}),E=U({queryKey:["admin-calendar-social-w0",x.start.toISOString(),x.end.toISOString()],refetchInterval:6e4,queryFn:async()=>{const{data:r,error:n}=await z.from("v_w0_carousel_calendar").select("id, title, slot_key, ff_destination_site, calendar_at, posted_at, li_calendar_state, li_post_url, pdf_url, story_titles, story_count, status_reason").not("calendar_at","is",null).gte("calendar_at",x.start.toISOString()).lt("calendar_at",x.end.toISOString());if(n)throw n;return r??[]}}),K=g.useMemo(()=>{const r=[],n=(_,w,F)=>
1{(_??[]).forEach(M=>{const A=bt(M,w,`${F}/${M.id}`);if(!A||!A.scheduled_for)return;const ve=new Date(A.scheduled_for).getTime();ve<x.start.getTime()||ve>=x.end.getTime()||r.push(A)})};return n(D.data,"w1","/admin/press-releases"),n(v.data,"w2","/admin/thought-leadership"),(W.data??[]).forEach(_=>{const w=yt(_);w&&r.push(w)}),(E.data??[]).forEach(_=>{const w=_t(_);w&&r.push(w)}),r},[D.data,v.data,W.data,E.data,x.start,x.end]),ae=(r,n)=>!B(r)||Q(r,n)==="posted"?!1:ne(r.scheduled_for),oe=g.useCallback(async(r,n,_)=>{if(new Date(n).getTime()<Date.now())return de.error("You can't schedule a clip in the past."),!1;if(n===_)return!0;try{const{error:w}=await z.from("w3.1_portrait_videos").update({scheduled_for:n}).eq("id",r);if(w)throw w;return de.success("Rescheduled"),await l(),s.invalidateQueries({queryKey:["portrait-videos"]}),!0}catch(w){return de.error(tt(w,"Reschedule failed.")),!1}},[s,l]),le=(r,n,_)=>{if(!ae(n,_)){r.preventDefault();return}r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",n.id),o({clipId:n.id,originalIso:n.scheduled_for,originalStatus:n.status})},ie=()=>{o(null),S(null)},ke=r=>{N(d==="day"?n=>H(n,r):d==="week"?n=>H(n,r*7):n=>{const _=new Date(n);return _.setMonth(_.getMonth()+r),_.setHours(0,0,0,0),_})},Fe=g.useMemo(()=>{if(d==="day")return u.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"});if(d==="week"){const r=V(u),n=H(r,6);return`${r.toLocaleDateString(void 0,{month:"short",day:"numeric"})} â ${n.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})}`}return u.toLocaleDateString(void 0,{month:"long",year:"numeric"})},[u,d]),Pe=g.useMemo(()=>{const r=I(new Date).getTime();return d==="day"?I(u).getTime()===r:d==="week"?V(new Date).getTime()===V(u).getTime():ge(new Date).getTime()===ge(u).getTime()},[u,d]),Z=g.useMemo(()=>[...T??[],...K].filter(ut),[T,K]),Ae=g.useMemo(()=>{const r={portrait:0,w0:0,w1:0,w2:0,w3:0};return Z.forEach(n=>{const _=n.source??"portrait";r[_]=(r[_]??0)+1}),r},[Z]),G=g.useMemo(()=>Z.filter(r=>h[r.source??"portrait"]),[Z,h]),J=g.useMemo(()=>G.map(r=>r.id),[G]),Re=g.useMemo(()=>J.slice().sort().join(","),[J]),{data:We}=U({queryKey:["admin-calendar-social-companies",Re],enabled:J.length>0,queryFn:async()=>{try{const{data:r,error:n}=await z.from("w3.1_portrait_video_companies").select("portrait_video_id, ff_companies(b2db_company_name)").in("portrait_video_id",J);if(n)throw n;const _=new Map;return(r??[]).forEach(w=>{var A;const F=(A=w==null?void 0:w.ff_companies)==null?void 0:A.b2db_company_name;if(!F)return;const M=_.get(w.portrait_video_id)??[];M.push(F),_.set(w.portrait_video_id,M)}),_}catch(r){return console.error("[calendar] companies fetch failed",r),new Map}}}),He=We??new Map;return t.jsx(Ce.Provider,{value:He,children:t.jsxs("div",{className:"w-full flex flex-col bg-background h-[calc(100vh-113px)]",children:[t.jsxs("div",{className:"sticky top-0 z-40 bg-background border-b border-border shadow-sm",children:[t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border bg-card/50 flex-wrap gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsx(rt,{className:"h-5 w-5 text-muted-foreground"}),t.jsx("h1",{className:"text-lg font-semibold tracking-tight mr-2",children:"Social Media Calendar"}),t.jsx("div",{className:"inline-flex rounded-md border border-border overflow-hidden",children:["day","week","month"].map(r=>t.jsx("button",{onClick:()=>C(r),className:`px-4 py-1.5 text-sm font-semibold uppercase tracking-wider transition ${d===r?"bg-foreground text-background":"bg-background text-muted-foreground hover:bg-muted"}`,children:r},r))}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(X,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>ke(-1),title:"Previous",children:t.jsx(Be,{className:"h-4 w-4"})}),t.jsxs(ze,{open:b,onOpenChange:y,children:[t.jsx(Ue,{asChild:!0,children:t.jsxs(X,{variant:"outline",size:"sm",className:"h-8 gap-2 font-semibold",children:[t.jsx(st,{className:"h-4 w-4"}),Fe]})}),t.jsx(qe,{className:"w-auto p-0",align:"start",children:t.jsx(Ge,{mode:"single",selected:u,onSelect:r=>{r&&(N(I(r)),y(!1))},initialFocus:!0,className:"p-3 pointer-events-auto"})})]}),t.jsx(X,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>ke(1),title:"Next",children:t.jsx(Ve,{className:"h-4 w-4"})}),!Pe&&t.jsx(X,{variant:"ghost",size:"sm",className:"h-8",onClick:()=>N(I(new Date)),children:"Today"})]}),t.jsxs(Qe,{value:c,onValueChange:$,children:[t.jsxs(Ze,{className:"h-8 w-[220px] text-xs",children:[t.jsx(Se,{className:"h-3.5 w-3.5 mr-1"}),t.jsx(Je,{})]}),t.jsx(Xe,{className:"z-50 bg-popover",children:ue.map(r=>
1t.jsx(et,{value:r.value,className:"text-xs",children:r.label},r.value))})]})]}),m&&t.jsxs("div",{className:"text-xs font-mono text-foreground bg-yellow-100 dark:bg-yellow-900/40 px-2 py-1 rounded border border-yellow-400",children:["â ",m]})]}),t.jsxs("div",{className:"flex items-center gap-2 px-6 py-1.5 border-b border-border bg-muted/50 text-[11px] font-medium text-muted-foreground uppercase tracking-widest",children:[t.jsx(Se,{className:"h-3.5 w-3.5"}),"Time Zone: ",t.jsxs("span",{className:"text-foreground",children:[k.short," - ",k.label]})]}),t.jsx(kt,{}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-6 py-2 border-b border-border bg-card/30",children:[t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-widest text-muted-foreground mr-1",children:"Show"}),nt.map(r=>{const n=h[r.key],_=Ae[r.key]??0;return t.jsxs("button",{type:"button",onClick:()=>P(r.key),"aria-pressed":n,title:n?`Hide ${r.label}`:`Show ${r.label}`,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-semibold uppercase tracking-wider transition ${n?"bg-foreground text-background border-foreground":"bg-background text-muted-foreground border-border hover:bg-muted"}`,children:[t.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${r.dotClass} ${n?"":"opacity-40"}`}),t.jsx("span",{children:r.label}),t.jsx("span",{className:`ml-0.5 rounded px-1 text-[10px] ${n?"bg-background/20":"bg-muted"}`,children:_})]},r.key)})]})]}),d==="day"&&t.jsx(vt,{anchor:u,tz:c,now:a,clips:G,isLoading:O,drag:j,setDragHint:S,onCardDragStart:le,onCardDragEnd:ie,onDropSlot:async(r,n,_)=>{_.preventDefault();const w=_.dataTransfer.getData("text/plain");if(!w||!j)return;const F=R(u,c),M=re(F.y,F.mo,F.d,r,n,c);await oe(w,M.toISOString(),j.originalIso),o(null),S(null)},openCard:(r,n)=>{if(Q(r,n)==="posted"){const w=ft(r,n);if(w){window.open(w,"_blank","noopener,noreferrer");return}}if(r.edit_href){e(r.edit_href);return}e(`/admin/portrait-videos#clip-${r.id}`)}}),d==="week"&&t.jsx(St,{anchor:u,tz:c,clips:G,isLoading:O,drag:j,onCardDragStart:le,onCardDragEnd:ie,onDropDay:async(r,n)=>{n.preventDefault();const _=n.dataTransfer.getData("text/plain");if(!_||!j)return;const w=new Date(j.originalIso),F=R(w,c),M=R(r,c),A=re(M.y,M.mo,M.d,F.h,F.mi,c);await oe(_,A.toISOString(),j.originalIso),o(null)},onOpen:r=>e(r.edit_href??`/admin/portrait-videos#clip-${r.id}`),onOpenPosted:r=>window.open(r,"_blank","noopener,noreferrer"),onJumpToDay:r=>{N(I(r)),C("day")}}),d==="month"&&t.jsx(jt,{anchor:u,tz:c,clips:G,isLoading:O,drag:j,onCardDragStart:le,onCardDragEnd:ie,onDropDay:async(r,n)=>{n.preventDefault();const _=n.dataTransfer.getData("text/plain");if(!_||!j)return;const w=new Date(j.originalIso),F=R(w,c),M=R(r,c),A=re(M.y,M.mo,M.d,F.h,F.mi,c);await oe(_,A.toISOString(),j.originalIso),o(null)},onJumpToDay:r=>{N(I(r)),C("day")},onOpen:r=>e(r.edit_href??`/admin/portrait-videos#clip-${r.id}`)})]})})},wt=({clip:e,lane:s,tz:a,drag:i,draggable:b,onDragStart:y,onDragEnd:c,onClick:$,showChannelLabel:k})=>{const d=Q(e,s),C=!B(e),u=e.li_calendar_state==="scheduled",N=e.li_calendar_state==="error"||d==="failed",j=C?d==="posted":e.status==="scheduled",o=d==="posted",m=!u&&C&&!o&&d==="idle"&&!e.li_post_status,S=e.scheduled_for?xe(new Date(e.scheduled_for),a):"",h=e.title||e.ai_title||"Untitled clip",L=Ee(e),P=Y.find(f=>f.key===s),x=(i==null?void 0:i.clipId)===e.id,T=Ie(e.id),O=e.source==="w0"?[(e.story_titles??[]).map((f,D)=>`${D+1}. ${f}`).join(` 2`),e.pdf_url?`PDF: ${e.pdf_url}`:""].filter(Boolean).join(` 3 4`):"",l=d==="failed"&&e.error_message?`Failed: ${e.error_message}`:u?"Projected - auto-posts to LinkedIn at go-live":m?"Published - not pushed to LinkedIn yet":!j&&!o?"Not scheduled yet - pencilled in, will not publish":b?"Drag to reschedule":o?"Already published - locked":"In the past",p=O?`${l} 5 6${O}`:l;return t.jsxs("button",{draggable:b,onDragStart:y,onDragEnd:c,onClick:$,title:p,className:`w-full text-left rounded-md border-2 px-2 py-1.5 transition hover:shadow-md hover:ring-2 border-l-4 ${L.bar} ${lt(L,d,j)} ${m?"opacity-60":""} ${u?"bg-transparent border-dashed opacity-75":""} ${N?"border-destructive text-destructive bg-destructive/5":""} ${x?"ring-2 ring-yellow-400 shadow-lg":""} ${o?"font-bold":""} ${b?"cursor-grab active:cursor-grabbing":"cursor-pointer"}`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-1 mb-1",children:[t.jsxs("span",{className:`inline-flex items-center gap-1 text-[10px] font-mono tracking-wider opacity-80 ${o?"font-bold":""}`,children:[C&&t.jsx(q,{className:"h-2.5 w-2.5"}),S]}),t.jsxs("div",{className:"flex items-center gap-1",children:[d==="posting"&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-[9px] font-semibold uppercase tracking-wider",children:[t.jsx(Ne,{className:"h-2.5 w-2.5 animate-spin"}),"Uploadingâ¦"]}),d==="failed"&&t.jsxs(te,{variant:"outline",className:"text-[9px] px-1 py-0 h-3.5 leading-none gap-0.5 border-current",children:[t.jsx(De,{className:"h-2.5 w-2.5"}),"Failed"]}),u&&t.jsx(te,{variant:"outline",className:"text-[9px] px-1 py-0 h-3.5 leading-none border-current border-dashed font-normal",children:"Auto-posts at go-live"}),o&&t.jsx(te,{className:"text-[9px] px-1 py-0 h-3.5 leading-none font-bold",children:"Posted"}),t.jsx(fe,{clip:e})]})]}),t.jsxs("div",{className:`text-[12px] leading-snug whitespace-normal break-words ${o?"font-bold":"font-medium"}`,children:[t.jsxs("span",{className:"inline-flex items-center gap-1 mr-1 text-[10px] uppercase tracking-wider opacity-80",children:[t.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${L.swatch}`}),L.name,k&&t.jsxs("span",{className:"opacity-60",children:["· ",P.short]})]}),h]}),t.jsx(me,{names:T})]})},kt=()=>t.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1.5 px-6 py-2 border-b border-border bg-card/30 text-[11px]",children:[t.jsx("span",{className:"font-semibold uppercase tracking-wider text-muted-foreground",children:"Colour = destination brand:"}),["insurtech","merchants","tradetech","ffnews","_blue"].map(e=>{const s=he[e];return t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{className:`inline-block w-3 h-3 rounded-sm border ${s.swatch} ${s.border}`}),t.jsx("span",{className:"text-foreground font-medium",children:s.name}),e==="_blue"&&t.jsx("span",{className:"text-muted-foreground",children:"(no LinkedIn destination)"})]},e)})]}),je=({clip:e,ch:s,size:a="sm"})=>{const i=ye(e,s),b=s==="yt"?Te:q,y=gt(e,s),c=s==="yt"?"YouTube":"LinkedIn",$=i==="posted"&&y?`${c}: ${y}`:i==="failed"&&e.error_message?`${c} failed: ${e.error_message}`:i==="posting"?`${c}: uploadingâ¦`:`${c}: not yet published`,k=a==="sm"?"h-3.5 w-3.5":"h-3 w-3",d=a==="sm"?"h-2 w-2":"h-1.5 w-1.5";return t.jsxs("span",{title:$,onClick:C=>{i==="posted"&&y&&(C.stopPropagation(),window.open(y,"_blank","noopener,noreferrer"))},className:`relative inline-flex items-center ${i==="posted"&&y?"cursor-pointer":""}`,children:[t.jsx(b,{className:k}),i==="posted"&&t.jsx("span",{className:`absolute -top-0.5 -right-1 ${d} rounded-full bg-emerald-500 border border-background`}),i==="posting"&&t.jsx(Ne,{className:`absolute -top-0.5 -right-1 ${d} animate-spin text-foreground`}),i==="failed"&&t.jsx(De,{className:"absolute -top-1 -right-1.5 h-2.5 w-2.5 text-amber-600"})]})},Oe=({clip:e,tz:s,drag:a,draggable:i,onDragStart:b,onDragEnd:y,onClick:c,dense:$=!1})=>{const{channels:k,allPosted:d,committed:C}=se(e),u=!B(e),N=e.li_calendar_state==="scheduled",j=e.li_calendar_state==="error",o=u?d:C,m=Ee(e),S=e.scheduled_for?xe(new Date(e.scheduled_for),s):"",h=e.title||e.ai_title||"Untitled clip",L=(a==null?void 0:a.clipId)===e.id,P=u?"LinkedIn":k.length===2?"YouTube + LinkedIn":k[0]==="li"?"LinkedIn only":"YouTube only",x=Ie(e.id),O=!o||!d&&se(e).anyFailed?"border-dashed":"border-solid",p=!N&&u&&!d&&!e.li_post_status?"opacity-60":!d&&k.every(f=>ye(e,f)==="idle")?"opacity-80":"";return t.jsxs("button",{draggable:i,onDragStart:b,onDragEnd:y,onClick:c,title:`${P} · ${m.name}`,className:`w-full text-left rounded-md border-2 border-l-4 px-2 py-1.5 transition hover:shadow-md hover:ring-2 ${m.bar} ${m.bg} ${m.border} ${m.text} ${m.ring} ${O} ${p} ${N?"bg-transparent border-dashed opacity-75":""} ${j?"border-destructive text-destructive bg-destructive/5":""} ${L?"ring-2 ring-yellow-400 shadow-lg":""} ${d?"font-bold":""} ${i?"cursor-grab active:cursor-grabbing":"cursor-pointer"}`,children:[$?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-[10px] font-mono opacity-70 shrink-0",children:S}),t.jsx("span",{className:"flex items-center gap-2 shrink-0",children:k.map(f=>t.jsx(je,{clip:e,ch:f,size:"xs"},f))}),t.jsx("span",{className:"truncate text-[10px]",children:h}),t.jsx("span",{className:"ml-auto shrink-0",children:t.jsx(fe,{clip:e})})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-1 mb-1",children:[t.jsx("span",{className:`text-[10px] font-mono tracking-wider opacity-80 ${d?"font-bold":""}`,children:S}),t.jsxs("span",{className:"flex items-center gap-2.5",children:[k.map(f=>t.jsx(je,{clip:e,ch:f,size:"sm"},f)),N&&t.jsx(te,{variant:"outline",className:"text-[9px] px-1 py-0 h-3.5 leading-none border-current border-dashed font-normal",children:"Auto-posts at go-live"}),t.jsx(fe,{clip:e})]})]}),t.jsxs("div",{className:`text-[12px] leading-snug whitespace-normal break-words ${d?"font-bold":"font-medium"}`,children:[t.jsxs("span",{className:"inline-flex items-center gap-1 mr-1 text-[10px] uppercase tracking-wider opacity-80",children:[t.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${m.swatch}`}),m.name,t.jsxs("span",{className:"opacity-60",children:["· ",P]})]}),h]}),t.jsx(me,{names:x})]}),$&&x.length>0&&t.jsx(me,{names:x,dense:!0})]})},vt=({anchor:e,tz:s,now:a,clips:i,isLoading:b,drag:y,setDragHint:c,onCardDragStart:$,onCardDragEnd:k,onDropSlot:d,openCard:C})=>{const u=g.useRef(null),N=g.useRef(null),j=g.useRef(null),o=g.useRef(new Map),[m,S]=g.useState(new Map),[h,L]=g.useState(null),P=g.useMemo(()=>{const l={};return Y.forEach(p=>{l[p.key]={},ee.forEach(f=>{l[p.key][f.key]=[]})}
6),i.forEach(p=>{if(!p.scheduled_for)return;const f=it(p.scheduled_for,s);be(p)&&l.yt[f]&&l.yt[f].push(p);const D=Y.find(v=>v.targetPage&&v.targetPage===p.target_page);D&&l[D.key][f]&&(!B(p)||_e(p))&&l[D.key][f].push(p)}),l},[i,s]),x=g.useMemo(()=>{const l={yt:0,"li-ffnews":0,"li-insurtech":0,"li-merchants":0,"li-tradetech":0};return Y.forEach(p=>{l[p.key]=ee.reduce((f,D)=>f+P[p.key][D.key].length,0)}),l},[P]);g.useLayoutEffect(()=>{const l=()=>{const f=N.current,D=j.current;if(!f||!D)return;L({top:f.offsetTop,height:D.offsetTop+D.offsetHeight-f.offsetTop});const v=new Map;o.current.forEach((W,E)=>{v.set(E,{top:W.offsetTop,height:W.offsetHeight})}),S(v)};l();const p=new ResizeObserver(l);return u.current&&p.observe(u.current),o.current.forEach(f=>p.observe(f)),window.addEventListener("resize",l),()=>{p.disconnect(),window.removeEventListener("resize",l)}},[i]);const T=I(a).getTime()===I(e).getTime(),O=g.useMemo(()=>{if(!T)return null;const l=R(a,s),p=l.h*60+l.mi+l.s/60;if(p<7*60||p>19*60)return null;const f=l.h,D=Math.floor(l.mi/20)*20,v=m.get(`${f}:${D}`);if(!v)return null;const W=p-(f*60+D);return v.top+W/20*v.height},[a,s,m,T]);return g.useEffect(()=>{if(!u.current||!h)return;const l=R(new Date,s),p=l.h*60+l.mi,f=h.top+(p-7*60-60)/(12*60)*h.height;f>0&&u.current.scrollTo({top:f,behavior:"smooth"})},[h==null?void 0:h.top,s]),t.jsxs("div",{ref:u,className:"flex-1 min-h-0 w-full border-t border-border overflow-auto relative",children:[O!==null&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"pointer-events-none absolute left-0 right-0 z-30",style:{top:`${O}px`},children:t.jsx("div",{className:"h-[3px] w-full bg-red-600 shadow-[0_0_8px_rgba(220,38,38,0.6)]"})}),t.jsx("div",{className:"pointer-events-none absolute z-30 flex items-center",style:{top:`${O-9}px`,left:0,width:72},children:t.jsx("span",{className:"ml-1 rounded-sm bg-red-600 px-1.5 py-0.5 text-[10px] font-mono font-bold text-white tracking-wider",children:xe(a,s)})})]}),t.jsxs("div",{className:"grid w-full",style:{gridTemplateColumns:`72px repeat(${Y.length}, minmax(200px, 1fr))`},children:[t.jsx("div",{className:"border-b border-r border-border bg-muted/40 sticky top-0 z-20"}),Y.map(l=>{const p=l.icon;return t.jsx("div",{className:"border-b border-r-2 border-border bg-card sticky top-0 z-20 flex items-center justify-between px-3 py-3",children:t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-semibold",children:[t.jsx(p,{className:"h-4 w-4"}),t.jsx("span",{children:l.label})]}),t.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:[x[l.key]," scheduled"]})]})},`h-${l.key}`)}),ee.map((l,p)=>{const f=`${String(l.h).padStart(2,"0")}:${String(l.m).padStart(2,"0")}`,D=l.isHour?"border-t-2 border-slate-300 dark:border-slate-600":"border-t border-slate-100 dark:border-slate-800";return t.jsxs("div",{className:"contents",children:[t.jsx("div",{ref:v=>{v?o.current.set(l.key,v):o.current.delete(l.key),p===0&&(N.current=v),p===ee.length-1&&(j.current=v)},className:`${D} border-r border-border bg-muted/30 px-2 py-2 text-[11px] font-mono tracking-widest text-right ${l.isHour?"text-foreground font-semibold":"text-muted-foreground/70"}`,children:f}),Y.map(v=>{const W=P[v.key][l.key]??[];return t.jsx("div",{onDragOver:E=>{if(!y)return;E.preventDefault(),E.dataTransfer.dropEffect="move";const K=R(e,s),ae=re(K.y,K.mo,K.d,l.h,l.m,s);c(`${f} - ${pt(ae)?"in the past - will be rejected":"will land here"}`)},onDrop:E=>d(l.h,l.m,E),className:`${D} border-r-2 border-border min-h-[44px] p-1.5 space-y-1.5 ${y?"hover:bg-yellow-50 dark:hover:bg-yellow-950/20":""}`,children:b?t.jsx(pe,{className:"h-8 w-full"}):W.map(E=>t.jsx(wt,{clip:E,lane:v.key,tz:s,drag:y,draggable:Q(E,v.key)!=="posted"&&ne(E.scheduled_for),onDragStart:K=>$(K,E,v.key),onDragEnd:k,onClick:()=>C(E,v.key)},`${v.key}-${E.id}`))},`cell-${v.key}-${l.key}`)})]},`row-${l.key}`)})]})]})},St=({anchor:e,tz:s,clips:a,isLoading:i,drag:b,onCardDragStart:y,onCardDragEnd:c,onDropDay:$,onOpen:k,onOpenPosted:d,onJumpToDay:C})=>{const u=g.useMemo(()=>V(e),[e]),N=g.useMemo(()=>Array.from({length:7},(o,m)=>H(u,m)),[u]),j=g.useMemo(()=>{const o=new Map;
6return N.forEach(m=>o.set(m.toDateString(),[])),a.forEach(m=>{if(!m.scheduled_for)return;const S=new Date(m.scheduled_for),h=I(S).toDateString();o.has(h)&&o.get(h).push(m)}),o.forEach(m=>m.sort((S,h)=>new Date(S.scheduled_for).getTime()-new Date(h.scheduled_for).getTime())),o},[a,N]);return t.jsx("div",{className:"flex-1 min-h-0 w-full border-t border-border overflow-auto",children:t.jsx("div",{className:"grid w-full h-full",style:{gridTemplateColumns:"repeat(7, minmax(160px, 1fr))"},children:N.map(o=>{const m=I(new Date).getTime()===I(o).getTime(),S=j.get(o.toDateString())??[];return t.jsxs("div",{onDragOver:h=>{b&&(h.preventDefault(),h.dataTransfer.dropEffect="move")},onDrop:h=>$(o,h),className:`border-r border-border flex flex-col ${b?"hover:bg-yellow-50 dark:hover:bg-yellow-950/20":""}`,children:[t.jsxs("button",{type:"button",onClick:()=>C(o),title:`View ${o.toLocaleDateString(void 0,{weekday:"long",day:"numeric",month:"long"})}`,className:`px-3 py-2 border-b border-border sticky top-0 z-10 text-left cursor-pointer hover:bg-muted transition-colors ${m?"bg-red-50 dark:bg-red-950/30 hover:bg-red-100 dark:hover:bg-red-950/40":"bg-card"}`,children:[t.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:o.toLocaleDateString(void 0,{weekday:"short"})}),t.jsx("div",{className:`text-lg font-bold ${m?"text-red-600":""}`,children:o.getDate()})]}),t.jsx("div",{className:"flex-1 p-1.5 space-y-1.5 overflow-auto",children:i?t.jsx(pe,{className:"h-8 w-full"}):S.length===0?t.jsx("div",{className:"text-[11px] text-muted-foreground italic px-1",children:"No posts"}):S.map(h=>t.jsx(Oe,{clip:h,tz:s,drag:b,draggable:!se(h).allPosted&&ne(h.scheduled_for),onDragStart:L=>y(L,h,"yt"),onDragEnd:c,onClick:()=>k(h)},h.id))})]},o.toISOString())})})})},jt=({anchor:e,tz:s,clips:a,isLoading:i,drag:b,onCardDragStart:y,onCardDragEnd:c,onDropDay:$,onJumpToDay:k,onOpen:d})=>{const C=g.useMemo(()=>Me(e),[e]),u=g.useMemo(()=>Array.from({length:42},(o,m)=>H(C,m)),[C]),N=e.getMonth(),j=g.useMemo(()=>{const o=new Map;return u.forEach(m=>o.set(m.toDateString(),[])),a.forEach(m=>{if(!m.scheduled_for)return;const S=new Date(m.scheduled_for),h=I(S).toDateString();o.has(h)&&o.get(h).push(m)}),o.forEach(m=>m.sort((S,h)=>new Date(S.scheduled_for).getTime()-new Date(h.scheduled_for).getTime())),o},[a,u]);return t.jsxs("div",{className:"flex-1 min-h-0 w-full border-t border-border overflow-auto flex flex-col",children:[t.jsx("div",{className:"grid grid-cols-7 border-b border-border sticky top-0 bg-card z-10",children:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"].map(o=>t.jsx("div",{className:"px-3 py-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground text-center border-r border-border",children:o},o))}),t.jsx("div",{className:"grid grid-cols-7 flex-1",style:{gridAutoRows:"minmax(120px, 1fr)"},children:u.map((o,m)=>{const S=j.get(o.toDateString())??[],h=o.getMonth()===N,L=I(new Date).getTime()===I(o).getTime(),P=S.slice(0,3),x=S.length-P.length;return t.jsxs("div",{onDragOver:T=>{b&&(T.preventDefault(),T.dataTransfer.dropEffect="move")},onDrop:T=>$(o,T),onDoubleClick:T=>{T.target===T.currentTarget&&k(o)},className:`border-r border-b border-border p-1.5 flex flex-col gap-1 ${h?"bg-background":"bg-muted/30"} ${b?"hover:bg-yellow-50 dark:hover:bg-yellow-950/20":""}`,children:[t.jsx("button",{type:"button",onClick:()=>k(o),title:`View ${o.toLocaleDateString(void 0,{weekday:"long",day:"numeric",month:"long"})}`,className:`self-start text-[11px] font-semibold cursor-pointer hover:underline ${L?"text-red-600":h?"text-foreground":"text-muted-foreground/50"}`,children:o.getDate()}),i?t.jsx(pe,{className:"h-4 w-full"}):t.jsxs(t.Fragment,{children:[P.map(T=>{const O=!se(T).allPosted&&ne(T.scheduled_for);return t.jsx(Oe,{clip:T,tz:s,drag:b,draggable:O,dense:!0,onDragStart:l=>y(l,T,"yt"),onDragEnd:c,onClick:()=>d(T)},T.id)}),x>0&&t.jsxs("button",{onClick:()=>k(o),className:"text-[10px] font-semibold text-primary hover:underline text-left",children:["+",x," more"]})]})]},m)})})]})};export{Wt 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.