PageSourceSearch

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

js analyticsindiamag.com collected 2026-10-01 08:35:38 UTC 97,366 bytes, 3 lines download raw bytes

1import{r as o,j as e,N as bs,V as fa,W as xa,Y as ba,aw as va,ax as ya,aQ as ja,aC as Re,az as Fe,aP as wa,aB as Ge,bP as Na,aM as _a,a1 as xe,S as Ee,I as Q,B as I,b5 as Sa,L as ue,X as ze,a9 as ct,s as _,f as be,y as ka,q as zt,P as vs,v as ys,w as js,a as Ut,F as Ct,ac as Ca,e as Ea,u as Ia,E as Pa,a$ as wt,bQ as Da,br as nt}from"./index-Bpe3UPrl.js";import{formatFileSize as as,calculateSavings as Aa,loadImageDimensions as Ta,optimizeImage as Ft}from"./imageOptimizer-DU1AwbgF.js";import{L as H}from"./label-zbJ2Yd-h.js";import{T as Ue}from"./textarea-DlfunI45.js";import{S as Ra,a as za,b as Ua,c as Fa,d as Oa}from"./select-ClLWnOzt.js";import{C as La}from"./calendar-DTWAiS89.js";import{A as rs}from"./AdminNav-BjH44lIk.js";import{l as he,R as Ma}from"./quill.snow-CHImboyy.js";import{D as Ve,a as We,b as He,c as Ke,f as ws,e as qa,d as $a}from"./dialog-C2-OG0H8.js";import{u as Ba,a as Ga}from"./useArticleCarousels-DQ54PRkW.js";import{s as Va}from"./sanitizeHTML-3eQ8Vumw.js";import{C as Et}from"./clock-drvits2u.js";import{S as $e}from"./scroll-area-Cfm_iZWk.js";import{M as Ns}from"./MediaLibraryPicker-BXDwjTPk.js";import{c as _s}from"./index-BdQq_4o_.js";import{U as Be}from"./upload-DJe7pf5f.js";import{F as It}from"./folder-open-BPeeYHwx.js";import{a as ot,M as Wa,L as Ha,I as is}from"./minimize-2-CtvY7KGe.js";import{C as ns}from"./chevron-left-D_CVT3fw.js";import{G as Ss}from"./grip-vertical-mF-YR4Ib.js";import{P as Pt}from"./plus-DqlpFVco.js";import{C as Ka}from"./checkbox-BJDx071Y.js";import{S as os}from"./star-CKiPnvoK.js";import{C as ks}from"./chevron-down-Gz4e3Y6q.js";import{E as Qa}from"./EmbedInsertDialog-D6bR_ntl.js";import{C as Ya}from"./chevron-up-DHWS-xLg.js";import{T as Ja}from"./trash-2-gJ8LxcYB.js";import{S as Xa}from"./settings-2-DQqMvDPq.js";import{A as ls,a as cs,b as ds,c as ms,d as us,e as hs,f as gs,g as ps}from"./alert-dialog-CW5GNd6F.js";import{A as Za}from"./arrow-left-DtUzy-m0.js";import{C as Nt}from"./circle-check-RRg2VT-M.js";import{C as _t}from"./circle-alert-bRtWbGIn.js";import{E as er}from"./eye-zdBGPbOw.js";import{M as tr}from"./maximize-2-AXLHpkET.js";import{C as fs}from"./calendar-hL_ZtHxz.js";import{S as sr}from"./save-B1ETdKgT.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-DT969Piu.js";import"./user-cog-4VgA4EMc.js";import"./book-open-B4EQwg6J.js";import"./receipt-CStKdnlA.js";import"./index-D9sln3ot.js";import"./carousel-CXUmMk_U.js";import"./purify.es--yiYCWnk.js";import"./htmlDecoder-Cz23cfvH.js";import"./code-xml-B48xY657.js";const ar=(a,i=225)=>{const l=a.replace(/<[^>]*>/g," ").trim().split(/\s+/).filter(d=>d.length>0).length,u=Math.ceil(l/i);return u<1?"< 1 min read":u===1?"1 min read":`${u} min read`},rr=a=>a.replace(/<[^>]*>/g," ").trim().split(/\s+/).filter(s=>s.length>0).length,ir=({title:a,excerpt:i,content:s,imageUrl:l,featuredImageCaption:u,categoryName:d,authorName:m="Unknown Author",authorImage:g,authorRole:f="Writer",keyTakeaways:x})=>{const{getArticleTextClass:v}=Ba(),p=o.useRef(null),b=ar(s);Ga(p,[s]);let D=[];if(x)try{const j=JSON.parse(x);D=Array.isArray(j)?j:[]}catch(j){console.error("Invalid key takeaways JSON",j)}return e.jsxs("article",{className:"max-w-3xl mx-auto px-4 py-8",children:[d&&e.jsx("div",{className:"mb-4",children:e.jsx(bs,{variant:"secondary",className:"text-xs uppercase tracking-wide",children:d})}),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(fa,{className:"h-12 w-12",children:[e.jsx(xa,{src:g||void 0,alt:m}),e.jsx(ba,{children:m.charAt(0)})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-semibold",children:m}),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(Et,{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"}),u&&e.jsx("figcaption",{className:"mt-3 text-sm text-center text-muted-foreground italic",children:u})]}),D.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:D.map((j,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:j})]},S))})]}),e.jsx("div",{ref:p,className:`article-content ${v()}`,dangerouslySetInnerHTML:{__html:Va(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."})})]})},nr=({open:a,onOpenChange:i,title:s,excerpt:l,content:u,imageUrl:d,featuredImageCaption:m,categoryName:g,authorName:f,authorImage:x,authorRole:v,keyTakeaways:p})=>e.jsx(Ve,{open:a,onOpenChange:i,children:e.jsxs(We,{className:"max-w-5xl h-[90vh] p-0",children:[e.jsx(He,{className:"px-6 pt-6 pb-4 border-b border-border",children:e.jsx(Ke,{className:"text-2xl font-serif",children:"Article Preview"})}),e.jsx($e,{className:"h-full",children:e.jsx(ir,{title:s,excerpt:l,content:u,imageUrl:d,featuredImageCaption:m,categoryName:g,authorName:f,authorImage:x,authorRole:v,keyTakeaways:p})})]})});var Cs=["PageUp","PageDown"],Es=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Is={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Oe="Slider",[Dt,or,lr]=va(Oe),[Ps,Ai]=ya(Oe,[lr]),[cr,dt]=Ps(Oe),Ds=o.forwardRef((a,i)=>{const{name:s,min:l=0,max:u=100,step:d=1,orientation:m="horizontal",disabled:g=!1,minStepsBetweenThumbs:f=0,defaultValue:x=[l],value:v,onValueChange:p=()=>{},onValueCommit:b=()=>{},inverted:D=!1,form:j,...S}=a,R=o.useRef(new Set),h=o.useRef(0),P=m==="horizontal"?dr:mr,[A=[],B]=ja({prop:v,defaultProp:x,onChange:$=>{var ae;
1(ae=[...R.current][h.current])==null||ae.focus(),p($)}}),M=o.useRef(A);function J($){const ee=fr(A,$);X($,ee)}function Y($){X($,h.current)}function se(){const $=M.current[h.current];A[h.current]!==$&&b(A)}function X($,ee,{commit:ae}={commit:!1}){const ge=yr(d),te=jr(Math.round(($-l)/d)*d+l,ge),z=_s(te,[l,u]);B((K=[])=>{const Z=gr(K,z,ee);if(vr(Z,f*d)){h.current=Z.indexOf(z);const me=String(Z)!==String(K);return me&&ae&&b(Z),me?Z:K}else return K})}return e.jsx(cr,{scope:a.__scopeSlider,name:s,disabled:g,min:l,max:u,valueIndexToChangeRef:h,thumbs:R.current,values:A,orientation:m,form:j,children:e.jsx(Dt.Provider,{scope:a.__scopeSlider,children:e.jsx(Dt.Slot,{scope:a.__scopeSlider,children:e.jsx(P,{"aria-disabled":g,"data-disabled":g?"":void 0,...S,ref:i,onPointerDown:Re(S.onPointerDown,()=>{g||(M.current=A)}),min:l,max:u,inverted:D,onSlideStart:g?void 0:J,onSlideMove:g?void 0:Y,onSlideEnd:g?void 0:se,onHomeKeyDown:()=>!g&&X(l,0,{commit:!0}),onEndKeyDown:()=>!g&&X(u,A.length-1,{commit:!0}),onStepKeyDown:({event:$,direction:ee})=>{if(!g){const te=Cs.includes($.key)||$.shiftKey&&Es.includes($.key)?10:1,z=h.current,K=A[z],Z=d*te*ee;X(K+Z,z,{commit:!0})}}})})})})});Ds.displayName=Oe;var[As,Ts]=Ps(Oe,{startEdge:"left",endEdge:"right",size:"width",direction:1}),dr=o.forwardRef((a,i)=>{const{min:s,max:l,dir:u,inverted:d,onSlideStart:m,onSlideMove:g,onSlideEnd:f,onStepKeyDown:x,...v}=a,[p,b]=o.useState(null),D=Fe(i,P=>b(P)),j=o.useRef(void 0),S=wa(u),R=S==="ltr",h=R&&!d||!R&&d;function k(P){const A=j.current||p.getBoundingClientRect(),B=[0,A.width],J=Ot(B,h?[s,l]:[l,s]);return j.current=A,J(P-A.left)}return e.jsx(As,{scope:a.__scopeSlider,startEdge:h?"left":"right",endEdge:h?"right":"left",direction:h?1:-1,size:"width",children:e.jsx(Rs,{dir:S,"data-orientation":"horizontal",...v,ref:D,style:{...v.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:P=>{const A=k(P.clientX);m==null||m(A)},onSlideMove:P=>{const A=k(P.clientX);g==null||g(A)},onSlideEnd:()=>{j.current=void 0,f==null||f()},onStepKeyDown:P=>{const B=Is[h?"from-left":"from-right"].includes(P.key);x==null||x({event:P,direction:B?-1:1})}})})}),mr=o.forwardRef((a,i)=>{const{min:s,max:l,inverted:u,onSlideStart:d,onSlideMove:m,onSlideEnd:g,onStepKeyDown:f,...x}=a,v=o.useRef(null),p=Fe(i,v),b=o.useRef(void 0),D=!u;function j(S){const R=b.current||v.current.getBoundingClientRect(),h=[0,R.height],P=Ot(h,D?[l,s]:[s,l]);return b.current=R,P(S-R.top)}return e.jsx(As,{scope:a.__scopeSlider,startEdge:D?"bottom":"top",endEdge:D?"top":"bottom",size:"height",direction:D?1:-1,children:e.jsx(Rs,{"data-orientation":"vertical",...x,ref:p,style:{...x.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:S=>{const R=j(S.clientY);d==null||d(R)},onSlideMove:S=>{const R=j(S.clientY);m==null||m(R)},onSlideEnd:()=>{b.current=void 0,g==null||g()},onStepKeyDown:S=>{const h=Is[D?"from-bottom":"from-top"].includes(S.key);f==null||f({event:S,direction:h?-1:1})}})})}),Rs=o.forwardRef((a,i)=>{const{__scopeSlider:s,onSlideStart:l,onSlideMove:u,onSlideEnd:d,onHomeKeyDown:m,onEndKeyDown:g,onStepKeyDown:f,...x}=a,v=dt(Oe,s);return e.jsx(Ge.span,{...x,ref:i,onKeyDown:Re(a.onKeyDown,p=>{p.key==="Home"?(m(p),p.preventDefault()):p.key==="End"?(g(p),p.preventDefault()):Cs.concat(Es).includes(p.key)&&(f(p),p.preventDefault())}),onPointerDown:Re(a.onPointerDown,p=>{const b=p.target;b.setPointerCapture(p.pointerId),p.preventDefault(),v.thumbs.has(b)?b.focus():l(p)}),onPointerMove:Re(a.onPointerMove,p=>{p.target.hasPointerCapture(p.pointerId)&&u(p)}),onPointerUp:Re(a.onPointerUp,p=>{const b=p.target;b.hasPointerCapture(p.pointerId)&&(b.releasePointerCapture(p.pointerId),d(p))})})}),zs="SliderTrack",Us=o.forwardRef((a,i)=>{const{__scopeSlider:s,...l}=a,u=dt(zs,s);return e.jsx(Ge.span,{"data-disabled":u.disabled?"":void 0,"data-orientation":u.orientation,...l,ref:i})});Us.displayName=zs;var At="SliderRange",Fs=o.forwardRef((a,i)=>{const{__scopeSlider:s,...l}=a,u=dt(At,s),d=Ts(At,s),m=o.useRef(null),g=Fe(i,m),f=u.values.length,x=u.values.map(b=>Ms(b,u.min,u.max)),v=f>1?Math.min(...x):0,p=100-Math.max(...x);return e.jsx(Ge.span,{"data-orientation":u.orientation,"data-disabled":u.disabled?"":void 0,...l,ref:g,style:{...a.style,[d.startEdge]:v+"%",[d.endEdge]:p+"%"}})});Fs.displayName=At;var Tt="SliderThumb",Os=o.forwardRef((a,i)=>{const s=or(a.__scopeSlider),[l,u]=o.useState(null),d=Fe(i,g=>u(g)),m=o.useMemo(()=>l?s().findIndex(g=>g.ref.current===l):-1,[s,l]);return e.jsx(ur,{...a,ref:d,index:m})}),ur=o.forwardRef((a,i)=>{const{__scopeSlider:s,index:l,name:u,...d}
1=a,m=dt(Tt,s),g=Ts(Tt,s),[f,x]=o.useState(null),v=Fe(i,k=>x(k)),p=f?m.form||!!f.closest("form"):!0,b=Na(f),D=m.values[l],j=D===void 0?0:Ms(D,m.min,m.max),S=pr(l,m.values.length),R=b==null?void 0:b[g.size],h=R?xr(R,j,g.direction):0;return o.useEffect(()=>{if(f)return m.thumbs.add(f),()=>{m.thumbs.delete(f)}},[f,m.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[g.startEdge]:`calc(${j}% + ${h}px)`},children:[e.jsx(Dt.ItemSlot,{scope:a.__scopeSlider,children:e.jsx(Ge.span,{role:"slider","aria-label":a["aria-label"]||S,"aria-valuemin":m.min,"aria-valuenow":D,"aria-valuemax":m.max,"aria-orientation":m.orientation,"data-orientation":m.orientation,"data-disabled":m.disabled?"":void 0,tabIndex:m.disabled?void 0:0,...d,ref:v,style:D===void 0?{display:"none"}:a.style,onFocus:Re(a.onFocus,()=>{m.valueIndexToChangeRef.current=l})})}),p&&e.jsx(Ls,{name:u??(m.name?m.name+(m.values.length>1?"[]":""):void 0),form:m.form,value:D},l)]})});Os.displayName=Tt;var hr="RadioBubbleInput",Ls=o.forwardRef(({__scopeSlider:a,value:i,...s},l)=>{const u=o.useRef(null),d=Fe(u,l),m=_a(i);return o.useEffect(()=>{const g=u.current;if(!g)return;const f=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(f,"value").set;if(m!==i&&v){const p=new Event("input",{bubbles:!0});v.call(g,i),g.dispatchEvent(p)}},[m,i]),e.jsx(Ge.input,{style:{display:"none"},...s,ref:d,defaultValue:i})});Ls.displayName=hr;function gr(a=[],i,s){const l=[...a];return l[s]=i,l.sort((u,d)=>u-d)}function Ms(a,i,s){const d=100/(s-i)*(a-i);return _s(d,[0,100])}function pr(a,i){return i>2?`Value ${a+1} of ${i}`:i===2?["Minimum","Maximum"][a]:void 0}function fr(a,i){if(a.length===1)return 0;const s=a.map(u=>Math.abs(u-i)),l=Math.min(...s);return s.indexOf(l)}function xr(a,i,s){const l=a/2,d=Ot([0,50],[0,l]);return(l-d(i)*s)*s}function br(a){return a.slice(0,-1).map((i,s)=>a[s+1]-i)}function vr(a,i){if(i>0){const s=br(a);return Math.min(...s)>=i}return!0}function Ot(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 yr(a){return(String(a).split(".")[1]||"").length}function jr(a,i){const s=Math.pow(10,i);return Math.round(a*s)/s}var qs=Ds,wr=Us,Nr=Fs,_r=Os;const Rt=o.forwardRef(({className:a,...i},s)=>e.jsxs(qs,{ref:s,className:xe("relative flex w-full touch-none select-none items-center",a),...i,children:[e.jsx(wr,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:e.jsx(Nr,{className:"absolute h-full bg-primary"})}),e.jsx(_r,{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"})]}));Rt.displayName=qs.displayName;const xs=({maxWidth:a,quality:i,originalDimensions:s,stats:l,onMaxWidthChange:u,onQualityChange:d})=>{const m=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(Ee,{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(H,{className:"text-xs font-medium",children:"Max Width"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[g,m?` × ${m}`:"","px"]})]}),e.jsx(Rt,{value:[a],min:200,max:2e3,step:50,onValueChange:([f])=>u(f)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(H,{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(Rt,{value:[i*100],min:50,max:100,step:5,onValueChange:([f])=>d(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(Ee,{className:"h-3 w-3 text-primary"}),e.jsxs("span",{children:[as(l.originalSize)," → ",as(l.optimizedSize)]}),e.jsxs("span",{className:"ml-auto font-semibold text-primary",children:["saved ",Aa(l.originalSize,l.optimizedSize)]})]})]})},Sr=({open:a,onOpenChange:i,onInsert:s,initialData:l})=>{const u=!!l,[d,m]=o.useState(""),[g,f]=o.useState(""),[x,v]=o.useState(""),[p,b]=o.useState(""),[D,j]=o.useState(!1),[S,R]=o.use
1State(!1),[h,k]=o.useState(null),[P,A]=o.useState(null),[B,M]=o.useState(1200),[J,Y]=o.useState(.85),[se,X]=o.useState(null),$=o.useCallback(()=>{m(""),f(""),v(""),b(""),k(null),A(null),M(1200),Y(.85),X(null)},[]);o.useEffect(()=>{a&&(l?(m(l.url||""),f(l.alt==="Image"?"":l.alt||""),v(l.caption||""),b(l.link||""),k(null),A(null),X(null)):$())},[a,l,$]);const ee=async z=>{var me;const K=(me=z.target.files)==null?void 0:me[0];if(!K)return;k(K),X(null),m("");try{const je=await Ta(K);A(je),M(Math.min(1200,je.width))}catch{A(null)}const Z=URL.createObjectURL(K);m(Z)},ae=async()=>{if(h){j(!0);try{const{isGif:z}=await ct(async()=>{const{isGif:pe}=await import("./imageOptimizer-DU1AwbgF.js");return{isGif:pe}},[]),K=z(h),Z=await Ft(h,{maxWidth:B,quality:J,format:"webp"}),me=K?"gif":"webp",je=K?"image/gif":"image/webp",Ie=`post-images/${`${Math.random().toString(36).slice(2)}.${me}`}`,{error:V}=await _.storage.from("images").upload(Ie,Z.blob,{contentType:je,cacheControl:"public, max-age=31536000, immutable"});if(V)throw V;const{data:{publicUrl:we}}=_.storage.from("images").getPublicUrl(Ie);d.startsWith("blob:")&&URL.revokeObjectURL(d),m(we),k(null),X({originalSize:Z.originalSize,optimizedSize:Z.optimizedSize}),_.from("media").insert({title:h.name.replace(/\.[^/.]+$/,""),image_url:we,type:"image"}).then(({error:pe})=>{pe&&console.error("Failed to register in media library:",pe)}),be.success("Image optimized & uploaded")}catch(z){console.error("Error uploading image:",z),be.error("Failed to upload image")}finally{j(!1)}}},ge=()=>{if(!d||d.startsWith("blob:")){be.error("Please upload the image first");return}let z=p.trim();z&&!/^(https?:\/\/|\/)/i.test(z)&&(z=`https://${z}`),s({url:d,alt:g||"Image",caption:x,link:z||void 0}),$(),i(!1)},te=!!h&&!!P;return e.jsxs(Ve,{open:a,onOpenChange:i,children:[e.jsxs(We,{className:"sm:max-w-lg max-h-[85vh] p-0 gap-0",children:[e.jsxs(He,{className:"px-4 py-3 border-b border-border",children:[e.jsx(Ke,{className:"text-base font-semibold",children:u?"Edit Image":"Upload Image"}),e.jsx(ws,{className:"sr-only",children:"Upload an image file or enter a URL, add alt text and an optional caption"})]}),e.jsx($e,{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(H,{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:ee,disabled:D,className:"text-sm h-9"}),e.jsx(I,{type:"button",variant:"outline",size:"icon",disabled:D,asChild:!0,className:"h-9 w-9 flex-shrink-0",children:e.jsx("label",{htmlFor:"file-upload",className:"cursor-pointer",children:e.jsx(Be,{className:"h-4 w-4"})})})]})]}),e.jsxs(I,{type:"button",variant:"outline",className:"w-full h-9 text-sm gap-2",onClick:()=>R(!0),children:[e.jsx(Sa,{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(H,{htmlFor:"image-url",className:"text-xs font-medium",children:"Image URL"}),e.jsx(Q,{id:"image-url",placeholder:"https://example.com/image.jpg",value:d.startsWith("blob:")?"":d,onChange:z=>{m(z.target.value),k(null),A(null),X(null)},className:"text-sm h-9"})]}),te&&e.jsx(xs,{maxWidth:B,quality:J,originalDimensions:P,stats:se,onMaxWidthChange:M,onQualityChange:Y}),h&&e.jsx(I,{type:"button",className:"w-full h-9 text-sm gap-2",onClick:ae,disabled:D,children:D?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"}),"Optimizing & Uploading…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"h-4 w-4"}),"Compress & Upload as WebP"]})}),!h&&se&&e.jsx(xs,{maxWidth:B,quality:J,originalDimensions:null,stats:se,onMaxWidthChange:()=>{},onQualityChange:()=>{}}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(H,{htmlFor:"alt-text",className:"text-xs font-medium",children:"Alt Text (for accessibility)"}),e.jsx(Q,{id:"alt-text",placeholder:"Describe the image",value:g,onChange:z=>f(z.target.value),className:"text-sm h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(H,{htmlFor:"image-link",className:"text-xs font-medium",children:"Link URL (optional)"}),e.jsx(Q,{id:"image-link",placeholder:"https://example.com — image opens this link in a new tab",value:p,onChange:z=>b(z.target.value),className:"text-sm h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(H,{htmlFor:"caption",className:"text-xs font-medium",children:"Caption (optional)"}),e.jsx(Ue,{id:"caption",placeholder:"Add a caption for this image",value:x,onChange:z=>v(z.target.value),rows:2,className:"text-sm resize-none"})]}),d&&e.jsxs("div",{className:"space-y-1.5 pt-2",children:[e.jsx(H,{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:d,alt:g||"Preview",className:"w-full h-auto max-h-48 object-contain"}
1),e.jsx(I,{type:"button",variant:"ghost",size:"icon",onClick:()=>{d.startsWith("blob:")&&URL.revokeObjectURL(d),m(""),k(null),A(null),X(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(ze,{className:"h-3.5 w-3.5"})})]}),x&&e.jsx("figcaption",{className:"px-3 py-2 text-xs text-center text-muted-foreground italic border-t border-border bg-background/50",children:x})]})]})]})}),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(I,{variant:"outline",size:"sm",onClick:()=>i(!1),className:"h-8 text-xs",children:"Cancel"}),e.jsx(I,{size:"sm",onClick:ge,disabled:!d||d.startsWith("blob:"),className:"h-8 text-xs",children:u?"Update Image":"Insert Image"})]})]}),e.jsx(Ns,{open:S,onOpenChange:R,onSelect:z=>{m(z),k(null),A(null),X(null)}})]})},St=()=>[{id:crypto.randomUUID(),url:"",alt:"",caption:""},{id:crypto.randomUUID(),url:"",alt:"",caption:""}],kr=({open:a,onOpenChange:i,onInsert:s,initialSlides:l,isEditing:u=!1})=>{var pe,fe,Se;const[d,m]=o.useState(St),[g,f]=o.useState(null),[x,v]=o.useState(0),[p,b]=o.useState(null),[D,j]=o.useState("slides"),[S,R]=o.use
1State(null),[h,k]=o.useState([]),[P,A]=o.useState(!1),[B,M]=o.useState(""),[J,Y]=o.useState(1),[se,X]=o.useState(0),$=18;o.useEffect(()=>{a&&l&&l.length>0?(m(l.map(w=>({id:crypto.randomUUID(),url:w.url,alt:w.alt,caption:w.caption}))),v(0)):a&&!l&&(m(St()),v(0))},[a,l]),o.useEffect(()=>{D==="gallery"&&ee()},[D,J,B]),o.useEffect(()=>{const w=setTimeout(()=>{D==="gallery"&&Y(1)},300);return()=>clearTimeout(w)},[B]);const ee=async()=>{A(!0);try{const w=(J-1)*$,F=w+$-1;let O=_.from("media").select("*",{count:"exact"}).order("created_at",{ascending:!1});B.trim()&&(O=O.ilike("title",`%${B}%`)),O=O.range(w,F);const{data:re,error:ie,count:Le}=await O;if(ie)throw ie;k(re||[]),X(Le||0)}catch(w){console.error("Error fetching media:",w)}finally{A(!1)}},ae=()=>{m([...d,{id:crypto.randomUUID(),url:"",alt:"",caption:""}])},ge=w=>{if(d.length<=2){be.error("Carousel requires at least 2 images");return}const F=d.filter((O,re)=>re!==w);m(F),x>=F.length&&v(Math.max(0,F.length-1))},te=(w,F,O)=>{const re=[...d];re[w]={...re[w],[F]:O},m(re)},z=async(w,F)=>{var re;const O=(re=F.target.files)==null?void 0:re[0];if(O){f(d[w].id);try{const ie=O.name.split(".").pop(),ve=`post-images/${`carousel-${Date.now()}-${Math.random().toString(36).substring(7)}.${ie}`}`,{error:ye}=await _.storage.from("images").upload(ve,O,{cacheControl:"public, max-age=31536000, immutable"});if(ye)throw ye;const{data:{publicUrl:Xe}}=_.storage.from("images").getPublicUrl(ve);te(w,"url",Xe),be.success("Image uploaded")}catch(ie){console.error("Error uploading image:",ie),be.error("Failed to upload image")}finally{f(null)}}},K=w=>{R(w),j("gallery"),M(""),Y(1)},Z=w=>{S!==null&&(te(S,"url",w),j("slides"),R(null))},me=w=>{b(w)},je=(w,F)=>{if(w.preventDefault(),p===null||p===F)return;const O=[...d],re=O[p];O.splice(p,1),O.splice(F,0,re),m(O),b(F)},Je=()=>{b(null)},Ie=()=>{const w=d.filter(F=>F.url.trim()!=="");if(w.length<2){be.error("Please add at least 2 images");return}s(w),m(St()),v(0),j("slides"),i(!1)},V=d.filter(w=>w.url.trim()!==""),we=Math.ceil(se/$);return e.jsx(Ve,{open:a,onOpenChange:i,children:e.jsxs(We,{className:"sm:max-w-xl max-h-[85vh] p-0 gap-0 overflow-hidden",children:[e.jsxs(He,{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(Ke,{className:"text-sm font-medium flex items-center gap-2",children:D==="gallery"?e.jsxs(e.Fragment,{children:[e.jsx(It,{className:"h-4 w-4 text-primary"}),e.jsx("span",{children:"Media Library"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"h-4 w-4 text-primary"}),e.jsx("span",{children:u?"Edit Carousel":"Image Carousel"})]})}),D==="gallery"&&e.jsxs(I,{variant:"ghost",size:"sm",onClick:()=>j("slides"),className:"h-7 text-xs gap-1",children:[e.jsx(ns,{className:"h-3 w-3"}),"Back"]})]}),e.jsx(ws,{className:"text-[11px] text-muted-foreground mt-0.5",children:D==="gallery"?`Select image for Slide ${(S??0)+1}`:u?"Edit slides, reorder, or add new images":"Add 2+ images to create a carousel"})]}),D==="slides"?e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"flex-1",style:{maxHeight:"calc(85vh - 120px)"},children:e.jsxs("div",{className:"p-3 space-y-1.5",children:[d.map((w,F)=>e.jsxs("div",{draggable:!0,onDragStart:()=>me(F),onDragOver:O=>je(O,F),onDragEnd:Je,onClick:()=>v(F),className:xe("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(Ss,{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(ot,{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=>te(F,"url",O.target.value),className:"h-6 text-[11px] flex-1"}
1),e.jsx(I,{type:"button",variant:"ghost",size:"icon",onClick:O=>{O.stopPropagation(),K(F)},className:"h-6 w-6 flex-shrink-0",title:"Choose from gallery",children:e.jsx(It,{className:"h-3 w-3"})}),e.jsx(I,{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(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Be,{className:"h-3 w-3"}),e.jsx("input",{type:"file",accept:"image/*",onChange:O=>z(F,O),className:"hidden"})]})})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(Q,{placeholder:"Alt text",value:w.alt,onChange:O=>te(F,"alt",O.target.value),className:"h-6 text-[11px] flex-1"}),e.jsx(Q,{placeholder:"Caption",value:w.caption,onChange:O=>te(F,"caption",O.target.value),className:"h-6 text-[11px] flex-1"})]})]}),d.length>2&&e.jsx(I,{type:"button",variant:"ghost",size:"icon",onClick:O=>{O.stopPropagation(),ge(F)},className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:e.jsx(ze,{className:"h-3 w-3"})})]},w.id)),e.jsxs(I,{type:"button",variant:"ghost",size:"sm",onClick:ae,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(Pt,{className:"h-3 w-3"}),"Add Slide"]}),V.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:(pe=V[x%V.length])==null?void 0:pe.url,alt:((fe=V[x%V.length])==null?void 0:fe.alt)||"Preview",className:"w-full h-full object-contain"}),V.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(I,{type:"button",variant:"secondary",size:"icon",onClick:()=>v((x-1+V.length)%V.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(ns,{className:"h-3.5 w-3.5"})}),e.jsx(I,{type:"button",variant:"secondary",size:"icon",onClick:()=>v((x+1)%V.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(ka,{className:"h-3.5 w-3.5"})})]}),V.length>1&&e.jsx("div",{className:"absolute bottom-1.5 left-1/2 -translate-x-1/2 flex gap-1",children:V.map((w,F)=>e.jsx("button",{onClick:()=>v(F),className:xe("w-1.5 h-1.5 rounded-full transition-all",F===x%V.length?"bg-foreground":"bg-foreground
1/30")},F))})]}),((Se=V[x%V.length])==null?void 0:Se.caption)&&e.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground italic text-center truncate",children:V[x%V.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:[V.length,"/",d.length," ready"]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>i(!1),className:"h-7 text-xs",children:"Cancel"}),e.jsxs(I,{size:"sm",onClick:Ie,disabled:V.length<2,className:"h-7 text-xs gap-1",children:[e.jsx(ot,{className:"h-3 w-3"}),u?"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(zt,{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:B,onChange:w=>M(w.target.value),className:"pl-8 h-7 text-xs"})]})}),e.jsx($e,{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(ue,{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(ot,{className:"h-8 w-8 mb-2 opacity-40"}),e.jsx("p",{className:"text-xs",children:B?"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:()=>Z(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))})})}),we>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(I,{variant:"ghost",size:"sm",disabled:J===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:[J,"/",we]}),e.jsx(I,{variant:"ghost",size:"sm",disabled:J===we,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:[se.toLocaleString()," images • Click to select"]})})]})]})})},Cr=({authors:a,selectedAuthors:i,onSelectionChange:s,className:l})=>{const[u,d]=o.useState(!1),[m,g]=o.useState(""),f=a.filter(h=>h.name.toLowerCase().includes(m.toLowerCase())),x=h=>a.find(k=>k.id===h),v=h=>i.some(k=>k.id===h),p=()=>{var h;return(h=i.find(k=>k.isPrimary))==null?void 0:h.id},b=h=>{var k;if(v(h)){const P=(k=i.find(B=>B.id===h))==null?void 0:k.isPrimary,A=i.filter(B=>B.id!==h);P&&A.length>0&&(A[0].isPrimary=!0),A.forEach((B,M)=>B.displayOrder=M),s(A)}else{const P={id:h,isPrimary:i.length===0,displayOrder:i.length};s([...i,P])}},D=h=>{const k=i.map(P=>({...P,isPrimary:P.id===h}));s(k)},j=h=>{b(h)},S=h=>{if(h===0)return;const k=[...i];
1[k[h-1],k[h]]=[k[h],k[h-1]],k.forEach((P,A)=>P.displayOrder=A),s(k)},R=[...i].sort((h,k)=>h.displayOrder-k.displayOrder);return e.jsxs("div",{className:xe("space-y-3",l),children:[R.length>0&&e.jsx("div",{className:"space-y-2",children:R.map((h,k)=>{const P=x(h.id);return P?e.jsxs("div",{className:xe("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(k),disabled:k===0,className:"text-muted-foreground hover:text-foreground disabled:opacity-30",children:e.jsx(Ss,{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(bs,{variant:"secondary",className:"text-xs gap-1",children:[e.jsx(os,{className:"h-3 w-3 fill-current"}),"Primary"]}):e.jsx(I,{type:"button",variant:"ghost",size:"sm",onClick:()=>D(h.id),className:"text-xs h-6",children:"Set Primary"}),e.jsx(I,{type:"button",variant:"ghost",size:"icon",onClick:()=>j(h.id),className:"h-6 w-6 text-muted-foreground hover:text-destructive",children:e.jsx(ze,{className:"h-3 w-3"})})]},h.id):null})}),e.jsxs(vs,{open:u,onOpenChange:d,children:[e.jsx(ys,{asChild:!0,children:e.jsxs(I,{type:"button",variant:"outline",role:"combobox","aria-expanded":u,className:"w-full justify-between",children:[i.length===0?"Select authors...":`${i.length} author${i.length>1?"s":""} selected`,e.jsx(ks,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxs(js,{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(zt,{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:m,onChange:h=>g(h.target.value),className:"pl-8 h-8"})]})}),e.jsx($e,{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:xe("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(Ka,{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(os,{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 Er({open:a,onOpenChange:i,onSelect:s}){const[l,u]=o.useState([]),[d,m]=o.useState(!0),[g,f]=o.useState(""),[x,v]=o.useState(!1),{toast:p}=Ut();o.useEffect(()=>{a&&b()},[a,g]);const b=async()=>{m(!0);let j=_.from("infographics").select("id, title, image_url, alt_text, caption").order("created_at",{ascending:!1}).limit(50);g&&(j=j.ilike("title",`%${g}%`));const{data:S}=await j;u(S||[]),m(!1)},D=async j=>{var R;const S=(R=j.target.files)==null?void 0:R[0];if(S){v(!0);try{const h=S.type==="application/pdf";let k=S,P=S.type,A=S.name.split(".").pop()||"bin";if(h)A="pdf",P="application/pdf";else{const{optimizeImage:se,isGif:X}=await ct(async()=>{const{optimizeImage:ae,isGif:ge}=await import("./imageOptimizer-DU1AwbgF.js");return{optimizeImage:ae,isGif:ge}},[]),$=X(S);k=(await se(S,{maxWidth:2e3,maxHeight:4e3,quality:.9,format:"webp"})).blob,P=$?"image/gif":"image/webp",A=$?"gif":"webp"}const B=`infographics/${Date.now()}-${Math.random().toString(36).substring(7)}.${A}`,{error:M}=await _.storage.from("imported-images").upload(B,k,{contentType:P,cacheControl:"public, max-age=31536000, immutable"});if(M)throw M;const{data:{publicUrl:J}}=_.storage.from("imported-images").getPublicUrl(B),{error:Y}=await _.from("infographics").insert({title:S.name.replace(/\.[^/.]+$/,""),image_url:J});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(Ve,{open:a,onOpenChange:i,children:e.jsxs(We,{className:"max-w-3xl max-h-[80vh] overflow-y-auto",children:[e.jsx(He,{children:e.jsx(Ke,{children:"Select Infographic"})}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(zt,{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:j=>
1f(j.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:D,disabled:x}),e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>{var j;return(j=document.getElementById("infographic-upload-picker"))==null?void 0:j.click()},disabled:x,children:[e.jsx(Be,{className:"mr-2 h-4 w-4"}),x?"Uploading...":"Upload"]})]})]}),d?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:Array.from({length:6}).map((j,S)=>e.jsx("div",{className:"aspect-[3/4] bg-muted rounded-lg animate-pulse"},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(j=>e.jsxs("button",{onClick:()=>{s(j),i(!1)},className:"group relative bg-muted rounded-lg overflow-hidden border border-border/50 hover:border-primary/50 transition-colors text-left",children:[j.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(Ct,{className:"h-10 w-10 text-primary/60"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"PDF"})]}):e.jsx("img",{src:j.image_url,alt:j.alt_text||j.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:j.title})})]},j.id))})]})})}const Ir=({value:a,onChange:i})=>{const[s,l]=o.useState([]);o.useEffect(()=>{try{const x=JSON.parse(a||"[]");Array.isArray(x)&&l(x)}catch{l([])}},[a]);const u=x=>{l(x),i(JSON.stringify(x))},d=(x,v)=>{const p=[...s];p[x]=v,u(p)},m=x=>u(s.filter((v,p)=>p!==x)),g=()=>u([...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]],u(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(I,{type:"button",variant:"outline",size:"sm",onClick:g,className:"gap-1.5 h-7 text-xs",children:[e.jsx(Pt,{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(Ya,{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(ks,{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=>d(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:()=>m(v),className:"opacity-0 group-hover:opacity-100 text-destructive hover:text-destructive/80 transition-opacity p-1",children:e.jsx(Ja,{className:"h-3.5 w-3.5"})})]},v)),e.jsxs(I,{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(Pt,{className:"h-3 w-3"})," Add takeaway"]})]})},Pr=()=>{const[a,i]=o.useState(!1),[s,l]=o.useState(""),[u,d]=o.useState(""),[m,g]=o.useState(!1),[f,x]=o.useState(!1),{toast:v}=Ut();o.useEffect(()=>{!a||f||_.from("editorial_guidelines").select("guidelines, examples").eq("guideline_type","key_takeaways").single().then(({data:b})=>{b&&(l(b.guidelines||""),d(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:u,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(Ve,{open:a,onOpenChange:i,children:[e.jsx(qa,{asChild:!0,children:e.jsx(I,{t
1ype:"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(Xa,{className:"h-3.5 w-3.5"})})}),e.jsxs(We,{className:"sm:max-w-lg",children:[e.jsxs(He,{children:[e.jsx(Ke,{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(H,{className:"text-sm",children:"Guidelines & Style Rules"}),e.jsx(Ue,{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(H,{className:"text-sm",children:"Example Takeaways (good examples)"}),e.jsx(Ue,{value:u,onChange:b=>d(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($a,{children:[e.jsx(I,{type:"button",variant:"outline",onClick:()=>i(!1),size:"sm",children:"Cancel"}),e.jsxs(I,{type:"button",onClick:p,disabled:m,size:"sm",className:"gap-1.5",children:[m&&e.jsx(ue,{className:"h-3 w-3 animate-spin"}),"Save Guidelines"]})]})]})]})},Qe=he.Quill.import("blots/block/embed"),Dr=he.Quill.import("blots/block"),Ar=he.Quill.import("blots/inline");class mt extends Dr{static create(i){return super.create()}}mt.blotName="pullquote";mt.tagName="blockquote";mt.className="pullquote";class Lt extends Qe{static create(){return super.create()}}Lt.blotName="divider";Lt.tagName="hr";class Mt extends Ar{static create(){return super.create()}}Mt.blotName="highlight";Mt.tagName="mark";class qt extends Qe{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}}qt.blotName="iframe";qt.tagName="iframe";class ut extends Qe{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")}}ut.blotName="video";ut.tagName="iframe";ut.className="ql-video";class Ye extends Qe{static create(i){const s=super.create(),l=document.createElement("img");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);const u=(i.link||"").trim();if(u&&/^(https?:\/\/|\/)/i.test(u)){const d=document.createElement("a");d.setAttribute("href",u),d.setAttribute("target","_blank"),d.setAttribute("rel","noopener noreferrer"),d.appendChild(l),s.appendChild(d)}else s.appendChild(l);if(i.caption){const d=document.createElement("figcaption");d.textContent=i.caption,s.appendChild(d)}return s}static value(i){const s=i.querySelector("img"),l=i.querySelector("figcaption"),u=i.querySelector("a");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)||"",link:(u==null?void 0:u.getAttribute("href"))||""}}}Ye.blotName="imagewithcaption";Ye.tagName="figure";Ye.className="image-with-caption";class ht extends Qe{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((u,d)=>{const m=document.createElement("figure");m.className="carousel-slide",m.setAttribute("data-index",String(d));const g=document.createElement("img");if(g.src=u.url,g.alt=u.alt||`Slide ${d+1}`,m.appendChild(g),u.caption){const f=document.createElement("figcaption");f.textContent=u.caption,m.appendChild(f)}l.appendChild(m)}),s.appendChild(l),s}static value(i){const s=[];return i.querySelectorAll(".carousel-slide").forEach(u=>{const d=u.querySelector("img"),m=u.querySelector("figcaption");s.push({url:(d==null?void 0:d.getAttribute("src"))||"",alt:(d==null?void 0:d.getAttribute("alt"))||"",caption:(m==null?void 0:m.textContent)||""})}),{id:i.getAttribute("data-carousel-id")||"",slides:s}}}ht.blotName="imagecarousel";ht.tagName="div";ht.className="image-carousel";he.Quill.register(mt);he.Quill.register(Lt);he.Quill.register(Mt);he.Quill.register(qt);he.Quill.register(ut);he.Quill.register(Ye);he.Quill.register(ht);const lt=a=>a.replace(/<img[^>]+src\s*=\s*["']data:[^"']*["'][^>]*\/?>/gi,""),Tr=a=>{try{const[i,s]=a.split(","),l=/data:([^;]+)/.exec(i||""),u=(l==null?void 0:l[1])||"image/png",d=atob(s),m=d.length,g=new Uint8Array(m);for(let f=0;f<m;f++)g[f]=d.charCodeAt(f);return new Blob([g],{type:u})}catch(i){return console.error("dataUrlToBlob failed",i),null}},kt=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 lt(a);const l=Array.from(s.querySelectorAll("img"));for(const u of l){const d=u.getAttribute("src")||"";if(!d.startsWith("data:image"))continue;const m=Tr(d);if(!m){u.remove();continue}try{const g=m.type==="image/gif";let f=m;if(!g){const S=new File([m],"inline.png",{type:m.type});f=(await Ft(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:D}=await _.storage.from("images").upload(b,f,{contentType:v,cacheControl:"public, max-age=31536000, immutable"});if(D)throw D;const{data:{publicUrl:j}}=_.storage.from("images").getPublicUrl(b);u.setAttribute("src",j),_.from("media").insert({title:u.getAttribute("alt")||"Inline image",image_url:j,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),u.remove()}}return s.innerHTML},Ti=()=>{var Zt,es,ts,ss;const{id:a}=Ca(),i=Ea(),{toast:s}=Ut(),{isAdmin:l}
3=Ia(),[u,d]=o.useState(!1),[m,g]=o.useState(!1),[f,x]=o.useState(!a),[v,p]=o.useState(!!a),[b,D]=o.useState(!1),[j,S]=o.useState(!1),[R,h]=o.useState([]),[k,P]=o.useState([]),[A,B]=o.useState(null),[M,J]=o.useState(""),[Y,se]=o.useState(null),[X,$]=o.useState(!1),[ee,ae]=o.useState(!1),[ge,te]=o.useState(null),[z,K]=o.useState(!1),[Z,me]=o.useState(!1),[je,Je]=o.useState(0),[Ie,V]=o.useState(!1),[we,pe]=o.useState(!1),[fe,Se]=o.useState(null),[w,F]=o.useState(!1),[O,re]=o.useState(!1),[ie,Le]=o.useState(!1),[ve,ye]=o.useState(null),[Xe,$s]=o.useState(null),Ze=o.useRef(null),[ke,et]=o.useState({open:!1,oldSlug:"",newSlug:""}),ne=o.useRef(null),tt=o.useRef(null),[Bs,st]=o.useState(!1),[gt,pt]=o.useState(null),[oe,ft]=o.useState([]),[Gs,$t]=o.useState(!1),[Pe,at]=o.useState([]),[De,xt]=o.useState([]),[Vs,rt]=o.useState(!1),[Bt,Ws]=o.useState([]),[r,q]=o.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()}),Gt=t=>new Date(t).toLocaleString("en-IN",{timeZone:"Asia/Kolkata",day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})+" IST",Ae=()=>r.published_at?new Date(r.published_at)>new Date:!1,Me=330*6e4,Hs=t=>{if(!t)return;const n=r.published_at?new Date(r.published_at):new Date,c=new Date(n.getTime()+Me),y=c.getUTCHours(),E=c.getUTCMinutes(),L=Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),y,E,0)-Me;q({...r,published_at:new Date(L).toISOString()})},Ks=t=>{if(!t)return;const[n,c]=t.split(":").map(Number),y=r.published_at?new Date(r.published_at):new Date,E=new Date(y.getTime()+Me),L=Date.UTC(E.getUTCFullYear(),E.getUTCMonth(),E.getUTCDate(),n,c,0)-Me;q({...r,published_at:new Date(L).toISOString()})},Qs=()=>{if(!r.published_at)return"";const t=new Date(r.published_at),n=new Date(t.getTime()+Me),c=n.getUTCHours().toString().padStart(2,"0"),y=n.getUTCMinutes().toString().padStart(2,"0");return`${c}:${y}`},[Te,bt]=o.useState(null),Ys=o.useCallback(t=>{var y;const n=(y=ne.current)==null?void 0:y.getEditor();if(!n){console.error("Quill editor not found");return}if(Te){const{index:E,data:L}=Te;n.deleteText(E,1,"user"),n.insertEmbed(E,"imagewithcaption",{...t,width:L.width,height:L.height},"user"),n.setSelection(E+1,0),bt(null);return}const c=ve||n.getSelection(!0)||{index:0};n.insertEmbed(c.index,"imagewithcaption",t,"user"),n.setSelection(c.index+1,0),ye(null)},[ve,Te]),Vt=o.useCallback(()=>{var n;const t=(n=ne.current)==null?void 0:n.getEditor();if(t){const c=t.getSelection(!0);ye(c)}V(!0)},[]),Wt=o.useCallback(()=>{var c;const t=(c=ne.current)==null?void 0:c.getEditor();if(!t)return;const n=t.getSelection(!0);t.formatLine(n.index,n.length,"pullquote",!0)},[]),Ht=o.useCallback(()=>{var c;const t=(c=ne.current)==null?void 0:c.getEditor();if(!t)return;const n=t.getSelection(!0);t.insertEmbed(n.index,"divider",!0,"user"),t.setSelection(n.index+1,0)},[]),Kt=o.useCallback(()=>{var n;const t=(n=ne.current)==null?void 0:n.getEditor();if(t){const c=t.getSelection(!0);ye(c)}Se(null),pe(!0)},[]),Qt=o.useCallback(()=>{var n;const t=(n=ne.current)==null?void 0:n.getEditor();if(t){const c=t.getSelection(!0);ye(c)}re(!0)},[]),Js=o.useCallback(t=>{var T;const n=(T=ne.current)==null?void 0:T.getEditor();if(!n){console.error("Quill editor not found");return}const c=ve||n.getSelection(!0)||{index:0},L=new DOMParser().parseFromString(t,"text/html").querySelector("iframe");if(L){const N={};Array.from(L.attributes).forEach(C=>{N[C.name]=C.value}),N.width||(N.width="100%"),N.height||(N.height="400"),n.insertEmbed(c.index,"iframe",N,"user")}else n.clipboard.dangerouslyPasteHTML(c.index,t,"user");n.setSelection(c.index+1,0),ye(null)},[ve]),vt=o.useCallback(t=>{const n=t.target,c=n.closest("figure.image-with-caption");if(c&&ne.current){t.preventDefault(),t.stopPropagation();const E=ne.current.getEditor(),L=he.Quill.find(c);if(L){const T=E.getIndex(L),N=Ye.value(c);bt({index:T,data:N}),V(!0)}return}const y=n.closest(".image-carousel");if(y&&ne.current){t.preventDefault(),t.stopPropagation();const E=ne.current.getEditor(),L=he.Quill.find(y);if(L){const T=E.getIndex(L),N=y.querySelectorAll(".carousel-slide"),C=[];
3N.forEach(W=>{const G=W.querySelector("img"),le=W.querySelector("figcaption");C.push({url:(G==null?void 0:G.getAttribute("src"))||"",alt:(G==null?void 0:G.getAttribute("alt"))||"",caption:(le==null?void 0:le.textContent)||""})}),C.length>0&&(Se({index:T,slides:C}),pe(!0))}}},[]);o.useEffect(()=>{var n,c;const t=(c=(n=ne.current)==null?void 0:n.getEditor())==null?void 0:c.root;if(t)return t.addEventListener("click",vt),()=>{t.removeEventListener("click",vt)}},[vt,r.content]),o.useEffect(()=>{var L;const t=(L=ne.current)==null?void 0:L.getEditor();if(!t)return;const n=t.root,c=async T=>{be.loading("Uploading pasted image…",{id:"paste-upload"});try{const{isGif:N}=await ct(async()=>{const{isGif:de}=await import("./imageOptimizer-DU1AwbgF.js");return{isGif:de}},[]),C=N(T),W=await Ft(T,{maxWidth:1200,quality:.85,format:"webp"}),G=C?"gif":"webp",le=C?"image/gif":"image/webp",_e=`post-images/${`${Math.random().toString(36).slice(2)}.${G}`}`,{error:Ce}=await _.storage.from("images").upload(_e,W.blob,{contentType:le,cacheControl:"public, max-age=31536000, immutable"});if(Ce)throw Ce;const{data:{publicUrl:U}}=_.storage.from("images").getPublicUrl(_e),ce=t.getSelection(!0)||{index:t.getLength()-1};t.insertEmbed(ce.index,"imagewithcaption",{url:U,alt:T.name.replace(/\.[^/.]+$/,""),caption:""},"user"),t.setSelection(ce.index+1,0),_.from("media").insert({title:T.name.replace(/\.[^/.]+$/,""),image_url:U,type:"image"}).then(({error:de})=>{de&&console.error("Failed to register in media library:",de)}),be.success("Image uploaded",{id:"paste-upload"})}catch(N){console.error("Paste image upload failed:",N),be.error("Failed to upload pasted image",{id:"paste-upload"})}},y=T=>{var W;const N=(W=T.clipboardData)==null?void 0:W.files;if(!N||N.length===0)return;const C=Array.from(N).filter(G=>G.type.startsWith("image/"));C.length!==0&&(T.preventDefault(),T.stopPropagation(),C.forEach(c))},E=T=>{var W;const N=(W=T.dataTransfer)==null?void 0:W.files;if(!N||N.length===0)return;const C=Array.from(N).filter(G=>G.type.startsWith("image/"));C.length!==0&&(T.preventDefault(),T.stopPropagation(),C.forEach(c))};return n.addEventListener("paste",y,!0),n.addEventListener("drop",E,!0),()=>{n.removeEventListener("paste",y,!0),n.removeEventListener("drop",E,!0)}},[r.content]);const Xs=o.useCallback(t=>{var y;const n=(y=ne.current)==null?void 0:y.getEditor();if(!n){console.error("Quill editor not found");return}const c={id:crypto.randomUUID(),slides:t.map(E=>({url:E.url,alt:E.alt,caption:E.caption}))};if(fe)n.deleteText(fe.index,1),n.insertEmbed(fe.index,"imagecarousel",c,"user"),Se(null);else{const E=ve||n.getSelection(!0)||{index:0};n.insertEmbed(E.index,"imagecarousel",c,"user"),n.setSelection(E.index+1,0)}ye(null)},[ve,fe]),Zs=o.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:Vt,imagecarousel:Kt,embed:Qt,pullquote:Wt,divider:Ht,highlight:function(){const t=this.quill,n=t.getSelection();if(n){const c=t.getFormat(n);t.format("highlight",!c.highlight)}}}},clipboard:{matchVisual:!1,matchers:[["IFRAME",(t,n)=>{const c=t.getAttribute("src"),y=t.getAttribute("width")||"100%",E=t.getAttribute("height")||"400",L=t.getAttribute("frameborder")||"0",T=t.getAttribute("allowfullscreen")||"true",N=t.getAttribute("title")||"Embedded content";return{ops:[{insert:{iframe:{src:c,width:y,height:E,frameborder:L,allowfullscreen:T,title:N}}}]}}],["#text",(t,n)=>{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"),C=T.getAttribute("width")||"100%",W=T.getAttribute("height")||"400",G=T.getAttribute("frameborder")||"0",le=T.getAttribute("allowfullscreen")||"true",Ne=T.getAttribute("title")||"Embedded content";return{ops:[{insert:{iframe:{src:N,width:C,height:W,frameborder:G,allowfullscreen:le,title:Ne}}}]}}}return n}]]}}),[Vt,Kt,Qt,Wt,Ht]),ea=["header","bold","italic","underline","strike","highlight","list","bullet","align","blockquote","pullquote","code-block","link","image","video","iframe","imagewithcaption","imagecarousel","divider"];o.useEffect(()=>{ta(),a&&sa()},[a]);const ta=async()=>{const[t,n]=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(y=>y.slug==="generative-ai");c&&q(y=>({...y,category_id:c.id}))}n.data&&P(n.data)},sa=async()=>
3{if(!a)return;p(!0);const[t,n]=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,y={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()};n.data&&n.data.length>0?ft(n.data.map(C=>({id:C.author_id,isPrimary:C.is_primary,displayOrder:C.display_order}))):c.author_id&&ft([{id:c.author_id,isPrimary:!0,displayOrder:0}]);const{data:E}=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});E&&at(E.map(C=>{var W,G;return{infographic_id:C.infographic_id,insert_after_paragraph:C.insert_after_paragraph,display_order:C.display_order,title:((W=C.infographics)==null?void 0:W.title)||"",image_url:((G=C.infographics)==null?void 0:G.image_url)||""}}));const{data:L}=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});L&&xt(L.map(C=>{var W,G;return{report_id:C.report_id,display_order:C.display_order,title:((W=C.research_reports)==null?void 0:W.title)||"",cover_image_url:((G=C.research_reports)==null?void 0:G.cover_image_url)||null}})),tt.current=JSON.stringify({formData:y,customSlug:c.slug||""}),q(y),B(c.slug);const T=c.slug||"",N=T.lastIndexOf("/");J(N>=0?T.substring(N+1):T),$s(c.category_id||null),Ze.current=c.slug||null,K(!1),te(new Date(c.updated_at)),x(!0),p(!1)}},aa=async t=>{var c;const n=(c=t.target.files)==null?void 0:c[0];if(n){g(!0);try{const{optimizeImage:y,formatFileSize:E,calculateSavings:L,isGif:T}=await ct(async()=>{const{optimizeImage:U,formatFileSize:ce,calculateSavings:de,isGif:pa}=await import("./imageOptimizer-DU1AwbgF.js");return{optimizeImage:U,formatFileSize:ce,calculateSavings:de,isGif:pa}},[]),N=T(n),C=await y(n,{maxWidth:2e3,maxHeight:2e3,quality:.85,format:"webp"}),W=N?"gif":"webp",G=N?"image/gif":"image/webp",le=`${Date.now()}-${Math.random().toString(36).substring(7)}.${W}`,{error:Ne}=await _.storage.from("imported-images").upload(le,C.blob,{contentType:G,cacheControl:"public, max-age=31536000, immutable"});if(Ne)throw Ne;const{data:{publicUrl:_e}}=_.storage.from("imported-images").getPublicUrl(le);q({...r,image_url:_e}),_.from("media").insert({title:n.name.replace(/\.[^/.]+$/,""),image_url:_e,type:"image"}).then(({error:U})=>{U&&console.error("Failed to register in media library:",U)});const Ce=L(C.originalSize,C.optimizedSize);s({title:"Success",description:`Image optimized and uploaded. ${Ce} size reduction.`})}catch(y){s({variant:"destructive",title:"Error uploading image",description:y.message})}finally{g(!1)}}},ra=t=>t.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""),ia=async t=>{if(!t||t.trim()===""){se(null);return}$(!0);try{const{data:n,error:c}=await _.from("posts").select("id").eq("slug",t).maybeSingle();if(c)throw c;a&&(n==null?void 0:n.id)===a?se(!0):se(!n)}catch(n){console.error("Error checking slug:",n),se(null)}finally{$(!1)}};o.useEffect(()=>{const t=setTimeout(()=>{if(M){const n=R.find(y=>y.id===r.category_id),c=n?`${n.slug}/${M}`:M;ia(c)}},500);return()=>clearTimeout(t)},[M]),o.useEffect(()=>{if(!a&&r.title){const t=ra(r.title);J(t)}},[r.title,r.category_id,a,R]);const na=t=>{const n=t.toLowerCase().replace(/\s+/g,"-").replace(/[^\w-/]+/g,"").replace(/\//g,"");J(n)},qe=R.find(t=>
3t.id===r.category_id),it=qe&&M?`${qe.slug}/${M}`:M,oa=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}D(!0);try{const{data:n,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;n&&(q({...r,seo_title:n.seo_title||"",seo_description:n.seo_description||"",seo_keywords:n.seo_keywords||""}),s({title:"Success",description:"SEO metadata generated successfully. You can edit it before saving."}))}catch(n){console.error("Error generating SEO:",n),s({variant:"destructive",title:"Error generating SEO",description:n.message||"Failed to generate SEO metadata. Please try again."})}finally{D(!1)}},[Yt,Jt]=o.useState(!1),la=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}Jt(!0);try{const{data:n,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;n&&n.takeaways&&(q({...r,key_takeaways:JSON.stringify(n.takeaways)}),s({title:"Success",description:"Key takeaways generated successfully."}))}catch(n){console.error("Error generating takeaways:",n),s({variant:"destructive",title:"Error",description:n.message||"Failed to generate key takeaways."})}finally{Jt(!1)}},ca=async()=>{var t,n;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=R.find(L=>L.id===r.category_id))==null?void 0:t.name)||"",{data:y,error:E}=await _.functions.invoke("generate-satirical-take",{body:{title:r.title,excerpt:r.excerpt,discussion_prompt:((n=r.discussion_prompt)==null?void 0:n.trim())||null,categoryName:c}});if(E)throw E;y&&y.satiricalTake&&(q({...r,satirical_take:y.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)}},da=async t=>{var Ne,_e,Ce;if(t.preventDefault(),r.published){const U=[];if(r.title.trim()||U.push("Title"),r.category_id||U.push("Category"),r.excerpt.trim()||U.push("Excerpt"),(!r.content.trim()||r.content==="<p><br></p>")&&U.push("Content"),r.image_url||U.push("Featured Image"),oe.length===0&&U.push("Authors"),U.length>0){s({variant:"destructive",title:"Required Fields Missing",description:`Please fill in: ${U.join(", ")}`});return}}if(Y===!1){s({variant:"destructive",title:"Invalid Slug",description:"This slug is already taken. Please choose a different one."});return}d(!0);const n=oe.find(U=>U.isPrimary)||oe[0],c=new Date(r.published_at)>new Date,y=c?!1:r.published,E=c?"scheduled":r.published?"published":"draft",L=await kt(r.content),T={...r,content:lt(L),slug:it||null,category_id:r.category_id||null,author_id:(n==null?void 0:n.id)||null,published:y,status:E};let N=a,C;if(a?C=await _.from("posts").update(T).eq("id",a):(C=await _.from("posts").insert([T]).select("id").single(),(Ne=C.data)!=null&&Ne.id&&(N=C.data.id)),C.error){s({variant:"destructive",title:`Error ${a?"updating":"creating"} post`,description:C.error.message}),d(!1);return}if(N&&oe.length>0){await _.from("post_authors").delete().eq("post_id",N);const U=oe.map(de=>({post_id:N,author_id:de.id,is_primary:de.isPrimary,display_order:de.displayOrder})),{error:ce}=await _.from("post_authors").insert(U);ce&&console.error("Error saving authors:",ce)}if(N){if(await _.from("post_infographics").delete().eq("post_id",N),Pe.length>0){const U=Pe.map((ce,de)=>({post_id:N,infographic_id:ce.infographic_id,insert_after_paragraph:ce.insert_after_paragraph,display_order:de}));await _.from("post_infographics").insert(U)}if(await _.from("post_research_reports").delete().eq("post_id",N),De.length>0){const U=De.map((ce,de)=>({post_id:N,report_id:ce.report_id,display_order:de}));await _.from("post_research_reports").insert(U)}}const W=new Date(r.published_at)>new Date;s({title:W?"Scheduled":"Success",description:W?`Post scheduled for ${Gt(r.published_at)}.`:`Post ${a?"updated":"created"} successfully.`}),K(!1),te(new Date);let G=it||M||r.title.toLowerCase().replace(/\s+/g,"-");if(N){const{data:U}=await _.from("posts").select("slug").eq("id",N).single();
3U!=null&&U.slug&&(G=U.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(U){console.error("Sitemap ping failed:",U)}if(oe.length>0)for(const U of oe)try{_.functions.invoke("notify-author-followers",{body:{author_id:U.id,post_id:N||"new",post_title:r.title,post_slug:G,post_excerpt:((_e=r.excerpt)==null?void 0:_e.substring(0,200))||""}}).catch(console.error)}catch(ce){console.error("Follower notification failed:",ce)}try{_.functions.invoke("send-push-notification",{body:{post_title:r.title,post_slug:G,post_excerpt:((Ce=r.excerpt)==null?void 0:Ce.substring(0,100))||"",post_image:r.image_url}}).catch(console.error)}catch(U){console.error("Push notification failed:",U)}}const le=G;if(a&&Ze.current&&le&&Ze.current!==le){et({open:!0,oldSlug:Ze.current,newSlug:le}),d(!1);return}i("/admin/posts"),d(!1)},[yt,jt]=o.useState(!1),ma=async()=>{var T;if(Y===!1){s({variant:"destructive",title:"Invalid Slug",description:"This slug is already taken. Please choose a different one."});return}jt(!0);const t=oe.find(N=>N.isPrimary)||oe[0],n=await kt(r.content),c={...r,content:lt(n),slug:M||null,category_id:r.category_id||null,author_id:(t==null?void 0:t.id)||null,published:!1};let y=a,E;if(a?E=await _.from("posts").update(c).eq("id",a):(E=await _.from("posts").insert([c]).select("id").single(),(T=E.data)!=null&&T.id&&(y=E.data.id)),E.error){s({variant:"destructive",title:"Error saving draft",description:E.error.message}),jt(!1);return}if(y&&oe.length>0){await _.from("post_authors").delete().eq("post_id",y);const N=oe.map(C=>({post_id:y,author_id:C.id,is_primary:C.isPrimary,display_order:C.displayOrder}));await _.from("post_authors").insert(N)}const L={...r,published:!1};tt.current=JSON.stringify({formData:L,customSlug:M}),q(L),K(!1),te(new Date),s({title:"Draft Saved",description:"Your changes have been saved as a draft."}),!a&&y&&i(`/admin/posts/edit/${y}`,{replace:!0}),jt(!1)},ua=async()=>{if(!(!a||!z||ee||!f)){ae(!0);try{const t=oe.find(E=>E.isPrimary)||oe[0],n=await kt(r.content),c={...r,content:lt(n),slug:M||null,category_id:r.category_id||null,author_id:(t==null?void 0:t.id)||null},{error:y}=await _.from("posts").update(c).eq("id",a);y||(te(new Date),K(!1))}catch(t){console.error("Autosave error:",t)}finally{ae(!1)}}};o.useEffect(()=>{if(a&&f&&tt.current){const n=JSON.stringify({formData:r,customSlug:M})!==tt.current;K(n)}},[r,M,f,a]),o.useEffect(()=>{const t=rr(r.content);Je(t)},[r.content]),o.useEffect(()=>{if(!a)return;const t=setInterval(()=>{ua()},3e4);return()=>clearInterval(t)},[a,z,ee,r,M]),o.useEffect(()=>{const t=n=>{if(z)return n.preventDefault(),n.returnValue="",""};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[z]),o.useEffect(()=>{if(ie){document.body.style.overflow="hidden";const t=n=>{n.key==="Escape"&&Le(!1)};return window.addEventListener("keydown",t),()=>{document.body.style.overflow="",window.removeEventListener("keydown",t)}}else document.body.style.overflow=""},[ie]);const Xt=o.useCallback(()=>{z?(pt("/admin/posts"),st(!0)):i("/admin/posts")},[z,i]),ha=o.useCallback(()=>{st(!1),gt&&(i(gt),pt(null))},[i,gt]),ga=o.useCallback(()=>{st(!1),pt(null)},[]);return v?e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-background via-background to-muted/30",children:[e.jsx(rs,{}),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(rs,{}),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(I,{variant:"ghost",size:"sm",onClick:Xt,className:"gap-1.5 text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(Za,{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:[je.toLocaleStr
3ing()," words"]}),a&&e.jsx(e.Fragment,{children:ee?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(ue,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Saving"})]}):ge?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(Nt,{className:"h-3 w-3"}),e.jsx("span",{children:new Date(ge).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}):z?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 dark:text-rose-400 rounded-md",children:[e.jsx(_t,{className:"h-3 w-3"}),e.jsx("span",{children:"Unsaved"})]}):null})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>me(!0),className:"gap-1.5 border-border/50 hover:bg-muted/50 transition-all",children:[e.jsx(er,{className:"h-3.5 w-3.5"}),"Preview"]}),a&&r.published&&e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>window.open(`/${A||a}`,"_blank"),className:"gap-1.5 border-border/50 hover:bg-muted/50 transition-all",children:[e.jsx(Pa,{className:"h-3.5 w-3.5"}),"View"]}
3)]})]})}),e.jsx("div",{className:"max-w-5xl mx-auto px-6 py-6",children:e.jsxs("form",{onSubmit:da,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(H,{className:"text-sm font-medium text-foreground/80",children:"Category"}),e.jsxs(Ra,{value:r.category_id||void 0,onValueChange:t=>q({...r,category_id:t}),children:[e.jsx(za,{className:"border-border/50 focus:border-primary/50",children:e.jsx(Ua,{placeholder:"Select category"})}),e.jsx(Fa,{children:R.map(t=>e.jsx(Oa,{value:t.id,children:t.name},t.id))})]}),a&&Xe&&r.category_id&&r.category_id!==Xe&&e.jsxs("p",{className:"text-xs text-amber-600 dark:text-amber-400 flex items-center gap-1 animate-fade-in",children:[e.jsx(_t,{className:"h-3 w-3"}),"Category change will affect the URL"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(H,{htmlFor:"title",className:"text-sm font-medium text-foreground/80",children:"Title"}),e.jsx(Q,{id:"title",value:r.title,onChange:t=>q({...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(H,{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:[qe&&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:[qe.slug,"/"]}),e.jsx(Q,{id:"slug",value:M,onChange:t=>na(t.target.value),placeholder:"article-slug",className:`pr-10 border-border/50 transition-all ${qe?"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:X?e.jsx(ue,{className:"h-4 w-4 animate-spin text-muted-foreground"}):Y===!0?e.jsx(Nt,{className:"h-4 w-4 text-emerald-500"}):Y===!1?e.jsx(_t,{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&&it&&e.jsxs("p",{className:"text-xs text-emerald-600 dark:text-emerald-400 animate-fade-in",children:["✓ /",it]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(H,{htmlFor:"excerpt",className:"text-sm font-medium text-foreground/80",children:"Excerpt"}),e.jsx(Ue,{id:"excerpt",value:r.excerpt,onChange:t=>q({...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(H,{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(Ue,{id:"discussion_prompt",value:r.discussion_prompt,onChange:t=>q({...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:xe("bg-card rounded-xl border border-border/40 p-5 shadow-sm transition-shadow duration-300",ie?"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(H,{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(I,{type:"button",variant:"ghost",size:"sm",onClick:()=>Le(!ie),className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground transition-colors",title:ie?"Exit fullscreen":"Expand editor",children:ie?e.jsx(Wa,{className:"h-3.5 w-3.5"}):e.jsx(tr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx(Ma,{ref:ne,theme:"snow",value:r.content,onChange:t=>q({...r,content:t}),modules:Zs,formats:ea,className:xe("bg-background rounded-lg border border-border/30 editor-compact",ie&&"flex-1 [&_.ql-container]:flex-1 flex flex-col [&_.ql-toolbar]:shrink-0"),style:ie?{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(Ha,{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(Pr,{}),e.jsxs(I,{type:"button",variant:"ghost",size:"sm",onClick:la,disabled:Yt||!r.title||!r.content,className:"gap-1.5 h-7 text-xs hover:bg-amber-100/50 dark:hover:bg-amber-900/30",children:[Yt?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ee,{className:"h-3 w-3"}),"Generate"]})]})]}),e.jsx(Ir,{value:r.key_takeaways,onChange:t=>q({...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(Ee,{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(I,{type:"button",variant:"ghost",size:"sm",onClick:oa,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(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ee,{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=>q({...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(Ue,{value:r.seo_description||"",onChange:t=>q({...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=>q({...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(Ee,{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(I,{type:"button",variant:"ghost",size:"sm",onClick:ca,disabled:j||!r.title,className:"gap-1.5 h-7 text-xs hover:bg-fuchsia-100/50 dark:hover:bg-fuchsia-900/30",children:[j?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ee,{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=>q({...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(is,{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(I,{type:"button",variant:"outline",size:"sm",onClick:()=>{var t;return(t=document.getElementById("image-upload"))==null?void 0:t.click()},disabled:m,className:"gap-1.5 border-dashed hover:border-solid transition-all",children:[m?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Be,{className:"h-3.5 w-3.5"}),m?"Uploading":"Upload"]}),e.jsxs(I,{type:"button",variant:"outline",size:"sm",onClick:()=>F(!0),className:"gap-1.5",children:[e.jsx(It,{className:"h-3.5 w-3.5"}),"Library"]}),e.jsx("input",{id:"image-upload",type:"file",accept:"image/*",className:"hidden",onChange:aa}),e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsx(Q,{value:r.image_url,onChange:t=>q({...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(I,{type:"button",variant:"destructive",size:"icon",onClick:()=>q({...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(ze,{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=>q({...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(H,{className:"text-xs text-muted-foreground",children:"Authors"}),e.jsx(Cr,{authors:k,selectedAuthors:oe,onSelectionChange:ft})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(H,{className:"text-xs text-muted-foreground",children:"Read Time"}),e.jsx(Q,{placeholder:"5 min read",value:r.read_time,onChange:t=>q({...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(wt,{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(I,{type:"button",variant:"outline",size:"sm",onClick:()=>$t(!0),className:"gap-1.5 mb-3",children:[e.jsx(is,{className:"h-3.5 w-3.5"}),"Add Infographic"]}),Pe.length>0&&e.jsx("div",{className:"space-y-2",children:Pe.map((t,n)=>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 y=[...Pe];y[n]={...y[n],insert_after_paragraph:parseInt(c.target.value)||3},at(y)},className:"h-6 w-16 text-xs"})]})]}
3),e.jsx(I,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",onClick:()=>at(Pe.filter((c,y)=>y!==n)),children:e.jsx(ze,{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(wt,{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(I,{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});Ws(t||[]),rt(!0)},className:"gap-1.5 mb-3",children:[e.jsx(wt,{className:"h-3.5 w-3.5"}),"Attach Report"]}),De.length>0&&e.jsx("div",{className:"space-y-2",children:De.map((t,n)=>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(Ct,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("p",{className:"flex-1 text-xs font-medium truncate",children:t.title}),e.jsx(I,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",onClick:()=>xt(De.filter((c,y)=>y!==n)),children:e.jsx(ze,{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(fs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(H,{className:"text-sm font-medium",children:"Publish Date"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(vs,{children:[e.jsx(ys,{asChild:!0,children:e.jsxs(I,{type:"button",variant:"outline",size:"sm",className:xe("gap-2 text-xs",Ae()&&"border-amber-400/50 bg-amber-50/50 dark:bg-amber-950/20"),children:[e.jsx(fs,{className:"h-3.5 w-3.5"}),r.published_at?Da(r.published_at):"Pick date"]})}),e.jsx(js,{className:"w-auto p-0",align:"start",children:e.jsx(La,{mode:"single",selected:r.published_at?new Date(r.published_at):void 0,onSelect:Hs,initialFocus:!0,className:xe("p-3 pointer-events-auto")})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Et,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx(Q,{type:"time",value:Qs(),onChange:t=>Ks(t.target.value),className:"h-8 w-24 text-xs border-border/50"})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"IST"})]}),Ae()&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-400 rounded-md text-xs animate-fade-in",children:[e.jsx(Et,{className:"h-3 w-3"}),e.jsxs("span",{children:["Scheduled for ",Gt(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(nt,{id:"featured",checked:r.featured,onCheckedChange:t=>q({...r,featured:t}),className:"data-[state=checked]:bg-amber-500"}),e.jsx(H,{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(nt,{id:"pinned",checked:!!r.pinned_at,onCheckedChange:t=>q({...r,pinned_at:t?new Date().toISOString():null}),className:"data-[state=checked]:bg-rose-500"}),e.jsx(H,{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(nt,{id:"ai_compass",checked:r.show_on_ai_compass,onCheckedChange:t=>q({...r,show_on_ai_compass:t}),className:"data-[state=checked]:bg-violet-500"}),e.jsx(H,{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=>q({...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(nt,{id:"published",checked:r.published,onCheckedChange:t=>q({...r,published:t}),className:"data-[state=checked]:bg-emerald-500",disabled:Ae()}),e.jsx(H,{htmlFor:"published",className:xe("text-sm cursor-pointer",Ae()&&"text-muted-foreground"),children:Ae()?"Will publish on 
3schedule":"Published"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{type:"button",variant:"ghost",size:"sm",onClick:Xt,className:"text-muted-foreground hover:text-foreground",children:"Cancel"}),e.jsxs(I,{type:"button",variant:"outline",size:"sm",onClick:ma,disabled:yt||u,className:"gap-1.5",children:[yt?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(sr,{className:"h-3.5 w-3.5"}),"Save Draft"]}),e.jsxs(I,{type:"submit",size:"sm",disabled:u||yt,className:"gap-1.5 bg-primary hover:bg-primary/90 shadow-sm",children:[u?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Nt,{className:"h-3.5 w-3.5"}),Ae()?"Schedule":a?"Update":"Publish"]})]})]})]})]})})]}),e.jsx(nr,{open:Z,onOpenChange:me,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:(Zt=R.find(t=>t.id===r.category_id))==null?void 0:Zt.name,authorName:(es=k.find(t=>t.id===r.author_id))==null?void 0:es.name,authorImage:(ts=k.find(t=>t.id===r.author_id))==null?void 0:ts.image_url,authorRole:(ss=k.find(t=>t.id===r.author_id))==null?void 0:ss.role,keyTakeaways:r.key_takeaways}),e.jsx(Sr,{open:Ie,onOpenChange:t=>{V(t),t||bt(null)},onInsert:Ys,initialData:Te==null?void 0:Te.data}),e.jsx(kr,{open:we,onOpenChange:t=>{pe(t),t||Se(null)},onInsert:Xs,initialSlides:fe==null?void 0:fe.slides,isEditing:!!fe}),e.jsx(Qa,{open:O,onOpenChange:re,onInsert:Js}),e.jsx(ls,{open:Bs,onOpenChange:st,children:e.jsxs(cs,{className:"animate-scale-in",children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Unsaved Changes"}),e.jsx(us,{children:"You have unsaved changes. Are you sure you want to leave?"})]}),e.jsxs(hs,{children:[e.jsx(gs,{onClick:ga,children:"Stay"}),e.jsx(ps,{onClick:ha,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Discard"})]})]})}),e.jsx(ls,{open:ke.open,onOpenChange:t=>{t||(et({open:!1,oldSlug:"",newSlug:""}),i("/admin/posts"))},children:e.jsxs(cs,{className:"animate-scale-in",children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"URL Changed"}),e.jsxs(us,{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:["/",ke.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:["/",ke.newSlug]}),e.jsx("span",{className:"block mt-2",children:"Would you like to create a redirect from the old URL?"})]})]}),e.jsxs(hs,{children:[e.jsx(gs,{onClick:()=>{et({open:!1,oldSlug:"",newSlug:""}),i("/admin/posts")},children:"Skip"}),e.jsx(ps,{onClick:async()=>{try{await _.from("redirects").insert({from_path:ke.oldSlug,to_path:ke.newSlug,is_permanent:!0}),s({title:"Redirect created",description:`/${ke.oldSlug} → /${ke.newSlug}`})}catch(t){s({variant:"destructive",title:"Failed to create redirect",description:t.message})}et({open:!1,oldSlug:"",newSlug:""}),i("/admin/posts")},children:"Create Redirect"})]})]})}),e.jsx(Ns,{open:w,onOpenChange:F,onSelect:t=>q({...r,image_url:t})}),e.jsx(Er,{open:Gs,onOpenChange:$t,onSelect:t=>{at(n=>[...n,{infographic_id:t.id,insert_after_paragraph:3,display_order:n.length,title:t.title,image_url:t.image_url}])}}),Vs&&e.jsx("div",{className:"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm flex items-center justify-center",onClick:()=>rt(!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"}),Bt.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:Bt.filter(t=>!De.some(n=>n.report_id===t.id)).map(t=>e.jsxs("button",{onClick:()=>{xt(n=>[...n,{report_id:t.id,display_order:n.length,title:t.title,cover_image_url:t.cover_image_url}]),rt(!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(Ct,{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(I,{variant:"ghost",size:"sm",onClick:()=>rt(!1),children:"Close"})})]})})]})};export{Ti 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.