1import{j as e,A as O,m as M}from"./vendor-motion-DeqZC-4t.js";import{r as a}from"./vendor-react-DhMA_kEV.js";import{u as Q}from"./InlineListenButton-D_OiQfHa.js";import{a as V,u as K,b as G}from"./vendor-query-cy1x5wk5.js";import{s as c}from"./index-WqAUWWUN.js";import{u as W,c as N,B as d,T as Y}from"./App-CVGAgymZ.js";import{b3 as H,aG as J,V as X,M as Z,ax as ee,L as z,an as te,r as se,a$ as ae,ab as re}from"./vendor-icons-xAlReevQ.js";import{f as ne}from"./formatDistanceToNow-Co1kTc3G.js";import"./voiceClone-kQzdWElW.js";import"./vendor-supabase-CHGq0V2O.js";import"./vendor-charts-DKUbyPp_.js";import"./logChunkLoadFailure-BWuYLh8E.js";import"./constructFrom-rJN6zrQ_.js";import"./en-US-tuXCdAZL.js";function je({slug:l,title:w}){const{user:r}=W(),q=V(),[u,f]=a.useState(""),[_,R]=a.useState(!1),[B,C]=a.useState(0),[h,p]=a.useState(null),[S,g]=a.useState(!1),k=a.useRef(null),v=a.useRef([]),y=a.useRef(null),m=a.useRef(null);Q(m,()=>p(null));const[o,j]=a.useState(null),{data:P=[],isLoading:L}=K({queryKey:["community-perspectives",l],queryFn:async()=>{const{data:t}=await c.from("community_perspectives").select("id, user_id, author_name, perspective_text, audio_url, transcript, moderation_status, created_at").eq("entry_slug",l).order("created_at",{ascending:!1}).limit(50);return t||[]}}),b=G({mutationFn:async()=>{var A;if(!r)throw new Error("Not logged in");if(!u.trim()&&!o)throw new Error("Add text or voice");let t=null;if(o){const T=`perspectives/${l}/${r.id}-${Date.now()}.webm`,{error:E}=await c.storage.from("voice-recordings").upload(T,o,{contentType:"audio/webm"});if(E)throw E;const{data:U}=c.storage.from("voice-recordings").getPublicUrl(T);t=U.publicUrl}const n=((A=r.email)==null?void 0:A.split("@")[0])||"Anonymous",{data:s,error:i}=await c.from("community_perspectives").insert({entry_slug:l,user_id:r.id,author_name:n,perspective_text:u.trim(),audio_url:t}).select("id").single();if(i)throw i;return c.functions.invoke("moderate-perspective",{body:{perspectiveId:s.id}}),t&&c.functions.invoke("transcribe-voice",{body:{audioUrl:t,perspectiveId:s.id}}),s},onSuccess:()=>{f(""),j(null),g(!1),q.invalidateQueries({queryKey:["community-perspectives",l]}),N.success("Perspective submitted! It'll appear once reviewed.")},onError:t=>N.error(t instanceof Error?t.message:"Failed to submit")}),D=a.useCallback(async()=>{try{const t=await navigator.mediaDevices.getUserMedia({audio:!0}),n=new MediaRecorder(t,{mimeType:"audio/webm"});v.current=[],n.ondataavailable=s=>v.current.push(s.data),n.onstop=()=>{const s=new Blob(v.current,{type:"audio/webm"});j(s),t.getTracks().forEach(i=>i.stop())},n.start(),k.current=n,R(!0),C(0),y.current=setInterval(()=>C(s=>s+1),1e3)}catch{N.error("Could not access microphone")}},[]),F=a.useCallback(()=>{var t;(t=k.current)==null||t.stop(),R(!1),y.current&&clearInterval(y.current)},[]),$=(t,n)=>{var i;if(h===n){(i=m.current)==null||i.pause(),p(null);return}m.current&&m.current.pause();const s=new Audio(t);s.onended=()=>p(null),s.play(),m.current=s,p(n)},x=P.filter(t=>t.moderation_status==="approved"),I=P.filter(t=>t.moderation_status==="pending"&&t.user_id===(r==null?void 0:r.id));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground uppercase tracking-wider",children:[x.length," perspective",x.length!==1?"s":""]})]}),r&&!S&&e.jsx(d,{size:"sm",variant:"outline",onClick:()=>g(!0),className:"font-mono text-xs",children:"Share yours"})]}),!r&&e.jsxs("div",{className:"brutal-card bg-muted/30 p-4 text-center space-y-2",children:[e.jsx(J,{className:"w-5 h-5 mx-auto text-muted-foreground"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground",children:["Sign in to share your perspective on ",e.jsx("strong",{children:w})]}),e.jsx(d,{size:"sm",variant:"outline",asChild:!0,children:e.jsx("a",{href:"/admin",children:"Sign in"})})]}),e.jsx(O,{children:S&&r&&e.jsxs(M.div,{initial:{opacity:0,height:0}
1,animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"brutal-card bg-card p-4 space-y-3 overflow-hidden",children:[e.jsx(Y,{value:u,onChange:t=>f(t.target.value),placeholder:`What's your take on ${w}?`,className:"min-h-[80px] font-body text-sm resize-none",maxLength:1e3}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[_?e.jsxs(d,{size:"sm",variant:"destructive",onClick:F,className:"font-mono text-xs gap-1.5",children:[e.jsx(X,{className:"w-3.5 h-3.5"}),"Stop (",B,"s)"]}):e.jsxs(d,{size:"sm",variant:"outline",onClick:D,className:"font-mono text-xs gap-1.5",children:[e.jsx(Z,{className:"w-3.5 h-3.5"}),o?"Re-record":"Voice note"]}),o&&!_&&e.jsxs("span",{className:"font-mono text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(ee,{className:"w-3 h-3"})," Recorded"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>{g(!1),j(null),f("")},className:"font-mono text-xs",children:"Cancel"}),e.jsxs(d,{size:"sm",onClick:()=>b.mutate(),disabled:b.isPending||!u.trim()&&!o,className:"font-mono text-xs gap-1.5",children:[b.isPending?e.jsx(z,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(te,{className:"w-3.5 h-3.5"}),"Submit"]})]})]}),e.jsx("p",{className:"font-mono text-[10px] text-muted-foreground/60",children:"Your perspective will be reviewed by AI before appearing publicly."})]})}),I.length>0&&e.jsx("div",{className:"space-y-2",children:I.map(t=>e.jsxs("div",{className:"brutal-card bg-muted/20 p-3 border-dashed",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(se,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground uppercase",children:"Pending review"})]}),e.jsx("p",{className:"font-body text-sm text-muted-foreground",children:t.perspective_text})]},t.id))}),L?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(z,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):x.length===0?e.jsx("p",{className:"font-body text-sm text-muted-foreground text-center py-4",children:"No perspectives yet. Be the first to share yours!"}):e.jsx("div",{className:"space-y-3",children:x.map(t=>e.jsxs(M.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"brutal-card bg-card p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-display font-bold text-sm",children:t.author_name}),e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:ne(new Date(t.created_at),{addSuffix:!0})})]}),t.perspective_text&&e.jsx("p",{className:"font-body text-sm leading-relaxed",children:t.perspective_text}),t.transcript&&!t.perspective_text&&e.jsxs("p",{className:"font-body text-sm leading-relaxed italic text-muted-foreground",children:['"',t.transcript,'"']}),t.audio_url&&e.jsxs("button",{onClick:()=>$(t.audio_url,t.id),className:"flex items-center gap-1.5 font-mono text-xs text-muted-foreground hover:text-foreground transition-colors",children:[h===t.id?e.jsx(ae,{className:"w-3 h-3"}):e.jsx(re,{className:"w-3 h-3"}),h===t.id?"Pause":"Listen"]})]},t.id))})]})}export{je 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.