1import{r as u,c as $,j as e,w as te,x as ie,y as ae,z as ne,Y as oe,L as k,S as re,B as N,k as d,a as O,o as le,p as q,V as E,m as M,C as L,d as de,e as ce,A as me,f as D,T as ue,n as he}from"./index-IxvR3ybE.js";import{A as T}from"./AttendeeRouteGuard-C1aKvFLF.js";import{A as xe,a as pe,b as fe}from"./avatar-BaQ7HthH.js";import{T as V}from"./textarea-DABzMORD.js";import{S as ge}from"./switch-CVhsjzBh.js";import{S as je,a as ve,b as be,c as ye,d as Y}from"./select-C66k4zpo.js";import{S as we}from"./separator-BhPaKMmy.js";import{s as A,g as Ne,a as Se}from"./queryCache-BtqcWBRl.js";import{M as K}from"./message-square-D78-i2rO.js";import{L as _e}from"./lightbulb-SYqac5W0.js";import{L as ke}from"./loader-circle-Dv3Jv63Q.js";import{S as Qe}from"./send-ApBDavNU.js";import{A as qe}from"./arrow-up-CpiJPQUV.js";import{T as Ae}from"./trash-2-DklbPQfi.js";import{f as B}from"./format-DUXQdFez.js";import"./loader-IuTMkbZP.js";import"./index-BdQq_4o_.js";import"./index-PCA-xeVB.js";import"./chevron-up-Kie37_ZB.js";import"./en-US-CujKlCMr.js";import"./startOfWeek-CKe6unVT.js";const Ce=({questionId:s,isOpen:c,onClose:n})=>{const[a,x]=u.useState(0),[g,j]=u.useState(""),[v,b]=u.useState(!1),{toast:y}=$(),w=async()=>{if(a===0){y({title:"Error",description:"Please provide a rating",variant:"destructive"});return}b(!0);try{const r=await d.auth.getUser();if(!r.data.user)throw new Error("User not authenticated");const{error:p}=await d.from("suggestions").insert([{content:`Question Feedback (Rating: ${a}/5): ${g.trim()||"No additional feedback"}`,type:"feedback",rating:a,user_id:r.data.user.id}]);if(p)throw p;y({title:"Success",description:"Thank you for your feedback!"}),n(),x(0),j("")}catch(r){console.error("Error submitting feedback:",r),y({title:"Error",description:"Failed to submit feedback",variant:"destructive"})}finally{b(!1)}};return e.jsx(te,{open:c,onOpenChange:n,children:e.jsxs(ie,{children:[e.jsxs(ae,{children:[e.jsx(ne,{children:"Rate the Answer"}),e.jsx(oe,{children:"How satisfied were you with the answer to this question?"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(k,{children:"Satisfaction Level"}),e.jsx("div",{className:"flex gap-1 mt-2",children:[1,2,3,4,5].map(r=>e.jsx(re,{size:24,className:`cursor-pointer ${r<=a?"fill-yellow-400 text-yellow-400":"text-gray-300"}`,onClick:()=>x(r)},r))})]}),e.jsxs("div",{children:[e.jsx(k,{htmlFor:"feedback",children:"Additional Feedback (Optional)"}),e.jsx(V,{id:"feedback",placeholder:"Share your thoughts about the answer...",value:g,onChange:r=>j(r.target.value),rows:3})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(N,{variant:"outline",onClick:n,children:"Cancel"}),e.jsx(N,{onClick:w,disabled:v||a===0,children:v?"Submitting...":"Submit Feedback"})]})]})]})})},H="attendee-questions",Fe=()=>{const{currentUser:s}=O(),{toast:c}=$(),n=le(),{data:a}=q({queryKey:["current-event-id",s==null?void 0:s.id],queryFn:async()=>{if(!(s!=null&&s.id))return null;const{data:i}=await d.from("profiles").select("current_event_id").eq("id",s.id).single();return(i==null?void 0:i.current_event_id)||null},enabled:!!(s!=null&&s.id),...A}),x=q({queryKey:["is-participant",s==null?void 0:s.id,a],queryFn:async()=>{if(!(s!=null&&s.id)||!a)return!1;const{data:i}=await d.from("event_participants").select("id").eq("user_id",s.id).eq("event_id",a).maybeSingle();return!!i},enabled:!!(s!=null&&s.id)&&!!a,...A}),{data:g=[],isLoading:j,error:v}=q({queryKey:["attendee-questions",s==null?void 0:s.id,a],queryFn:async()=>{if(!(s!=null&&s.id)||!a)return[];const{data:i,error:o}=await d.from("questions").select("id, content, created_at, upvotes, is_answered, user_id, session_id, event_id, is_anonymous").eq("event_id",a).order("created_at",{ascending:!1});if(o)throw o;const m=[...new Set((i||[]).filter(l=>!l.is_anonymous).map(l=>l.user_id))],f={};if(m.length>0){const{data:l}=await d.from("profiles").select("id, name, photo_url").in("id",m);l==null||l.forEach(S=>{f[S.id]={name:S.name||"",photo_url:S.photo_url}})}const Q=(i||[]).map(l=>({...l,profiles:l.is_anonymous?null:f[l.user_id]||null}));return Se(`${H}-${s.id}`,Q),Q},enabled:!!(s!=null&&s.id)&&!!a,...A,placeholderData:()=>s!=null&&s.id?Ne(`${H}-${s.id}`)??void 0:void 0}),{data:b=[],isLoading:y}=q({queryKey:["attendee-sessions",s==null?void 0:s.id,a],queryFn:async()=>
1{if(!(s!=null&&s.id)||!a)return[];const{data:i,error:o}=await d.from("speakers").select("id, name, session_title, session_time").eq("event_id",a).not("session_time","is",null).not("session_title","is",null).order("session_time",{ascending:!0});if(o)throw o;return i||[]},enabled:!!(s!=null&&s.id)&&!!a,...A}),w=E({mutationFn:async i=>{if(!(s!=null&&s.id))throw new Error("User not authenticated");if(!a)throw new Error("No current event found");const{data:o}=await d.from("event_participants").select("id").eq("user_id",s.id).eq("event_id",a).maybeSingle();if(!o)throw new Error("You must join the event to submit questions.");const{error:m}=await d.from("questions").insert([{content:i.content.trim(),user_id:s.id,is_anonymous:i.isAnonymous,session_id:i.selectedSessionId==="general"?null:i.selectedSessionId||null,event_id:a,upvotes:0,is_answered:!1}]);if(m)throw m},onSuccess:()=>{n.invalidateQueries({queryKey:["attendee-questions"]}),c({title:"Success",description:"Your question has been submitted!"})},onError:i=>{c({title:"Error",description:(i==null?void 0:i.message)||"Failed to submit question",variant:"destructive"})}}),r=E({mutationFn:async i=>{const{data:o,error:m}=await d.from("questions").select("upvotes").eq("id",i).single();if(m)throw m;const{error:f}=await d.from("questions").update({upvotes:o.upvotes+1}).eq("id",i);if(f)throw f;return i},onSuccess:()=>{n.invalidateQueries({queryKey:["attendee-questions"]}),c({title:"Success",description:"Question upvoted!"})},onError:()=>{c({title:"Error",description:"Failed to upvote question",variant:"destructive"})}}),p=E({mutationFn:async i=>{if(!(s!=null&&s.id))throw new Error("User not authenticated");const{error:o}=await d.from("questions").delete().eq("id",i).eq("user_id",s.id);if(o)throw o;return i},onSuccess:()=>{n.invalidateQueries({queryKey:["attendee-questions"]}),c({title:"Success",description:"Question deleted successfully!"})},onError:()=>{c({title:"Error",description:"Failed to delete question",variant:"destructive"})}});return{questions:g,sessions:b,currentEventId:a,isLoading:j||y,error:v,submitQuestion:w.mutate,upvoteQuestion:r.mutate,deleteQuestion:p.mutate,isSubmitting:w.isPending,isDeleting:p.isPending,isParticipant:x.data,isParticipantLoading:x.isLoading}},Ue=()=>{const{currentUser:s}=O(),{toast:c}=$(),[n,a]=u.useState(""),[x,g]=u.useState(""),[j,v]=u.useState(!1),[b,y]=u.useState(!1),[w,r]=u.useState(null),[p,i]=u.useState(new Set),[o,m]=u.useState(!1),{questions:f,sessions:Q,currentEventId:l,isLoading:S,submitQuestion:G,upvoteQuestion:J,deleteQuestion:W,isSubmitting:I,isDeleting:X}=Fe(),Z=async()=>{if(!n.trim()){c({title:"No question to refine",description:"Please enter a question first",variant:"destructive"});return}m(!0);try{const{data:t,error:h}=await d.functions.invoke("refine-question",{body:{question:n}});if(h)throw h;t!=null&&t.refinedQuestion&&(a(t.refinedQuestion),c({title:"Question refined",description:"Your question has been improved by AI"}))}catch(t){console.error("Error refining question:",t),c({title:"Failed to refine question",description:"Please try again",variant:"destructive"})}finally{m(!1)}},U=async()=>{n.trim()&&l&&(G({content:n,isAnonymous:j,selectedSessionId:x}),a(""),g(""),v(!1))},ee=t=>{J(t),i(h=>new Set([...h,t])),setTimeout(()=>{i(h=>{const _=new Set(h);return _.delete(t),_})},600)},se=t=>{window.confirm("Are you sure you want to delete this question?")&&W(t)},C=f.filter(t=>t.user_id===(s==null?void 0:s.id)),F=f.filter(t=>t.user_id!==(s==null?void 0:s.id));if(S)return e.jsx(T,{children: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..."})]})})});if(!l)return e.jsx(T,{children:e.jsx("div",{className:"animate-fade-in max-w-4xl mx-auto",children:e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:"Ask a Question"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"You need to join an event first to ask questions"})]})})});const z=t=>{var R,P;const h=((R=t.profiles)==null?void 0:R.name)||"Anonymous",_=(P=t.profiles)==null?void 0:P.photo_url;return e.jsx(L,{className:`glass-card overflow-hidden hover:shadow-xl transition-all ${t.upvotes>0?"fire-border animate-fade-in":""} mb-3 sm:mb-4${t.is_answered?" border-green-200 bg-green-50/60":""}`,children:e.jsx(D,{className:"pt-6 pb-4",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(xe,{className:"flex-shrink-0",children:!t.is_anonymous&&_?e.jsx(pe,{src:_}):e.jsx(fe,{children:t.is_anonymous?e.jsx(he,{className:"h-4 w-4"}):h.charAt(0)})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("span",{className:"font-medium text-sm",children:t.is_anonymous?"Anonymous":h}),e.jsx("span",{className:"text-xs text-muted-foreground",children:B(new Date(t.created_at),"MMM d, yyyy")}),t.is_answered&&e.jsx(M,{className:"bg-green-100 text-green-800",children:"Answered"})]}),e.jsx("p",{className:"text-gray-800 dark:text-gray-200 mb-3",children:t.content}),t.response&&e.jsxs("div",{className:"mt-4 p-4 bg-blue-50 border-l-4 border-blue-200 rounded",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-6 h-6 bg-blue-600 rounded-full flex items-center justify-center",children:e.jsx("span",{className:"text-xs font-semibold text-white",children:"A"})}),e.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Admin Response"}),t.response_created_at&&e.jsxs("span",{className:"text-xs text-blue-600",children:["â¢"," ",B(new Date(t.response_created_at),"MMM d, h:mm a")]})]}),e.jsx("p",{className:"text-blue-700 pl-8",children:t.response})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-3",children:[e.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>ee(t.id),className:`text-gray-600 hover:text-connect-600 transition-all duration-300 ${p.has(t.id)?"animate-pulse scale-110 text-connect-600 bg-connect-50":""}`,children:[e.jsx(qe,{className:`h-4 w-4 mr-1 transition-transform duration-300 ${p.has(t.id)?"scale-125":""}`}),t.upvotes," ",t.upvotes>0&&e.jsx("span",{"aria-hidden":"true",children:"ð¥"})]}),t.user_id===(s==null?void 0:s.id)&&e.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>se(t.id),disabled:X,className:"text-red-600 hover:text-red-700 hover:bg-red-50",children:[e.jsx(Ae,{className:"h-4 w-4 mr-1"}),"Delete"]})]})]})]})})},t.id)};return e.jsxs(T,{children:[e.jsxs("div",{className:"animate-fade-in max-w-4xl mx-auto px-0 sm:px-6 pb-8",children:[e.jsxs("div",{className:"mb-8 relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-purple-600 to-pink-500 p-6 sm:p-10 text-white z-10 shadow-xl",children:[e.jsx("div",{className:"absolute inset-0 bg-black/25 z-0"}),e.jsx("div",{className:"relative z-10",children:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center sm:items-start",children:[e.jsx("div",{className:"w-16 h-16 bg-white/20 rounded-full flex items-center justify-center mb-4",children:e.jsx(K,{className:"h-8 w-8 text-yellow-300"})}),e.jsx("h1",{className:"text-3xl sm:text-4xl font-bold mb-2",children:"Ask a Question"}),e.jsx("p",{className:"text-lg opacity-95 max-w-2xl",children:"Ask questions and engage with the event speakers!"})]}),e.jsx("div",{className:"flex flex-col items-center sm:items-end space-y-1 mt-4 sm:mt-0",children:e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(M,{variant:"info",className:"font-medium",children:[C.length," My Questions"]}),e.jsxs(M,{variant:"warning",className:"font-medium",children:[F.length," Community"]})]})})]})}),e.jsx("div",{className:"absolute -bottom-12 -right-12 w-44 h-44 bg-white/10 rounded-full z-0"}),e.jsx("div",{className:"absolute -top-12 -left-12 w-60 h-60 bg-white/5 rounded-full z-0"})]}),e.jsx("div",{className:"w-full mb-8",children:e.jsxs(L,{className:"rounded-2xl shadow-lg bg-white/95 backdrop-blur-sm border-0",children:[e.jsxs(de,{children:[e.jsxs(ce,{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-5 w-5 text-connect-600"}),"Ask Your Question"]}),e.jsx(me,{children:"Your question will be visible to speakers and other attendees"})]}),e.jsxs(D,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(k,{htmlFor:"session",children:"Select Session"}),e.jsxs(je,{value:x,onValueChange:g,children:[e.jsx(ve,{children:e.jsx(be,{placeholder:"Choose a session (optional)"})}),e.jsxs(ye,{className:"bg-white dark:bg-gray-800 z-30 p-1",children:[e.jsx(Y,{value:"general",className:"py-2",children:"General Question"}),Q.map(t=>e.jsx(Y,{value:t.id,className:"py-2",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-sm",children:t.session_title||`${t.name}'s Session`}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["by ",t.name,t.session_time&&` ⢠${new Date(t.session_time).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}`]})]})},t.id))]})]})]}),e.jsxs("div",{children:[e.jsx(k,{htmlFor:"question",children:"Your Question"}),e.jsxs("div",{className:"relative",children:[e.jsx(V,{id:"question",placeholder:"Type your question here...",value:n,onChange:t=>a(t.target.value),rows:4,className:"pr-36"}),e.jsxs(N,{type:"button",variant:"ghost",size:"sm",onClick:Z,disabled:!n.trim()||o,className:"absolute bottom-2 right-2 text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:hover:bg-purple-900/20",children:[o?e.jsx(ke,{className:"h-4 w-4 animate-spin"}):e.jsx(ue,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"Refine with AI"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ge,{id:"anonymous",checked:j,onCheckedChange:v}),e.jsx(k,{htmlFor:"anonymous",children:"Ask anonymously"})]}),e.jsxs("div",{className:"space-y-2 bg-gray-50 dark:bg-gray-800 p-3 rounded-lg",children:[e.jsx("p",{className:"text-sm text-muted-foreground font-medium",children:"Tips for good questions:"}),e.jsxs("ul",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("li",{children:"⢠Be specific and concise"}),e.jsx("li",{children:"⢠Ask about topics relevant to the session"}),e.jsx("li",{children:"⢠Avoid yes/no questions"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(N,{variant:"outline",className:"flex-1",children:"Cancel"}),e.jsxs(N,{onClick:U,disabled:!n.trim()||I,className:"flex-1",children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),I?"Submitting...":"Submit Question"]})]})]})]})}),C.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-4",children:e.jsx("h2",{className:"text-xl font-semibold",children:"My Questions"})}),e.jsx("div",{className:"space-y-4 mb-6",children:C.map(t=>z(t))}),e.jsx(we,{className:"my-6"})]}),e.jsx("div",{className:"mb-4",children:e.jsx("h2",{className:"text-xl font-semibold",children:"Community Questions"})}),e.jsx("div",{className:"space-y-4",children:F.length>0?F.map(t=>z(t)):e.jsx(L,{children:e.jsxs(D,{className:"py-10 text-center text-muted-foreground",children:[e.jsx(K,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No questions from other attendees yet."}),e.jsx("p",{className:"text-sm",children:"Be the first to ask a question!"})]})})})]}),b&&w&&e.jsx(Ce,{questionId:w,isOpen:b,onClose:()=>{y(!1),r(null)}})]})};export{Ue 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.