PageSourceSearch

https://analyticsindiamag.com/assets/PostEditor-CNERcvlW.js

js analyticsindiamag.com collected 2026-09-24 08:27:10 UTC 95,994 bytes, 3 lines download raw bytes

1import{r as n,j as e,N as xs,V as ga,W as pa,Y as xa,av as fa,aw as ba,aP as va,aB as Ae,ay as ze,aO as ya,aA as Be,bO as ja,aL as wa,a1 as he,S as ke,I as Q,B as E,b4 as Na,L as me,X as Te,a9 as nt,s as _,f as fe,y as _a,q as Tt,P as fs,v as bs,w as vs,a as Rt,F as St,ac as Sa,e as ka,u as Ca,E as Ea,a_ as yt,bP as Pa,bq as at}from"./index-KSWbwNeY.js";import{formatFileSize as ts,calculateSavings as Da,loadImageDimensions as Ia,optimizeImage as zt}from"./imageOptimizer-DU1AwbgF.js";import{L as W}from"./label-ndOKmXJw.js";import{T as Re}from"./textarea-BXv-lbww.js";import{S as Aa,a as Ta,b as Ra,c as za,d as Ua}from"./select-DzTIkJMJ.js";import{C as Fa}from"./calendar-CtzmsIKO.js";import{A as ss}from"./AdminNav-DsaLvjFx.js";import{l as ge,R as Oa}from"./quill.snow-CYjwR_8r.js";import{D as Ge,a as Ve,b as We,c as He,f as ys,e as Ma,d as La}from"./dialog-Bpfij23O.js";import{u as qa,a as $a}from"./useArticleCarousels-a_3h2v-m.js";import{s as Ba}from"./sanitizeHTML-3eQ8Vumw.js";import{C as kt}from"./clock-CzRotAbS.js";import{S as qe}from"./scroll-area-DlihVgX7.js";import{M as js}from"./MediaLibraryPicker-CRVpp0Z2.js";import{c as ws}from"./index-BdQq_4o_.js";import{U as $e}from"./upload-CstIFHrJ.js";import{F as Ct}from"./folder-open-DdjcdZ5b.js";import{a as rt,M as Ga,L as Va,I as as}from"./minimize-2-DZ_0eBEd.js";import{C as rs}from"./chevron-left-C0OR5oyH.js";import{G as Ns}from"./grip-vertical-CeQgvVnP.js";import{P as Et}from"./plus-oseq6Y0_.js";import{C as Wa}from"./checkbox-CU8ALz2k.js";import{S as is}from"./star-DnX2lA9e.js";import{C as _s}from"./chevron-down-D7IdZFzc.js";import{E as Ha}from"./EmbedInsertDialog-BsoEYfzC.js";import{C as Ka}from"./chevron-up-B5q4f77c.js";import{T as Qa}from"./trash-2-CwcwS_bf.js";import{S as Ya}from"./settings-2-DosyAUqX.js";import{A as ns,a as os,b as ls,c as cs,d as ds,e as ms,f as us,g as hs}from"./alert-dialog-DFWe8irl.js";import{A as Ja}from"./arrow-left-1kEvYP7w.js";import{C as jt}from"./circle-check-8n8_Yy4E.js";import{C as wt}from"./circle-alert-B57G6NgG.js";import{E as Xa}from"./eye-Cwzmef_1.js";import{M as Za}from"./maximize-2-yYWjcX_b.js";import{C as gs}from"./calendar-Cdsbx2VF.js";import{S as er}from"./save-xjMYTeam.js";import"./isSameDay-BgYctTaA.js";import"./format-hhvI2L0z.js";import"./en-US-BOoww7nS.js";import"./subDays-BXRnlTIb.js";import"./endOfMonth-bNOLQZ7P.js";import"./addMonths-CiokD12n.js";import"./isSameMonth-BG6o1LAn.js";import"./index-DsYLezIw.js";import"./user-cog-DvqSS7bY.js";import"./book-open-DS7Nmuzn.js";import"./receipt-DgWJf9Ou.js";import"./index-BpbyRUKB.js";import"./carousel-iJcqtr9a.js";import"./purify.es--yiYCWnk.js";import"./htmlDecoder-Cz23cfvH.js";import"./code-xml-DKN-dImL.js";const tr=(a,i=225)=>{const l=a.replace(/<[^>]*>/g," ").trim().split(/\s+/).filter(u=>u.length>0).length,m=Math.ceil(l/i);return m<1?"< 1 min read":m===1?"1 min read":`${m} min read`},sr=a=>a.replace(/<[^>]*>/g," ").trim().split(/\s+/).filter(s=>s.length>0).length,ar=({title:a,excerpt:i,content:s,imageUrl:l,featuredImageCaption:m,categoryName:u,authorName:d="Unknown Author",authorImage:g,authorRole:f="Writer",keyTakeaways:x})=>{const{getArticleTextClass:v}=qa(),p=n.useRef(null),b=tr(s);$a(p,[s]);let C=[];if(x)try{const y=JSON.parse(x);C=Array.isArray(y)?y:[]}catch(y){console.error("Invalid key takeaways JSON",y)}return e.jsxs("article",{className:"max-w-3xl mx-auto px-4 py-8",children:[u&&e.jsx("div",{className:"mb-4",children:e.jsx(xs,{variant:"secondary",className:"text-xs uppercase tracking-wide",children:u})}),e.jsx("h1",{className:"font-serif text-4xl md:text-5xl font-bold leading-tight mb-4",children:a}),i&&e.jsx("p",{className:"text-lg text-muted-foreground mb-6 leading-relaxed",children:i}),e.jsxs("div",{className:"flex items-center gap-4 py-4 border-y border-border mb-6",children:[e.jsxs(ga,{className:"h-12 w-12",children:[e.jsx(pa,{src:g||void 0,alt:d}),e.jsx(xa,{children:d.charAt(0)})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-semibold",children:d}),e.jsx("div",{className:"text-sm text-muted-foreground",children:f})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(kt,{className:"h-4 w-4"}),e.jsx("span",{children:b})]})]}),l&&e.jsxs("figure",{className:"mb-8",children:[e.jsx("img",{src:l,alt:a,className:"w-full h-auto rounded-lg",loading:"eager"}),m&&e.jsx("figcaption",{className:"mt-3 text-sm text-center text-muted-foreground italic",children:m})]}),C.length>0&&e.jsxs("div",{className:"bg-muted/30 border border-border rounded-lg p-6 mb-8",children:[e.jsx("h3",{className:"font-serif text-xl font-bold mb-4",children:"Key Takeaways"}),e.jsx("ul",{className:"space-y-2",children:C.map((y,S)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary mt-1",children:"•"}),e.jsx("span",{className:"flex-1",children:y})]},S))})]}),e.jsx("div",{ref:p,className:`article-content ${v()}`,dangerouslySetInnerHTML:{__html:Ba(s)}}),e.jsx("div",{className:"mt-12 p-4 bg-muted/50 border border-border rounded-lg text-center",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This is a preview. Comments, sharing, and other interactive elements will be available after publishing."})})]})},rr=({open:a,onOpenChange:i,title:s,excerpt:l,content:m,imageUrl:u,featuredImageCaption:d,categoryName:g,authorName:f,authorImage:x,authorRole:v,keyTakeaways:p})=>e.jsx(Ge,{open:a,onOpenChange:i,children:e.jsxs(Ve,{className:"max-w-5xl h-[90vh] p-0",children:[e.jsx(We,{className:"px-6 pt-6 pb-4 border-b border-border",children:e.jsx(He,{className:"text-2xl font-serif",children:"Article Preview"})}),e.jsx(qe,{className:"h-full",children:e.jsx(ar,{title:s,excerpt:l,content:m,imageUrl:u,featuredImageCaption:d,categoryName:g,authorName:f,authorImage:x,authorRole:v,keyTakeaways:p})})]})});var Ss=["PageUp","PageDown"],ks=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Cs={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Ue="Slider",[Pt,ir,nr]=fa(Ue),[Es,Di]=ba(Ue,[nr]),[or,ot]=Es(Ue),Ps=n.forwardRef((a,i)=>{const{name:s,min:l=0,max:m=100,step:u=1,orientation:d="horizontal",disabled:g=!1,minStepsBetweenThumbs:f=0,defaultValue:x=[l],value:v,onValueChange:p=()=>{},onValueCommit:b=()=>{},inverted:C=!1,form:y,...S}=a,I=n.useRef(new Set),h=n.useRef(0),P=d==="horizontal"?lr:cr,[R=[],q]=va({prop:v,defaultProp:x,onChange:B=>{var H;(H=[...I.current][h.current])==null||H.focus(),p(B)}}),U=n.useRef(R);function Z(B){const L=gr(R,B);ce(B,L)}function Y(B){ce(B,h.current)}function le(){const B=U.current[h.current];
1R[h.current]!==B&&b(R)}function ce(B,L,{commit:H}={commit:!1}){const ee=br(u),X=vr(Math.round((B-l)/u)*u+l,ee),J=ws(X,[l,m]);q((te=[])=>{const re=ur(te,J,L);if(fr(re,f*u)){h.current=re.indexOf(J);const pe=String(re)!==String(te);return pe&&H&&b(re),pe?re:te}else return te})}return e.jsx(or,{scope:a.__scopeSlider,name:s,disabled:g,min:l,max:m,valueIndexToChangeRef:h,thumbs:I.current,values:R,orientation:d,form:y,children:e.jsx(Pt.Provider,{scope:a.__scopeSlider,children:e.jsx(Pt.Slot,{scope:a.__scopeSlider,children:e.jsx(P,{"aria-disabled":g,"data-disabled":g?"":void 0,...S,ref:i,onPointerDown:Ae(S.onPointerDown,()=>{g||(U.current=R)}),min:l,max:m,inverted:C,onSlideStart:g?void 0:Z,onSlideMove:g?void 0:Y,onSlideEnd:g?void 0:le,onHomeKeyDown:()=>!g&&ce(l,0,{commit:!0}),onEndKeyDown:()=>!g&&ce(m,R.length-1,{commit:!0}),onStepKeyDown:({event:B,direction:L})=>{if(!g){const X=Ss.includes(B.key)||B.shiftKey&&ks.includes(B.key)?10:1,J=h.current,te=R[J],re=u*X*L;ce(te+re,J,{commit:!0})}}})})})})});Ps.displayName=Ue;var[Ds,Is]=Es(Ue,{startEdge:"left",endEdge:"right",size:"width",direction:1}),lr=n.forwardRef((a,i)=>{const{min:s,max:l,dir:m,inverted:u,onSlideStart:d,onSlideMove:g,onSlideEnd:f,onStepKeyDown:x,...v}=a,[p,b]=n.useState(null),C=ze(i,P=>b(P)),y=n.useRef(void 0),S=ya(m),I=S==="ltr",h=I&&!u||!I&&u;function D(P){const R=y.current||p.getBoundingClientRect(),q=[0,R.width],Z=Ut(q,h?[s,l]:[l,s]);return y.current=R,Z(P-R.left)}return e.jsx(Ds,{scope:a.__scopeSlider,startEdge:h?"left":"right",endEdge:h?"right":"left",direction:h?1:-1,size:"width",children:e.jsx(As,{dir:S,"data-orientation":"horizontal",...v,ref:C,style:{...v.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:P=>{const R=D(P.clientX);d==null||d(R)},onSlideMove:P=>{const R=D(P.clientX);g==null||g(R)},onSlideEnd:()=>{y.current=void 0,f==null||f()},onStepKeyDown:P=>{const q=Cs[h?"from-left":"from-right"].includes(P.key);x==null||x({event:P,direction:q?-1:1})}})})}),cr=n.forwardRef((a,i)=>{const{min:s,max:l,inverted:m,onSlideStart:u,onSlideMove:d,onSlideEnd:g,onStepKeyDown:f,...x}=a,v=n.useRef(null),p=ze(i,v),b=n.useRef(void 0),C=!m;function y(S){const I=b.current||v.current.getBoundingClientRect(),h=[0,I.height],P=Ut(h,C?[l,s]:[s,l]);return b.current=I,P(S-I.top)}return e.jsx(Ds,{scope:a.__scopeSlider,startEdge:C?"bottom":"top",endEdge:C?"top":"bottom",size:"height",direction:C?1:-1,children:e.jsx(As,{"data-orientation":"vertical",...x,ref:p,style:{...x.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:S=>{const I=y(S.clientY);u==null||u(I)},onSlideMove:S=>{const I=y(S.clientY);d==null||d(I)},onSlideEnd:()=>{b.current=void 0,g==null||g()},onStepKeyDown:S=>{const h=Cs[C?"from-bottom":"from-top"].includes(S.key);f==null||f({event:S,direction:h?-1:1})}})})}),As=n.forwardRef((a,i)=>{const{__scopeSlider:s,onSlideStart:l,onSlideMove:m,onSlideEnd:u,onHomeKeyDown:d,onEndKeyDown:g,onStepKeyDown:f,...x}=a,v=ot(Ue,s);return e.jsx(Be.span,{...x,ref:i,onKeyDown:Ae(a.onKeyDown,p=>{p.key==="Home"?(d(p),p.preventDefault()):p.key==="End"?(g(p),p.preventDefault()):Ss.concat(ks).includes(p.key)&&(f(p),p.preventDefault())}),onPointerDown:Ae(a.onPointerDown,p=>{const b=p.target;b.setPointerCapture(p.pointerId),p.preventDefault(),v.thumbs.has(b)?b.focus():l(p)}),onPointerMove:Ae(a.onPointerMove,p=>{p.target.hasPointerCapture(p.pointerId)&&m(p)}),onPointerUp:Ae(a.onPointerUp,p=>{const b=p.target;b.hasPointerCapture(p.pointerId)&&(b.releasePointerCapture(p.pointerId),u(p))})})}),Ts="SliderTrack",Rs=n.forwardRef((a,i)=>{const{__scopeSlider:s,...l}=a,m=ot(Ts,s);return e.jsx(Be.span,{"data-disabled":m.disabled?"":void 0,"data-orientation":m.orientation,...l,ref:i})});Rs.displayName=Ts;var Dt="SliderRange",zs=n.forwardRef((a,i)=>{const{__scopeSlider:s,...l}=a,m=ot(Dt,s),u=Is(Dt,s),d=n.useRef(null),g=ze(i,d),f=m.values.length,x=m.values.map(b=>Os(b,m.min,m.max)),v=f>1?Math.min(...x):0,p=100-Math.max(...x);return e.jsx(Be.span,{"data-orientation":m.orientation,"data-disabled":m.disabled?"":void 0,...l,ref:g,style:{...a.style,[u.startEdge]:v+"%",[u.endEdge]:p+"%"}})});zs.displayName=Dt;var It="SliderThumb",Us=n.forwardRef((a,i)=>{const s=ir(a.__scopeSlider),[l,m]=n.useState(null),u=ze(i,g=>m(g)),d=n.useMemo(()=>l?s().findIndex(g=>g.ref.current===l):-1,[s,l]);return e.jsx(dr,{...a,ref:u,index:d})}),dr=n.forwardRef((a,i)=>{const{__scopeSlider:s,index:l,name:m,...u}=a,d=ot(It,s),g=Is(It,s),[f,x]=n.useState(null),v=ze(i,D=>x(D)),p=f?d.form||!!f.closest("form"):!0,b=ja(f),C=d.values[l],y=C===void 0?0:Os(C,d.min,d.max),S=hr(l,d.values.length),I=b==null?void 0:b[g.size],h=I?pr(I,y,g.direction):0;return n.useEffect(()=>{if(f)return d.thumbs.add(f),()=>{d.thumbs.delete(f)}},[f,d.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[g.startEdge]:`calc(${y}% + ${h}px)`},children:[e.jsx(Pt.ItemSlot,{scope:a.__scopeSlider,children:e.jsx(Be.span,{role:"slider","aria-label":a["aria-label"]||S,"aria-valuemin":d.min,"aria-valuenow":C,"aria-valuemax":d.max,"aria-orientation":d.orientation,"data-orientation":d.orientation,"data-disabled":d.disabled?"":void 0,tabIndex:d.disabled?void 0:0,...u,ref:v,style:C===void 0?{display:"none"}:a.style,onFocus:Ae(a.onFocus,()=>{d.valueIndexToChangeRef.current=l})})}),p&&e.jsx(Fs,{name:m??(d.name?d.name+(d.values.length>1?"[]":""):void 0),form:d.form,value:C},l)]})});Us.displayName=It;var mr="RadioBubbleInput",Fs=n.forwardRef(({__scopeSlider:a,value:i,...s},l)=>{const m=n.useRef(null),u=ze(m,l),d=wa(i);return n.useEffect(()=>{const g=m.current;if(!g)return;const f=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(f,"value").set;if(d!==i&&v){const p=new Event("input",{bubbles:!0});v.call(g,i),g.dispatchEvent(p)}},[d,i]),e.jsx(Be.input,{style:{display:"none"},...s,ref:u,defaultValue:i})});Fs.displayName=mr;function ur(a=[],i,s){const l=[...a];return l[s]=i,l.sort((m,u)=>m-u)}function Os(a,i,s){const u=100/(s-i)*(a-i);return ws(u,[0,100])}function hr(a,i){return i>2?`Value ${a+1} of ${i}`:i===2?["Minimum","Maximum"][a]:void 0}function gr(a,i){if(a.length===1)return 0;const s=a.map(m=>Math.abs(m-i)),l=Math.min(...s);return s.indexOf(l)}function pr(a,i,s){const l=a/2,u=Ut([0,50],[0,l]);return(l-u(i)*s)*s}function xr(a){return a.slice(0,-1).map((i,s)=>a[s+1]-i)}function fr(a,i){if(i>0){const s=xr(a);return Math.min(...s)>=i}return!0}function Ut(a,i){return s=>{if(a[0]===a[1]||i[0]===i[1])return i[0];const l=(i[1]-i[0])/(a[1]-a[0]);return i[0]+l*(s-a[0])}}function br(a){return(String(a).split(".")[1]||"").length}function vr(a,i){const s=Math.pow(10,i);return Math.round(a*s)/s}var Ms=Ps,yr=Rs,jr=zs,wr=Us;const At=n.forwardRef(({className:a,...i},s)=>e.jsxs(Ms,{ref:s,className:he("relative flex w-full touch-none select-none items-center",a),...i,children:[e.jsx(yr,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:e.jsx(jr,{className:"absolute h-full bg-primary"})}),e.jsx(wr,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));At.displayName=Ms.displayName;const ps=({maxWidth:a,quality:i,originalDimensions:s,stats:l,onMaxWidthChange:m,onQualityChange:u})=>{const d=s?Math.round(s.height/s.width*Math.min(a,s.width)):null,g=s?Math.min(a,s.width):a;return e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground uppercase tracking-wide",children:[e.jsx(ke,{className:"h-3 w-3"}),"Optimization"]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(W,{className:"text-xs font-medium",children:"Max Width"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[g,d?` × ${d}`:"","px"]})]}),e.jsx(At,{value:[a],min:200,max:2e3,step:50,onValueChange:([f])=>m(f)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(W,{className:"text-xs font-medium",children:"Quality"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[Math.round(i*100),"%"]})]}),e.jsx(At,{value:[i*100],min:50,max:100,step:5,onValueChange:([f])=>u(f/100)})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Format"}),e.jsx("span",{className:"font-medium",children:"WebP (auto)"})]}),l&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-primary/10 px-2.5 py-1.5 text-xs",children:[e.jsx(ke,{className:"h-3 w-3 text-primary"}),e.jsxs("span",{children:[ts(l.originalSize)," → ",ts(l.optimizedSize)]}),e.jsxs("span",{className:"ml-auto font-semibold text-primary",children:["saved ",Da(l.originalSize,l.optimizedSize)]})]})]})},Nr=({open:a,onOpenChange:i,onInsert:s})=>{const[l,m]=n.useState(""),[u,d]=n.useState(""),[g,f]=n.useState(""),[x,v]=n.useState(!1),[p,b]=n.useState(!1),[C,y]=n.useState(null),[S,I]=n.useState(null),[h,D]=n.useState(1200),[P,R]=n.useState(.85),[q,U]=n.useState(null),Z=n.useCallback(()=>{m(""),d(""),f(""),y(null),I(null),D(1200),R(.85),U(null)},[]),Y=async L=>{var X;const H=(X=L.target.files)==null?void 0:X[0];if(!H)return;y(H),U(null),m("");try{const J=await Ia(H);I(J),D(Math.min(1200,J.width))}catch{I(null)}const ee=URL.createObjectURL(H);m(ee)},le=async()=>
1{if(C){v(!0);try{const{isGif:L}=await nt(async()=>{const{isGif:ye}=await import("./imageOptimizer-DU1AwbgF.js");return{isGif:ye}},[]),H=L(C),ee=await zt(C,{maxWidth:h,quality:P,format:"webp"}),X=H?"gif":"webp",J=H?"image/gif":"image/webp",re=`post-images/${`${Math.random().toString(36).slice(2)}.${X}`}`,{error:pe}=await _.storage.from("images").upload(re,ee.blob,{contentType:J,cacheControl:"public, max-age=31536000, immutable"});if(pe)throw pe;const{data:{publicUrl:Ce}}=_.storage.from("images").getPublicUrl(re);l.startsWith("blob:")&&URL.revokeObjectURL(l),m(Ce),y(null),U({originalSize:ee.originalSize,optimizedSize:ee.optimizedSize}),_.from("media").insert({title:C.name.replace(/\.[^/.]+$/,""),image_url:Ce,type:"image"}).then(({error:ye})=>{ye&&console.error("Failed to register in media library:",ye)}),fe.success("Image optimized & uploaded")}catch(L){console.error("Error uploading image:",L),fe.error("Failed to upload image")}finally{v(!1)}}},ce=()=>{if(!l||l.startsWith("blob:")){fe.error("Please upload the image first");return}s({url:l,alt:u||"Image",caption:g}),Z(),i(!1)},B=!!C&&!!S;return e.jsxs(Ge,{open:a,onOpenChange:i,children:[e.jsxs(Ve,{className:"sm:max-w-lg max-h-[85vh] p-0 gap-0",children:[e.jsxs(We,{className:"px-4 py-3 border-b border-border",children:[e.jsx(He,{className:"text-base font-semibold",children:"Upload Image"}),e.jsx(ys,{className:"sr-only",children:"Upload an image file or enter a URL, add alt text and an optional caption"})]}),e.jsx(qe,{className:"max-h-[calc(85vh-8rem)]",children:e.jsxs("div",{className:"px-4 py-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"file-upload",className:"text-xs font-medium",children:"Choose file"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{id:"file-upload",type:"file",accept:"image/*",onChange:Y,disabled:x,className:"text-sm h-9"}),e.jsx(E,{type:"button",variant:"outline",size:"icon",disabled:x,asChild:!0,className:"h-9 w-9 flex-shrink-0",children:e.jsx("label",{htmlFor:"file-upload",className:"cursor-pointer",children:e.jsx($e,{className:"h-4 w-4"})})})]})]}),e.jsxs(E,{type:"button",variant:"outline",className:"w-full h-9 text-sm gap-2",onClick:()=>b(!0),children:[e.jsx(Na,{className:"h-4 w-4"}),"Browse Media Library"]}),e.jsxs("div",{className:"relative py-2",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t border-border"})}),e.jsx("div",{className:"relative flex justify-center text-xs",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground uppercase tracking-wide",children:"Or enter URL"})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"image-url",className:"text-xs font-medium",children:"Image URL"}),e.jsx(Q,{id:"image-url",placeholder:"https://example.com/image.jpg",value:l.startsWith("blob:")?"":l,onChange:L=>{m(L.target.value),y(null),I(null),U(null)},className:"text-sm h-9"})]}),B&&e.jsx(ps,{maxWidth:h,quality:P,originalDimensions:S,stats:q,onMaxWidthChange:D,onQualityChange:R}),C&&e.jsx(E,{type:"button",className:"w-full h-9 text-sm gap-2",onClick:le,disabled:x,children:x?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 animate-spin"}),"Optimizing & Uploading…"]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"h-4 w-4"}),"Compress & Upload as WebP"]})}),!C&&q&&e.jsx(ps,{maxWidth:h,quality:P,originalDimensions:null,stats:q,onMaxWidthChange:()=>{},onQualityChange:()=>{}}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"alt-text",className:"text-xs font-medium",children:"Alt Text (for accessibility)"}),e.jsx(Q,{id:"alt-text",placeholder:"Describe the image",value:u,onChange:L=>d(L.target.value),className:"text-sm h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"caption",className:"text-xs font-medium",children:"Caption (optional)"}),e.jsx(Re,{id:"caption",placeholder:"Add a caption for this image",value:g,onChange:L=>f(L.target.value),rows:2,className:"text-sm resize-none"})]}),l&&e.jsxs("div",{className:"space-y-1.5 pt-2",children:[e.jsx(W,{className:"text-xs font-medium",children:"Preview"}),e.jsxs("figure",{className:"border border-border rounded overflow-hidden bg-muted/20",children:[e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:l,alt:u||"Preview",className:"w-full h-auto max-h-48 object-contain"}),e.jsx(E,{type:"button",variant:"ghost",size:"icon",onClick:()=>{l.startsWith("blob:")&&URL.revokeObjectURL(l),m(""),y(null),I(null),U(null)},className:"absolute top-2 right-2 h-7 w-7 bg-background/80 hover:bg-background opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(Te,{className:"h-3.5 w-3.5"})})]}),g&&e.jsx("figcaption",{className:"px-3 py-2 text-xs text-center text-muted-foreground italic border-t border-border bg-background/50",children:g})]})]})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border bg-muted/30",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:()=>i(!1),className:"h-8 text-xs",children:"Cancel"}),e.jsx(E,{size:"sm",onClick:ce,disabled:!l||l.startsWith("blob:"),className:"h-8 text-xs",children:"Insert Image"})]})]}),e.jsx(js,{open:p,onOpenChange:b,onSelect:L=>{m(L),y(null),I(null),U(null)}})]})},Nt=()=>[{id:crypto.randomUUID(),url:"",alt:"",caption:""},{id:crypto.randomUUID(),url:"",alt:"",caption:""}],_r=({open:a,onOpenChange:i,onInsert:s,initialSlides:l,isEditing:m=!1})=>{var Ee,ue,Ne;const[u,d]=n.useState(Nt),[g,f]=n.useState(null),[x,v]=n.useState(0),[p,b]=n.useState(null),[C,y]=n.useState("slides"),[S,I]=n.useState(null),[h,D]=n.useState([]),[P,R]=n.useState(!1),[q,U]=n.useState(""),[Z,Y]=n.useState(1),[le,ce]=n.useState(0),B=18;n.useEffect(()=>{a&&l&&l.length>0?(d(l.map(w=>({id:crypto.randomUUID(),url:w.url,alt:w.alt,caption:w.caption}
1))),v(0)):a&&!l&&(d(Nt()),v(0))},[a,l]),n.useEffect(()=>{C==="gallery"&&L()},[C,Z,q]),n.useEffect(()=>{const w=setTimeout(()=>{C==="gallery"&&Y(1)},300);return()=>clearTimeout(w)},[q]);const L=async()=>{R(!0);try{const w=(Z-1)*B,F=w+B-1;let O=_.from("media").select("*",{count:"exact"}).order("created_at",{ascending:!1});q.trim()&&(O=O.ilike("title",`%${q}%`)),O=O.range(w,F);const{data:se,error:ae,count:Oe}=await O;if(ae)throw ae;D(se||[]),ce(Oe||0)}catch(w){console.error("Error fetching media:",w)}finally{R(!1)}},H=()=>{d([...u,{id:crypto.randomUUID(),url:"",alt:"",caption:""}])},ee=w=>{if(u.length<=2){fe.error("Carousel requires at least 2 images");return}const F=u.filter((O,se)=>se!==w);d(F),x>=F.length&&v(Math.max(0,F.length-1))},X=(w,F,O)=>{const se=[...u];se[w]={...se[w],[F]:O},d(se)},J=async(w,F)=>{var se;const O=(se=F.target.files)==null?void 0:se[0];if(O){f(u[w].id);try{const ae=O.name.split(".").pop(),be=`post-images/${`carousel-${Date.now()}-${Math.random().toString(36).substring(7)}.${ae}`}`,{error:ve}=await _.storage.from("images").upload(be,O,{cacheControl:"public, max-age=31536000, immutable"});if(ve)throw ve;const{data:{publicUrl:Qe}}=_.storage.from("images").getPublicUrl(be);X(w,"url",Qe),fe.success("Image uploaded")}catch(ae){console.error("Error uploading image:",ae),fe.error("Failed to upload image")}finally{f(null)}}},te=w=>{I(w),y("gallery"),U(""),Y(1)},re=w=>{S!==null&&(X(S,"url",w),y("slides"),I(null))},pe=w=>{b(w)},Ce=(w,F)=>{if(w.preventDefault(),p===null||p===F)return;const O=[...u],se=O[p];O.splice(p,1),O.splice(F,0,se),d(O),b(F)},ye=()=>{b(null)},ut=()=>{const w=u.filter(F=>F.url.trim()!=="");if(w.length<2){fe.error("Please add at least 2 images");return}s(w),d(Nt()),v(0),y("slides"),i(!1)},K=u.filter(w=>w.url.trim()!==""),Fe=Math.ceil(le/B);return e.jsx(Ge,{open:a,onOpenChange:i,children:e.jsxs(Ve,{className:"sm:max-w-xl max-h-[85vh] p-0 gap-0 overflow-hidden",children:[e.jsxs(We,{className:"px-4 py-2.5 border-b border-border/50 bg-muted/20",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(He,{className:"text-sm font-medium flex items-center gap-2",children:C==="gallery"?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"h-4 w-4 text-primary"}),e.jsx("span",{children:"Media Library"})]}):e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"h-4 w-4 text-primary"}),e.jsx("span",{children:m?"Edit Carousel":"Image Carousel"})]})}),C==="gallery"&&e.jsxs(E,{variant:"ghost",size:"sm",onClick:()=>y("slides"),className:"h-7 text-xs gap-1",children:[e.jsx(rs,{className:"h-3 w-3"}),"Back"]})]}),e.jsx(ys,{className:"text-[11px] text-muted-foreground mt-0.5",children:C==="gallery"?`Select image for Slide ${(S??0)+1}`:m?"Edit slides, reorder, or add new images":"Add 2+ images to create a carousel"})]}),C==="slides"?e.jsxs(e.Fragment,{children:[e.jsx(qe,{className:"flex-1",style:{maxHeight:"calc(85vh - 120px)"},children:e.jsxs("div",{className:"p-3 space-y-1.5",children:[u.map((w,F)=>e.jsxs("div",{draggable:!0,onDragStart:()=>pe(F),onDragOver:O=>Ce(O,F),onDragEnd:ye,onClick:()=>v(F),className:he("group flex items-start gap-2 p-2 rounded-lg border bg-background transition-all cursor-pointer",p===F&&"opacity-50 border-primary",x===F?"border-primary/50 bg-primary/5":"border-border/50 hover:border-border"),children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(Ns,{className:"h-3.5 w-3.5 text-muted-foreground/50 cursor-grab"}),e.jsx("div",{className:"w-12 h-12 rounded bg-muted/50 overflow-hidden flex items-center justify-center",children:w.url?e.jsx("img",{src:w.url,alt:"",className:"w-full h-full object-cover"}):e.jsx(rt,{className:"h-4 w-4 text-muted-foreground/40"})})]}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Q,{placeholder:"Image URL or select from gallery",value:w.url,onChange:O=>X(F,"url",O.target.value),className:"h-6 text-[11px] flex-1"}),e.jsx(E,{type:"button",variant:"ghost",size:"icon",onClick:O=>{O.stopPropagation(),te(F)}
1,className:"h-6 w-6 flex-shrink-0",title:"Choose from gallery",children:e.jsx(Ct,{className:"h-3 w-3"})}),e.jsx(E,{type:"button",variant:"ghost",size:"icon",disabled:g===w.id,asChild:!0,className:"h-6 w-6 flex-shrink-0",children:e.jsxs("label",{className:"cursor-pointer",title:"Upload file",children:[g===w.id?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx($e,{className:"h-3 w-3"}),e.jsx("input",{type:"file",accept:"image/*",onChange:O=>J(F,O),className:"hidden"})]})})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(Q,{placeholder:"Alt text",value:w.alt,onChange:O=>X(F,"alt",O.target.value),className:"h-6 text-[11px] flex-1"}),e.jsx(Q,{placeholder:"Caption",value:w.caption,onChange:O=>X(F,"caption",O.target.value),className:"h-6 text-[11px] flex-1"})]})]}),u.length>2&&e.jsx(E,{type:"button",variant:"ghost",size:"icon",onClick:O=>{O.stopPropagation(),ee(F)},className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:e.jsx(Te,{className:"h-3 w-3"})})]},w.id)),e.jsxs(E,{type:"button",variant:"ghost",size:"sm",onClick:H,className:"w-full h-7 text-[11px] gap-1 border border-dashed border-border/50 hover:border-primary/50 hover:bg-primary/5",children:[e.jsx(Et,{className:"h-3 w-3"}),"Add Slide"]}),K.length>0&&e.jsxs("div",{className:"pt-3 mt-2 border-t border-border/30",children:[e.jsxs("div",{className:"relative bg-muted/30 rounded-lg overflow-hidden aspect-[16/9]",children:[e.jsx("img",{src:(Ee=K[x%K.length])==null?void 0:Ee.url,alt:((ue=K[x%K.length])==null?void 0:ue.alt)||"Preview",className:"w-full h-full object-contain"}),K.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(E,{type:"button",variant:"secondary",size:"icon",onClick:()=>v((x-1+K.length)%K.length),className:"absolute left-1.5 top-1/2 -translate-y-1/2 h-6 w-6 bg-background/80 backdrop-blur-sm",children:e.jsx(rs,{className:"h-3.5 w-3.5"})}),e.jsx(E,{type:"button",variant:"secondary",size:"icon",onClick:()=>v((x+1)%K.length),className:"absolute right-1.5 top-1/2 -translate-y-1/2 h-6 w-6 bg-background/80 backdrop-blur-sm",children:e.jsx(_a,{className:"h-3.5 w-3.5"})})]}),K.length>1&&e.jsx("div",{className:"absolute bottom-1.5 left-1/2 -translate-x-1/2 flex gap-1",children:K.map((w,F)=>e.jsx("button",{onClick:()=>v(F),className:he("w-1.5 h-1.5 rounded-full transition-all",F===x%K.length?"bg-foreground":"bg-foreground
1/30")},F))})]}),((Ne=K[x%K.length])==null?void 0:Ne.caption)&&e.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground italic text-center truncate",children:K[x%K.length].caption})]})]})}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-border/50 bg-muted/20",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[K.length,"/",u.length," ready"]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>i(!1),className:"h-7 text-xs",children:"Cancel"}),e.jsxs(E,{size:"sm",onClick:ut,disabled:K.length<2,className:"h-7 text-xs gap-1",children:[e.jsx(rt,{className:"h-3 w-3"}),m?"Update":"Insert"]})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-2 border-b border-border/50",children:e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(Q,{placeholder:"Search media...",value:q,onChange:w=>U(w.target.value),className:"pl-8 h-7 text-xs"})]})}),e.jsx(qe,{className:"h-[300px]",children:e.jsx("div",{className:"p-3",children:P?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(me,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):h.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(rt,{className:"h-8 w-8 mb-2 opacity-40"}),e.jsx("p",{className:"text-xs",children:q?"No results":"No media"})]}):e.jsx("div",{className:"grid grid-cols-5 sm:grid-cols-6 gap-1.5",children:h.map(w=>e.jsx("button",{type:"button",onClick:()=>re(w.image_url),className:"relative aspect-square rounded overflow-hidden border border-transparent hover:border-primary transition-all focus:outline-none focus:ring-1 focus:ring-primary",children:e.jsx("img",{src:w.image_url,alt:w.title,className:"w-full h-full object-cover",loading:"lazy"})},w.id))})})}),Fe>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2 px-3 py-1.5 border-t border-border/50",children:[e.jsx(E,{variant:"ghost",size:"sm",disabled:Z===1,onClick:()=>Y(w=>w-1),className:"h-6 text-[10px] px-2",children:"Prev"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Z,"/",Fe]}),e.jsx(E,{variant:"ghost",size:"sm",disabled:Z===Fe,onClick:()=>Y(w=>w+1),className:"h-6 text-[10px] px-2",children:"Next"})]}),e.jsx("div",{className:"px-3 py-2 border-t border-border/50 bg-muted/20",children:e.jsxs("p",{className:"text-[10px] text-muted-foreground text-center",children:[le.toLocaleString()," images • Click to select"]})})]})]})})},Sr=({authors:a,selectedAuthors:i,onSelectionChange:s,className:l})=>{const[m,u]=n.useState(!1),[d,g]=n.useState(""),f=a.filter(h=>h.name.toLowerCase().includes(d.toLowerCase())),x=h=>a.find(D=>D.id===h),v=h=>i.some(D=>D.id===h),p=()=>{var h;return(h=i.find(D=>D.isPrimary))==null?void 0:h.id},b=h=>{var D;if(v(h)){const P=(D=i.find(q=>q.id===h))==null?void 0:D.isPrimary,R=i.filter(q=>q.id!==h);P&&R.length>0&&(R[0].isPrimary=!0),R.forEach((q,U)=>q.displayOrder=U),s(R)}else{const P={id:h,isPrimary:i.length===0,displayOrder:i.length};s([...i,P])}},C=h=>{const D=i.map(P=>({...P,isPrimary:P.id===h}));s(D)},y=h=>{b(h)},S=h=>{if(h===0)return;const D=[...i];[D[h-1],D[h]]=[D[h],D[h-1]],D.forEach((P,R)=>P.displayOrder=R),s(D)},I=[...i].sort((h,D)=>h.displayOrder-D.displayOrder);return e.jsxs("div",{className:he("space-y-3",l),children:[I.length>0&&e.jsx("div",{className:"space-y-2",children:I.map((h,D)=>{const P=x(h.id);return P?e.jsxs("div",{className:he("flex items-center gap-2 p-2 rounded-lg border bg-background",h.isPrimary&&"border-primary/50 bg-primary/5"),children:[e.jsx("div",{className:"flex flex-col gap-0.5",children:e.jsx("button",{type:"button",onClick:()=>S(D),disabled:D===0,className:"text-muted-foreground hover:text-foreground disabled:opacity-30",children:e.jsx(Ns,{className:"h-3 w-3"})})}),P.image_url?e.jsx("img",{src:P.image_url,alt:P.name,className:"w-8 h-8 rounded-full object-cover"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium",children:P.name.charAt(0)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:P.name}),P.role&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:P.role})]}),h.isPrimary?e.jsxs(xs,{variant:"secondary",className:"text-xs gap-1",children:[e.jsx(is,{className:"h-3 w-3 fill-current"}),"Primary"]}):e.jsx(E,{type:"button",variant:"ghost",size:"sm",onClick:()=>C(h.id),className:"text-xs h-6",children:"Set Primary"}),e.jsx(E,{type:"button",variant:"ghost",size:"icon",onClick:()=>y(h.id),className:"h-6 w-6 text-muted-foreground hover:text-destructive",children:e.jsx(Te,{className:"h-3 w-3"})})]}
1,h.id):null})}),e.jsxs(fs,{open:m,onOpenChange:u,children:[e.jsx(bs,{asChild:!0,children:e.jsxs(E,{type:"button",variant:"outline",role:"combobox","aria-expanded":m,className:"w-full justify-between",children:[i.length===0?"Select authors...":`${i.length} author${i.length>1?"s":""} selected`,e.jsx(_s,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxs(vs,{className:"w-80 p-0",align:"start",children:[e.jsx("div",{className:"p-2 border-b",children:e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Q,{placeholder:"Search authors...",value:d,onChange:h=>g(h.target.value),className:"pl-8 h-8"})]})}),e.jsx(qe,{className:"h-60",children:e.jsx("div",{className:"p-2 space-y-1",children:f.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No authors found"}):f.map(h=>e.jsxs("div",{className:he("flex items-center gap-2 p-2 rounded-md hover:bg-muted cursor-pointer",v(h.id)&&"bg-muted"),onClick:()=>b(h.id),children:[e.jsx(Wa,{checked:v(h.id),onCheckedChange:()=>b(h.id)}),h.image_url?e.jsx("img",{src:h.image_url,alt:h.name,className:"w-6 h-6 rounded-full object-cover"}):e.jsx("div",{className:"w-6 h-6 rounded-full bg-muted-foreground/20 flex items-center justify-center text-xs",children:h.name.charAt(0)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:h.name}),h.role&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:h.role})]}),p()===h.id&&e.jsx(is,{className:"h-3 w-3 text-primary fill-current"})]},h.id))})})]})]}),i.length>1&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"The primary author will be shown first and used in feeds."})]})};function kr({open:a,onOpenChange:i,onSelect:s}){const[l,m]=n.useState([]),[u,d]=n.useState(!0),[g,f]=n.useState(""),[x,v]=n.useState(!1),{toast:p}=Rt();n.useEffect(()=>{a&&b()},[a,g]);const b=async()=>{d(!0);let y=_.from("infographics").select("id, title, image_url, alt_text, caption").order("created_at",{ascending:!1}).limit(50);g&&(y=y.ilike("title",`%${g}%`));const{data:S}=await y;m(S||[]),d(!1)},C=async y=>{var I;const S=(I=y.target.files)==null?void 0:I[0];if(S){v(!0);try{const h=S.type==="application/pdf";let D=S,P=S.type,R=S.name.split(".").pop()||"bin";if(h)R="pdf",P="application/pdf";else{const{optimizeImage:le,isGif:ce}=await nt(async()=>{const{optimizeImage:H,isGif:ee}=await import("./imageOptimizer-DU1AwbgF.js");return{optimizeImage:H,isGif:ee}},[]),B=ce(S);D=(await le(S,{maxWidth:2e3,maxHeight:4e3,quality:.9,format:"webp"})).blob,P=B?"image/gif":"image/webp",R=B?"gif":"webp"}const q=`infographics/${Date.now()}-${Math.random().toString(36).substring(7)}.${R}`,{error:U}=await _.storage.from("imported-images").upload(q,D,{contentType:P,cacheControl:"public, max-age=31536000, immutable"});if(U)throw U;const{data:{publicUrl:Z}}=_.storage.from("imported-images").getPublicUrl(q),{error:Y}=await _.from("infographics").insert({title:S.name.replace(/\.[^/.]+$/,""),image_url:Z});if(Y)throw Y;p({title:"Infographic uploaded"}),b()}catch(h){p({variant:"destructive",title:"Upload failed",description:h.message})}finally{v(!1)}}};return e.jsx(Ge,{open:a,onOpenChange:i,children:e.jsxs(Ve,{className:"max-w-3xl max-h-[80vh] overflow-y-auto",children:[e.jsx(We,{children:e.jsx(He,{children:"Select Infographic"})}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Q,{placeholder:"Search infographics...",value:g,onChange:y=>f(y.target.value),className:"pl-10"})]}),e.jsxs("div",{children:[e.jsx("input",{type:"file",id:"infographic-upload-picker",className:"hidden",accept:"image/*,application/pdf",onChange:C,disabled:x}),e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>{var y;return(y=document.getElementById("infographic-upload-picker"))==null?void 0:y.click()},disabled:x,children:[e.jsx($e,{className:"mr-2 h-4 w-4"}),x?"Uploading...":"Upload"]})]})]}),u?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:Array.from({length:6}).map((y,S)=>e.jsx("div",{className:"aspect-[3/4] bg-muted rounded-lg animate-pulse"}
1,S))}):l.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No infographics found. Upload one to get started."}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:l.map(y=>e.jsxs("button",{onClick:()=>{s(y),i(!1)},className:"group relative bg-muted rounded-lg overflow-hidden border border-border/50 hover:border-primary/50 transition-colors text-left",children:[y.image_url.endsWith(".pdf")?e.jsxs("div",{className:"w-full h-32 flex flex-col items-center justify-center bg-muted/50 gap-1",children:[e.jsx(St,{className:"h-10 w-10 text-primary/60"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"PDF"})]}):e.jsx("img",{src:y.image_url,alt:y.alt_text||y.title,className:"w-full h-auto max-h-48 object-cover",loading:"lazy"}),e.jsx("div",{className:"p-2",children:e.jsx("p",{className:"text-xs font-medium truncate",children:y.title})})]},y.id))})]})})}const Cr=({value:a,onChange:i})=>{const[s,l]=n.useState([]);n.useEffect(()=>{try{const x=JSON.parse(a||"[]");Array.isArray(x)&&l(x)}catch{l([])}},[a]);const m=x=>{l(x),i(JSON.stringify(x))},u=(x,v)=>{const p=[...s];p[x]=v,m(p)},d=x=>m(s.filter((v,p)=>p!==x)),g=()=>m([...s,""]),f=(x,v)=>{const p=x+v;if(p<0||p>=s.length)return;const b=[...s];[b[x],b[p]]=[b[p],b[x]],m(b)};return s.length===0?e.jsxs("div",{className:"text-center py-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"No takeaways yet"}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:g,className:"gap-1.5 h-7 text-xs",children:[e.jsx(Et,{className:"h-3 w-3"})," Add manually"]})]}):e.jsxs("div",{className:"space-y-2",children:[s.map((x,v)=>e.jsxs("div",{className:"flex items-center gap-1.5 group",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("button",{type:"button",onClick:()=>f(v,-1),disabled:v===0,className:"text-muted-foreground hover:text-foreground disabled:opacity-20 transition-opacity p-0.5",children:e.jsx(Ka,{className:"h-3 w-3"})}),e.jsx("button",{type:"button",onClick:()=>f(v,1),disabled:v===s.length-1,className:"text-muted-foreground hover:text-foreground disabled:opacity-20 transition-opacity p-0.5",children:e.jsx(_s,{className:"h-3 w-3"})})]}),e.jsxs("span",{className:"text-amber-500 font-bold text-xs shrink-0",children:[v+1,"."]}),e.jsx(Q,{value:x,onChange:p=>u(v,p.target.value),className:"text-xs h-8 bg-white/50 dark:bg-black/20 border-amber-200/50 dark:border-amber-800/30",placeholder:`Takeaway ${v+1}`}),e.jsx("button",{type:"button",onClick:()=>d(v),className:"opacity-0 group-hover:opacity-100 text-destructive hover:text-destructive/80 transition-opacity p-1",children:e.jsx(Qa,{className:"h-3.5 w-3.5"})})]},v)),e.jsxs(E,{type:"button",variant:"ghost",size:"sm",onClick:g,className:"gap-1 h-7 text-xs w-full hover:bg-amber-100/50 dark:hover:bg-amber-900/30",children:[e.jsx(Et,{className:"h-3 w-3"})," Add takeaway"]})]})},Er=()=>{const[a,i]=n.useState(!1),[s,l]=n.useState(""),[m,u]=n.useState(""),[d,g]=n.useState(!1),[f,x]=n.useState(!1),{toast:v}=Rt();n.useEffect(()=>{!a||f||_.from("editorial_guidelines").select("guidelines, examples").eq("guideline_type","key_takeaways").single().then(({data:b})=>{b&&(l(b.guidelines||""),u(b.examples||"")),x(!0)})},[a,f]);const p=async()=>{g(!0);try{const{error:b}=await _.from("editorial_guidelines").upsert({guideline_type:"key_takeaways",guidelines:s,examples:m,updated_at:new Date().toISOString()},{onConflict:"guideline_type"});if(b)throw b;v({title:"Guidelines saved",description:"Your editorial guidelines will be used for future AI generations."}),i(!1)}catch(b){v({variant:"destructive",title:"Error",description:b.message})}finally{g(!1)}};return e.jsxs(Ge,{open:a,onOpenChange:i,children:[e.jsx(Ma,{asChild:!0,children:e.jsx(E,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0 hover:bg-amber-100/50 dark:hover:bg-amber-900/30",title:"Editorial Guidelines",children:e.jsx(Ya,{className:"h-3.5 w-3.5"})})}),e.jsxs(Ve,{className:"sm:max-w-lg",children:[e.jsxs(We,{children:[e.jsx(He,{className:"text-base",children:"Takeaway Editorial Guidelines"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"These guidelines are injected into the AI prompt when generating takeaways."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{className:"text-sm",children:"Guidelines & Style Rules"}),e.jsx(Re,{value:s,onChange:b=>l(b.target.value),placeholder:"e.g. Write in active voice. Keep each takeaway under 15 words. Focus on industry impact rather than technical details...",className:"min-h-[120px] text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{className:"text-sm",children:"Example Takeaways (good examples)"}),e.jsx(Re,{value:m,onChange:b=>u(b.target.value),placeholder:`e.g.
2Good: 'OpenAI launches GPT-5, raising the bar for enterprise AI adoption'
3Bad: 'GPT-5 is released by OpenAI'`,className:"min-h-[100px] text-sm"})]})]}),e.jsxs(La,{children:[e.jsx(E,{type:"button",variant:"outline",onClick:()=>i(!1),size:"sm",children:"Cancel"}),e.jsxs(E,{type:"button",onClick:p,disabled:d,size:"sm",className:"gap-1.5",children:[d&&e.jsx(me,{className:"h-3 w-3 animate-spin"}),"Save Guidelines"]})]})]})]})},Ke=ge.Quill.import("blots/block/embed"),Pr=ge.Quill.import("blots/block"),Dr=ge.Quill.import("blots/inline");class lt extends Pr{static create(i){return super.create()}}lt.blotName="pullquote";lt.tagName="blockquote";lt.className="pullquote";class Ft extends Ke{static create(){return super.create()}}Ft.blotName="divider";Ft.tagName="hr";class Ot extends Dr{static create(){return super.create()}}Ot.blotName="highlight";Ot.tagName="mark";class Mt extends Ke{static create(i){const s=super.create();return typeof i=="string"?(s.setAttribute("src",i),s.setAttribute("frameborder","0"),s.setAttribute("allowfullscreen","true"),s.setAttribute("width","100%"),s.setAttribute("height","400")):typeof i=="object"&&Object.keys(i).forEac
3h(l=>{s.setAttribute(l,i[l])}),s}static value(i){const s={};return Array.from(i.attributes).forEach(l=>{s[l.name]=l.value}),s}}Mt.blotName="iframe";Mt.tagName="iframe";class ct extends Ke{static create(i){const s=super.create();return s.setAttribute("src",i),s.setAttribute("frameborder","0"),s.setAttribute("allowfullscreen","true"),s.setAttribute("width","100%"),s.setAttribute("height","400"),s}static value(i){return i.getAttribute("src")}}ct.blotName="video";ct.tagName="iframe";ct.className="ql-video";class dt extends Ke{static create(i){const s=super.create(),l=document.createElement("img");if(l.setAttribute("src",i.url),l.setAttribute("alt",i.alt),i.width?l.style.width=i.width:l.style.width="100%",i.height&&(l.style.height=i.height),s.appendChild(l),i.caption){const m=document.createElement("figcaption");m.textContent=i.caption,s.appendChild(m)}return s}static value(i){const s=i.querySelector("img"),l=i.querySelector("figcaption");return{url:(s==null?void 0:s.getAttribute("src"))||"",alt:(s==null?void 0:s.getAttribute("alt"))||"",caption:(l==null?void 0:l.textContent)||"",width:(s==null?void 0:s.style.width)||"",height:(s==null?void 0:s.style.height)||""}}}dt.blotName="imagewithcaption";dt.tagName="figure";dt.className="image-with-caption";class mt extends Ke{static create(i){const s=super.create();s.setAttribute("class","image-carousel"),s.setAttribute("data-carousel-id",i.id);const l=document.createElement("div");return l.className="carousel-slides",i.slides.forEach((m,u)=>{const d=document.createElement("figure");d.className="carousel-slide",d.setAttribute("data-index",String(u));const g=document.createElement("img");if(g.src=m.url,g.alt=m.alt||`Slide ${u+1}`,d.appendChild(g),m.caption){const f=document.createElement("figcaption");f.textContent=m.caption,d.appendChild(f)}l.appendChild(d)}),s.appendChild(l),s}static value(i){const s=[];return i.querySelectorAll(".carousel-slide").forEach(m=>{const u=m.querySelector("img"),d=m.querySelector("figcaption");s.push({url:(u==null?void 0:u.getAttribute("src"))||"",alt:(u==null?void 0:u.getAttribute("alt"))||"",caption:(d==null?void 0:d.textContent)||""})}),{id:i.getAttribute("data-carousel-id")||"",slides:s}}}mt.blotName="imagecarousel";mt.tagName="div";mt.className="image-carousel";ge.Quill.register(lt);ge.Quill.register(Ft);ge.Quill.register(Ot);ge.Quill.register(Mt);ge.Quill.register(ct);ge.Quill.register(dt);ge.Quill.register(mt);const it=a=>a.replace(/<img[^>]+src\s*=\s*["']data:[^"']*["'][^>]*\/?>/gi,""),Ir=a=>{try{const[i,s]=a.split(","),l=/data:([^;]+)/.exec(i||""),m=(l==null?void 0:l[1])||"image/png",u=atob(s),d=u.length,g=new Uint8Array(d);for(let f=0;f<d;f++)g[f]=u.charCodeAt(f);return new Blob([g],{type:m})}catch(i){return console.error("dataUrlToBlob failed",i),null}},_t=async a=>{if(!a||!a.includes("data:image"))return a;const s=new DOMParser().parseFromString(`<div id="__root">${a}</div>`,"text/html").getElementById("__root");if(!s)return it(a);const l=Array.from(s.querySelectorAll("img"));for(const m of l){const u=m.getAttribute("src")||"";if(!u.startsWith("data:image"))continue;const d=Ir(u);if(!d){m.remove();continue}try{const g=d.type==="image/gif";let f=d;if(!g){const S=new File([d],"inline.png",{type:d.type});f=(await zt(S,{maxWidth:1200,quality:.85,format:"webp"})).blob}const x=g?"gif":"webp",v=g?"image/gif":"image/webp",b=`post-images/${`${Date.now()}-${Math.random().toString(36).slice(2)}.${x}`}`,{error:C}=await _.storage.from("images").upload(b,f,{contentType:v,cacheControl:"public, max-age=31536000, immutable"});if(C)throw C;const{data:{publicUrl:y}}=_.storage.from("images").getPublicUrl(b);m.setAttribute("src",y),_.from("media").insert({title:m.getAttribute("alt")||"Inline image",image_url:y,type:"image"}).then(({error:S})=>{S&&console.error("Failed to register inline image in media library:",S)})}catch(g){console.error("Inline image upload failed, removing:",g),m.remove()}}return s.innerHTML},Ii=()=>{var Jt,Xt,Zt,es;const{id:a}=Sa(),i=ka(),{toast:s}=Rt(),{isAdmin:l}=Ca(),[m,u]=n.useState(!1),[d,g]=n.useState(!1),[f,x]=n.useState(!a),[v,p]=n.useState(!!a),[b,C]=n.useState(!1),[y,S]=n.useState(!1),[I,h]=n.useState([]),[D,P]=n.useState([]),[R,q]=n.useState(null),[U,Z]=n.useState(""),[Y,le]=n.useState(null),[ce,B]=n.useState(!1),[L,H]=n.useState(!1),[ee,X]=n.useState(null),[J,te]=n.useState(!1),[re,pe]=n.useState(!1),[Ce,ye]=n.useState(0),[ut,K]=n.useState(!1),[Fe,Ee]=n.useState(!1),[ue,Ne]=n.useState(null),[w,F]=n.useState(!1),[O,se]=n.useState(!1),[ae,Oe]=n.useState(!1),[be,ve]=n.useState(null),[Qe,Ls]=n.useState(null),Ye=n.useRef(null),[_e,Je]=n.useState({open:!1,oldSlug:"",newSlug:""}),de=n.useRef(null),Xe=n.useRef(null),[qs,Ze]=n.useState(!1),[ht,gt]=n.useState(null),[ie,pt]=n.useState([]),[$s,Lt]=n.useState(!1),[Pe,et]=n.useState([]),[De,xt]=n.useState([]),[Bs,tt]=n.useState(!1),[qt,Gs]=n.useState([]),[r,M]=n.useState({title:"",slug:"",excerpt:"",discussion_prompt:"",content:"",image_url:"",featured_image_caption:"",category_id:"",author_id:"",read_time:"",featured:!1,pinned_at:null,published:!1,seo_title:"",seo_description:"",seo_keywords:"",key_takeaways:"",satirical_take:"",show_on_ai_compass:!1,ai_compass_order:null,published_at:new Date().toISOString()}),$t=t=>
3new Date(t).toLocaleString("en-IN",{timeZone:"Asia/Kolkata",day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})+" IST",Ie=()=>r.published_at?new Date(r.published_at)>new Date:!1,Me=330*6e4,Vs=t=>{if(!t)return;const o=r.published_at?new Date(r.published_at):new Date,c=new Date(o.getTime()+Me),j=c.getUTCHours(),A=c.getUTCMinutes(),G=Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),j,A,0)-Me;M({...r,published_at:new Date(G).toISOString()})},Ws=t=>{if(!t)return;const[o,c]=t.split(":").map(Number),j=r.published_at?new Date(r.published_at):new Date,A=new Date(j.getTime()+Me),G=Date.UTC(A.getUTCFullYear(),A.getUTCMonth(),A.getUTCDate(),o,c,0)-Me;M({...r,published_at:new Date(G).toISOString()})},Hs=()=>{if(!r.published_at)return"";const t=new Date(r.published_at),o=new Date(t.getTime()+Me),c=o.getUTCHours().toString().padStart(2,"0"),j=o.getUTCMinutes().toString().padStart(2,"0");return`${c}:${j}`},Ks=n.useCallback(t=>{var j;const o=(j=de.current)==null?void 0:j.getEditor();if(!o){console.error("Quill editor not found");return}const c=be||o.getSelection(!0)||{index:0};console.log("Inserting image at index:",c.index,"with data:",t),o.insertEmbed(c.index,"imagewithcaption",t,"user"),o.setSelection(c.index+1,0),ve(null)},[be]),Bt=n.useCallback(()=>{var o;const t=(o=de.current)==null?void 0:o.getEditor();if(t){const c=t.getSelection(!0);ve(c)}K(!0)},[]),Gt=n.useCallback(()=>{var c;const t=(c=de.current)==null?void 0:c.getEditor();if(!t)return;const o=t.getSelection(!0);t.formatLine(o.index,o.length,"pullquote",!0)},[]),Vt=n.useCallback(()=>{var c;const t=(c=de.current)==null?void 0:c.getEditor();if(!t)return;const o=t.getSelection(!0);t.insertEmbed(o.index,"divider",!0,"user"),t.setSelection(o.index+1,0)},[]),Wt=n.useCallback(()=>{var o;const t=(o=de.current)==null?void 0:o.getEditor();if(t){const c=t.getSelection(!0);ve(c)}Ne(null),Ee(!0)},[]),Ht=n.useCallback(()=>{var o;const t=(o=de.current)==null?void 0:o.getEditor();if(t){const c=t.getSelection(!0);ve(c)}se(!0)},[]),Qs=n.useCallback(t=>{var T;const o=(T=de.current)==null?void 0:T.getEditor();if(!o){console.error("Quill editor not found");return}const c=be||o.getSelection(!0)||{index:0},G=new DOMParser().parseFromString(t,"text/html").querySelector("iframe");if(G){const N={};Array.from(G.attributes).forEach(k=>{N[k.name]=k.value}),N.width||(N.width="100%"),N.height||(N.height="400"),o.insertEmbed(c.index,"iframe",N,"user")}else o.clipboard.dangerouslyPasteHTML(c.index,t,"user");o.setSelection(c.index+1,0),ve(null)},[be]),ft=n.useCallback(t=>{const c=t.target.closest(".image-carousel");if(c&&de.current){t.preventDefault(),t.stopPropagation();const j=de.current.getEditor(),A=ge.Quill.find(c);if(A){const G=j.getIndex(A),T=c.querySelectorAll(".carousel-slide"),N=[];T.forEach(k=>{const $=k.querySelector("img"),V=k.querySelector("figcaption");N.push({url:($==null?void 0:$.getAttribute("src"))||"",alt:($==null?void 0:$.getAttribute("alt"))||"",caption:(V==null?void 0:V.textContent)||""})}),N.length>0&&(Ne({index:G,slides:N}),Ee(!0))}}},[]);n.useEffect(()=>{var o,c;const t=(c=(o=de.current)==null?void 0:o.getEditor())==null?void 0:c.root;if(t)return t.addEventListener("click",ft),()=>{t.removeEventListener("click",ft)}},[ft,r.content]),n.useEffect(()=>{var G;const t=(G=de.current)==null?void 0:G.getEditor();if(!t)return;const o=t.root,c=async T=>{fe.loading("Uploading pasted image…",{id:"paste-upload"});try{const{isGif:N}=await nt(async()=>{const{isGif:oe}=await import("./imageOptimizer-DU1AwbgF.js");return{isGif:oe}},[]),k=N(T),$=await zt(T,{maxWidth:1200,quality:.85,format:"webp"}),V=k?"gif":"webp",xe=k?"image/gif":"image/webp",we=`post-images/${`${Math.random().toString(36).slice(2)}.${V}`}`,{error:Se}=await _.storage.from("images").upload(we,$.blob,{contentType:xe,cacheControl:"public, max-age=31536000, immutable"});if(Se)throw Se;const{data:{publicUrl:z}}=_.storage.from("images").getPublicUrl(we),ne=t.getSelection(!0)||{index:t.getLength()-1};t.insertEmbed(ne.index,"imagewithcaption",{url:z,alt:T.name.replace(/\.[^/.]+$/,""),caption:""},"user"),t.setSelection(ne.index+1,0),_.from("media").insert({title:T.name.replace(/\.[^/.]+$/,""),image_url:z,type:"image"}).then(({error:oe})=>{oe&&console.error("Failed to register in media library:",oe)}),fe.success("Image uploaded",{id:"paste-upload"})}catch(N){console.error("Paste image upload failed:",N),fe.error("Failed to upload pasted image",{id:"paste-upload"})}},j=T=>{var $;const N=($=T.clipboardData)==null?void 0:$.files;if(!N||N.length===0)return;const k=Array.from(N).filter(V=>
3V.type.startsWith("image/"));k.length!==0&&(T.preventDefault(),T.stopPropagation(),k.forEach(c))},A=T=>{var $;const N=($=T.dataTransfer)==null?void 0:$.files;if(!N||N.length===0)return;const k=Array.from(N).filter(V=>V.type.startsWith("image/"));k.length!==0&&(T.preventDefault(),T.stopPropagation(),k.forEach(c))};return o.addEventListener("paste",j,!0),o.addEventListener("drop",A,!0),()=>{o.removeEventListener("paste",j,!0),o.removeEventListener("drop",A,!0)}},[r.content]);const Ys=n.useCallback(t=>{var j;const o=(j=de.current)==null?void 0:j.getEditor();if(!o){console.error("Quill editor not found");return}const c={id:crypto.randomUUID(),slides:t.map(A=>({url:A.url,alt:A.alt,caption:A.caption}))};if(ue)o.deleteText(ue.index,1),o.insertEmbed(ue.index,"imagecarousel",c,"user"),Ne(null);else{const A=be||o.getSelection(!0)||{index:0};o.insertEmbed(A.index,"imagecarousel",c,"user"),o.setSelection(A.index+1,0)}ve(null)},[be,ue]),Js=n.useMemo(()=>({toolbar:{container:[[{header:[1,2,3,4,!1]}],["bold","italic","underline","strike"],["highlight"],[{list:"ordered"},{list:"bullet"}],[{align:[]}],["blockquote","pullquote","code-block"],["link","imagewithcaption","imagecarousel","embed"],["divider"],["clean"]],handlers:{imagewithcaption:Bt,imagecarousel:Wt,embed:Ht,pullquote:Gt,divider:Vt,highlight:function(){const t=this.quill,o=t.getSelection();if(o){const c=t.getFormat(o);t.format("highlight",!c.highlight)}}}},clipboard:{matchVisual:!1,matchers:[["IFRAME",(t,o)=>{const c=t.getAttribute("src"),j=t.getAttribute("width")||"100%",A=t.getAttribute("height")||"400",G=t.getAttribute("frameborder")||"0",T=t.getAttribute("allowfullscreen")||"true",N=t.getAttribute("title")||"Embedded content";return{ops:[{insert:{iframe:{src:c,width:j,height:A,frameborder:G,allowfullscreen:T,title:N}}}]}}],["#text",(t,o)=>{const c=t.data;if(c.match(/<iframe[^>]*>/i)){const T=new DOMParser().parseFromString(c,"text/html").querySelector("iframe");if(T){const N=T.getAttribute("src"),k=T.getAttribute("width")||"100%",$=T.getAttribute("height")||"400",V=T.getAttribute("frameborder")||"0",xe=T.getAttribute("allowfullscreen")||"true",je=T.getAttribute("title")||"Embedded content";return{ops:[{insert:{iframe:{src:N,width:k,height:$,frameborder:V,allowfullscreen:xe,title:je}}}]}}}return o}]]}}),[Bt,Wt,Ht,Gt,Vt]),Xs=["header","bold","italic","underline","strike","highlight","list","bullet","align","blockquote","pullquote","code-block","link","image","video","iframe","imagewithcaption","imagecarousel","divider"];n.useEffect(()=>{Zs(),a&&ea()},[a]);const Zs=async()=>{const[t,o]=await Promise.all([_.from("categories").select("id, name, slug").order("name"),_.from("authors_public").select("id, name, image_url, role").order("name")]);if(t.data&&(h(t.data),!a)){const c=t.data.find(j=>j.slug==="generative-ai");c&&M(j=>({...j,category_id:c.id}))}o.data&&P(o.data)},ea=async()=>{if(!a)return;p(!0);const[t,o]=await Promise.all([_.from("posts").select("*").eq("id",a).single(),_.from("post_authors").select("author_id, is_primary, display_order").eq("post_id",a).order("display_order",{ascending:!0})]);if(t.error)s({variant:"destructive",title:"Error fetching post",description:t.error.message}),p(!1);else if(t.data){const c=t.data,j={title:c.title||"",slug:c.slug||"",excerpt:c.excerpt||"",discussion_prompt:c.discussion_prompt||"",content:c.content||"",image_url:c.image_url||"",featured_image_caption:c.featured_image_caption||"",category_id:c.category_id||"",author_id:c.author_id||"",read_time:c.read_time||"",featured:c.featured||!1,pinned_at:c.pinned_at||null,published:c.published||!1,seo_title:c.seo_title||"",seo_description:c.seo_description||"",seo_keywords:c.seo_keywords||"",key_takeaways:c.key_takeaways||"",satirical_take:c.satirical_take||"",show_on_ai_compass:c.show_on_ai_compass||!1,ai_compass_order:c.ai_compass_order??null,published_at:c.published_at||c.created_at||new Date().toISOString()};o.data&&o.data.length>0?pt(o.data.map(k=>({id:k.author_id,isPrimary:k.is_primary,displayOrder:k.display_order}))):c.author_id&&pt([{id:c.author_id,isPrimary:!0,displayOrder:0}]);const{data:A}=await _.from("post_infographics").select("infographic_id, insert_after_paragraph, display_order, infographics(title, image_url)").eq("post_id",a).order("display_order",{ascending:!0});A&&et(A.map(k=>{var $,V;return{infographic_id:k.infographic_id,insert_after_paragraph:k.insert_after_paragraph,display_order:k.display_order,title:(($=k.infographics)==null?void 0:$.t
3itle)||"",image_url:((V=k.infographics)==null?void 0:V.image_url)||""}}));const{data:G}=await _.from("post_research_reports").select("report_id, display_order, research_reports(title, cover_image_url)").eq("post_id",a).order("display_order",{ascending:!0});G&&xt(G.map(k=>{var $,V;return{report_id:k.report_id,display_order:k.display_order,title:(($=k.research_reports)==null?void 0:$.title)||"",cover_image_url:((V=k.research_reports)==null?void 0:V.cover_image_url)||null}})),Xe.current=JSON.stringify({formData:j,customSlug:c.slug||""}),M(j),q(c.slug);const T=c.slug||"",N=T.lastIndexOf("/");Z(N>=0?T.substring(N+1):T),Ls(c.category_id||null),Ye.current=c.slug||null,te(!1),X(new Date(c.updated_at)),x(!0),p(!1)}},ta=async t=>{var c;const o=(c=t.target.files)==null?void 0:c[0];if(o){g(!0);try{const{optimizeImage:j,formatFileSize:A,calculateSavings:G,isGif:T}=await nt(async()=>{const{optimizeImage:z,formatFileSize:ne,calculateSavings:oe,isGif:ha}=await import("./imageOptimizer-DU1AwbgF.js");return{optimizeImage:z,formatFileSize:ne,calculateSavings:oe,isGif:ha}},[]),N=T(o),k=await j(o,{maxWidth:2e3,maxHeight:2e3,quality:.85,format:"webp"}),$=N?"gif":"webp",V=N?"image/gif":"image/webp",xe=`${Date.now()}-${Math.random().toString(36).substring(7)}.${$}`,{error:je}=await _.storage.from("imported-images").upload(xe,k.blob,{contentType:V,cacheControl:"public, max-age=31536000, immutable"});if(je)throw je;const{data:{publicUrl:we}}=_.storage.from("imported-images").getPublicUrl(xe);M({...r,image_url:we}),_.from("media").insert({title:o.name.replace(/\.[^/.]+$/,""),image_url:we,type:"image"}).then(({error:z})=>{z&&console.error("Failed to register in media library:",z)});const Se=G(k.originalSize,k.optimizedSize);s({title:"Success",description:`Image optimized and uploaded. ${Se} size reduction.`})}catch(j){s({variant:"destructive",title:"Error uploading image",description:j.message})}finally{g(!1)}}},sa=t=>t.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""),aa=async t=>{if(!t||t.trim()===""){le(null);return}B(!0);try{const{data:o,error:c}=await _.from("posts").select("id").eq("slug",t).maybeSingle();if(c)throw c;a&&(o==null?void 0:o.id)===a?le(!0):le(!o)}catch(o){console.error("Error checking slug:",o),le(null)}finally{B(!1)}};n.useEffect(()=>{const t=setTimeout(()=>{if(U){const o=I.find(j=>j.id===r.category_id),c=o?`${o.slug}/${U}`:U;aa(c)}},500);return()=>clearTimeout(t)},[U]),n.useEffect(()=>{if(!a&&r.title){const t=sa(r.title);Z(t)}},[r.title,r.category_id,a,I]);const ra=t=>{const o=t.toLowerCase().replace(/\s+/g,"-").replace(/[^\w-/]+/g,"").replace(/\//g,"");Z(o)},Le=I.find(t=>t.id===r.category_id),st=Le&&U?`${Le.slug}/${U}`:U,ia=async()=>{var t;if(!r.title||!r.content){s({variant:"destructive",title:"Missing content",description:"Please add a title and content before generating SEO."});return}C(!0);try{const{data:o,error:c}=await _.functions.invoke("generate-seo",{body:{title:r.title,content:r.content,excerpt:r.excerpt,discussion_prompt:((t=r.discussion_prompt)==null?void 0:t.trim())||null}});if(c)throw c;o&&(M({...r,seo_title:o.seo_title||"",seo_description:o.seo_description||"",seo_keywords:o.seo_keywords||""}),s({title:"Success",description:"SEO metadata generated successfully. You can edit it before saving."}))}catch(o){console.error("Error generating SEO:",o),s({variant:"destructive",title:"Error generating SEO",description:o.message||"Failed to generate SEO metadata. Please try again."})}finally{C(!1)}},[Kt,Qt]=n.useState(!1),na=async()=>{var t;if(!r.title||!r.content){s({variant:"destructive",title:"Missing content",description:"Please add a title and content before generating key takeaways."});return}Qt(!0);try{const{data:o,error:c}=await _.functions.invoke("generate-takeaways",{body:{title:r.title,content:r.content,excerpt:r.excerpt,discussion_prompt:((t=r.discussion_prompt)==null?void 0:t.trim())||null}});if(c)throw c;o&&o.takeaways&&(M({...r,key_takeaways:JSON.stringify(o.takeaways)}),s({title:"Success",description:"Key takeaways generated successfully."}))}catch(o){console.error("Error generating takeaways:",o),s({variant:"destructive",title:"Error",description:o.message||"Failed to generate key takeaways."})}finally{Qt(!1)}},oa=async()=>{var t,o;if(!r.title){s({variant:"destructive",title:"Missing title",description:"Please add a title before generating a satirical take."});return}S(!0);try{const c=((t=I.find(G=>
3G.id===r.category_id))==null?void 0:t.name)||"",{data:j,error:A}=await _.functions.invoke("generate-satirical-take",{body:{title:r.title,excerpt:r.excerpt,discussion_prompt:((o=r.discussion_prompt)==null?void 0:o.trim())||null,categoryName:c}});if(A)throw A;j&&j.satiricalTake&&(M({...r,satirical_take:j.satiricalTake}),s({title:"Success",description:"Satirical take generated successfully."}))}catch(c){console.error("Error generating satirical take:",c),s({variant:"destructive",title:"Error",description:c.message||"Failed to generate satirical take."})}finally{S(!1)}},la=async t=>{var je,we,Se;if(t.preventDefault(),r.published){const z=[];if(r.title.trim()||z.push("Title"),r.category_id||z.push("Category"),r.excerpt.trim()||z.push("Excerpt"),(!r.content.trim()||r.content==="<p><br></p>")&&z.push("Content"),r.image_url||z.push("Featured Image"),ie.length===0&&z.push("Authors"),z.length>0){s({variant:"destructive",title:"Required Fields Missing",description:`Please fill in: ${z.join(", ")}`});return}}if(Y===!1){s({variant:"destructive",title:"Invalid Slug",description:"This slug is already taken. Please choose a different one."});return}u(!0);const o=ie.find(z=>z.isPrimary)||ie[0],c=new Date(r.published_at)>new Date,j=c?!1:r.published,A=c?"scheduled":r.published?"published":"draft",G=await _t(r.content),T={...r,content:it(G),slug:st||null,category_id:r.category_id||null,author_id:(o==null?void 0:o.id)||null,published:j,status:A};let N=a,k;if(a?k=await _.from("posts").update(T).eq("id",a):(k=await _.from("posts").insert([T]).select("id").single(),(je=k.data)!=null&&je.id&&(N=k.data.id)),k.error){s({variant:"destructive",title:`Error ${a?"updating":"creating"} post`,description:k.error.message}),u(!1);return}if(N&&ie.length>0){await _.from("post_authors").delete().eq("post_id",N);const z=ie.map(oe=>({post_id:N,author_id:oe.id,is_primary:oe.isPrimary,display_order:oe.displayOrder})),{error:ne}=await _.from("post_authors").insert(z);ne&&console.error("Error saving authors:",ne)}if(N){if(await _.from("post_infographics").delete().eq("post_id",N),Pe.length>0){const z=Pe.map((ne,oe)=>({post_id:N,infographic_id:ne.infographic_id,insert_after_paragraph:ne.insert_after_paragraph,display_order:oe}));await _.from("post_infographics").insert(z)}if(await _.from("post_research_reports").delete().eq("post_id",N),De.length>0){const z=De.map((ne,oe)=>({post_id:N,report_id:ne.report_id,display_order:oe}));await _.from("post_research_reports").insert(z)}}const $=new Date(r.published_at)>new Date;s({title:$?"Scheduled":"Success",description:$?`Post scheduled for ${$t(r.published_at)}.`:`Post ${a?"updated":"created"} successfully.`}),te(!1),X(new Date);let V=st||U||r.title.toLowerCase().replace(/\s+/g,"-");if(N){const{data:z}=await _.from("posts").select("slug").eq("id",N).single();z!=null&&z.slug&&(V=z.slug)}if(r.published){try{fetch("https://zdpdvwhvukelzzbzbjvh.supabase.co/functions/v1/ping-sitemap",{method:"POST",headers:{"Content-Type":"application/json"}}).catch(console.error)}catch(z){console.error("Sitemap ping failed:",z)}if(ie.length>0)for(const z of ie)try{_.functions.invoke("notify-author-followers",{body:{author_id:z.id,post_id:N||"new",post_title:r.title,post_slug:V,post_excerpt:((we=r.excerpt)==null?void 0:we.substring(0,200))||""}}).catch(console.error)}catch(ne){console.error("Follower notification failed:",ne)}try{_.functions.invoke("send-push-notification",{body:{post_title:r.title,post_slug:V,post_excerpt:((Se=r.excerpt)==null?void 0:Se.substring(0,100))||"",post_image:r.image_url}}).catch(console.error)}catch(z){console.error("Push notification failed:",z)}}const xe=V;if(a&&Ye.current&&xe&&Ye.current!==xe){Je({open:!0,oldSlug:Ye.current,newSlug:xe}),u(!1);return}i("/admin/posts"),u(!1)},[bt,vt]=n.useState(!1),ca=async()=>{var T;if(Y===!1){s({variant:"destructive",title:"Invalid Slug",description:"This slug is already taken. Please choose a different one."});return}vt(!0);const t=ie.find(N=>N.isPrimary)||ie[0],o=await _t(r.content),c={...r,content:it(o),slug:U||null,category_id:r.category_id||null,author_id:(t==null?void 0:t.id)||null,published:!1};let j=a,A;if(a?A=await _.from("posts").update(c).eq("id",a):(A=await _.from("posts").insert([c]).select("id").single(),(T=A.data)!=null&&T.id&&(j=A.data.id)),A.error){s({variant:"destructive",title:"Error saving draft",description:A.error.message}),vt(!1);return}if(j&&ie.length>0){await _.from("post_authors").delete().eq("post_id",j);const N=ie.map(k=>({post_id:j,author_id:k.id,is_primary:k.isPrimary,display_order:k.displayOrder}));await _.from("post_authors").insert(N)}const G={...r,published:!1};Xe.current=JSON.stringify({formData:G,customSlug:U}),M(G),te(!1),X(new Date),s({title:"Draft Saved",description:"Your changes have been saved as a draft."}),!a&&j&&i(`/admin/posts/edit/${j}`,{replace:!0}),vt(!1)},da=async()=>
3{if(!(!a||!J||L||!f)){H(!0);try{const t=ie.find(A=>A.isPrimary)||ie[0],o=await _t(r.content),c={...r,content:it(o),slug:U||null,category_id:r.category_id||null,author_id:(t==null?void 0:t.id)||null},{error:j}=await _.from("posts").update(c).eq("id",a);j||(X(new Date),te(!1))}catch(t){console.error("Autosave error:",t)}finally{H(!1)}}};n.useEffect(()=>{if(a&&f&&Xe.current){const o=JSON.stringify({formData:r,customSlug:U})!==Xe.current;te(o)}},[r,U,f,a]),n.useEffect(()=>{const t=sr(r.content);ye(t)},[r.content]),n.useEffect(()=>{if(!a)return;const t=setInterval(()=>{da()},3e4);return()=>clearInterval(t)},[a,J,L,r,U]),n.useEffect(()=>{const t=o=>{if(J)return o.preventDefault(),o.returnValue="",""};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[J]),n.useEffect(()=>{if(ae){document.body.style.overflow="hidden";const t=o=>{o.key==="Escape"&&Oe(!1)};return window.addEventListener("keydown",t),()=>{document.body.style.overflow="",window.removeEventListener("keydown",t)}}else document.body.style.overflow=""},[ae]);const Yt=n.useCallback(()=>{J?(gt("/admin/posts"),Ze(!0)):i("/admin/posts")},[J,i]),ma=n.useCallback(()=>{Ze(!1),ht&&(i(ht),gt(null))},[i,ht]),ua=n.useCallback(()=>{Ze(!1),gt(null)},[]);return v?e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-background via-background to-muted/30",children:[e.jsx(ss,{}),e.jsx("main",{className:"md:ml-52 p-6 flex items-center justify-center min-h-screen",children:e.jsxs("div",{className:"flex items-center gap-3 animate-fade-in",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-primary/20 border-t-primary animate-spin"})}),e.jsx("span",{className:"text-muted-foreground font-medium",children:"Loading post..."})]})})]}):e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-background via-background to-muted/20",children:[e.jsx(ss,{}),e.jsxs("main",{className:"md:ml-52 overflow-y-auto",children:[e.jsx("div",{className:"sticky top-0 z-20 bg-background/80 backdrop-blur-md border-b border-border/50 px-6 py-3",children:e.jsxs("div",{className:"max-w-5xl mx-auto flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(E,{variant:"ghost",size:"sm",onClick:Yt,className:"gap-1.5 text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(Ja,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Posts"})]}),e.jsx("div",{className:"h-4 w-px bg-border"}),e.jsx("h1",{className:"font-semibold text-lg",children:a?"Edit Post":"New Post"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"px-2 py-1 bg-muted/50 rounded-md font-medium",children:[Ce.toLocaleString()," words"]}),a&&e.jsx(e.Fragment,{children:L?e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-amber-50 dark:bg-amber-950/30 text-amber-600 dark:text-amber-400 rounded-md",children:[e.jsx(me,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Saving"})]}):ee?e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-emerald-50 dark:bg-emerald-950/30 text-emerald-600 dark:text-emerald-400 rounded-md",children:[e.jsx(jt,{className:"h-3 w-3"}),e.jsx("span",{children:new Date(ee).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}):J?e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-rose-50 dark:bg-rose-950/30 text-rose-600 dar
3k:text-rose-400 rounded-md",children:[e.jsx(wt,{className:"h-3 w-3"}),e.jsx("span",{children:"Unsaved"})]}):null})]}),e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>pe(!0),className:"gap-1.5 border-border/50 hover:bg-muted/50 transition-all",children:[e.jsx(Xa,{className:"h-3.5 w-3.5"}),"Preview"]}),a&&r.published&&e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>window.open(`/${R||a}`,"_blank"),className:"gap-1.5 border-border/50 hover:bg-muted/50 transition-all",children:[e.jsx(Ea,{className:"h-3.5 w-3.5"}),"View"]})]})]})}),e.jsx("div",{className:"max-w-5xl mx-auto px-6 py-6",children:e.jsxs("form",{onSubmit:la,className:"space-y-5 animate-fade-in",children:[e.jsxs("div",{className:"bg-card rounded-xl border border-border/40 p-5 space-y-4 shadow-sm hover:shadow-md transition-shadow duration-300",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{className:"text-sm font-medium text-foreground/80",children:"Category"}),e.jsxs(Aa,{value:r.category_id||void 0,onValueChange:t=>M({...r,category_id:t}),children:[e.jsx(Ta,{className:"border-border/50 focus:border-primary/50",children:e.jsx(Ra,{placeholder:"Select category"})}),e.jsx(za,{children:I.map(t=>e.jsx(Ua,{value:t.id,children:t.name},t.id))})]}),a&&Qe&&r.category_id&&r.category_id!==Qe&&e.jsxs("p",{className:"text-xs text-amber-600 dark:text-amber-400 flex items-center gap-1 animate-fade-in",children:[e.jsx(wt,{className:"h-3 w-3"}),"Category change will affect the URL"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"title",className:"text-sm font-medium text-foreground/80",children:"Title"}),e.jsx(Q,{id:"title",value:r.title,onChange:t=>M({...r,title:t.target.value}),required:!0,disabled:!a&&!r.category_id,onFocus:t=>{!a&&!r.category_id&&(t.target.blur(),s({title:"Please select category first",description:"A category must be chosen before entering the title.",variant:"destructive"}))},className:"text-lg font-medium border-border/50 focus:border-primary/50 transition-colors",placeholder:"Enter your post title..."})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(W,{htmlFor:"slug",className:"text-sm font-medium text-foreground/80 flex items-center gap-2",children:["URL Slug",e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-muted rounded text-muted-foreground font-normal",children:"Auto-generated"})]}),e.jsxs("div",{className:"relative flex items-center",children:[Le&&e.jsxs("span",{className:"inline-flex items-center px-3 h-10 border border-r-0 border-border/50 bg-muted/50 text-muted-foreground text-sm rounded-l-md whitespace-nowrap",children:[Le.slug,"/"]}),e.jsx(Q,{id:"slug",value:U,onChange:t=>ra(t.target.value),placeholder:"article-slug",className:`pr-10 border-border/50 transition-all ${Le?"rounded-l-none":""} ${Y===!0?"border-emerald-400/50 focus:border-emerald-500 bg-emerald-50/30 dark:bg-emerald-950/10":Y===!1?"border-rose-400/50 focus:border-rose-500 bg-rose-50/30 dark:bg-rose-950/10":"focus:border-primary/50"}`}),e.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:ce?e.jsx(me,{className:"h-4 w-4 animate-spin text-muted-foreground"}):Y===!0?e.jsx(jt,{className:"h-4 w-4 text-emerald-500"}):Y===!1?e.jsx(wt,{className:"h-4 w-4 text-rose-500"}):null})]}),Y===!1&&e.jsx("p",{className:"text-xs text-rose-500 animate-fade-in",children:"Slug already taken"}),Y===!0&&st&&e.jsxs("p",{className:"text-xs text-emerald-600 dark:text-emerald-400 animate-fade-in",children:["✓ /",st]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{htmlFor:"excerpt",className:"text-sm font-medium text-foreground/80",children:"Excerpt"}),e.jsx(Re,{id:"excerpt",value:r.excerpt,onChange:t=>M({...r,excerpt:t.target.value}),rows:2,required:!0,className:"resize-none border-border/50 focus:border-primary/50 transition-colors",placeholder:"Brief summary of your post..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(W,{htmlFor:"discussion_prompt",className:"text-sm font-medium text-foreground/80",children:["Discussion prompt ",e.jsx("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),e.jsx(Re,{id:"discussion_prompt",value:r.discussion_prompt,onChange:t=>M({...r,discussion_prompt:t.target.value}),rows:2,maxLength:200,className:"resize-none border-border/50 focus:border-primary/50 transition-colors",placeholder:"A question to spark reader comments, e.g. Will domain expertise beat model scale?"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Shown above the comment box and mid-article."})]})]})]}),e.jsxs("div",{className:he("bg-card rounded-xl border border-border/40 p-5 shadow-sm transition-shadow duration-300",ae?"fixed inset-0 z-50 rounded-none border-0 flex flex-col overflow-hidden":"hover:shadow-md"),children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 shrink-0",children:[e.jsx(W,{className:"text-sm font-medium text-foreground
3/80",children:"Content"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-muted rounded text-muted-foreground",children:"Rich Text Editor"}),e.jsx(E,{type:"button",variant:"ghost",size:"sm",onClick:()=>Oe(!ae),className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground transition-colors",title:ae?"Exit fullscreen":"Expand editor",children:ae?e.jsx(Ga,{className:"h-3.5 w-3.5"}):e.jsx(Za,{className:"h-3.5 w-3.5"})})]})]}),e.jsx(Oa,{ref:de,theme:"snow",value:r.content,onChange:t=>M({...r,content:t}),modules:Js,formats:Xs,className:he("bg-background rounded-lg border border-border/30 editor-compact",ae&&"flex-1 [&_.ql-container]:flex-1 flex flex-col [&_.ql-toolbar]:shrink-0"),style:ae?{height:"100%",marginBottom:0}:{height:"400px",marginBottom:"50px"}})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"bg-gradient-to-br from-amber-50/50 to-orange-50/30 dark:from-amber-950/20 dark:to-orange-950/10 rounded-xl border border-amber-200/30 dark:border-amber-800/20 p-5 space-y-3 shadow-sm hover:shadow-md transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-amber-100 dark:bg-amber-900/30 rounded-lg",children:e.jsx(Va,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"})}),e.jsx("h3",{className:"font-medium text-sm",children:"Key Takeaways"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[l&&e.jsx(Er,{}),e.jsxs(E,{type:"button",variant:"ghost",size:"sm",onClick:na,disabled:Kt||!r.title||!r.content,className:"gap-1.5 h-7 text-xs hover:bg-amber-100/50 dark:hover:bg-amber-900/30",children:[Kt?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(ke,{className:"h-3 w-3"}),"Generate"]})]})]}),e.jsx(Cr,{value:r.key_takeaways,onChange:t=>M({...r,key_takeaways:t})})]}),e.jsxs("div",{className:"bg-gradient-to-br from-sky-50/50 to-blue-50/30 dark:from-sky-950/20 dark:to-blue-950/10 rounded-xl border border-sky-200/30 dark:border-sky-800/20 p-5 space-y-3 shadow-sm hover:shadow-md transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-sky-100 dark:bg-sky-900/30 rounded-lg",children:e.jsx(ke,{className:"h-4 w-4 text-sky-600 dark:text-sky-400"})}),e.jsx("h3",{className:"font-medium text-sm",children:"SEO Settings"})]}),e.jsxs(E,{type:"button",variant:"ghost",size:"sm",onClick:ia,disabled:b||!r.title||!r.content,className:"gap-1.5 h-7 text-xs hover:bg-sky-100/50 dark:hover:bg-sky-900/30",children:[b?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(ke,{className:"h-3 w-3"}),"Generate"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Q,{value:r.seo_title||"",onChange:t=>M({...r,seo_title:t.target.value}),placeholder:"SEO Title",className:`text-xs bg-white/50 dark:bg-black/20 border-sky-200/50 dark:border-sky-800/30 pr-12 ${(r.seo_title||"").length>60?"border-rose-400":""}`}),e.jsxs("span",{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] ${(r.seo_title||"").length>60?"text-rose-500":"text-muted-foreground"}`,children:[(r.seo_title||"").length,"/60"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Re,{value:r.seo_description||"",onChange:t=>M({...r,seo_description:t.target.value}),rows:2,placeholder:"SEO Description",className:`text-xs resize-none bg-white/50 dark:bg-black/20 border-sky-200/50 dark:border-sky-800/30 pr-12 ${(r.seo_description||"").length>160?"border-rose-400":""}`}),e.jsxs("span",{className:`absolute right-2 bottom-2 text-[10px] ${(r.seo_description||"").length>160?"text-rose-500":"text-muted-foreground"}`,children:[(r.seo_description||"").length,"/160"]})]}),e.jsx(Q,{value:r.seo_keywords||"",onChange:t=>M({...r,seo_keywords:t.target.value}),placeholder:"Keywords (comma separated)",className:"text-xs bg-white/50 dark:bg-black/20 border-sky-200/50 dark:border-sky-800/30"})]})]}),e.jsxs("div",{className:"bg-gradient-to-br from-fuchsia-50/50 to-pink-50/30 dark:from-fuchsia-950/20 dark:to-pink-950/10 rounded-xl border border-fuchsia-200/30 dark:border-fuchsia-800/20 p-5 space-y-3 shadow-sm hover:shadow-md transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-fuchsia-100 dark:bg-fuchsia-900/30 rounded-lg",children:e.jsx(ke,{className:"h-4 w-4 text-fuchsia-600 dark:text-fuchsia-400"})}),e.jsx("h3",{className:"font-medium text-sm",children:"Satirical Take"}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-fuchsia-100/50 dark:bg-fuchsia-900/20 text-fuchsia-600 dark:text-fuchsia-400 rounded",children:"2-3 words"})]}),e.jsxs(E,{type:"button",variant:"ghost",size:"sm",onClick:oa,disabled:y||!r.title,className:"gap-1.5 h-7 text-xs hover:bg-fuchsia-100/50 dark:hover:bg-fuchsia-900/30",children:[y?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(ke,{className:"h-3 w-3"}),"Generate"]})]}),r.satirical_take&&e.jsx("div",{className:"rounded-lg bg-white/50 dark:bg-black/20 p-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fuchsia-500",children:"🎭"}),e.jsxs("span",{className:"text-sm font-medium italic text-foreground
3/80",children:['"',r.satirical_take,'"']})]})}),e.jsx(Q,{value:r.satirical_take||"",onChange:t=>M({...r,satirical_take:t.target.value}),placeholder:"e.g., 'Peak VC Energy', 'Tech Theatre'",maxLength:50,className:"text-xs bg-white/50 dark:bg-black/20 border-fuchsia-200/50 dark:border-fuchsia-800/30"})]})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/40 p-5 shadow-sm hover:shadow-md transition-shadow duration-300",children:[e.jsxs("h3",{className:"font-medium text-sm mb-4 flex items-center gap-2",children:[e.jsx(as,{className:"h-4 w-4 text-muted-foreground"}),"Featured Image & Details"]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2 flex-wrap",children:[e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:()=>{var t;return(t=document.getElementById("image-upload"))==null?void 0:t.click()},disabled:d,className:"gap-1.5 border-dashed hover:border-solid transition-all",children:[d?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx($e,{className:"h-3.5 w-3.5"}),d?"Uploading":"Upload"]}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:()=>F(!0),className:"gap-1.5",children:[e.jsx(Ct,{className:"h-3.5 w-3.5"}),"Library"]}),e.jsx("input",{id:"image-upload",type:"file",accept:"image/*",className:"hidden",onChange:ta}),e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsx(Q,{value:r.image_url,onChange:t=>M({...r,image_url:t.target.value}),placeholder:"Or enter image URL...",className:"text-xs border-border/50"})})]}),r.image_url&&e.jsxs("div",{className:"relative group animate-scale-in rounded-lg overflow-hidden border border-border/40 bg-[linear-gradient(45deg,#f5f5f5_25%,transparent_25%),linear-gradient(-45deg,#f5f5f5_25%,transparent_25%),linear-gradient(45deg,transparent_75%,#f5f5f5_75%),linear-gradient(-45deg,transparent_75%,#f5f5f5_75%)] [background-size:16px_16px] [background-position:0_0,0_8px,8px_-8px,-8px_0px] dark:bg-muted/20",children:[e.jsx("img",{src:r.image_url,alt:"Featured",className:"w-full h-auto max-h-[420px] object-contain mx-auto"}),e.jsx(E,{type:"button",variant:"destructive",size:"icon",onClick:()=>M({...r,image_url:""}),className:"absolute top-2 right-2 h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity shadow-md",children:e.jsx(Te,{className:"h-3.5 w-3.5"})}),e.jsx("a",{href:r.image_url,target:"_blank",rel:"noreferrer",className:"absolute bottom-2 left-2 text-[10px] uppercase tracking-wider px-2 py-1 rounded-md bg-background/80 backdrop-blur text-muted-foreground hover:text-foreground border border-border/40 opacity-0 group-hover:opacity-100 transition-opacity",children:"Open original"})]}),e.jsx(Q,{value:r.featured_image_caption,onChange:t=>M({...r,featured_image_caption:t.target.value}),placeholder:"Image caption (optional)",className:"text-xs border-border/50"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{className:"text-xs text-muted-foreground",children:"Authors"}),e.jsx(Sr,{authors:D,selectedAuthors:ie,onSelectionChange:pt})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(W,{className:"text-xs text-muted-foreground",children:"Read Time"}),e.jsx(Q,{placeholder:"5 min read",value:r.read_time,onChange:t=>M({...r,read_time:t.target.value}),className:"h-9 text-xs border-border/50"})]})]})]})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/40 p-5 shadow-sm hover:shadow-md transition-shadow duration-300",children:[e.jsxs("h3",{className:"font-medium text-sm mb-4 flex items-center gap-2",children:[e.jsx(yt,{className:"h-4 w-4 text-muted-foreground"}),"Infographics",e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-muted rounded text-muted-foreground font-normal",children:"Bypass paywall"})]}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:()=>Lt(!0),className:"gap-1.5 mb-3",children:[e.jsx(as,{className:"h-3.5 w-3.5"}),"Add Infographic"]}),Pe.length>0&&e.jsx("div",{className:"space-y-2",children:Pe.map((t,o)=>e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-lg border border-border/30 bg-muted/20",children:[e.jsx("img",{src:t.image_url,alt:t.title,className:"w-12 h-12 object-cover rounded"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:t.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("label",{className:"text-[10px] text-muted-foreground",children:"After paragraph:"}),e.jsx(Q,{type:"number",min:1,max:50,value:t.insert_after_paragraph,onChange:c=>{const j=[...Pe];j[o]={...j[o],insert_after_paragraph:parseInt(c.target.value)||3},et(j)},className:"h-6 w-16 text-xs"})]})]}),e.jsx(E,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",onClick:()=>et(Pe.filter((c,j)=>j!==o)),children:e.jsx(Te,{className:"h-3.5 w-3.5"})})]},t.infographic_id))})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/40 p-5 shadow-sm",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[e.jsx(yt,{className:"h-4 w-4 text-primary"}),"Research Reports",e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-muted rounded text-muted-foreground font-normal",children:"Bypass paywall"})]}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:async()=>{const{data:t}=await _.from("research_reports").select("id, title, cover_image_url").eq("is_published",!0).order("created_at",{ascending:!1});Gs(t||[]),tt(!0)},className:"gap-1.5 mb-3",children:[e.jsx(yt,{className:"h-3.5 w-3.5"}),"Attach Report"]}),De.length>0&&e.jsx("div",{className:"space-y-2",children:De.map((t,o)=>e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-lg border border-border/30 bg-muted/20",children:[t.cover_image_url?e.jsx("img",{src:t.cover_image_url,alt:t.title,className:"w-10 h-14 object-cover rounded"}):e.jsx("div",{className:"w-10 h-14 bg-muted rounded flex items-center justify-center",children:e.jsx(St,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("p",{className:"flex-1 text-xs font-medium truncate",children:t.title}),e.jsx(E,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",onClick:()=>xt(De.filter((c,j)=>j!==o)),children:e.jsx(Te,{className:"h-3.5 w-3.5"})})]},t.report_id))})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/40 p-5 shadow-sm space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(gs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(W,{className:"text-sm font-medium",children:"Publish Date"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(fs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(E,{type:"button",variant:"outline",size:"sm",className:he("gap-2 text-xs",Ie()&&"border-amber-400/50 bg-amber-50/50 dark:bg-amber-950/20"),children:[e.jsx(gs,{className:"h-3.5 w-3.5"}),r.published_at?Pa(r.published_at):"Pick date"]})}),e.jsx(vs,{className:"w-auto p-0",align:"start",children:e.jsx(Fa,{mode:"single",selected:r.published_at?new Date(r.published_at):void 0,onSelect:Vs,initialFocus:!0,className:he("p-3 pointer-events-auto")})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(kt,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx(Q,{type:"time",value:Hs(),onChange:t=>Ws(t.target.value),className:"h-8 w-24 text-xs border-border/50"})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"IST"})]}),Ie()&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-amber-100 dar
3k:bg-amber-900/30 text-amber-700 dark:text-amber-400 rounded-md text-xs animate-fade-in",children:[e.jsx(kt,{className:"h-3 w-3"}),e.jsxs("span",{children:["Scheduled for ",$t(r.published_at)]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 pt-2 border-t border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(at,{id:"featured",checked:r.featured,onCheckedChange:t=>M({...r,featured:t}),className:"data-[state=checked]:bg-amber-500"}),e.jsx(W,{htmlFor:"featured",className:"text-sm cursor-pointer",children:"Featured"})]}),e.jsxs("div",{className:"flex items-center gap-2",title:"Locks this post into the homepage hero slot until unpinned or another post is pinned.",children:[e.jsx(at,{id:"pinned",checked:!!r.pinned_at,onCheckedChange:t=>M({...r,pinned_at:t?new Date().toISOString():null}),className:"data-[state=checked]:bg-rose-500"}),e.jsx(W,{htmlFor:"pinned",className:"text-sm cursor-pointer",children:"Pin Post"})]}),e.jsxs("div",{className:"flex items-center gap-2",title:"Show this post on the AI Compass page. Lower order numbers appear first.",children:[e.jsx(at,{id:"ai_compass",checked:r.show_on_ai_compass,onCheckedChange:t=>M({...r,show_on_ai_compass:t}),className:"data-[state=checked]:bg-violet-500"}),e.jsx(W,{htmlFor:"ai_compass",className:"text-sm cursor-pointer",children:"AI Compass"}),r.show_on_ai_compass&&e.jsx(Q,{type:"number","aria-label":"AI Compass order",placeholder:"Order",value:r.ai_compass_order??"",onChange:t=>M({...r,ai_compass_order:t.target.value===""?null:Number(t.target.value)}),className:"h-8 w-20 animate-fade-in"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(at,{id:"published",checked:r.published,onCheckedChange:t=>M({...r,published:t}),className:"data-[state=checked]:bg-emerald-500",disabled:Ie()}),e.jsx(W,{htmlFor:"published",className:he("text-sm cursor-pointer",Ie()&&"text-muted-foreground"),children:Ie()?"Will publish on schedule":"Published"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{type:"button",variant:"ghost",size:"sm",onClick:Yt,className:"text-muted-foreground hover:text-foreground",children:"Cancel"}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:ca,disabled:bt||m,className:"gap-1.5",children:[bt?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(er,{className:"h-3.5 w-3.5"}),"Save Draft"]}),e.jsxs(E,{type:"submit",size:"sm",disabled:m||bt,className:"gap-1.5 bg-primary hover:bg-primary/90 shadow-sm",children:[m?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(jt,{className:"h-3.5 w-3.5"}),Ie()?"Schedule":a?"Update":"Publish"]})]})]})]})]})})]}),e.jsx(rr,{open:re,onOpenChange:pe,title:r.title||"Untitled Post",excerpt:r.excerpt||"",content:r.content||"<p>No content yet...</p>",imageUrl:r.image_url,featuredImageCaption:r.featured_image_caption,categoryName:(Jt=I.find(t=>t.id===r.category_id))==null?void 0:Jt.name,authorName:(Xt=D.find(t=>t.id===r.author_id))==null?void 0:Xt.name,authorImage:(Zt=D.find(t=>t.id===r.author_id))==null?void 0:Zt.image_url,authorRole:(es=D.find(t=>t.id===r.author_id))==null?void 0:es.role,keyTakeaways:r.key_takeaways}),e.jsx(Nr,{open:ut,onOpenChange:K,onInsert:Ks}),e.jsx(_r,{open:Fe,onOpenChange:t=>{Ee(t),t||Ne(null)},onInsert:Ys,initialSlides:ue==null?void 0:ue.slides,isEditing:!!ue}),e.jsx(Ha,{open:O,onOpenChange:se,onInsert:Qs}),e.jsx(ns,{open:qs,onOpenChange:Ze,children:e.jsxs(os,{className:"animate-scale-in",children:[e.jsxs(ls,{children:[e.jsx(cs,{children:"Unsaved Changes"}),e.jsx(ds,{children:"You have unsaved changes. Are you sure you want to leave?"})]}),e.jsxs(ms,{children:[e.jsx(us,{onClick:ua,children:"Stay"}),e.jsx(hs,{onClick:ma,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Discard"})]})]})}),e.jsx(ns,{open:_e.open,onOpenChange:t=>{t||(Je({open:!1,oldSlug:"",newSlug:""}),i("/admin/posts"))},children:e.jsxs(os,{className:"animate-scale-in",children:[e.jsxs(ls,{children:[e.jsx(cs,{children:"URL Changed"}),e.jsxs(ds,{className:"space-y-2",children:[e.jsx("span",{children:"The post URL has changed:"}),e.jsxs("span",{className:"block font-mono text-xs bg-muted rounded px-2 py-1 break-all",children:["/",_e.oldSlug]}),e.jsx("span",{className:"block text-center",children:"→"}),e.jsxs("span",{className:"block font-mono text-xs bg-muted rounded px-2 py-1 break-all",children:["/",_e.newSlug]}),e.jsx("span",{className:"block mt-2",children:"Would you like to create a redirect from the old URL?"})]})]}
3),e.jsxs(ms,{children:[e.jsx(us,{onClick:()=>{Je({open:!1,oldSlug:"",newSlug:""}),i("/admin/posts")},children:"Skip"}),e.jsx(hs,{onClick:async()=>{try{await _.from("redirects").insert({from_path:_e.oldSlug,to_path:_e.newSlug,is_permanent:!0}),s({title:"Redirect created",description:`/${_e.oldSlug} → /${_e.newSlug}`})}catch(t){s({variant:"destructive",title:"Failed to create redirect",description:t.message})}Je({open:!1,oldSlug:"",newSlug:""}),i("/admin/posts")},children:"Create Redirect"})]})]})}),e.jsx(js,{open:w,onOpenChange:F,onSelect:t=>M({...r,image_url:t})}),e.jsx(kr,{open:$s,onOpenChange:Lt,onSelect:t=>{et(o=>[...o,{infographic_id:t.id,insert_after_paragraph:3,display_order:o.length,title:t.title,image_url:t.image_url}])}}),Bs&&e.jsx("div",{className:"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm flex items-center justify-center",onClick:()=>tt(!1),children:e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-lg max-w-lg w-full mx-4 max-h-[70vh] overflow-y-auto p-5",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{className:"text-sm font-semibold mb-4",children:"Select Research Report"}),qt.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No published research reports found."}):e.jsx("div",{className:"space-y-2",children:qt.filter(t=>!De.some(o=>o.report_id===t.id)).map(t=>e.jsxs("button",{onClick:()=>{xt(o=>[...o,{report_id:t.id,display_order:o.length,title:t.title,cover_image_url:t.cover_image_url}]),tt(!1)},className:"flex items-center gap-3 w-full p-3 rounded-lg border border-border/30 hover:border-primary/50 transition-colors text-left",children:[t.cover_image_url?e.jsx("img",{src:t.cover_image_url,alt:t.title,className:"w-10 h-14 object-cover rounded"}):e.jsx("div",{className:"w-10 h-14 bg-muted rounded flex items-center justify-center",children:e.jsx(St,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("p",{className:"text-sm font-medium",children:t.title})]},t.id))}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>tt(!1),children:"Close"})})]})})]})};export{Ii 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.