1import{j as e,C as z,f as K,G as re,d as ie,e as oe,A as le,m as C,B as y,a4 as de,a as ce,c as B,o as me,p as ue,k as h,r as w,V as R,X as xe,I as pe,T as he,L as fe,w as ge,a0 as we,x as ve,y as be,z as je}from"./index-IxvR3ybE.js";import{M as T}from"./message-square-D78-i2rO.js";import{C as O}from"./circle-check-big-DrZso9hg.js";import{C as G}from"./circle-arrow-up-CSKy2m4n.js";import{A as ye,a as Ne,b as _e}from"./avatar-BaQ7HthH.js";import{T as ke}from"./textarea-DABzMORD.js";import{f as P}from"./format-DUXQdFez.js";import{E as q}from"./EventSelector-Bpv922Gw.js";import{s as Ce,g as Se,a as Ae}from"./queryCache-BtqcWBRl.js";import{P as Ee}from"./PaymentGuard-CsV7Fhnv.js";import{S as Qe}from"./switch-CVhsjzBh.js";import{P as F}from"./plus-ByP2IBiw.js";import{S as I}from"./share-2-G_q9z15a.js";import{C as De}from"./copy-l3phfS-J.js";import{E as Me}from"./external-link-DjtQGYET.js";import"./en-US-CujKlCMr.js";import"./startOfWeek-CKe6unVT.js";import"./select-C66k4zpo.js";import"./index-BdQq_4o_.js";import"./index-PCA-xeVB.js";import"./chevron-up-Kie37_ZB.js";import"./usePaystackConfig-BiPyfAu1.js";import"./usePayment-DbOsPFvK.js";import"./loader-IuTMkbZP.js";import"./credit-card-CqkMcI0L.js";import"./useReferralCode-DoUD49Ha.js";import"./AccessCodeInput-MBolaJC1.js";import"./lock-open-BznoiT3l.js";import"./key-p_SgkhAy.js";const Re=[{key:"total",icon:T,bg:"from-blue-400 to-indigo-400",label:"Total Questions"},{key:"answered",icon:O,bg:"from-green-300 to-emerald-400",label:"Answered"},{key:"trending",icon:G,bg:"from-purple-400 to-pink-400",label:"Trending"}],Te=({total:s,answered:a,trending:f,loading:d})=>{const N={total:s,answered:a,trending:f};return e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-5",children:Re.map(c=>e.jsxs(z,{className:re("glass-card flex items-center p-4 min-h-[84px] relative",d&&"animate-pulse"),children:[e.jsx("div",{className:`bg-gradient-to-br ${c.bg} rounded-full p-3 mr-4 flex items-center justify-center`,children:e.jsx(c.icon,{className:"text-white w-5 h-5"})}),e.jsxs(K,{className:"p-0 flex flex-col",children:[e.jsx("span",{className:"text-2xl font-bold",children:d?"â":N[c.key]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1 font-medium",children:c.label})]})]},c.key))})},Le=({question:s,isMarkingAnswered:a,isDeleting:f,isResponding:d,respondingTo:N,responseText:c,onStartResponse:v,onSubmitResponse:S,onCancelResponse:A,onMarkAsAnswered:k,onDelete:n,setResponseText:o,selectedEventId:g})=>{var u,r;const j=((u=s.profiles)==null?void 0:u.name)||"Anonymous User",_=(r=s.profiles)==null?void 0:r.photo_url;return e.jsxs(z,{className:`glass-card overflow-hidden hover:shadow-xl transition-all ${s.upvotes>0?"fire-border animate-enter":""}`,children:[e.jsxs(ie,{className:"pb-2 flex flex-row items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(ye,{children:[e.jsx(Ne,{src:_||""}),e.jsx(_e,{children:j.charAt(0)})]}),e.jsxs("div",{children:[e.jsx(oe,{className:"text-base",children:j}),e.jsx(le,{children:P(new Date(s.created_at),"MMM d, yyyy h:mm a")}),s.is_panelist&&s.panelist_name&&e.jsxs("div",{className:"flex flex-col gap-1 mt-1",children:[e.jsx(C,{variant:"secondary",className:"text-xs w-fit",children:"PANELIST"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.panelist_name})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx(C,{variant:s.is_answered?"success":"info",className:"text-xs",children:s.is_answered?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"h-3 w-3 mr-1"}),"Answered"]}):e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"h-3 w-3 mr-1"}),"Pending"]})}),s.session_info?e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx(C,{variant:"secondary",className:"flex items-center gap-1 text-xs",children:e.jsx("span",{children:s.session_info.session_title||`${s.session_info.speaker_name}'s Session`})}),s.session_info.speaker_name&&e.jsx("span",{className:"text-xs text-muted-foreground mt-1 text-right",children:s.session_info.speaker_name})]}):e.jsxs(C,{variant:"outline",className:"flex items-center gap-1 text-xs",children:[e.jsx(T,{size:12}),"General"]}),!g&&s.event_name&&e.jsx(C,{variant:"secondary",className:"flex items-center gap-1 text-xs",children:s.event_name})]})]}),e.jsxs(K,{children:[e.jsx("p",{className:"text-base mb-3",children:s.content}),s.response&&e.jsxs("div",{className:"mt-4 p-3 bg-blue-50 border-l-4 border-blue-200 rounded",children:[e.jsx("p",{className:"text-sm font-medium text-blue-800 mb-1",children:"Admin Response:"}),e.jsx("p",{className:"text-blue-700",children:s.response}),s.response_created_at&&e.jsxs("p",{className:"text-xs text-blue-600 mt-1",children:["Responded on"," ",P(new Date(s.response_created_at),"MMM d, yyyy h:mm a")]})]}),N===s.id&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx(ke,{placeholder:"Type your response here...",value:c,onChange:i=>o(i.target.value),rows:3}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",onClick:()=>S(s.id,c??""),disabled:!(c!=null&&c.trim())||d,children:d?"Submitting...":"Submit Response"}),e.jsx(y,{size:"sm",variant:"outline",onClick:A,children:"Cancel"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm mt-3",children:[e.jsxs(C,{variant:"outline",className:"flex items-center gap-1",children:[e.jsx(G,{size:14}),s.upvotes," upvotes ",s.upvotes>0&&e.jsx("span",{"aria-hidden":"true",children:"ð¥"})]}),s.is_anonymous&&e.jsx(C,{variant:"secondary",children:"Anonymous"})]})]}),e.jsxs(de,{className:` 2 flex flex-col gap-2 3 sm:flex-row sm:items-center sm:justify-between sm:gap-0 4 border-t pt-3 5 `,children:[e.jsxs("div",{className:"text-xs text-muted-foreground mb-2 sm:mb-0",children:["Question ID: ",s.id]}),e.jsxs("div",{className:` 6 flex flex-col gap-2 w-full
7 sm:flex-row sm:justify-end sm:w-auto sm:gap-2 8 `,children:[!s.response&&N!==s.id&&e.jsx(y,{size:"sm",variant:"outline",className:"text-blue-600 border-blue-200 hover:bg-blue-50 w-full sm:w-auto",onClick:()=>v(s.id),children:"Respond"}),!s.is_answered&&e.jsx(y,{size:"sm",variant:"outline",className:"text-green-600 border-green-200 hover:bg-green-50 w-full sm:w-auto",onClick:()=>k(s.id),disabled:a,children:"Mark Answered"}),e.jsx(y,{size:"sm",variant:"outline",className:"text-destructive border-destructive/20 hover:bg-destructive/10 w-full sm:w-auto",onClick:()=>n(s.id),disabled:f,children:"Remove"})]})]})]})},$="admin-questions",Pe=s=>{const{currentUser:a}=ce(),{toast:f}=B(),d=me(),{data:N=[],isLoading:c,error:v}=ue({queryKey:["admin-questions",a==null?void 0:a.id,s],queryFn:async()=>{if(!(a!=null&&a.id))throw new Error("User not authenticated");let n,o;if(s){const{data:r,error:i}=await h.from("questions").select("*").eq("event_id",s).order("created_at",{ascending:!1});n=r,o=i}else{const{data:r,error:i}=await h.from("events").select("id, name").eq("host_id",a.id);if(i)throw i;if(!r||r.length===0)return[];const x=r.map(p=>p.id),{data:b,error:E}=await h.from("questions").select("*").in("event_id",x).order("created_at",{ascending:!1});n=b,o=E}if(o)throw o;if(!n||n.length===0)return[];const g=n.map(r=>r.user_id).filter(Boolean),{data:j}=await h.from("profiles").select("id, name, photo_url").in("id",g);let _={};if(!s){const r=n.map(x=>x.event_id).filter(Boolean),{data:i}=await h.from("events").select("id, name").in("id",r);
8i&&(_=i.reduce((x,b)=>(x[b.id]=b.name,x),{}))}const u=await Promise.all(n.map(async r=>{let i=null;if(r.session_id){const{data:p}=await h.from("speakers").select("name, session_title, session_time").eq("id",r.session_id).single();p&&(i={session_title:p.session_title,speaker_name:p.name,session_time:p.session_time})}const x=j==null?void 0:j.find(p=>p.id===r.user_id);let b=!1,E=null;if(r.user_id&&r.event_id){const{data:p}=await h.from("speakers").select("name").eq("event_id",r.event_id).eq("created_by",r.user_id).single();p&&(b=!0,E=p.name)}return{...r,profiles:r.is_anonymous?null:x?{name:x.name||"Unknown User",photo_url:x.photo_url}:null,session_info:i,event_name:_[r.event_id]||"Unknown Event",is_panelist:b,panelist_name:E}}));return Ae(`${$}-${a.id}-${s||"all"}`,u),u},enabled:!!(a!=null&&a.id),placeholderData:()=>Se(`${$}-${a==null?void 0:a.id}-${s||"all"}`)||[],...Ce});w.useEffect(()=>{if(!(a!=null&&a.id))return;let n;const o=()=>{clearTimeout(n),n=setTimeout(()=>{d.invalidateQueries({queryKey:["admin-questions",a.id]})},2e3)},g=h.channel("questions-realtime").on("postgres_changes",{event:"*",schema:"public",table:"questions"},o).subscribe();return()=>{clearTimeout(n),h.removeChannel(g)}},[a==null?void 0:a.id,s,d]);const S=R({mutationFn:async n=>{if(console.log("Marking question as answered:",n),!(a!=null&&a.id))throw new Error("User not authenticated");const{error:o}=await h.from("questions").update({is_answered:!0,answered_at:new Date().toISOString(),answered_by:a.id}).eq("id",n);if(o)throw console.error("Error marking question as answered:",o),o},onSuccess:()=>{d.invalidateQueries({queryKey:["admin-questions"]}),d.invalidateQueries({queryKey:["attendee-questions"]}),f({title:"Success",description:"Question marked as answered"})},onError:n=>{console.error("Error updating question:",n),f({title:"Error",description:n.message||"Failed to update question",variant:"destructive"})}}),A=R({mutationFn:async n=>{if(console.log("Deleting question:",n),!(a!=null&&a.id))throw new Error("User not authenticated");const{error:o}=await h.from("questions").delete().eq("id",n);if(o)throw console.error("Error deleting question:",o),o},onSuccess:()=>{d.invalidateQueries({queryKey:["admin-questions"]}),d.invalidateQueries({queryKey:["attendee-questions"]}),f({title:"Success",description:"Question deleted successfully"})},onError:n=>{console.error("Error deleting question:",n),f({title:"Error",description:n.message||"Failed to delete question",variant:"destructive"})}}),k=R({mutationFn:async({questionId:n,response:o})=>{if(console.log("Responding to question:",n,o),!(a!=null&&a.id))throw new Error("User not authenticated");const{error:g}=await h.from("questions").update({response:o,response_created_at:new Date().toISOString(),is_answered:!0,answered_at:new Date().toISOString(),answered_by:a.id}).eq("id",n);if(g)throw console.error("Error responding to question:",g),g},onSuccess:()=>{d.invalidateQueries({queryKey:["admin-questions"]}),d.invalidateQueries({queryKey:["attendee-questions"]}),f({title:"Success",description:"Response submitted successfully"})},onError:n=>{console.error("Error responding to question:",n),f({title:"Error",description:n.message||"Failed to submit response",variant:"destructive"})}});return{questions:N,isLoading:c,error:v,markAsAnswered:S.mutate,deleteQuestion:A.mutate,respondToQuestion:k.mutate,isMarkingAnswered:S.isPending,isDeleting:A.isPending,isResponding:k.isPending}},qe=[{id:"all",label:"All"},{id:"unanswered",label:"Unanswered"},{id:"answered",label:"Answered"},{id:"trending",label:"Trending"}],Fe=()=>{const[s,a]=w.useState("all"),[f,d]=w.useState(null),[N,c]=w.useState(""),[v,S]=w.useState(""),[A,k]=w.useState(!1),[n,o]=w.useState(!1),[g,j]=w.useState(new Set),{toast:_}=B(),{selectedEventId:u,selectedEvent:r}=xe(),{questions:i,isLoading:x,error:b,markAsAnswered:E,deleteQuestion:p,respondToQuestion:D,isMarkingAnswered:H,isDeleting:V,isResponding:W}=Pe(u||void 0);w.useEffect(()=>{if(!n||!i||!r)return;i.filter(l=>!l.is_answered&&!l.response&&!g.has(l.id)).forEach(async l=>{j(m=>new Set(m).add(l.id));try{const{data:m,error:Q}=await h.functions.invoke("auto-respond-question",{body:{question:l.content,eventName:r.name}});if(Q)throw Q;m!=null&&m.response&&(await D({questionId:l.id,response:m.response}),_({title:"Auto-response sent",description:"AI generated response has been posted"}))}catch(m){console.error("Error auto-responding to question:",m)}finally{j(m=>{const Q=new Set(m);return Q.delete(l.id),Q})}})},[i,n,r,g,D,_]);const X=i.length,Y=i.filter(t=>t.is_answered).length,J=w.useMemo(()=>i.filter(t=>t.upvotes>=2).length,[i]),L=w.useMemo(()=>{let t=i;return s==="answered"?t=t.filter(l=>l.is_answered):s==="unanswered"?t=t.filter(l=>!l.is_answered):s==="trending"&&(t=[...i].sort((l,m)=>m.upvotes-l.upvotes)),v.trim().length>0&&(t=t.filter(l=>{var m;return l.content.toLowerCase().includes(v.toLowerCase())||(((m=l.profiles)==null?void 0:m.name)||"").toLowerCase().includes(v.toLowerCase())||(l.event_name||"").toLowerCase().includes(v.toLowerCase())})),t},[i,s,v]),Z=t=>{d(t),c("")},U=(t,l)=>{l.trim()&&(D({questionId:t,response:l.trim()}),d(null),c(""))},ee=()=>{d(null),c("")},se=t=>{E(t)},ae=t=>{p(t)},M=()=>u?`${window.location.origin}/live-questions/${u}`:"",te=()=>{const t=M();navigator.clipboard.writeText(t),_({title:"Link copied!",description:"Shareable link has been copied to clipboard"})},ne=()=>{const t=M();window.open(t,"_blank")};return x?e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx(q,{})}),e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"Loading questions..."})]})})]}):e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx(q,{})}),!u&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"p-4 rounded-full bg-primary/10
8inline-block mb-4",children:e.jsx(F,{className:"h-8 w-8 text-primary"})}),e.jsx("p",{className:"text-muted-foreground text-lg mb-2",children:"No event selected"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please select an event above to manage questions"})]}),u&&e.jsxs(Ee,{eventId:u,eventName:(r==null?void 0:r.name)||"this event",feature:"Questions Management",children:[e.jsxs("div",{className:"p-8 rounded-2xl bg-gradient-to-br from-primary-100 via-blue-100 to-indigo-50 text-primary-900 dark:text-white shadow-2xl shadow-primary/10 mb-2 relative overflow-hidden",children:[e.jsx("div",{className:"absolute -top-12 -right-10 w-56 h-56 bg-white/10 rounded-full opacity-40 blur-2xl pointer-events-none"}),e.jsx("div",{className:"absolute -bottom-14 -left-14 w-36 h-36 bg-white/20 rounded-full opacity-30 pointer-events-none"}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("h1",{className:"text-4xl font-bold tracking-tight",children:"Questions Management"}),e.jsxs("p",{className:"mt-2 max-w-2xl text-primary-700 dark:text-primary-100",children:["Manage attendee questions and answers for ",e.jsx("span",{className:"font-semibold",children:r==null?void 0:r.name}),"."]}),e.jsx("div",{className:"mt-6",children:e.jsx(Te,{total:X,answered:Y,trending:J,loading:x})})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Questions & Answers"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Review, moderate and respond to attendee questions."})]}),e.jsx("div",{className:"flex gap-2 mt-2 sm:mt-0",children:qe.map(t=>e.jsx("button",{className:`px-3 py-1.5 rounded-full font-medium transition ${s===t.id?"bg-primary text-primary-foreground shadow":"bg-muted text-muted-foreground hover:bg-muted/80"}`,onClick:()=>a(t.id),children:t.label},t.id))})]}),e.jsxs("div",{className:"flex justify-between items-center mb-4 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4 flex-1",children:[e.jsx(pe,{placeholder:"Search questions...",value:v,onChange:t=>S(t.target.value),className:"max-w-sm"}),e.jsxs("div",{className:"flex items-center gap-2 bg-white dark:bg-gray-800 px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700",children:[e.jsx(he,{className:"h-4 w-4 text-purple-600"}),e.jsx(fe,{htmlFor:"auto-response",className:"text-sm font-medium cursor-pointer whitespace-nowrap",children:"AI Auto-Response"}),e.jsx(Qe,{id:"auto-response",checked:n,onCheckedChange:o})]})]}),e.jsxs(ge,{open:A,onOpenChange:k,children:[e.jsx(we,{asChild:!0,children:e.jsxs(y,{variant:"outline",className:"gap-2 hover-scale",children:[e.jsx(I,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Share Live View"}),e.jsx("span",{className:"sm:hidden",children:"Share"})]})}),e.jsxs(ve,{className:"sm:max-w-lg max-w-[95vw] w-full mx-4 rounded-xl border-0 bg-gradient-to-br from-background via-background to-primary/5 shadow-2xl",children:[e.jsxs(be,{className:"space-y-3 pb-4",children:[e.jsxs(je,{className:"flex items-center gap-3 text-xl font-semibold",children:[e.jsx("div",{className:"p-2 rounded-full bg-primary/10",children:e.jsx(I,{className:"h-5 w-5 text-primary"})}),"Share Live Questions"]}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:"Share this link to allow anyone to view questions and answers in real-time without needing to log in."})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Shareable Link"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"flex items-center rounded-lg border border-border bg-muted/50 p-3 pr-12 min-h-[44px] overflow-hidden",children:e.jsx("span",{className:"text-sm text-foreground break-all font-mono leading-relaxed max-w-full",children:M()})}),e.jsxs(y,{size:"sm",onClick:te,className:"absolute right-2 top-1/2 -translate-y-1/2 h-8 px-3 bg-primary hover:bg-primary/90 text-primary-foreground shadow-sm",children:[e.jsx(De,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"sr-only",children:"Copy link"})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 pt-2",children:[e.jsxs(y,{onClick:ne,variant:"outline",className:"flex-1 gap-2 h-11 border-primary/20 hover:border-primary/40 hover:bg-primary/5",children:[e.jsx(Me,{className:"h-4 w-4"}),"Preview Live View"]}),e.jsx(y,{onClick:()=>k(!1),className:"flex-1 h-11 bg-primary hover:bg-primary/90 text-primary-foreground shadow-sm",children:"Done"})]})]})]})]})]}),e.jsx("div",{className:"space-y-4",children:L.length>0?L.map(t=>e.jsx(Le,{question:t,isMarkingAnswered:H,isDeleting:V,isResponding:W,respondingTo:f,responseText:N,onStartResponse:Z,onSubmitResponse:U,onCancelResponse:ee,onMarkAsAnswered:se,onDelete:ae,setResponseText:c,selectedEventId:u},t.id)):e.jsxs("div",{className:"col-span-2 text-center py-8",children:[e.jsx(F,{className:"mx-auto h-12 w-12 text-muted-foreground opacity-30"}),e.jsx("h3",{className:"mt-4 text-lg font-medium",children:"No questions foun
8d"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"No questions match your search criteria."})]})}),b&&e.jsxs("div",{className:"bg-destructive/10 text-destructive p-3 rounded-lg text-sm",children:["Error loading questions: ",b.message]})]})]})},ps=Fe;export{ps 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.