1import{j as e,r as u}from"./vendor-ui-D_r7OC7V.js";import{L as C,c as pe,a as xe}from"./vendor-react-BU1Prldx.js";import{v as w,W as T,aP as he,aZ as fe,aw as je,aN as ge,y as U,M,N as $,O as V,Q as B,a3 as Y,R as J,U as K,B as h,o as A,h as X,V as ee,u as se,s as o,r as _,cE as ve,K as Ne,i as te,cK as re,q as l,a as ye,ab as we,ac as _e,d6 as be,a5 as O,a6 as Ce,be as Ae,es as Se,w as qe,p as ke}from"./index-B-fGkebm.js";import{V as Q,u as Pe}from"./useCommunityVotes-ey0XqN3y.js";import{b as Ee}from"./vendor-query-ejTojVwg.js";import{f as Me}from"./vendor-utils-BjrDmlTK.js";function Ve({points:r,showLabel:c=!0,size:n="md"}){const x=r>=1e3?{name:"Expert",icon:he,color:"text-amber-500"}:r>=500?{name:"Pro",icon:fe,color:"text-purple-500"}:r>=100?{name:"Rising",icon:je,color:"text-blue-500"}:{name:"Contributor",icon:ge,color:"text-muted-foreground"},j=x.icon,m=n==="sm"?"h-3 w-3":"h-4 w-4";return e.jsxs(w,{variant:"outline",className:T("gap-1 font-medium",n==="sm"?"text-xs px-1.5 py-0":"text-sm"),children:[e.jsx(j,{className:T(m,x.color)}),e.jsx("span",{className:x.color,children:r}),c&&e.jsx("span",{className:"text-muted-foreground",children:x.name})]})}function Be({answer:r,userVote:c,onVote:n,canAccept:p,onAccept:x,onMessage:j,isPaidRequest:m,price:g,isCheckoutLoading:t}){return e.jsx("div",{className:T("p-4 rounded-lg border bg-card",r.is_accepted&&"border-primary bg-primary/5"),children:e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:"hidden sm:block",children:e.jsx(Q,{upvoteCount:r.upvote_count||0,userVote:c,onVote:n,size:"sm"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[r.is_accepted&&e.jsxs(w,{className:"bg-primary hover:bg-primary/90 mb-2 gap-1",children:[e.jsx(U,{className:"h-3 w-3"}),"Accepted Answer"]}),e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs(M,{className:"h-10 w-10",children:[e.jsx($,{src:r.mentor?.profile?.avatar_url||void 0,loading:"lazy"}),e.jsx(V,{children:B(r.mentor?.profile?.full_name,"M")})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-foreground",children:r.mentor?.profile?.full_name||"Mentor"}),r.mentor?.reputation_points!==void 0&&e.jsx(Ve,{points:r.mentor.reputation_points,size:"sm",showLabel:!1})]}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-1",children:r.mentor?.headline})]})]}),e.jsx("p",{className:"text-foreground whitespace-pre-wrap mb-3",children:r.message||"No message provided."}),r.proposed_rate&&e.jsxs("div",{className:"text-sm text-primary font-medium mb-3",children:["Proposed rate: ",Y(r.proposed_rate,{decimals:"never"}),"/session"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pt-3 border-t",children:[e.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:K(r.created_at)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[p&&!r.is_accepted&&e.jsx(h,{variant:m?"default":"outline",size:"sm",className:m?"gap-1":"text-primary hover:bg-primary/10",onClick:x,disabled:t,children:t?e.jsx(A,{className:"h-4 w-4 animate-spin"}):m&&g?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-4 w-4"}),"Accept & Pay ",Y(g,{decimals:"never"})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"h-4 w-4 mr-1"}),"Accept Answer"]})}),j&&e.jsxs(h,{variant:"outline",size:"sm",onClick:j,children:[e.jsx(ee,{className:"h-4 w-4 mr-1"}),"Message"]})]})]}),e.jsx("div",{className:"flex sm:hidden items-center gap-4 mt-3 pt-3 border-t",children:e.jsx(Q,{upvoteCount:r.upvote_count||0,userVote:c,onVote:n,size:"sm"})})]})]})})}function Qe({opportunityId:r}){const{user:c}=se(),[n,p]=u.useState([]),[x,j]=u.useState(!0),[m,g]=u.useState(!1),[t,S]=u.useState("");u.useEffect(()=>{d();const a=o.channel(`comments-${r}`).on("postgres_changes",{event:"*",schema:"public",table:"opportunity_comments",filter:`opportunity_id=eq.${r}`},()=>{d()}).subscribe();return()=>{o.removeChannel(a)}},[r]);const d=async()=>{try{const{data:a,error:f}=await o.from("opportunity_comments").select("*").eq("opportunity_id",r).order("created_at",{ascending:!0});if(f)throw f;const b=[...new Set(a?.map(N=>
1N.user_id)||[])],{data:v}=await o.from("profiles_public").select("user_id, full_name, avatar_url").in("user_id",b),q=(a||[]).map(N=>({...N,user:v?.find(F=>F.user_id===N.user_id)||void 0}));p(q)}catch(a){_("Error fetching comments",a,"CommentSection")}finally{j(!1)}},z=async()=>{if(!c){l.error("Please sign in to comment");return}if(!t.trim()){l.error("Please write a comment");return}g(!0);try{const{error:a}=await o.from("opportunity_comments").insert({opportunity_id:r,user_id:c.id,content:t.trim()});if(a)throw a;l.success("Comment posted!"),S("")}catch(a){_("Error posting comment",a,"CommentSection"),l.error("Failed to post comment")}finally{g(!1)}},L=async a=>{try{const{error:f}=await o.from("opportunity_comments").delete().eq("id",a);if(f)throw f;l.success("Comment deleted")}catch(f){_("Error deleting comment",f,"CommentSection"),l.error("Failed to delete comment")}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(ve,{className:"h-5 w-5"}),"Comments (",n.length,")"]}),x?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(A,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n.length>0?e.jsx("div",{className:"space-y-3",children:n.map(a=>e.jsxs("div",{className:"flex gap-3 p-3 rounded-lg bg-muted/50",children:[e.jsxs(M,{className:"h-8 w-8 flex-shrink-0",children:[e.jsx($,{src:a.user?.avatar_url||void 0}),e.jsx(V,{children:B(a.user?.full_name)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-sm",children:a.user?.full_name||"Anonymous"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:K(a.created_at)}),c?.id===a.user_id&&e.jsx(h,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 ml-auto text-muted-foreground hover:text-destructive",onClick:()=>L(a.id),children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:a.content})]})]},a.id))}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No comments yet. Be the first to comment!"}),c?e.jsxs("div",{className:"flex gap-3 pt-2",children:[e.jsx(M,{className:"h-8 w-8 flex-shrink-0",children:e.jsx(V,{children:B(c.email,"U")})}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(te,{value:t,onChange:a=>S(a.target.value),placeholder:"Add a comment...",rows:2,className:"resize-none"}),e.jsxs(h,{size:"sm",onClick:z,disabled:m||!t.trim(),className:"gap-2",children:[m?e.jsx(A,{className:"h-4 w-4 animate-spin"}):e.jsx(re,{className:"h-4 w-4"}),"Comment"]})]})]}):e.jsxs("div",{className:"text-center py-4 bg-muted/30 rounded-lg",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Sign in to leave a comment"}),e.jsx(h,{asChild:!0,size:"sm",variant:"outline",children:e.jsx(C,{to:"/login",children:"Sign In"})})]})]})}function ze(){return Ee({mutationFn:async({opportunityId:r,responseId:c})=>{const{data:n,error:p}=await o.functions.invoke("create-qa-checkout",{body:{opportunity_id:r,response_id:c}});if(p)throw p;if(n?.error)throw new Error(n.error);if(n?.requires_setup)throw new Error("Stripe is not configured. Please contact support.");return n},onSuccess:r=>{r?.url&&(window.location.href=r.url)},onError:r=>{l.error(r.message||"Failed to create payment session")}})}function Te(){const{questionId:r}=pe(),c=xe(),{user:n}=se(),{getUserVote:p,vote:x}=Pe(),{checkAndBlock:j,isChecking:m}=ye(),g=ze(),[t,S]=u.useState(null),[d,z]=u.useState([]),[L,a]=u.useState(!0),[f,b]=u.useState(!1),[v,q]=u.useState(""),[N,F]=u.useState(!1),[I,ae]=u.useState(null);we(t?_e.qaPage({question:{title:t.title,body:t.description,authorName:t.poster?.full_name||"Anonymous",dateCreated:t.created_at,upvoteCount:t.upvote_count||0,url:`https://sidetrain.com/community/${t.id}`},answers:d.map(s=>({body:s.message,authorName:s.mentor?.profile?.full_name||"Mentor",dateCreated:s.created_at,upvoteCount:s.upvote_count||0,isAccepted:s.is_accepted}))}):null),u.useEffect(()=>{r&&(W(),k()),n&&ne()},[r,n]);const W=async()=>
1{if(r)try{const{data:s,error:i}=await o.from("opportunities").select("*").eq("id",r).single();if(i)throw i;const{data:P}=await o.from("profiles_public").select("full_name, avatar_url").eq("user_id",s.user_id).single();S({...s,type:s.type,poster:P||void 0})}catch(s){_("Error fetching question",s,"QuestionDetail"),l.error("Failed to load question"),c("/community")}finally{a(!1)}},k=async()=>{if(r)try{const{data:s,error:i}=await o.from("opportunity_responses").select("*").eq("opportunity_id",r).order("is_accepted",{ascending:!1}).order("upvote_count",{ascending:!1});if(i)throw i;const P=s?.map(y=>y.mentor_id)||[],{data:G}=await o.from("mentor_profiles").select("id, headline, user_id, reputation_points").in("id",P),le=G?.map(y=>y.user_id)||[],{data:de}=await o.from("profiles_public").select("user_id, full_name, avatar_url").in("user_id",le),me=(s||[]).map(y=>{const E=G?.find(R=>R.id===y.mentor_id),ue=de?.find(R=>R.user_id===E?.user_id);return{...y,is_accepted:y.is_accepted||!1,mentor:E?{headline:E.headline,reputation_points:E.reputation_points,profile:ue||void 0}:void 0}});z(me)}catch(s){_("Error fetching answers",s,"QuestionDetail")}},ne=async()=>{if(!n)return;const{data:s}=await o.from("mentor_profiles").select("id, is_active, approval_status").eq("user_id",n.id).maybeSingle();s&&s.is_active&&s.approval_status===be.APPROVED&&(F(!0),ae(s.id))},Z=async s=>{if(!r)return;await x("opportunity",r,s)&&W()},ie=async(s,i)=>{await x("response",s,i)&&k()},oe=async()=>{if(!n||!I||!r){l.error("You must be a mentor to answer");return}if(!v.trim()){l.error("Please write an answer");return}b(!0);try{const{allowed:s}=await j(v.trim(),"community_response");if(!s){b(!1);return}const{error:i}=await o.from("opportunity_responses").insert({opportunity_id:r,mentor_id:I,message:v.trim()});if(i)throw i;l.success("Answer posted!"),q(""),k()}catch(s){_("Error submitting answer",s,"QuestionDetail"),(s!==null&&typeof s=="object"&&"code"in s?s.code:void 0)==="23505"?l.error("You've already answered this question"):l.error("Failed to post answer")}finally{b(!1)}},ce=async s=>{if(!(!t||t.user_id!==n?.id)){if(t.type==="paid_request"&&t.price&&t.price>0){g.mutate({opportunityId:t.id,responseId:s});return}try{await o.from("opportunity_responses").update({is_accepted:!1}).eq("opportunity_id",t.id).eq("is_accepted",!0);const{error:i}=await o.from("opportunity_responses").update({is_accepted:!0}).eq("id",s);if(i)throw i;l.success("Answer accepted!"),k()}catch(i){_("Error accepting answer",i,"QuestionDetail"),l.error("Failed to accept answer")}}},H=()=>t?.price?Y(t.price,{decimals:"never"}):null,D=n?.id===t?.user_id;return d.some(s=>s.mentor?.profile?.full_name&&I&&s.id),L?e.jsxs(O,{children:[e.jsx(Ce,{title:t?.title||"Question",description:t?.description?.slice(0,160)||"Community question on Sidetrain."}),e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",children:e.jsx(A,{className:"h-8 w-8 animate-spin text-primary"})})]}):t?e.jsx(O,{children:e.jsx("div",{className:"bg-muted/30 min-h-screen",children:e.jsxs("div",{className:"container-wide py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs(h,{variant:"ghost",onClick:()=>c("/community"),className:"gap-2",children:[e.jsx(Ae,{className:"h-4 w-4"}),"Back to Community"]}),e.jsx(Se,{title:"question.title",description:"question.description"})]}),e.jsxs("div",{className:"grid lg:grid-cols-[1fr,300px] gap-8",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"card-elevated p-6",children:e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:"hidden sm:block",children:e.jsx(Q,{upvoteCount:t.upvote_count||0,userVote:p("opportunity",t.id),onVote:Z})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[e.jsx(w,{variant:t.type==="paid_request"?"default":"secondary",children:t.type==="paid_request"?"Paid Request":"Question"}),t.category&&e.jsx(w,{variant:"outline",children:t.category}),t.is_urgent&&e.jsxs(w,{variant:"destructive",className:"gap-1",children:[e.jsx(qe,{className:"h-3 w-3"}),"Urgent"]}),d.some(s=>s.is_accepted)&&e.jsxs(w,{variant:"outline",className:"text-primary border-primary gap-1",children:[e.jsx(U,{className:"h-3 w-3"}),"Answered"]})]}),e.jsx("h1",{className:"text-2xl font-bold text-foreground mb-4",children:t.title}),e.jsx("p",{className:"text-foreground whitespace-pre-wrap mb-4",children:t.description}),t.type==="paid_request"&&H()&&e.jsxs("div",{className:"flex items-center gap-2 text-primary font-medium mb-4",children:[e.jsx(X,{className:"h-4 w-4"}),"Reward: ",H()]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 pt-4 border-t text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(M,{className:"h-6 w-6",children:[e.jsx($,{src:t.poster?.avatar_url||void 0}),e.jsx(V,{children:B(t.poster?.full_name)})]}),e.jsx("span",{children:t.poster?.full_name||"Anonymous"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:["Asked ",K(t.created_at)]})]})]}),e.jsx("div",{className:"flex sm:hidden items-center gap-4 mt-4 pt-4 border-t",children:e.jsx(Q,{upvoteCount:t.upvote_count||0,userVote:p("opportunity",t.id),onVote:Z,size:"sm"})})]})]})}),e.jsx("div",{className:"card-elevated p-6",children:e.jsx(Qe,{opportunityId:t.id})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-semibold mb-4",children:[d.length," ",d.length===1?"Answer":"Answers"]}),d.length>0?e.jsx("div",{className:"space-y-4",children:d.map(s=>e.jsx(Be,{answer:s,userVote:p("response",s.id),onVote:i=>ie(s.id,i),canAccept:D&&!d.some(i=>i.is_accepted),onAccept:()=>ce(s.id),isPaidRequest:t?.type==="paid_request",price:t?.price,isCheckoutLoading:g.isPending},s.id))}):e.jsxs("div",{className:"text-center py-8 card-elevated",children:[e.jsx(ee,{className:"h-12 w-12 text-muted-foreground mx-auto mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:"No answers yet. Be the first to answer!"})]})]}),N&&!D&&e.jsxs("div",{className:"card-elevated p-6",children:[e.jsx("h3",{className:"font-semibold mb-4",children:"Your Answer"}
1),e.jsx(te,{value:v,onChange:s=>q(s.target.value),placeholder:"Share your knowledge and help the community...",rows:5,className:"mb-4"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(h,{onClick:oe,disabled:f||m||!v.trim(),className:"gap-2",children:[f||m?e.jsx(A,{className:"h-4 w-4 animate-spin"}):e.jsx(re,{className:"h-4 w-4"}),m?"Checking...":"Post Answer"]}),m&&e.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(ke,{className:"h-3 w-3"}),"Reviewing for safety"]})]})]}),!N&&!D&&n&&e.jsxs("div",{className:"card-elevated p-6 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Only mentors can answer questions. Want to share your expertise?"}),e.jsx(h,{asChild:!0,variant:"outline",children:e.jsx(C,{to:"/creator-signup",children:"Become a Creator"})})]}),!n&&e.jsxs("div",{className:"card-elevated p-6 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Sign in to answer this question"}),e.jsx(h,{asChild:!0,children:e.jsx(C,{to:"/login",children:"Sign In"})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"card-elevated p-4",children:[e.jsx("h3",{className:"font-semibold mb-3",children:"About this post"}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Posted"}),e.jsx("span",{children:Me(new Date(t.created_at),"MMM d, yyyy")})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Votes"}),e.jsx("span",{children:t.upvote_count||0})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Answers"}),e.jsx("span",{children:d.length})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status"}),e.jsx(w,{variant:d.some(s=>s.is_accepted)?"default":"secondary",children:d.some(s=>s.is_accepted)?"Answered":"Open"})]})]})]}),e.jsxs("div",{className:"card-elevated p-4",children:[e.jsx("h3",{className:"font-semibold mb-3",children:"Looking for mentorship?"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Browse our top mentors for personalized guidance."}),e.jsx(h,{asChild:!0,variant:"outline",className:"w-full",children:e.jsx(C,{to:"/mentors",children:"Browse Mentors"})})]})]})]})]})})}):e.jsx(O,{children:e.jsxs("div",{className:"container-wide py-16 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Question not found"}),e.jsx(h,{asChild:!0,children:e.jsx(C,{to:"/community",children:"Back to Community"})})]})})}export{Te 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.