1import{u as us,r as t,f as r,s as c,j as e,B as l,I as m,bq as xs,X as ps,a3 as Oe,N as hs,E as gs,b4 as fs}from"./index-KSWbwNeY.js";import{A as js}from"./AdminNav-DsaLvjFx.js";import{R as S}from"./quill.snow-CYjwR_8r.js";import{L as o}from"./label-ndOKmXJw.js";import{C as G,b as K,c as J,a as V}from"./card-CwL_ed79.js";import{A as bs,h as vs,a as Ns,b as ws,c as ks,d as Ss,e as Cs,f as Ts,g as ys}from"./alert-dialog-DFWe8irl.js";import{D as Y,a as Z,b as ee,c as se,f as te}from"./dialog-Bpfij23O.js";import{M as ae}from"./MediaLibraryPicker-CRVpp0Z2.js";import{s as _s}from"./sanitizeHTML-3eQ8Vumw.js";import{P as Es}from"./plus-oseq6Y0_.js";import{R as Be}from"./radio-BbIxXjYG.js";import{P as Fe}from"./pencil-BI2V26IC.js";import{S as ie}from"./share-2-DMKgqov0.js";import{T as Us}from"./trash-2-CwcwS_bf.js";import{U as qs}from"./upload-CstIFHrJ.js";import{f as Ds}from"./formatDistanceToNow-C8SfwPCw.js";import"./index-DsYLezIw.js";import"./user-cog-DvqSS7bY.js";import"./book-open-DS7Nmuzn.js";import"./receipt-DgWJf9Ou.js";import"./chevron-down-D7IdZFzc.js";import"./index-BpbyRUKB.js";import"./scroll-area-DlihVgX7.js";import"./index-BdQq_4o_.js";import"./purify.es--yiYCWnk.js";import"./htmlDecoder-Cz23cfvH.js";import"./constructNow-CAQUuh76.js";import"./en-US-BOoww7nS.js";import"./endOfMonth-bNOLQZ7P.js";import"./endOfDay-CTvcx9iE.js";const ct=()=>{const{user:C}=us(),[Qe,$e]=t.useState([]),[d,T]=t.useState(""),[y,re]=t.useState([]),[f,le]=t.useState(""),[oe,_]=t.useState(""),[ne,ce]=t.useState(""),[E,de]=t.useState(""),[me,ue]=t.useState(!1),[Xe,U]=t.useState(!1),[We,x]=t.useState(!1),[Ge,q]=t.useState(!1),[Ke,p]=t.useState(!1),[j,b]=t.useState(""),[xe,pe]=t.useState("new"),[h,he]=t.useState(!1),D=t.useRef(null);t.useRef(null);const Je=t.useRef(null),Ve=t.useRef(null),ge=t.useRef(null),[I,fe]=t.useState(""),[L,je]=t.useState(""),[be,ve]=t.useState(""),[Ne,we]=t.useState(!1),[P,v]=t.useState(null),[N,ke]=t.useState(""),[Se,R]=t.useState(""),[Ce,Te]=t.useState(""),[ye,_e]=t.useState(""),[Ye,M]=t.useState(!1),[z,Ee]=t.useState(!1),Ze=s=>{v(s.id),ke(s.title),R(s.slug),Te(s.description||""),_e(s.featured_image_url||"")},es=async()=>{if(!P||!N){r.error("Title is required");return}Ee(!0);const{error:s}=await c.from("live_topics").update({title:N,slug:Se||k(N),description:Ce||null,featured_image_url:ye}).eq("id",P);if(Ee(!1),s){r.error(s.message);return}r.success("Topic updated"),v(null),g()},[H,Ue]=t.useState(null),[A,O]=t.useState(""),[B,F]=t.useState(""),[qe,Q]=t.useState(""),[$,De]=t.useState(!1),X=t.useRef(null),ss=s=>{Ue(s.id),O(s.headline),F(s.summary),Q(s.link_url||"")},Ie=()=>{Ue(null),O(""),F(""),Q("")},ts=async()=>{if(!H||!A||!B){r.error("Headline and summary are required");return}De(!0);const{error:s}=await c.from("live_updates").update({headline:A,summary:B,link_url:qe||null}).eq("id",H);if(De(!1),s){r.error(s.message);return}r.success("Update saved"),Ie(),w(d)},[Le,Pe]=t.useState("new"),W=t.useCallback(s=>{var n;const i=(n=(Le==="edit"?X:D).current)==null?void 0:n.getEditor();if(i){const u=i.getSelection(!0);i.insertEmbed(u.index,"image",s),i.setSelection(u.index+1,0)}},[Le]),as=t.useCallback(async s=>{if(!s.type.startsWith("image/")){r.error("Please select an image file");return}we(!0);try{const a=s.name.split(".").pop(),i=`live-updates/${Date.now()}.${a}`,{error:n}=await c.storage.from("images").upload(i,s);if(n)throw n;const{data:{publicUrl:u}}=c.storage.from("images").getPublicUrl(i);W(u),r.success("Image uploaded")}catch(a){r.error(a.message||"Upload failed")}finally{we(!1),x(!1)}},[W]),Re=t.useCallback(()=>{Pe("new"),x(!0)},[]),Me=t.useCallback(()=>{Pe("edit"),x(!0)},[]),is=async s=>{const a=s.trim();try{const{data:i,error:n}=await c.functions.invoke("fetch-oembed",{body:{url:a}});if(n)throw n;return i!=null&&i.html?{html:i.html,platform:i.platform}:null}catch(i){return console.error("[fetchSocialEmbedHtml]",i),null}},ze=t.useCallback(async s=>{var u;if(!s.trim())return;he(!0);const a=await is(s);if(he(!1),!a){r.error("Unsupported URL or failed to fetch embed. Paste a Twitter/X, Instagram, TikTok, or LinkedIn post URL.");return}const n=(u=(xe==="edit"?X:D).current)==null?void 0:u.getEditor();if(n){const Ae=n.getSelection(!0);n.clipboard.dangerouslyPasteHTML(Ae.index,a.html+"<p><br></p>"),n.setSelection(Ae.index+a.html.length+5,0)}r.success(`${a.platform} embed inserted`),b(""),p(!1)},[xe]),rs=t.useMemo(()=>({toolbar:{container:[["bold","italic","underline","strike"],["blockquote"],[{list:"ordered"},{list:"bullet"}],["link","image","video"],["clean"]],handlers:{image:Re}}}),[Re]),ls=t.useMemo(()=>({toolbar:{container:[["bold","italic","underline","strike"],["blockquote"],[{list:"ordered"},{list:"bullet"}],["link","image","video"],["clean"]],handlers:{image:Me}}}),[Me]),He=t.useMemo(()=>({toolbar:[[{header:[2,3,!1]}],["bold","italic","underline"],[{list:"ordered"},{list:"bullet"}],["blockquote","link"],["clean"]]}),[]);t.useEffect(()=>{g()},[]),t.useEffect(()=>{d&&w(d)},[d]);const g=async()=>{const{data:s}=await c.from("live_topics").select("*").order("created_at",{ascending:!1});$e(s||[]),s&&s.length>0&&!d&&T(s[0].id)},w=async s=>{const{data:a}=await c.from("live_updates").select("*, authors:author_id(name)").eq("topic_id",s).order("created_at",{ascending:!1});re(a||[])},k=s=>s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),os=async()=>
1{if(!f||!E){r.error("Title and featured image are required");return}const s=oe||k(f),{error:a}=await c.from("live_topics").insert({title:f,slug:s,description:ne||null,featured_image_url:E,created_by:C==null?void 0:C.id});if(a){r.error(a.message);return}r.success("Topic created"),le(""),_(""),ce(""),de(""),ue(!1),g()},ns=async(s,a)=>{await c.from("live_topics").update({is_active:a}).eq("id",s),g()},cs=async s=>{await c.from("live_updates").delete().eq("topic_id",s);const{error:a}=await c.from("live_topics").delete().eq("id",s);if(a){r.error(a.message);return}r.success("Topic deleted"),d===s&&(T(""),re([])),g()},ds=async()=>{if(!I||!L||!d){r.error("Headline and summary are required");return}const{error:s}=await c.from("live_updates").insert({topic_id:d,headline:I,summary:L,link_url:be||null});if(s){r.error(s.message);return}r.success("Update posted!"),fe(""),je(""),ve(""),w(d)},ms=async s=>{await c.from("live_updates").delete().eq("id",s),w(d),r.success("Update deleted")};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(js,{}),e.jsxs("div",{className:"ml-52 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Live Updates"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage live topics and post real-time updates"})]}),e.jsxs(l,{onClick:()=>ue(!me),size:"sm",children:[e.jsx(Es,{className:"h-4 w-4 mr-1"})," New Topic"]})]}),me&&e.jsxs(G,{className:"mb-6",children:[e.jsx(K,{children:e.jsx(J,{className:"text-base",children:"Create Topic"})}),e.jsxs(V,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Title"}),e.jsx(m,{value:f,onChange:s=>{le(s.target.value),_(k(s.target.value))},placeholder:"Google I/O 2026 Live"})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Slug"}),e.jsx(m,{value:oe,onChange:s=>_(s.target.value),placeholder:"google-io-2026-live"})]})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Description (optional)"}),e.jsx("div",{className:"mt-1 rounded-md border border-input overflow-hidden [&_.ql-toolbar]:border-b [&_.ql-toolbar]:border-border [&_.ql-toolbar]:bg-muted/30 [&_.ql-container]:border-0 [&_.ql-editor]:min-h-[100px] [&_.ql-editor]:text-sm [&_.ql-editor]:text-foreground [&_.ql-editor.ql-blank::before]:text-muted-foreground",children:e.jsx(S,{ref:Je,theme:"snow",value:ne,onChange:ce,modules:He,placeholder:"Write a brief description of this topic..."})})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Featured Image"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m,{value:E,readOnly:!0,placeholder:"Select from media library",className:"flex-1"}),e.jsx(l,{type:"button",variant:"outline",size:"sm",onClick:()=>U(!0),children:"Browse"})]}),e.jsx(ae,{open:Xe,onOpenChange:U,onSelect:s=>{de(s),U(!1)}})]}),e.jsx(l,{onClick:os,size:"sm",children:"Create Topic"})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-6",children:Qe.map(s=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("button",{onClick:()=>T(s.id),className:`flex items-center gap-2 px-3 py-1.5 rounded-full text-xs font-medium border transition-colors ${d===s.id?"bg-accent text-accent-foreground border-accent":"bg-card text-card-foreground border-border hover:border-accent/50"}`,children:[s.is_active&&e.jsx(Be,{className:"h-3 w-3 text-destructive"}),s.title,e.jsx(xs,{checked:s.is_active,onCheckedChange:a=>ns(s.id,a),className:"scale-75",onClick:a=>a.stopPropagation()})]}),e.jsx("button",{className:"p-1 rounded-full hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",onClick:a=>{a.stopPropagation(),Ze(s)},title:"Edit topic",children:e.jsx(Fe,{className:"h-3.5 w-3.5"})}),e.jsxs(bs,{children:[e.jsx(vs,{asChild:!0,children:e.jsx("button",{className:"p-1 rounded-full hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",onClick:a=>a.stopPropagation(),children:e.jsx(ps,{className:"h-3.5 w-3.5"})})}),e.jsxs(Ns,{children:[e.jsxs(ws,{children:[e.jsxs(ks,{children:['Delete "',s.title,'"?']}),e.jsx(Ss,{children:"This will permanently delete this topic and all its updates. This action cannot be undone."})]}),e.jsxs(Cs,{children:[e.jsx(Ts,{children:"Cancel"}),e.jsx(ys,{onClick:()=>cs(s.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]},s.id))}),e.jsx(Y,{open:!!P,onOpenChange:s=>{s||v(null)},children:e.jsxs(Z,{className:"sm:max-w-lg",children:[e.jsxs(ee,{children:[e.jsx(se,{className:"text-base",children:"Edit Topic"}),e.jsx(te,{className:"text-sm text-muted-foreground",children:"Update the topic title, slug, description, and featured image."})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Title"}),e.jsx(m,{value:N,onChange:s=>{ke(s.target.value),R(k(s.target.value))},placeholder:"Topic title"})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Slug"}),e.jsx(m,{value:Se,onChange:s=>R(s.target.value),placeholder:"topic-slug"})]})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Description (optional)"}),e.jsx("div",{className:"mt-1 rounded-md border border-input overflow-hidden [&_.ql-toolbar]:border-b [&_.ql-toolbar]:border-border [&_.ql-toolbar]:bg-muted/30 [&_.ql-container]:border-0 [&_.ql-editor]:min-h-[100px] [&_.ql-editor]:text-sm [&_.ql-editor]:text-foreground [&_.ql-editor.ql-blank::before]:text-muted-foreground",children:e.jsx(S,{ref:Ve,theme:"snow",value:Ce,onChange:Te,modules:He,placeholder:"Brief description of this topic..."})})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Featured Image"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m,{value:ye,readOnly:!0,placeholder:"Select from media library",className:"flex-1"}),e.jsx(l,{type:"button",variant:"outline",size:"sm",onClick:()=>M(!0),children:"Browse"})]}),e.jsx(ae,{open:Ye,onOpenChange:M,onSelect:s=>{_e(s),M(!1)}})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsxs(l,{onClick:es,size:"sm",disabled:z,children:[e.jsx(Oe,{className:"h-3.5 w-3.5 mr-1"}),z?"Saving...":"Save Changes"]}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>v(null),disabled:z,children:"Cancel"})]})]})]})}),d&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs(G,{className:"lg:col-span-1",children:[e.jsx(K,{children:e.jsx(J,{className:"text-base",children:"Post Update"})}),e.jsxs(V,{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Headline"}),e.jsx(m,{value:I,onChange:s=>fe(s.target.value),placeholder:"Breaking: New feature announced"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx(o,{className:"text-xs",children:"Summary"}),e.jsxs(l,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-[11px] px-2 text-muted-foreground hover:text-foreground gap-1",onClick:()=>{pe("new"),p(!0)},children:[e.jsx(ie,{className:"h-3 w-3"}),"Embed Social Post"]})]}),e.jsx(S,{ref:D,theme:"snow",value:L,onChange:je,modules:rs,placeholder:"Rich text summary with images, links, embeds...",className:"bg-background [&_.ql-editor]:min-h-[80px]"})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Link (optional)"}),e.jsx(m,{value:be,onChange:s=>ve(s.target.value),placeholder:"https://..."})]}),e.jsxs(l,{onClick:ds,className:"w-full",size:"sm",children:[e.jsx(Be,{className:"h-3.5 w-3.5 mr-1.5"}),"Post Live Update"]})]})]}),e.jsxs(G,{className:"lg:col-span-2",children:[e.jsx(K,{children:e.jsxs(J,{className:"text-base",children:["Updates (",y.length,")"]})}),e.jsx(V,{children:y.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No updates yet."}):e.jsx("div",{className:"space-y-3",children:y.map(s=>{var a;return e.jsx("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-border bg-card",children:H===s.id?e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Headline"}),e.jsx(m,{value:A,onChange:i=>O(i.target.value)})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx(o,{className:"text-xs",children:"Summary"}),e.jsxs(l,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-[11px] px-2 text-muted-foreground hover:text-foreground gap-1",onClick:()=>{pe("edit"),p(!0)},children:[e.jsx(ie,{className:"h-3 w-3"}),"Embed Social Post"]})]}
1),e.jsx(S,{ref:X,theme:"snow",value:B,onChange:F,modules:ls,className:"bg-background [&_.ql-editor]:min-h-[60px]"})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs",children:"Link (optional)"}),e.jsx(m,{value:qe,onChange:i=>Q(i.target.value),placeholder:"https://..."})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsxs(l,{size:"sm",onClick:ts,disabled:$,children:[e.jsx(Oe,{className:"h-3.5 w-3.5 mr-1"}),$?"Saving...":"Save"]}),e.jsx(l,{size:"sm",variant:"ghost",onClick:Ie,disabled:$,children:"Cancel"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Ds(new Date(s.created_at),{addSuffix:!0})}),((a=s.authors)==null?void 0:a.name)&&e.jsx(hs,{variant:"secondary",className:"text-[10px] h-4",children:s.authors.name})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s.headline}),e.jsx("div",{dangerouslySetInnerHTML:{__html:_s(s.summary)},className:"text-xs text-muted-foreground mt-0.5 line-clamp-2 [&_img]:inline [&_img]:h-4 [&_a]:text-accent [&_a]:underline"}),s.link_url&&e.jsxs("a",{href:s.link_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-accent hover:underline mt-1",children:[e.jsx(gs,{className:"h-3 w-3"}),s.link_url]})]}),e.jsxs("div",{className:"flex flex-col gap-1 shrink-0",children:[e.jsx(l,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>ss(s),children:e.jsx(Fe,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx(l,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>ms(s.id),children:e.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})]})},s.id)})})})]})]})]}),e.jsx(Y,{open:We,onOpenChange:x,children:e.jsxs(Z,{className:"sm:max-w-sm",children:[e.jsxs(ee,{children:[e.jsx(se,{className:"text-base",children:"Insert Image"}),e.jsx(te,{className:"text-sm text-muted-foreground",children:"Upload a new image or pick from your media library."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 pt-2",children:[e.jsxs(l,{variant:"outline",className:"h-24 flex-col gap-2",disabled:Ne,onClick:()=>{var s;return(s=ge.current)==null?void 0:s.click()},children:[e.jsx(qs,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("span",{className:"text-xs",children:Ne?"Uploading...":"Upload"})]}),e.jsxs(l,{variant:"outline",className:"h-24 flex-col gap-2",onClick:()=>{x(!1),q(!0)},children:[e.jsx(fs,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("span",{className:"text-xs",children:"Browse Library"})]})]})]})}),e.jsx(ae,{open:Ge,onOpenChange:q,onSelect:s=>{W(s),q(!1)}}),e.jsx(Y,{open:Ke,onOpenChange:s=>{p(s),s||b("")},children:e.jsxs(Z,{className:"sm:max-w-md",children:[e.jsxs(ee,{children:[e.jsx(se,{className:"text-base",children:"Embed Social Post"}),e.jsx(te,{className:"text-sm text-muted-foreground",children:"Paste a post URL from Twitter/X, Instagram, TikTok, or LinkedIn."})]}),e.jsxs("div",{className:"space-y-4 pt-1",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2 text-xs text-muted-foreground",children:[{icon:"ð",label:"Twitter / X",example:"x.com/user/status/..."},{icon:"ð¸",label:"Instagram",example:"instagram.com/p/..."},{icon:"ðµ",label:"TikTok",example:"tiktok.com/@user/video/..."},{icon:"ð¼",label:"LinkedIn",example:"linkedin.com/posts/..."}].map(s=>e.jsxs("div",{className:"flex items-start gap-1.5 p-2 rounded-md border border-border bg-muted/30",children:[e.jsx("span",{className:"text-base leading-none mt-0.5",children:s.icon}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground text-[11px]",children:s.label}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s.example})]})]},s.label))}),e.jsx(m,{value:j,onChange:s=>b(s.target.value),placeholder:"https://x.com/user/status/123...",onKeyDown:s=>{s.key==="Enter"&&!h&&ze(j)},autoFocus:!0,disabled:h}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(l,{onClick:()=>ze(j),size:"sm",className:"flex-1",disabled:!j.trim()||h,children:[e.jsx(ie,{className:"h-3.5 w-3.5 mr-1.5"}),h?"Fetching embedâ¦":"Insert Embed"]}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>{p(!1),b("")},disabled:h,children:"Cancel"})]})]})]})}),e.jsx("input",{ref:ge,type:"file",accept:"image/*",className:"hidden",onChange:s=>{var i;const a=(i=s.target.files)==null?void 0:i[0];a&&as(a),s.target.value=""}})]})};export{ct 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.