// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
// @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{a as t,qi as n}from"./lucide-icons-BdRF0moN.js";import{t as r}from"./jsx-runtime-By8HlURe.js";import{t as i}from"./dist-DQ82bf9M.js";import{t as a}from"./useQuery-rCAlChE8.js";import{l as o}from"./useCurrentUser-C6OJJlWo.js";import{n as s,o as c,r as l,t as u}from"./avatar--oX_CTF4.js";import{n as d}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as f}from"./useProfileUrl-DoFhqUUR.js";import{r as p}from"./BioContent-BjUPDB1O.js";import{t as m}from"./usePortalContainer-mvErHojv.js";import{t as h}from"./skeleton-CVls4GW9.js";import{E as g}from"./EmbeddedPost-Bb-ngBHS.js";import{t as _}from"./timeAgo-BXjjbyXp.js";import{t as v}from"./getDisplayName-B6lnEGRj.js";var y=e(n(),1),b=r();function x(e,t){return e.find(([e])=>e===t)?.[1]}function S(e){let{nostr:t}=i(),n=e?`${e.kind}:${e.pubkey}:${x(e.tags,`d`)??``}`:void 0;return a({queryKey:[`event-comments`,n??e?.id??``],queryFn:async({signal:r})=>{if(!e)return[];let i=AbortSignal.any([r,AbortSignal.timeout(5e3)]),a=e.kind>=3e4&&e.kind<4e4&&n?[{kinds:[1111,1244],"#A":[n],limit:80}]:e.kind===1?[{kinds:[1,1111],"#e":[e.id],limit:80},{kinds:[1111],"#E":[e.id],limit:80}]:[{kinds:[1111],"#e":[e.id],limit:80}],o=await t.query(a,{signal:i}),s=new Set;return o.filter(e=>s.has(e.id)?!1:(s.add(e.id),!0)).sort((e,t)=>t.created_at-e.created_at)},enabled:!!e,staleTime:15e3,refetchInterval:2e4})}function C({event:e}){let t=o(e.pubkey),n=t.data?.metadata,r=c(n),i=v(n,e.pubkey),a=f(e.pubkey,n);return(0,b.jsxs)(`div`,{className:`flex gap-2.5 px-4 py-2.5 hover:bg-muted/30 transition-colors`,children:[(0,b.jsx)(p,{pubkey:e.pubkey,asChild:!0,children:(0,b.jsx)(d,{to:a,className:`shrink-0`,children:t.isLoading?(0,b.jsx)(h,{className:`size-7 rounded-full`}):(0,b.jsxs)(u,{shape:r,className:`size-7`,children:[(0,b.jsx)(l,{src:n?.picture,alt:i}),(0,b.jsx)(s,{className:`text-[10px] bg-primary/20 text-primary`,children:i[0]?.toUpperCase()})]})})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsxs)(`div`,{className:`flex items-baseline gap-1.5 mb-0.5`,children:[(0,b.jsx)(p,{pubkey:e.pubkey,asChild:!0,children:(0,b.jsx)(d,{to:a,className:`text-xs font-semibold hover:underline truncate max-w-[140px]`,children:i})}),(0,b.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:_(e.created_at)})]}),(0,b.jsx)(`p`,{className:`text-xs text-foreground/90 leading-relaxed break-words line-clamp-4`,children:e.content})]})]})}function w(){return(0,b.jsxs)(`div`,{className:`flex gap-2.5 px-4 py-2.5`,children:[(0,b.jsx)(h,{className:`size-7 rounded-full shrink-0`}),(0,b.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,b.jsx)(h,{className:`h-3 w-20`}),(0,b.jsx)(h,{className:`h-3 w-full`}),(0,b.jsx)(h,{className:`h-3 w-3/4`})]})]})}function T({event:e,open:n,onClose:r}){let{data:i=[],isLoading:a,dataUpdatedAt:o}=S(e),[s,c]=(0,y.useState)(void 0),l=(0,y.useMemo)(()=>{if(o===0)return[];let e=new Set;return i.filter(t=>e.has(t.id)?!1:(e.add(t.id),!0))},[i,o]),u=(0,y.useCallback)(e=>{c(e??void 0)},[]);return n?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`fixed inset-0 z-[200] bg-black/60 backdrop-blur-sm cursor-pointer animate-in fade-in-0 duration-200`,onClick:e=>{e.stopPropagation(),r()}}),(0,b.jsx)(`div`,{className:`fixed inset-0 z-[200] flex items-center justify-center p-4 pointer-events-none`,children:(0,b.jsx)(`div`,{ref:u,className:`pointer-events-auto w-full max-w-lg max-h-[80vh] flex flex-col bg-background/90 backdrop-blur-md rounded-2xl shadow-2xl overflow-hidden animate-in zoom-in-95 fade-in-0 duration-200`,onClick:e=>e.stopPropagation(),children:(0,b.jsxs)(m,{value:s,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 shrink-0`,children:[(0,b.jsx)(`h3`,{className:`font-semibold text-sm`,children:e?.kind===1?`Replies`:`Comments`}),(0,b.jsx)(`button`,{className:`p-1.5 rounded-full hover:bg-secondary transition-colors text-muted-foreground`,onClick:r,children:(0,b.jsx)(t,{className:`size-4`,strokeWidth:4})})]}),e&&(0,b.jsx)(`div`,{className:`shrink-0 -mb-px overflow-hidden`,children:(0,b.jsx)(g,{replyTo:e,compact:!0,placeholder:e?.kind===1?`Add a reply…`:`Add a comment…`})}),(0,b.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto divide-y divide-border/50`,children:a?(0,b.jsx)(`div`,{className:`py-2`,children:Array.from({length:5}).map((e,t)=>(0,b.jsx)(w,{},t))}):l.length===0?(0,b.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e?.kind===1?`No replies yet. Be the first!`:`No comments yet. Be the first!`})}):l.map(e=>(0,b.jsx)(C,{event:e},e.id))})]})})})]}):null}export{T as t};
// @license-end
