PageSourceSearch

https://www.intellicontract.ai/assets/InsightsAdmin-BbMJwdjE.js

js intellicontract.ai collected 2026-10-05 12:11:45 UTC 23,322 bytes, 3 lines download raw bytes

1import{r as C,av as E,M as k,j as e,O as Z,J as m,s as h,n as R,B as g,h as J,D as $,aK as K,ao as L,a as O,b as U,d as Q,L as c,I as j,ap as F,W as q,Y as A,Z as S,$ as T,a0 as y}from"./index-CyCBd4px.js";import{u as D}from"./useMutation-eawVkqb6.js";import{T as X,a as ee,b as P,c as I}from"./tabs-CRirZm4W.js";import{S as M}from"./switch-DdKwYkig.js";import{R as se}from"./quill.snow-Drwuwrge.js";import{B as te}from"./book-open-DFNWZ7UA.js";import{H as ae}from"./headphones-BQNpRnfV.js";import{F as re}from"./file-text-DBDmLy66.js";import{C as ie}from"./calendar-BZ_eE7FB.js";import{T as z}from"./trash-2-CSQwgK4d.js";import{P as B}from"./pencil-BnWtBr6O.js";import"./isEqual-iD3aGHy1.js";function we(){const[r,o]=C.useState("articles"),t=E(),{data:s}=k({queryKey:["insights-articles-admin"],queryFn:async()=>{const{data:n,error:d}=await h.from("insights_articles").select("*").order("created_at",{ascending:!1});if(d)throw d;return n}}),{data:l}=k({queryKey:["insights-podcasts-admin"],queryFn:async()=>{const{data:n,error:d}=await h.from("insights_podcasts").select("*").order("created_at",{ascending:!1});if(d)throw d;return n}}),{data:f}=k({queryKey:["insights-reports-admin"],queryFn:async()=>{const{data:n,error:d}=await h.from("insights_reports").select("*").order("created_at",{ascending:!1});if(d)throw d;return n}}),{data:N}=k({queryKey:["insights-events-admin"],queryFn:async()=>{const{data:n,error:d}=await h.from("insights_events").select("*").order("event_date",{ascending:!1});if(d)throw d;return n}}),i=D({mutationFn:async({type:n,id:d})=>{const a=`insights_${n}`,{error:v}=await h.from(a).delete().eq("id",d);if(v)throw v},onSuccess:(n,{type:d})=>{t.invalidateQueries({queryKey:[`insights-${d}-admin`]}),m.success("Item deleted successfully")},onError:()=>{m.error("Failed to delete item")}});return e.jsxs(e.Fragment,{children:[e.jsx(Z,{children:e.jsx("title",{children:"Resources Admin | Intellicontract AI"})}),e.jsx("div",{className:"min-h-screen bg-background p-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsx("div",{className:"flex items-center justify-between mb-8",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-bold text-foreground mb-2",children:"Resources Admin"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage articles, podcasts, reports, and events"})]})}),e.jsxs(X,{value:r,onValueChange:n=>o(n),className:"mt-6",children:[e.jsxs(ee,{className:"grid w-full grid-cols-4",children:[e.jsxs(P,{value:"articles",children:[e.jsx(te,{className:"w-4 h-4 mr-2"}),"Articles"]}),e.jsxs(P,{value:"podcasts",children:[e.jsx(ae,{className:"w-4 h-4 mr-2"}),"Podcasts"]}),e.jsxs(P,{value:"reports",children:[e.jsx(re,{className:"w-4 h-4 mr-2"}),"Reports"]}),e.jsxs(P,{value:"events",children:[e.jsx(ie,{className:"w-4 h-4 mr-2"}),"Events"]})]}),e.jsx(I,{value:"articles",className:"mt-6",children:e.jsx(le,{articles:s||[],onDelete:n=>i.mutate({type:"articles",id:n})})}),e.jsx(I,{value:"podcasts",className:"mt-6",children:e.jsx(de,{podcasts:l||[],onDelete:n=>i.mutate({type:"podcasts",id:n})})}),e.jsx(I,{value:"reports",className:"mt-6",children:e.jsx(ce,{reports:f||[],onDelete:n=>i.mutate({type:"reports",id:n})})}),e.jsx(I,{value:"events",className:"mt-6",children:e.jsx(oe,{events:N||[],onDelete:n=>i.mutate({type:"events",id:n})})})]})]})})]})}function ne({articleId:r}){const o=E(),t=D({mutationFn:async()=>{const{data:s,error:l}=await h.from("insights_articles").select("content").eq("id",r).single();if(l)throw l;let f=s.content;const N=n=>{if(!n)return"";if(/(<(p|h1|h2|h3|ul|ol|li|blockquote|strong|em|br|a)\b)/i.test(n))return n;const d=w=>w.replace(/(https?:\/\/[^\s)]+)|www\.[^\s)]+/gi,u=>`<a href="${u.startsWith("http")?u:`https://${u}`}" target="_blank" rel="noopener noreferrer">${u}</a>`),a=n.trim().split(/\n\s*\n+/),v=[];for(const w of a){const u=w.split(/\n/).map(b=>b.trim()).filter(Boolean),x=u.length>0&&u.every(b=>/^[\-*•]\s+/.test(b)),p=u.length>0&&u.every(b=>/^\d+[\.)]\s+/.test(b));x?v.push("<ul>"+u.map(b=>`<li>${d(b.replace(/^[\-*•]\s+/,""))}</li>`).join("")+"</ul>"):p?v.push("<ol>"+u.map(b=>`<li>${d(b.replace(/^\d+[\.)]\s+/,""))}</li>`).join("")+"</ol>"):v.push("<p>"+d(u.join(" "))+"</p>")}return v.join(`
2`)};try{const{data:n,error:d}=await h.functions.invoke("format-article",{body:{content:s.content}});d?(console.error("Formatting error:",d),m.error("Failed to format article, publishing with original formatting")):n!=null&&n.formattedContent&&(f=n.formattedContent)}catch(n){console.error("Format function error:",n),m.error("Failed to format article, publishing with original formatting")}/(<p|<h2|<ul|<ol|<li|<blockquote|<strong|<em)/i.test(f||"")||(f=N(f||""));const{error:i}=await h.from("insights_articles").update({status:"published",is_featured:!0,content:f,image_url:"/lovable-uploads/3cee6ba7-d5ef-493d-862f-8381c330d715.png"}).eq("id",r);
2if(i)throw i},onSuccess:()=>{o.invalidateQueries({queryKey:["insights-articles-admin"]}),o.invalidateQueries({queryKey:["insights-articles"]}),m.success("Article published, featured, and formatted!")},onError:()=>{m.error("Failed to publish article")}});return e.jsx(g,{variant:"default",size:"sm",onClick:()=>t.mutate(),disabled:t.isPending,children:t.isPending?"Publishing...":"Publish & Feature"})}function le({articles:r,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(V,{})}),e.jsx("div",{className:"grid gap-4",children:r.map(t=>e.jsx(R,{className:"p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h3",{className:"text-xl font-bold",children:t.title}),e.jsx("span",{className:`text-xs px-2 py-1 rounded ${t.status==="published"?"bg-green-100 text-green-800":t.status==="draft"?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}`,children:t.status}),t.is_featured&&e.jsx("span",{className:"text-xs px-2 py-1 rounded bg-blue-100 text-blue-800",children:"Featured"})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:t.excerpt}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsx("span",{children:t.author}),e.jsx("span",{children:"•"}),e.jsx("span",{children:t.category}),e.jsx("span",{children:"•"}),e.jsx("span",{children:t.read_time})]})]}),e.jsxs("div",{className:"flex gap-2",children:[t.status!=="published"&&e.jsx(ne,{articleId:t.id}),e.jsx(V,{article:t}),e.jsx(g,{variant:"destructive",size:"sm",onClick:()=>o(t.id),children:e.jsx(z,{className:"w-4 h-4"})})]})]})},t.id))})]})}function V({article:r}){const[o,t]=C.useState(!1),[s,l]=C.useState(r||{title:"",excerpt:"",content:"",author:"",category:"",read_time:"",image_url:"/lovable-uploads/3cee6ba7-d5ef-493d-862f-8381c330d715.png",status:"published",is_featured:!1}),[f,N]=C.useState(!0),i=a=>{if(!a)return"";if(/(<(p|h1|h2|h3|ul|ol|li|blockquote|strong|em|br|a)\b)/i.test(a))return a;const v=x=>x.replace(/(https?:\/\/[^\s)]+)|www\.[^\s)]+/gi,p=>`<a href="${p.startsWith("http")?p:`https://${p}`}" target="_blank" rel="noopener noreferrer">${p}</a>`),w=a.trim().split(/\n\s*\n+/),u=[];for(const x of w){const p=x.split(/\n/).map(_=>_.trim()).filter(Boolean),b=p.length>0&&p.every(_=>/^[\-*•]\s+/.test(_)),Y=p.length>0&&p.every(_=>/^\d+[\.)]\s+/.test(_));b?u.push("<ul>"+p.map(_=>`<li>${v(_.replace(/^[\-*•]\s+/,""))}</li>`).join("")+"</ul>"):Y?u.push("<ol>"+p.map(_=>`<li>${v(_.replace(/^\d+[\.)]\s+/,""))}</li>`).join("")+"</ol>"):u.push("<p>"+v(p.join(" "))+"</p>")}return u.join(`
3`)},n=E();C.useEffect(()=>{r&&o&&l({title:r.title||"",excerpt:r.excerpt||"",content:r.content||"",author:r.author||"",category:r.category||"",read_time:r.read_time||"",image_url:r.image_url||"/lovable-uploads/3cee6ba7-d5ef-493d-862f-8381c330d715.png",status:r.status||"published",is_featured:r.is_featured||!1})},[r,o]);const d=D({mutationFn:async a=>{const{data:{user:v}}=await h.auth.getUser();if(!v)throw new Error("Not authenticated");let w=a.content;if(a.content&&a.status==="published"){try{const{data:x,error:p}=await h.functions.invoke("format-article",{body:{content:a.content}});p?(console.error("Formatting error:",p),m.error("Failed to format article, saving with original formatting")):x!=null&&x.formattedContent&&(w=x.formattedContent)}catch(x){console.error("Format function error:",x),m.error("Failed to format article, saving with original formatting")}/(<p|<h2|<ul|<ol|<li|<blockquote|<strong|<em)/i.test(w||"")||(w=i(w||""))}const u={...a,content:w,created_by:v.id,image_url:a.image_url||"/lovable-uploads/3cee6ba7-d5ef-493d-862f-8381c330d715.png"};if(r){const{error:x}=await h.from("insights_articles").update(u).eq("id",r.id);if(x)throw x}else{const{error:x}=await h.from("insights_articles").insert(u);if(x)throw x}},onSuccess:()=>{n.invalidateQueries({queryKey:["insights-articles-admin"]}),n.invalidateQueries({queryKey:["insights-articles"]}),m.success(r?"Article updated and formatted!":"Article created and formatted!"),t(!1)},onError:()=>{m.error("Failed to save article")}});return e.jsxs($,{open:o,onOpenChange:t,children:[e.jsx(K,{asChild:!0,children:r?e.jsx(g,{variant:"outline",size:"sm",children:e.jsx(B,{className:"w-4 h-4"})}):e.jsxs(g,{children:[e.jsx(L,{className:"w-4 h-4 mr-2"}),"Add Article"]})}),e.jsxs(O,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(U,{children:e.jsx(Q,{children:r?"Edit Article":"Create Article"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Title"}),e.jsx(j,{value:s.title,onChange:a=>l({...s,title:a.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Excerpt"}),e.jsx(F,{value:s.excerpt,onChange:a=>l({...s,excerpt:a.target.value})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(c,{children:"Content"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{checked:f,onCheckedChange:N}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Rich editor"})]}),e.jsx(g,{type:"button",variant:"secondary",onClick:async()=>{try{const{data:a,error:v}=await h.functions.invoke("format-article",{body:{content:s.content}});if(v){m.error("AI formatting failed");return}a!=null&&a.formattedContent&&(l({...s,content:a.formattedContent}),m.success("Formatted with AI"))}catch{m.error("AI formatting failed")}},children:"AI Format"})]})]}),f?e.jsx("div",{className:"mt-2",children:e.jsx(se,{theme:"snow",value:s.content,onChange:a=>l({...s,content:a})})}):e.jsx(F,{value:s.content,onChange:a=>l({...s,content:a.target.value}),rows:8,className:"mt-2"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Author"}),e.jsx(j,{value:s.author,onChange:a=>l({...s,author:a.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Read Time"}),e.jsx(j,{value:s.read_time,onChange:a=>l({...s,read_time:a.target.value}),placeholder:"e.g., 5 min"})]})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Category"}),e.jsxs(q,{value:s.category,onValueChange:a=>l({...s,category:a}),children:[e.jsx(A,{children:e.jsx(S,{})}),e.jsxs(T,{children:[e.jsx(y,{value:"AI in Contracts",children:"AI in Contracts"}),e.jsx(y,{value:"LegalTech Trends",children:"LegalTech Trends"}),e.jsx(y,{value:"CLM",children:"CLM"}),e.jsx(y,{value:"Global Legal Insights",children:"Global Legal Insights"})]})]})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Image URL (leave blank to use default logo)"}),e.jsx(j,{value:s.image_url,onChange:a=>l({...s,image_url:a.target.value}),placeholder:"/lovable-uploads/3cee6ba7-d5ef-493d-862f-8381c330d715.png"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Default: Your Intellicontract AI logo"})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Status"}),e.jsxs(q,{value:s.status,onValueChange:a=>l({...s,status:a}),children:[e.jsx(A,{children:e.jsx(S,{})}),e.jsxs(T,{children:[e.jsx(y,{value:"draft",children:"Draft"}),e.jsx(y,{value:"published",children:"Published"}),e.jsx(y,{value:"archived",children:"Archived"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{checked:s.is_featured,onCheckedChange:a=>l({...s,is_featured:a})}),e.jsx(c,{children:"Featured Article"})]}),e.jsxs(g,{onClick:()=>d.mutate(s),className:"w-full",children:[r?"Update":"Create"," Article"]})]})]})]})}function de({podcasts:r,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(W,{})}),e.jsx("div",{className:"grid gap-4",children:r.map(t=>e.jsx(R,{className:"p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h3",{className:"text-xl font-bold",children:t.title}),e.jsx("span",{className:`text-xs px-2 py-1 rounded ${t.status==="published"?"bg-green-100 text-green-800":t.status==="draft"?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}`,children:t.status})]}),e.jsxs("p",{className:"text-muted-foreground mb-2",children:["Guest: ",t.guest]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsx("span",{children:t.duration}),e.jsx("span",{children:"•"}),e.jsx("span",{children:J(t.published_date)})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(W,{podcast:t}),e.jsx(g,{variant:"destructive",size:"sm",onClick:()=>o(t.id),children:e.jsx(z,{className:"w-4 h-4"})})]})]})},t.id))})]})}function W({podcast:r}){const[o,t]=C.useState(!1),[s,l]=C.useState(r||{title:"",guest:"",duration:"",spotify_url:"",description:"",published_date:new Date().toISOString().split("T")[0],status:"draft"}),f=E(),N=D({mutationFn:async i=>{const{data:{user:n}}=await h.auth.getUser();if(!n)throw new Error("Not authenticated");const d={...i,created_by:n.id};if(r){const{error:a}=await h.from("insights_podcasts").update(d).eq("id",r.id);if(a)throw a}else{const{error:a}=await h.from("insights_podcasts").insert(d);if(a)throw a}},onSuccess:()=>{f.invalidateQueries({queryKey:["insights-podcasts-admin"]}),m.success(r?"Podcast updated":"Podcast created"),t(!1)},onError:()=>{m.error("Failed to save podcast")}});return e.jsxs($,{open:o,onOpenChange:t,children:[e.jsx(K,{asChild:!0,children:r?e.jsx(g,{variant:"outline",size:"sm",children:e.jsx(B,{className:"w-4 h-4"})}):e.jsxs(g,{children:[e.jsx(L,{className:"w-4 h-4 mr-2"}),"Add Podcast"]})}),e.jsxs(O,{className:"max-w-2xl",children:[e.jsx(U,{children:e.jsx(Q,{children:r?"Edit Podcast":"Create Podcast"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Title"}),e.jsx(j,{value:s.title,onChange:i=>l({...s,title:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Guest"}),e.jsx(j,{value:s.guest,onChange:i=>l({...s,guest:i.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Duration"}),e.jsx(j,{value:s.duration,onChange:i=>l({...s,duration:i.target.value}),placeholder:"e.g., 45 min"})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Published Date"}),e.jsx(j,{type:"date",value:s.published_date,onChange:i=>l({...s,published_date:i.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Spotify URL"}),e.jsx(j,{value:s.spotify_url,onChange:i=>l({...s,spotify_url:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Description"}),e.jsx(F,{value:s.description,onChange:i=>l({...s,description:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Status"}),e.jsxs(q,{value:s.status,onValueChange:i=>l({...s,status:i}),children:[e.jsx(A,{children:e.jsx(S,{})}),e.jsxs(T,{children:[e.jsx(y,{value:"draft",children:"Draft"}),e.jsx(y,{value:"published",children:"Published"}),e.jsx(y,{value:"archived",children:"Archived"})]})]})]}),e.jsxs(g,{onClick:()=>N.mutate(s),className:"w-full",children:[r?"Update":"Create"," Podcast"]})]})]})]})}function ce({reports:r,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{})}),e.jsx("div",{className:"grid gap-4",children:r.map(t=>e.jsx(R,{className:"p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h3",{className:"text-xl font-bold",children:t.title}),e.jsx("span",{className:`text-xs px-2 py-1 rounded ${t.status==="published"?"bg-green-100 text-green-800":t.status==="draft"?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}`,children:t.status})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:t.description}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsx("span",{children:t.pages}),e.jsx("span",{children:"•"}),e.jsx("span",{children:t.published_month})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{report:t}),e.jsx(g,{variant:"destructive",size:"sm",onClick:()=>o(t.id),children:e.jsx(z,{className:"w-4 h-4"})})]})]})},t.id))})]})}function G({report:r}){const[o,t]=C.useState(!1),[s,l]=C.useState(r||{title:"",description:"",download_url:"",pages:"",published_month:"",status:"draft"}),f=E(),N=D({mutationFn:async i=>{const{data:{user:n}}=await h.auth.getUser();if(!n)throw new Error("Not authenticated");const d={...i,created_by:n.id};if(r){const{error:a}=await h.from("insights_reports").update(d).eq("id",r.id);if(a)throw a}else{const{error:a}=await h.from("insights_reports").insert(d);if(a)throw a}},onSuccess:()=>{f.invalidateQueries({queryKey:["insights-reports-admin"]}),m.success(r?"Report updated":"Report created"),t(!1)},onError:()=>{m.error("Failed to save report")}});return e.jsxs($,{open:o,onOpenChange:t,children:[e.jsx(K,{asChild:!0,children:r?e.jsx(g,{variant:"outline",size:"sm",children:e.jsx(B,{className:"w-4 h-4"})}):e.jsxs(g,{children:[e.jsx(L,{className:"w-4 h-4 mr-2"}),"Add Report"]})}),e.jsxs(O,{className:"max-w-2xl",children:[e.jsx(U,{children:e.jsx(Q,{children:r?"Edit Report":"Create Report"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Title"}),e.jsx(j,{value:s.title,onChange:i=>l({...s,title:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Description"}),e.jsx(F,{value:s.description,onChange:i=>l({...s,description:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Download URL"}),e.jsx(j,{value:s.download_url,onChange:i=>l({...s,download_url:i.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Pages"}),e.jsx(j,{value:s.pages,onChange:i=>l({...s,pages:i.target.value}),placeholder:"e.g., 48 pages"})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Published Month"}),e.jsx(j,{value:s.published_month,onChange:i=>l({...s,published_month:i.target.value}),placeholder:"e.g., October 2025"})]})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Status"}),e.jsxs(q,{value:s.status,onValueChange:i=>l({...s,status:i}),children:[e.jsx(A,{children:e.jsx(S,{})}),e.jsxs(T,{children:[e.jsx(y,{value:"draft",children:"Draft"}),e.jsx(y,{value:"published",children:"Published"}),e.jsx(y,{value:"archived",children:"Archived"})]})]})]}),e.jsxs(g,{onClick:()=>N.mutate(s),className:"w-full",children:[r?"Update":"Create"," Report"]})]})]})]})}function oe({events:r,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(H,{})}),e.jsx("div",{className:"grid gap-4",children:r.map(t=>e.jsx(R,{className:"p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h3",{className:"text-xl font-bold",children:t.title}),e.jsx("span",{className:`text-xs px-2 py-1 rounded ${t.status==="published"?"bg-green-100 text-green-800":t.status==="draft"?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}`,children:t.status})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:t.description}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsx("span",{children:J(t.event_date)}),e.jsx("span",{children:"•"}),e.jsx("span",{children:t.event_time}),e.jsx("span",{children:"•"}),e.jsx("span",{children:t.event_type})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{event:t}),e.jsx(g,{variant:"destructive",size:"sm",onClick:()=>o(t.id),children:e.jsx(z,{className:"w-4 h-4"})})]})]})},t.id))})]})}function H({event:r}){const[o,t]=C.useState(!1),[s,l]=C.useState(r||{title:"",description:"",event_date:new Date().toISOString().split("T")[0],event_time:"",event_type:"Virtual Event",registration_url:"",status:"draft"}),f=E(),N=D({mutationFn:async i=>{const{data:{user:n}}=await h.auth.getUser();if(!n)throw new Error("Not authenticated");const d={...i,created_by:n.id};if(r){const{error:a}=await h.from("insights_events").update(d).eq("id",r.id);if(a)throw a}else{const{error:a}=awai
3t h.from("insights_events").insert(d);if(a)throw a}},onSuccess:()=>{f.invalidateQueries({queryKey:["insights-events-admin"]}),m.success(r?"Event updated":"Event created"),t(!1)},onError:()=>{m.error("Failed to save event")}});return e.jsxs($,{open:o,onOpenChange:t,children:[e.jsx(K,{asChild:!0,children:r?e.jsx(g,{variant:"outline",size:"sm",children:e.jsx(B,{className:"w-4 h-4"})}):e.jsxs(g,{children:[e.jsx(L,{className:"w-4 h-4 mr-2"}),"Add Event"]})}),e.jsxs(O,{className:"max-w-2xl",children:[e.jsx(U,{children:e.jsx(Q,{children:r?"Edit Event":"Create Event"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Title"}),e.jsx(j,{value:s.title,onChange:i=>l({...s,title:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Description"}),e.jsx(F,{value:s.description,onChange:i=>l({...s,description:i.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Event Date"}),e.jsx(j,{type:"date",value:s.event_date,onChange:i=>l({...s,event_date:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Event Time"}),e.jsx(j,{value:s.event_time,onChange:i=>l({...s,event_time:i.target.value}),placeholder:"e.g., 10:00 AM EST"})]})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Event Type"}),e.jsx(j,{value:s.event_type,onChange:i=>l({...s,event_type:i.target.value}),placeholder:"e.g., Virtual Event, Webinar, Workshop"})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Registration URL"}),e.jsx(j,{value:s.registration_url,onChange:i=>l({...s,registration_url:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Status"}),e.jsxs(q,{value:s.status,onValueChange:i=>l({...s,status:i}),children:[e.jsx(A,{children:e.jsx(S,{})}),e.jsxs(T,{children:[e.jsx(y,{value:"draft",children:"Draft"}),e.jsx(y,{value:"published",children:"Published"}),e.jsx(y,{value:"archived",children:"Archived"})]})]})]}),e.jsxs(g,{onClick:()=>N.mutate(s),className:"w-full",children:[r?"Update":"Create"," Event"]})]})]})]})}export{we 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.