1import{r as i,a as Ve,j as e,bj as J,B as u,s as m,b as it,u as ot,m as H,A as he,V as $e,Y as Le,X as lt,I as Pe,t as dt,N as xe,bg as ct,bh as mt,bi as ut}from"./index-KSWbwNeY.js";import{T as $}from"./textarea-BXv-lbww.js";import{D as te,a as se,b as ae,c as ne,f as re,d as ie}from"./dialog-Bpfij23O.js";import{L as w}from"./label-ndOKmXJw.js";import{R as Te,a as G}from"./radio-group-B_sKY98x.js";import{E as ze}from"./eye-Cwzmef_1.js";import{E as Ae}from"./eye-off-DqR1XpTQ.js";import{F as qe}from"./flag-DhaMxnCI.js";import{B as Ge}from"./ban-Dw9y4DYY.js";import{M as ht}from"./message-square-D9MVWo21.js";import{S as xt}from"./send-Diy0wlsk.js";import{S as ft}from"./shield-check-CHHnEQz_.js";import{H as pt,C as gt}from"./heart-BKeMwoxw.js";import{E as jt}from"./ellipsis-aIaacu3o.js";import{o as Ye,s as pe,Z as fe}from"./schemas-eq1hNim8.js";import"./index-BpbyRUKB.js";const vt=({commentId:E,userId:W,isHidden:v,isFlagged:_,onUpdate:c,asDropdownItems:N=!1})=>{const[L,h]=i.useState(!1),[p,b]=i.useState(!1),[D,O]=i.useState(""),[l,F]=i.useState(""),[y,C]=i.useState("7days"),[x,S]=i.useState(!1),{toast:g}=Ve(),P=async()=>{var o;S(!0);try{const{error:f}=await m.from("comments").update({is_hidden:!v,hidden_by:v?null:(o=(await m.auth.getUser()).data.user)==null?void 0:o.id,hidden_at:v?null:new Date().toISOString()}).eq("id",E);if(f)throw f;g({title:v?"Comment shown":"Comment hidden",description:`Comment has been ${v?"made visible":"hidden"} successfully.`}),c()}catch{g({title:"Error",description:"Failed to update comment visibility.",variant:"destructive"})}finally{S(!1)}},I=async()=>{if(!D.trim()){g({title:"Reason required",description:"Please provide a reason for flagging this comment.",variant:"destructive"});return}S(!0);try{const{error:o}=await m.from("comments").update({is_flagged:!0,flag_reason:D}).eq("id",E);if(o)throw o;g({title:"Comment flagged",description:"Comment has been flagged for review."}),h(!1),O(""),c()}catch{g({title:"Error",description:"Failed to flag comment.",variant:"destructive"})}finally{S(!1)}},Z=async()=>{if(!l.trim()){g({title:"Reason required",description:"Please provide a reason for banning this user.",variant:"destructive"});return}S(!0);try{const o=(await m.auth.getUser()).data.user;if(!o)throw new Error("Not authenticated");const f={user_id:W,banned_by:o.id,reason:l,is_permanent:y==="permanent"};if(y!=="permanent"){const T=y==="7days"?7:30,z=new Date;z.setDate(z.getDate()+T),f.expires_at=z.toISOString()}const{error:U}=await m.from("user_bans").insert(f);if(U)throw U;g({title:"User banned",description:`User has been banned ${y==="permanent"?"permanently":`for ${y==="7days"?"7 days":"30 days"}`}.`}),b(!1),F(""),c()}
1catch(o){g({title:"Error",description:o.message||"Failed to ban user.",variant:"destructive"})}finally{S(!1)}};return N?e.jsxs(e.Fragment,{children:[e.jsx(J,{onClick:P,disabled:x,children:v?e.jsxs(e.Fragment,{children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Show comment"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Hide comment"]})}),e.jsxs(J,{onClick:()=>h(!0),disabled:x||_,children:[e.jsx(qe,{className:`h-4 w-4 mr-2 ${_?"fill-current text-red-600":""}`}),_?"Already flagged":"Flag comment"]}),e.jsxs(J,{onClick:()=>b(!0),disabled:x,className:"text-destructive",children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Ban user"]}),e.jsx(te,{open:L,onOpenChange:h,children:e.jsxs(se,{children:[e.jsxs(ae,{children:[e.jsx(ne,{children:"Flag Comment"}),e.jsx(re,{children:"Provide a reason for flagging this comment for review."})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsx($,{placeholder:"Reason for flagging...",value:D,onChange:o=>O(o.target.value),rows:4})}),e.jsxs(ie,{children:[e.jsx(u,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),e.jsx(u,{onClick:I,disabled:x,children:"Flag Comment"})]})]})}),e.jsx(te,{open:p,onOpenChange:b,children:e.jsxs(se,{children:[e.jsxs(ae,{children:[e.jsx(ne,{children:"Ban User"}),e.jsx(re,{children:"This will prevent the user from posting new comments."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(w,{children:"Ban Duration"}),e.jsxs(Te,{value:y,onValueChange:o=>C(o),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"7days",id:"7days-dropdown"}),e.jsx(w,{htmlFor:"7days-dropdown",className:"font-normal",children:"7 days"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"30days",id:"30days-dropdown"}),e.jsx(w,{htmlFor:"30days-dropdown",className:"font-normal",children:"30 days"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"permanent",id:"permanent-dropdown"}),e.jsx(w,{htmlFor:"permanent-dropdown",className:"font-normal",children:"Permanent"})]})]})]}),e.jsxs("div",{children:[e.jsx(w,{children:"Reason for Ban"}),e.jsx($,{placeholder:"Explain why this user is being banned...",value:l,onChange:o=>F(o.target.value),rows:4})]})]}),e.jsxs(ie,{children:[e.jsx(u,{variant:"outline",onClick:()=>b(!1),children:"Cancel"}),e.jsx(u,{onClick:Z,disabled:x,variant:"destructive",children:"Ban User"})]})]})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{variant:"ghost",size:"sm",onClick:P,disabled:x,className:"h-8 px-2",title:v?"Show comment":"Hide comment",children:v?e.jsx(ze,{className:"h-4 w-4"}):e.jsx(Ae,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>h(!0),disabled:x||_,className:"h-8 px-2",title:"Flag comment",children:e.jsx(qe,{className:`h-4 w-4 ${_?"fill-current text-red-600":""}`})}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>b(!0),disabled:x,className:"h-8 px-2 text-red-600 hover:text-red-700",title:"Ban user",children:e.jsx(Ge,{className:"h-4 w-4"})})]}),e.jsx(te,{open:L,onOpenChange:h,children:e.jsxs(se,{children:[e.jsxs(ae,{children:[e.jsx(ne,{children:"Flag Comment"}),e.jsx(re,{children:"Provide a reason for flagging this comment for review."})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsx($,{placeholder:"Reason for flagging...",value:D,onChange:o=>O(o.target.value),rows:4})}),e.jsxs(ie,{children:[e.jsx(u,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),e.jsx(u,{onClick:I,disabled:x,children:"Flag Comment"})]})]})}),e.jsx(te,{open:p,onOpenChange:b,children:e.jsxs(se,{children:[e.jsxs(ae,{children:[e.jsx(ne,{children:"Ban User"}),e.jsx(re,{children:"This will prevent the user from posting new comments."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(w,{children:"Ban Duration"}),e.jsxs(Te,{value:y,onValueChange:o=>C(o),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"7days",id:"7days"}),e.jsx(w,{htmlFor:"7days",className:"font-normal",children:"7 days"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"30days",id:"30days"}),e.jsx(w,{htmlFor:"30days",className:"font-normal",children:"30 days"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"permanent",id:"permanent"}),e.jsx(w,{htmlFor:"permanent",className:"font-normal",children:"Permanent"})]})]})]}),e.jsxs("div",{children:[e.jsx(w,{children:"Reason for Ban"}),e.jsx($,{placeholder:"Explain why this user is being banned...",value:l,onCh
1ange:o=>F(o.target.value),rows:4})]})]}),e.jsxs(ie,{children:[e.jsx(u,{variant:"outline",onClick:()=>b(!1),children:"Cancel"}),e.jsx(u,{onClick:Z,disabled:x,variant:"destructive",children:"Ban User"})]})]})})]})},Oe=Ye({content:pe().trim().min(1,{message:"Comment cannot be empty"}).max(1e3,{message:"Comment must be less than 1000 characters"})}),yt=Ye({name:pe().trim().min(2,{message:"Please enter your name"}).max(60),email:pe().trim().email({message:"Please enter a valid email"}).max(255)}),Ue="aim_guest_identity",bt=()=>e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),Tt=({postId:E,listId:W,listEntryId:v,storySlug:_,user:c,isAdmin:N=!1,discussionPrompt:L})=>{var Me;const h=_?"story_slug":v?"list_entry_id":W?"list_id":"post_id",p=_||v||W||E,b=h==="story_slug"?"visual_story":h==="post_id"?"post":h==="list_id"?"list":"list_entry",D=it(),{signInWithGoogle:O}=ot(),{toast:l}=Ve(),[F,y]=i.useState([]),[C,x]=i.useState(""),[S,g]=i.useState(null),[P,I]=i.useState(""),[Z,o]=i.useState(!1),[f,U]=i.useState(!1),[T,z]=i.useState("newest"),[He,ge]=i.useState(null),[K,Q]=i.useState(null),[oe,V]=i.useState(""),[je,Je]=i.useState(!1),[M,le]=i.useState(null),[Y,ve]=i.useState(""),[ye,be]=i.useState(""),[we,Ne]=i.useState(!1),[_e,Ce]=i.useState([]),[Se,ke]=i.useState(!1),Ee=i.useRef(null),De=i.useRef(""),X=i.useRef(Date.now());i.useEffect(()=>{if(!E)return;let t=!1;return Ce([]),ke(!0),m.functions.invoke("generate-comment-starters",{body:{postId:E}}).then(({data:s})=>{!t&&Array.isArray(s==null?void 0:s.prompts)&&Ce(s.prompts)}).catch(()=>{}).finally(()=>{t||ke(!1)}),()=>{t=!0}},[E]);const We=t=>{const s=t.trim().endsWith("?");x(a=>{const n=s?`${t.trim()} `:`${t.trim().replace(/[.?!]+$/,"")} `;return a.trim()?`${a.replace(/\s+$/,"")} ${n}`:n}),window.setTimeout(()=>{const a=Ee.current;a&&(a.focus(),a.setSelectionRange(a.value.length,a.value.length))},50)};i.useEffect(()=>{try{const t=localStorage.getItem(Ue);if(t){const s=JSON.parse(t);ve(s.name||""),be(s.email||"")}}catch{}},[]),i.useEffect(()=>{A()},[p,h,T]),i.useEffect(()=>{const t=m.channel(`comments:${h}:${p}`).on("postgres_changes",{event:"*",schema:"public",table:"comments",filter:`${h}=eq.${p}`},()=>A()).subscribe();return()=>{m.removeChannel(t)}},[p,h]);const A=async()=>{o(!0);try{const{data:t,error:s}=await m.from("public_comments").select("id, content, created_at, updated_at, user_id, is_hidden, is_flagged, flag_reason, parent_id, guest_name").eq(h,p).order("created_at",{ascending:T==="oldest"});if(s)throw s;if(!t||t.length===0){y([]);return}const a=t.map(r=>r.id),n=[...new Set(t.map(r=>r.user_id).filter(Boolean))],[{data:d},{data:R},{data:j}]=await Promise.all([n.length?m.from("profiles").select("id, full_name").in("id",n):Promise.resolve({data:[]}),n.length?m.from("user_roles").select("user_id, role").in("user_id",n):Promise.resolve({data:[]}),m.from("comment_likes").select("comment_id").in("comment_id",a)]);let k=[];if(c){const{data:r}=await m.from("comment_likes").select("comment_id").eq("user_id",c.id).in("comment_id",a);k=(r==null?void 0:r.map(ee=>ee.comment_id))||[]}const q=new Map;(j||[]).forEach(r=>{q.set(r.comment_id,(q.get(r.comment_id)||0)+1)});const nt=new Map((d||[]).map(r=>[r.id,r])),rt=new Set((R||[]).filter(r=>["admin","editor","author"].includes(r.role)).map(r=>r.user_id)),Be=t.map(r=>({...r,profiles:r.user_id&&nt.get(r.user_id)||null,is_staff:r.user_id?rt.has(r.user_id):!1,likes_count:q.get(r.id)||0,user_has_liked:k.includes(r.id)})),Re=Be.filter(r=>!r.parent_id),ue=new Map;Be.forEach(r=>{if(r.parent_id){const ee=ue.get(r.parent_id)||[];ee.push(r),ue.set(r.parent_id,ee)}}),Re.forEach(r=>{r.replies=ue.get(r.id)||[]}),y(Re)}catch(t){console.error("Error fetching comments:",t)}finally{o(!1)}},de=async(t,s,a)=>{var n,d,R;U(!0);try{const{data:j,error:k}=await m.functions.invoke("submit-comment",{body:{targetType:b,targetId:p,content:t,parentId:s,guestName:a==null?void 0:a.name,guestEmail:a==null?void 0:a.email,hp:De.current,elapsedMs:Date.now()-X.current}}),q=(j==null?void 0:j.error)||(k?(R=await((d=(n=k==null?void 0:k.context)==null?void 0:n.json)==null?void 0:d.call(n).catch(()=>null)))==null?void 0:R.error:null);if(k||q)return l({title:"Couldn't post your comment",description:q||"Please try again in a moment.",variant:"destructive"}),!1;if(a)try{localStorage.setItem(Ue,JSON.stringify(a))}catch{}return l({title:j!=null&&j.flagged?"Comment submitted for review":"Comment posted",description:j!=null&&j.flagged?"It will appear once our team takes a quick look.":"Thanks for joining the conversation."}),X.current=Date.now(),A(),!0}catch{return l({title:"Error",description:"Failed to post comment.",variant:"destructive"}),!1}finally{U(!1)}},Fe=async(t,s)=>{let a;try{a=Oe.parse({content:t}).content}catch(n){n instanceof fe&&l({title:"Validation error",description:n.issues[0].message,variant:"destructive"});return}if(c){await de(a,s)&&(s?(V(""),Q(null)):x(""));return}le({parentId:s,content:a})},Ze=async()=>
1{if(M)try{const t=yt.parse({name:Y,email:ye});await de(M.content,M.parentId,t)&&(M.parentId?(V(""),Q(null)):x(""),le(null))}catch(t){t instanceof fe&&l({title:"Check your details",description:t.issues[0].message,variant:"destructive"})}},Ke=async()=>{Ne(!0);const t=D.pathname+D.search;try{M&&sessionStorage.setItem("aim_pending_comment",JSON.stringify({...M,targetId:p,targetType:b})),localStorage.setItem("auth_redirect",t);const{error:s}=await O(t);s?l({variant:"destructive",title:"Error signing in",description:s.message}):dt({method:"google"})}catch{l({variant:"destructive",title:"Error",description:"Failed to sign in with Google."})}finally{Ne(!1)}};i.useEffect(()=>{if(!c)return;const t=sessionStorage.getItem("aim_pending_comment");if(t)try{const s=JSON.parse(t);sessionStorage.removeItem("aim_pending_comment"),s.targetId===p&&s.content&&de(s.content,s.parentId??null)}catch{sessionStorage.removeItem("aim_pending_comment")}},[c,p]);const Qe=async t=>{if(P.trim())try{const s=Oe.parse({content:P}),{error:a}=await m.from("comments").update({content:s.content}).eq("id",t);if(a)throw a;g(null),I(""),l({title:"Comment updated"}),A()}catch(s){s instanceof fe?l({title:"Validation error",description:s.issues[0].message,variant:"destructive"}):l({title:"Error",description:"Failed to update comment.",variant:"destructive"})}},Xe=async t=>{if(!confirm("Are you sure you want to delete this comment?"))return;const{error:s}=await m.from("comments").delete().eq("id",t);if(s){l({title:"Error",description:"Failed to delete comment.",variant:"destructive"});return}l({title:"Comment deleted"}),A()},et=async(t,s)=>{if(!c){l({title:"Sign in to recommend",description:"You can still comment as a guest without signing in."});return}ge(t);try{if(s){const{error:n}=await m.from("comment_likes").delete().eq("comment_id",t).eq("user_id",c.id);if(n)throw n}else{const{error:n}=await m.from("comment_likes").insert({comment_id:t,user_id:c.id});if(n)throw n}const a=n=>n.map(d=>d.id===t?{...d,likes_count:s?d.likes_count-1:d.likes_count+1,user_has_liked:!s}:d.replies?{...d,replies:a(d.replies)}:d);y(a)}catch{l({title:"Error",description:"Failed to update recommendation.",variant:"destructive"})}finally{ge(null)}},tt=t=>{const s=new Date(t),a=Math.floor((Date.now()-s.getTime())/1e3),n=Math.floor(a/60),d=Math.floor(n/60),R=Math.floor(d/24);return a<60?"Just now":n<60?`${n}m ago`:d<24?`${d}h ago`:R<7?`${R}d ago`:s.toLocaleDateString("en-IN",{month:"short",day:"numeric"})},ce=t=>{var s;return((s=t.profiles)==null?void 0:s.full_name)||t.guest_name||"Reader"},st=t=>ce(t).split(" ").map(a=>a[0]).join("").toUpperCase().slice(0,2),B=i.useMemo(()=>F.filter(t=>!t.is_hidden||N),[F,N]),me=i.useMemo(()=>{let t=0;return B.forEach(s=>{t+=1,s.replies&&(t+=s.replies.filter(a=>!a.is_hidden||N).length)}),t},[B,N]),at=je?B:B.slice(0,5),Ie=(t,s=!1,a=0)=>e.jsxs(H.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.3,delay:Math.min(a,6)*.04},className:`group py-5 transition-colors duration-200 ${t.is_hidden?"opacity-60":""} ${s?"pl-6 sm:pl-10 border-l-2 border-muted ml-3 sm:ml-4":"border-b border-border/50"} ${t.is_staff?"bg-primary/[0.04] rounded-sm px-3":""}`,children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx($e,{className:"h-8 w-8 flex-shrink-0",children:e.jsx(Le,{className:`text-xs font-medium ${t.is_staff?"bg-primary text-primary-foreground":"bg-primary/10 text-primary"}`,children:st(t)})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-sm text-foreground",children:ce(t)}),t.is_staff&&e.jsxs(xe,{className:"text-[10px] px-1.5 py-0 gap-1",children:[e.jsx(ft,{className:"h-3 w-3"}),"AIM"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:tt(t.created_at)}),t.is_flagged&&e.jsx(xe,{variant:"destructive",className:"text-[10px] px-1.5 py-0",children:"Flagged"}),t.is_hidden&&e.jsx(xe,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"Hidden"})]}),S===t.id?e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{value:P,onChange:n=>I(n.target.value),className:"min-h-[80px] text-sm resize-none rounded-none border-border/50 focus:border-primary"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{size:"sm",onClick:()=>Qe(t.id),className:"rounded-none h-7 text-xs",children:"Save"}),e.jsx(u,{size:"sm",variant:"ghost",onClick:()=>{g(null),I("")},className:"rounded-none h-7 text-xs",children:"Cancel"})]})]}
1):e.jsx("p",{className:"text-sm text-foreground/85 leading-relaxed whitespace-pre-wrap",children:t.content}),e.jsxs("div",{className:"flex items-center gap-4 mt-3",children:[e.jsxs("button",{onClick:()=>et(t.id,t.user_has_liked),disabled:He===t.id,className:`flex items-center gap-1.5 text-xs transition-colors ${t.user_has_liked?"text-primary":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(pt,{className:`h-3.5 w-3.5 transition-transform hover:scale-110 ${t.user_has_liked?"fill-current":""}`}),e.jsx("span",{children:t.likes_count>0?t.likes_count:""})]}),!s&&e.jsxs("button",{onClick:()=>{Q({id:t.id,name:ce(t)}),V(""),X.current=Date.now()},className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(gt,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Reply"})]}),c&&(t.user_id&&c.id===t.user_id||N)&&e.jsxs(ct,{children:[e.jsx(mt,{asChild:!0,children:e.jsx("button",{className:"opacity-0 group-hover:opacity-100 transition-opacity","aria-label":"Comment options",children:e.jsx(jt,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsxs(ut,{align:"start",className:"rounded-none",children:[t.user_id&&c.id===t.user_id&&e.jsxs(e.Fragment,{children:[e.jsx(J,{onClick:()=>{g(t.id),I(t.content)},children:"Edit"}),e.jsx(J,{onClick:()=>Xe(t.id),className:"text-destructive",children:"Delete"})]}),N&&e.jsx(vt,{commentId:t.id,userId:t.user_id||"",isHidden:t.is_hidden,isFlagged:t.is_flagged,onUpdate:A,asDropdownItems:!0})]})]})]}),e.jsx(he,{children:(K==null?void 0:K.id)===t.id&&e.jsxs(H.form,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},onSubmit:n=>{n.preventDefault(),Fe(oe,t.id)},className:"mt-4 space-y-2 overflow-hidden",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Replying to ",K.name]}),e.jsx($,{value:oe,onChange:n=>V(n.target.value),placeholder:"Write a reply...",maxLength:1e3,className:"min-h-[70px] text-sm resize-none rounded-none border-border/50 focus:border-primary"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{type:"submit",size:"sm",disabled:f||!oe.trim(),className:"rounded-none h-7 text-xs",children:f?"Posting...":"Post reply"}),e.jsx(u,{type:"button",size:"sm",variant:"ghost",onClick:()=>{Q(null),V("")},className:"rounded-none h-7 text-xs",children:"Cancel"})]})]})})]})]}),t.replies&&t.replies.length>0&&e.jsx("div",{className:"mt-4",children:t.replies.filter(n=>!n.is_hidden||N).map((n,d)=>Ie(n,!0,d))})]},t.id);return e.jsxs("section",{id:"comments",className:"mt-12 mb-6 scroll-mt-24",children:[e.jsxs("div",{className:"flex items-baseline justify-between border-b border-foreground
1/80 pb-2 mb-6",children:[e.jsxs("h2",{className:"font-body text-xs uppercase tracking-[0.18em] text-foreground flex items-center gap-2",children:[e.jsx(ht,{className:"h-3.5 w-3.5"}),"Discussion ",me>0&&e.jsxs("span",{className:"text-muted-foreground",children:["(",me,")"]})]}),me>1&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("button",{onClick:()=>z("newest"),className:T==="newest"?"text-foreground font-medium":"text-muted-foreground hover:text-foreground",children:"Newest"}),e.jsx("span",{className:"text-border",children:"/"}),e.jsx("button",{onClick:()=>z("oldest"),className:T==="oldest"?"text-foreground font-medium":"text-muted-foreground hover:text-foreground",children:"Oldest"})]})]}),e.jsxs(H.div,{initial:{opacity:0,y:8},whileInView:{opacity:1,y:0},viewport:{once:!0},transition:{duration:.4},className:"mb-8",children:[e.jsx("p",{className:"font-serif text-lg sm:text-xl text-foreground mb-3 leading-snug",children:(L==null?void 0:L.trim())||"What's your take on this story?"}),(Se||_e.length>0)&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground mb-2",children:"Start with a thought"}),Se?e.jsx("div",{className:"flex flex-wrap gap-2",children:[0,1,2].map(t=>e.jsx("div",{className:"h-7 w-44 bg-muted/60 animate-pulse rounded-none"},t))}):e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(he,{children:_e.map((t,s)=>e.jsx(H.button,{type:"button",initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.25,delay:s*.05},onClick:()=>We(t),className:"text-xs text-left px-3 py-1.5 border border-border/70 text-muted-foreground hover:text-foreground hover:border-foreground transition-colors max-w-full",children:t},t))})})]}),e.jsx("form",{onSubmit:t=>{t.preventDefault(),Fe(C,null)},className:"space-y-3",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx($e,{className:"h-9 w-9 flex-shrink-0 hidden sm:flex",children:e.jsx(Le,{className:"bg-primary/10 text-primary text-sm font-medium",children:(((Me=c==null?void 0:c.email)==null?void 0:Me[0])||(Y==null?void 0:Y[0])||"?").toUpperCase()})}),e.jsxs("div",{className:"flex-1",children:[e.jsx($,{ref:Ee,value:C,onFocus:()=>{C||(X.current=Date.now())},onChange:t=>x(t.target.value),placeholder:"Share your thoughts â no account needed",className:"min-h-[96px] text-sm resize-none rounded-none border-border/60 focus:border-primary bg-transparent",maxLength:1e3}),e.jsx("input",{type:"text",tabIndex:-1,autoComplete:"off","aria-hidden":"true",onChange:t=>De.current=t.target.value,className:"absolute w-0 h-0 opacity-0 pointer-events-none"}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[C.length,"/1000"]}),e.jsxs(u,{type:"submit",size:"sm",disabled:f||!C.trim(),className:"rounded-none gap-2",children:[e.jsx(xt,{className:"h-3.5 w-3.5"}),f?"Posting...":"Post comment"]})]})]})]})}),e.jsx(he,{children:M&&e.jsx(H.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"overflow-hidden",children:e.jsxs("div",{className:"mt-4 border border-border/60 p-4 sm:p-5 bg-muted/20",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Almost there â how should we credit you?"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Your comment is saved. Your email is never shown publicly."})]}),e.jsx("button",{onClick:()=>le(null),"aria-label":"Cancel",className:"text-muted-foreground hover:text-foreground",children:e.jsx(lt,{className:"h-4 w-4"})})]}),e.jsxs("button",{onClick:Ke,disabled:we,className:"inline-flex items-center justify-center gap-2 w-full px-4 py-2.5 bg-foreground text-background text-sm font-medium rounded-sm hover:bg-foreground
1/90 transition-colors disabled:opacity-70",children:[e.jsx(bt,{}),we?"Signing in...":"Continue with Google"]}),e.jsxs("div",{className:"flex items-center gap-3 my-4",children:[e.jsx("div",{className:"flex-1 h-px bg-border"}),e.jsx("span",{className:"text-[10px] text-muted-foreground uppercase tracking-widest",children:"or post as guest"}),e.jsx("div",{className:"flex-1 h-px bg-border"})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-2",children:[e.jsx(Pe,{value:Y,onChange:t=>ve(t.target.value),placeholder:"Your name",maxLength:60,className:"rounded-none h-9 text-sm"}),e.jsx(Pe,{value:ye,onChange:t=>be(t.target.value),placeholder:"Email (not published)",type:"email",maxLength:255,className:"rounded-none h-9 text-sm"})]}),e.jsx(u,{onClick:Ze,disabled:f,size:"sm",variant:"outline",className:"rounded-none mt-3 w-full",children:f?"Posting...":"Post as guest"})]})})})]}),Z&&F.length===0?e.jsx("div",{className:"py-10 text-center",children:e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-primary mx-auto"})}):B.length===0?e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No comments yet â be the first to share your view."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{children:at.map((t,s)=>Ie(t,!1,s))}),!je&&B.length>5&&e.jsxs("button",{onClick:()=>Je(!0),className:"mt-5 text-xs uppercase tracking-[0.14em] text-foreground border-b border-foreground
1/40 hover:border-foreground pb-0.5 transition-colors",children:["View all ",B.length," comments"]})]})]})};export{Tt 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.