// @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{qi as t}from"./lucide-icons-BdRF0moN.js";import{t as n}from"./jsx-runtime-By8HlURe.js";import{t as r}from"./dist-DQ82bf9M.js";import{u as i}from"./esm-CRVqHnq2.js";import{t as a}from"./useQuery-rCAlChE8.js";import{o}from"./react-intl-eZirkCBg.js";import{l as s,t as c}from"./useCurrentUser-C6OJJlWo.js";import{n as l}from"./useFollowActions-cve70R08.js";import{n as u,o as d,r as f,t as p}from"./avatar--oX_CTF4.js";import{n as m}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as h}from"./skeleton-CVls4GW9.js";import{t as g}from"./timeAgo-BXjjbyXp.js";import{s as _}from"./index-CYEZWNq6.js";var v=e(t(),1),y=n();function b({kinds:e,feedPath:t,feedLabel:n,limit:i=5,emptyMessage:s}){let u=o(),{nostr:d}=r(),{user:f}=c(),{data:p}=l(),{data:g}=_(),b=p?.pubkeys,S=s??u.formatMessage({id:`widgets.feed.empty`,defaultMessage:`No content yet.`}),C=e.join(`,`),w=f&&b?.length?b:g,{data:T,isLoading:E}=a({queryKey:[`widget-feed`,C,f?`follows`:`curator`,i],queryFn:async()=>d.query([{kinds:e,limit:i,...w?{authors:w}:{}}]),staleTime:5*6e4,enabled:f?b!==void 0:g!==void 0}),D=(0,v.useMemo)(()=>(T??[]).slice(0,i),[T,i]);return E?(0,y.jsx)(`div`,{className:`space-y-3 p-1`,children:Array.from({length:3}).map((e,t)=>(0,y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(h,{className:`size-5 rounded-full`}),(0,y.jsx)(h,{className:`h-3 w-20`})]}),(0,y.jsx)(h,{className:`h-3.5 w-full`})]},t))}):D.length===0?(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground p-1`,children:S}):(0,y.jsxs)(`div`,{className:`space-y-0.5`,children:[D.map(e=>(0,y.jsx)(x,{event:e},e.id)),(0,y.jsx)(`div`,{className:`pt-1 px-2`,children:(0,y.jsx)(m,{to:t,className:`text-xs text-primary hover:underline`,children:n})})]})}function x({event:e}){let t=o(),n=s(e.pubkey).data?.metadata,r=d(n),a=n?.name||n?.display_name||t.formatMessage({id:`common.anonymous`,defaultMessage:`Anonymous`}),c=(0,v.useMemo)(()=>i.neventEncode({id:e.id,author:e.pubkey}),[e]),l=e.tags.find(([e])=>e===`title`)?.[1],h=(0,v.useMemo)(()=>{if(l)return l;let n=e.content.replace(/https?:\/\/\S+/g,``).trim();return n.length>100?n.slice(0,100)+`...`:n||t.formatMessage({id:`widgets.common.media`,defaultMessage:`(media)`})},[e.content,l,t]);return(0,y.jsxs)(m,{to:`/${c}`,className:`block hover:bg-secondary/40 px-2 py-2 rounded-lg transition-colors`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[(0,y.jsxs)(p,{shape:r,className:`size-4`,children:[(0,y.jsx)(f,{src:n?.picture,alt:a}),(0,y.jsx)(u,{className:`bg-primary/20 text-primary text-[8px]`,children:a[0]?.toUpperCase()})]}),(0,y.jsx)(`span`,{className:`text-xs font-semibold truncate`,children:a}),(0,y.jsxs)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[`· `,g(e.created_at)]})]}),(0,y.jsx)(`p`,{className:`text-[13px] text-muted-foreground leading-snug line-clamp-2`,children:h})]})}export{b as FeedWidget};
// @license-end
