// @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{Mt as t,Ni as n,Pi as r,_n as i,fn as a,ln as o,mt as s,qi as c,qr as l,r as u}from"./lucide-icons-BdRF0moN.js";import{t as d}from"./jsx-runtime-By8HlURe.js";import{t as f}from"./dist-DQ82bf9M.js";import{u as p}from"./esm-CRVqHnq2.js";import{h as ee}from"./useQuery-rCAlChE8.js";import{t as m}from"./useInfiniteQuery-BFtb_-3K.js";import{r as h}from"./EmbeddedNote-BKfkvcrg.js";import{t as g}from"./useAppContext-Ughdk2-Z.js";import{r as te}from"./useEncryptedSettings-DPGHcvzd.js";import{r as _}from"./react-intl-eZirkCBg.js";import{l as v,t as y}from"./useCurrentUser-C6OJJlWo.js";import{t as b}from"./utils-BFSTDHdM.js";import{t as x}from"./button-Cs26nq0r.js";import{n as S}from"./useFollowActions-cve70R08.js";import{o as C}from"./letterTypes-BLLFWtiN.js";import{i as w,n as T,o as E,r as D,t as O}from"./avatar--oX_CTF4.js";import{c as k,n as A}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{n as j,r as ne}from"./CustomEmoji-DRcU63lJ.js";import{n as re,t as M}from"./useProfileUrl-DoFhqUUR.js";import{_ as N,c as P,i as F,r as I,v as L,y as ie}from"./BioContent-BjUPDB1O.js";import{t as R}from"./skeleton-CVls4GW9.js";import{g as z,h as B,p as ae}from"./ComposeDialogContent-YxhSZA-Y.js";import{k as oe}from"./EmbeddedPost-Bb-ngBHS.js";import{t as se}from"./timeAgo-BXjjbyXp.js";import{i as ce,r as le}from"./useLinkPreview-CqNF97jn.js";import{u as ue}from"./quiz-kCjrdDeU.js";import{p as de}from"./extraKinds-BydAXtVV.js";import{c as fe}from"./LayoutContext-CjQBLGO-.js";import{t as pe}from"./useInView-DAJQSIvc.js";import{J as me,Y as he,r as V,tt as ge}from"./NoteCard-COwLfrJJ.js";import{t as _e}from"./SubHeaderBar-BYwNp4Nc.js";import{C as ve,M as ye,ft as be,o as xe,w as Se,y as Ce}from"./index-CYEZWNq6.js";import{a as we,n as Te,t as Ee}from"./LetterDetailSheet-B-TeR0v1.js";var H=e(c(),1),De=20;function U(e){return e.tags.findLast(([e])=>e===`e`)?.[1]}function Oe(e){let{event:t}=e,n=e.referencedEvent?.id??U(t);return(t.kind===7||t.kind===6||t.kind===16||t.kind===9735||t.kind===8333||t.kind===9802||t.kind===7849)&&n?t.kind===7&&(e.referencedEvent?.kind===0||t.tags.some(([e,t])=>e===`k`&&t===`0`))?t.id:t.kind===9802?`highlight:${n}:${t.id}`:`${t.kind===6||t.kind===16?`repost`:t.kind===9735||t.kind===8333?`zap`:String(t.kind)}:${n}`:t.id}function ke(e,t){let n=new Map,r=[];for(let i of e){let e=Oe(i);n.has(e)||(r.push(e),n.set(e,{key:e,kind:i.event.kind,actors:[],referencedEvent:i.referencedEvent,isNew:!1,newestAt:i.event.created_at}));let a=n.get(e);a.actors.some(e=>e.event.pubkey===i.event.pubkey)||(a.actors.push(i),t.has(i.event.id)&&(a.isNew=!0),i.event.created_at>a.newestAt&&(a.newestAt=i.event.created_at),!a.referencedEvent&&i.referencedEvent&&(a.referencedEvent=i.referencedEvent))}return r.map(e=>n.get(e))}function Ae(){let{nostr:e}=f(),t=ee(),{user:n}=y(),{settings:r,updateSettings:i}=te(),{data:a}=S(),o=r?.notificationPreferences,s=(0,H.useMemo)(()=>be(o),[o]),c=[...s].sort().join(`,`),l=(0,H.useMemo)(()=>a?.pubkeys??[],[a?.pubkeys]),u=o?.onlyFollowing===!0&&l.length>0?l:void 0,d=u?u.slice().sort().join(`,`):`all`,{data:p,isLoading:h,isFetched:g,hasNextPage:_,isFetchingNextPage:v,fetchNextPage:b}=m({queryKey:[`notifications`,n?.pubkey??``,c,d],queryFn:async({pageParam:r,signal:i})=>{if(!n)return{items:[],oldestTimestamp:Math.floor(Date.now()/1e3),newestRawTimestamp:0};let a={kinds:s,"#p":[n.pubkey],limit:De};u&&(a.authors=u),r&&(a.until=r);let o=await e.query([a],{signal:AbortSignal.any([i,AbortSignal.timeout(5e3)])}),c=(Array.isArray(o)?o:[]).filter(e=>e.pubkey!==n.pubkey).sort((e,t)=>t.created_at-e.created_at),l=c.length>0?Math.min(...c.map(e=>e.created_at)):Math.floor(Date.now()/1e3),d=c.length>0?Math.max(...c.map(e=>e.created_at)):0,f=[];for(let e of c)if(e.kind!==1&&e.kind!==1222&&e.kind!==1244&&e.kind!==8211){let t=U(e);t&&f.push(t)}let p=new Map;if(f.length>0){let n=[];for(let e of f){let r=t.getQueryData([`event`,e]);r?p.set(e,r):n.push(e)}if(n.length>0)try{let r=await e.query([{ids:n,limit:n.length}],{signal:AbortSignal.any([i,AbortSignal.timeout(5e3)])});for(let e of r)p.set(e.id,e),t.getQueryData([`event`,e.id])||t.setQueryData([`event`,e.id],e)}catch{}}return{items:c.flatMap(e=>{let t=e.kind!==1&&e.kind!==1222&&e.kind!==1244&&e.kind!==8211?U(e):void 0,r=t?p.get(t):void 0;return(e.kind===7||e.kind===6||e.kind===16||e.kind===9802||e.kind===7849)&&r&&r.pubkey!==n.pubkey?[]:[{event:e,referencedEvent:r}]}),oldestTimestamp:l,newestRawTimestamp:d}},getNextPageParam:e=>{if(!(!e||e.items.length===0))return e.oldestTimestamp-1},initialPageParam:void 0,enabled:!!n,staleTime:3e4}),x=(0,H.useMemo)(()=>{if(!p?.pages)return[];let e=new Set;return p.pages.flatMap(e=>e.items).filter(t=>e.has(t.event.id)?!1:(e.add(t.event.id),!0))},[p?.pages]),C=r==null?null:r.notificationsCursor??0,w=(0,H.useRef)(null),T=w.current===null?C:Math.max(w.current,C??0),E=(0,H.useMemo)(()=>p?.pages?Math.max(0,...p.pages.map(e=>e.newestRawTimestamp??0)):0,[p?.pages]),D=(0,H.useMemo)(()=>T===null?new Set:new Set(x.filter(e=>e.event.created_at>T).map(e=>e.event.id)),[x,T]),O=T!==null&&E>T;return{items:x,groupedItems:(0,H.useMemo)(()=>ke(x,D),[x,D]),newNotificationIds:D,hasUnread:O,markAsRead:(0,H.useCallback)(async()=>{if(!n||E===0||T===null)return;let e=E;if(!(e<=T)){w.current=e;try{await i.mutateAsync({notificationsCursor:e}),t.setQueriesData({queryKey:[`notifications-unread`,n.pubkey]},!1)}catch(e){console.error(`Failed to mark notifications as read:`,e),w.current=null}}},[n?.pubkey,E,T]),isLoading:h,hasFetched:g,hasNextPage:_??!1,isFetchingNextPage:v,fetchNextPage:b}}var W=32;function je(e,t){let n=new Set;for(let[r,i]of e.tags)r!==`p`||!i||i===t||n.add(i);return n.size<=W?[...n]:[...n].sort().slice(0,W)}function Me(e){if(e.length<2)return 1/0;let t=[...e].sort((e,t)=>e-t);return(t[t.length-1]-t[0])/(t.length-1)}function Ne(e,t={}){let n=new Set;if(e.length<5)return n;let{self:r,follows:i}=t,a=new Map;for(let t of e)if(!(t.pubkey===r||i?.has(t.pubkey)))for(let e of je(t,r)){let n=a.get(e);n||a.set(e,n={ids:[],authors:new Set,times:[]}),n.ids.push(t.id),n.authors.add(t.pubkey),n.times.push(t.created_at)}for(let e of a.values())if(!(e.authors.size<5)&&!(e.authors.size/e.ids.length<.8)&&!(Me(e.times)>10))for(let t of e.ids)n.add(t);return n}function Pe(){let{user:e}=y(),{data:t}=S(),n=e?.pubkey,r=t?.pubkeys,i=(0,H.useMemo)(()=>{if(r?.length)return new Set(r)},[r]);return{floodIds:(0,H.useCallback)(e=>{let t={...n===void 0?{}:{self:n},...i===void 0?{}:{follows:i}},r=ye(e,t);for(let n of Ne(e,t))r.add(n);return r},[n,i])}}var G=d(),Fe={0:`profile`,1:`post`,4:`encrypted message`,6:`repost`,7:`reaction`,8:`badge award`,16:`repost`,20:`photo`,21:`video`,22:`video`,62:`request to vanish`,1063:`file`,1068:`poll`,11:`post`,1111:`comment`,1222:`voice message`,1244:`voice message`,1311:`live chat message`,1617:`patch`,1618:`pull request`,1619:`pull request update`,1621:`issue`,1630:`status update`,1631:`status update`,1632:`status update`,1633:`status update`,9802:`highlight`,2256:`tarot reading`,10002:`relay list`,39701:`web bookmark`,15683:`Love List`,31871:`attestation`,1984:`report`,2473:`bird detection`,12473:`Birdex`,3367:`color moment`,7516:`found log`,5128:`nsite snapshot`,15128:`nsite`,16767:`theme`,10008:`profile badges`,30008:`badge set`,30009:`badge`,30023:`article`,33953:`ebook`,34609:`magazine`,39731:`magazine issue`,30030:`emoji pack`,30054:`podcast episode`,30055:`podcast trailer`,3063:`Zapstore asset`,30063:`Zapstore release`,30311:`stream`,30312:`room`,30313:`meeting`,30315:`status`,30402:`listing`,30617:`repository`,30618:`repository update`,30817:`custom NIP`,31922:`calendar event`,31923:`calendar event`,32267:`Zapstore app`,34139:`playlist`,34236:`short video`,34550:`community`,35128:`nsite`,36767:`theme`,36787:`track`,37381:`Magic deck`,37516:`treasure`,37849:`quiz`,7849:`quiz result`,30621:`constellation`,39089:`follow pack`},Ie=new Set([`1`,`11`,`1111`,`1222`,`1244`]),Le=new Set([1,1111]);function K(e){return e===void 0?`post`:Fe[e]??`post`}function Re(e,t){let{content:n}=e;if(!n.includes(`nostr:`))return!1;let r=p.npubEncode(t);if(n.includes(`nostr:${r}`))return!0;let i=n.matchAll(/nostr:(nprofile1[a-z0-9]+)/g);for(let e of i)try{let n=p.decode(e[1]);if(n.type===`nprofile`&&n.data.pubkey===t)return!0}catch{}return!1}function ze(){let{config:e}=g();Se({title:`Notifications | ${e.appName}`,description:`Your Nostr notifications`}),fe({hasSubHeader:!0});let[t,n]=(0,H.useState)(`all`),{user:r}=y(),a=ee(),{groupedItems:o,hasUnread:s,isLoading:c,hasFetched:l,markAsRead:u,hasNextPage:d,isFetchingNextPage:f,fetchNextPage:p}=Ae(),{isMuted:m}=Ce(),{floodIds:h}=Pe(),te=(0,H.useCallback)(async()=>{await a.invalidateQueries({queryKey:[`notifications`,r?.pubkey??``]})},[a,r?.pubkey]);(0,H.useEffect)(()=>{if(!r||!s)return;let e=setTimeout(()=>{u()},1e3);return()=>clearTimeout(e)},[r,s,u]);let{ref:_,inView:v}=pe({threshold:0,rootMargin:`400px`});(0,H.useEffect)(()=>{v&&d&&!f&&p()},[v,d,f,p]),(0,H.useEffect)(()=>{d&&!f&&o.length>0&&o.length<=20&&p()},[d,f,o.length,p]);let b=(0,H.useMemo)(()=>{let e=o;return e=e.filter(e=>e.actors.every(e=>!m(e.event))),t===`mentions`&&(e=e.filter(e=>e.kind!==1&&e.kind!==1111?!1:r?Re(e.actors[0].event,r.pubkey):!1)),e},[o,t,m,r]),x=(0,H.useMemo)(()=>{let e=[];for(let t of b)if(Le.has(t.kind))for(let n of t.actors)e.push(n.event);return e.length>0?h(e):new Set},[b,h]),S=(0,H.useMemo)(()=>{if(x.size===0)return b.map(e=>({type:`group`,key:e.key,group:e}));let e=[];for(let t of b){let n=t.actors.every(e=>x.has(e.event.id)),r=e[e.length-1];n?r?.type===`flood`?r.groups.push(t):e.push({type:`flood`,key:`flood:${t.key}`,groups:[t]}):e.push({type:`group`,key:t.key,group:t})}return e},[b,x]);return(0,G.jsxs)(`main`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(_e,{children:[{key:`all`,label:`All`},{key:`mentions`,label:`Mentions`}].map(({key:e,label:r})=>(0,G.jsx)(xe,{label:r,active:t===e,onClick:()=>n(e),className:`sidebar:py-5 sidebar:font-semibold`},e))}),(0,G.jsx)(`div`,{style:{height:20}}),(0,G.jsx)(ve,{onRefresh:te,children:r?c||!l?(0,G.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:4}).map((e,t)=>(0,G.jsx)(ut,{},t))}):S.length>0?(0,G.jsxs)(`div`,{children:[S.map(e=>e.type===`flood`?(0,G.jsx)(Be,{groups:e.groups},e.key):(0,G.jsx)(q,{group:e.group},e.key)),d&&(0,G.jsx)(`div`,{ref:_,className:`py-4`,children:f&&(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(i,{className:`size-5 animate-spin text-muted-foreground`})})})]}):(0,G.jsx)(`div`,{className:`py-16 text-center text-muted-foreground`,children:`No notifications yet.`}):(0,G.jsx)(`div`,{className:`py-16 text-center text-muted-foreground`,children:`Log in to see your notifications.`})})]})}function q({group:e}){let t=e.actors.length===1;switch(e.kind){case 7:return t?(0,G.jsx)(Ge,{item:e.actors[0],isNew:e.isNew}):(0,G.jsx)(Ye,{group:e});case 6:case 16:return t?(0,G.jsx)(Ke,{item:e.actors[0],isNew:e.isNew}):(0,G.jsx)(Xe,{group:e});case 9735:case 8333:return t?(0,G.jsx)(qe,{item:e.actors[0],isNew:e.isNew}):(0,G.jsx)(Ze,{group:e});case 1:return(0,G.jsx)(Qe,{item:e.actors[0],isNew:e.isNew});case 1111:return(0,G.jsx)($e,{item:e.actors[0],isNew:e.isNew});case 8:return t?(0,G.jsx)(ct,{item:e.actors[0],isNew:e.isNew}):(0,G.jsx)(lt,{group:e});case C:return(0,G.jsx)(et,{item:e.actors[0],isNew:e.isNew});case 9802:return t?(0,G.jsx)(nt,{item:e.actors[0],isNew:e.isNew}):(0,G.jsx)(rt,{group:e});case 7849:return t?(0,G.jsx)(at,{item:e.actors[0],isNew:e.isNew}):(0,G.jsx)(ot,{group:e});default:return null}}function Be({groups:e}){let[t,n]=(0,H.useState)(!1);return e.length===0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`button`,{onClick:()=>n(e=>!e),className:`flex items-center gap-2 px-4 py-3 w-full text-left text-sm text-muted-foreground hover:text-foreground transition-colors group border-b border-border`,children:[(0,G.jsx)(s,{className:`size-4 shrink-0`}),(0,G.jsx)(`span`,{className:`group-hover:underline`,children:t?(0,G.jsx)(_,{id:`notifications.floodHide`,defaultMessage:`Hide {count} {count, plural, one {notification} other {notifications}} marked as spam`,values:{count:e.length}}):(0,G.jsx)(_,{id:`notifications.floodShow`,defaultMessage:`{count} {count, plural, one {notification} other {notifications}} marked as spam`,values:{count:e.length}})})]}),t&&e.map(e=>(0,G.jsx)(q,{group:e},e.key))]})}function J({isNew:e,children:t}){return(0,G.jsxs)(`div`,{className:b(`relative border-b border-border`,e&&`bg-primary/5`),children:[e&&(0,G.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-1 bg-primary z-10`}),t]})}function Y({item:e}){let t=e.event.tags.findLast(([e])=>e===`e`),n=t?.[1],r=t?.[2]||void 0,i=t?.[4]||e.event.tags.find(([e])=>e===`p`)?.[1]||void 0,{data:a}=le(e.referencedEvent?void 0:n,r?[r]:void 0,i),o=e.referencedEvent??a;return o?(0,G.jsx)(V,{event:o,className:`border-0`,hideKindHeader:!0}):null}var Ve=5;function He({actors:e}){let t=e.slice(0,Ve),n=e.length-Ve;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[t.map(e=>(0,G.jsx)(Ue,{pubkey:e.event.pubkey},e.event.id)),n>0&&(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground font-medium pl-0.5`,children:[`+`,n,` more`]})]})}function Ue({pubkey:e}){let t=v(e).data?.metadata,n=t?.name??t?.display_name??`Anonymous`,r=M(e,t),i=E(t),a=!!i;return(0,G.jsx)(I,{pubkey:e,asChild:!0,children:(0,G.jsx)(A,{to:r,title:n,className:`shrink-0`,style:a?w:void 0,children:(0,G.jsxs)(O,{className:b(`size-7`,!a&&`ring-2 ring-background`),shape:i,children:[t?.picture&&(0,G.jsx)(D,{src:t.picture,alt:n}),(0,G.jsx)(T,{className:`text-[10px]`,children:n.slice(0,2).toUpperCase()})]})})})}function X({actors:e,icon:t,action:n}){let r=e[0],i=e[1],a=e.length,o=We(r.event.pubkey),s=We(i?.event.pubkey??``),c;return c=a===1?(0,G.jsx)(Z,{pubkey:r.event.pubkey,name:o}):a===2?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Z,{pubkey:r.event.pubkey,name:o}),` and `,(0,G.jsx)(Z,{pubkey:i.event.pubkey,name:s})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Z,{pubkey:r.event.pubkey,name:o}),` and ${a-1} others`]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 pt-3 pb-2`,children:[(0,G.jsx)(He,{actors:e}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm`,children:[(0,G.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:t}),(0,G.jsx)(`span`,{className:`font-medium min-w-0 truncate`,children:c}),(0,G.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:n})]})]})}function We(e){let t=v(e||`dummy`);return t.data?.metadata?.name??t.data?.metadata?.display_name??`Anonymous`}function Z({pubkey:e,name:t}){let n=v(e),r=n.data?.metadata;return(0,G.jsx)(I,{pubkey:e,asChild:!0,children:(0,G.jsx)(A,{to:M(e,r),className:`font-bold hover:underline`,children:n.data?.event?(0,G.jsx)(j,{tags:n.data.event.tags,children:t}):t})})}function Ge({item:e,isNew:t}){let n=e.referencedEvent?.kind===0||e.event.tags.some(([e,t])=>e===`a`&&t?.startsWith(`0:`)),r=n?`profile`:K(e.referencedEvent?.kind);return(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:b(`px-4 pt-3`,n&&`pb-3`),children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:(0,G.jsx)(`span`,{className:`text-base leading-none size-4 flex items-center justify-center`,children:(0,G.jsx)(ne,{content:e.event.content.trim(),tags:e.event.tags,className:`inline-block h-4 w-4 object-contain`})}),action:(0,G.jsx)(Q,{event:e.event,children:`reacted to your ${r}`})})}),!n&&(0,G.jsx)(Y,{item:e})]})}function Ke({item:e,isNew:t}){let n=K(e.referencedEvent?.kind);return(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:(0,G.jsx)(de,{className:`size-4 text-accent`}),action:(0,G.jsx)(Q,{event:e.event,children:`reposted your ${n}`})})}),(0,G.jsx)(Y,{item:e})]})}function Q({event:e,children:t}){let n=(0,H.useMemo)(()=>e?`/${ce(e)}`:void 0,[e]);return n?(0,G.jsx)(A,{to:n,className:`hover:underline`,children:t}):(0,G.jsx)(G.Fragment,{children:t})}function qe({item:e,isNew:t}){let{event:n}=e,r=(0,H.useMemo)(()=>B(n),[n]),i=(0,H.useMemo)(()=>z(n),[n]),a=(0,H.useMemo)(()=>ae(n),[n]),{format:o}=h(),s=n.kind===8333&&a>1?a-1:0,c=`zapped you${s>0?` and ${s.toLocaleString()} ${s===1?`other`:`others`}`:``}${r>0?` ${o(r)}`:``}`,l=n.tags.some(([e])=>e===`e`)?void 0:n.tags.find(([e])=>e===`p`)?.[1];return(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:i,icon:(0,G.jsx)(u,{className:`size-4 text-amber-500 fill-amber-500`}),action:(0,G.jsx)(Q,{event:n,children:c})})}),l?(0,G.jsx)(Je,{recipientPubkey:l,timestamp:n.created_at}):(0,G.jsx)(Y,{item:e})]})}function Je({recipientPubkey:e,timestamp:t}){let n=v(e),r=n.data?.metadata,i=E(r),a=r?.name??r?.display_name??`Anonymous`,o=M(e,r),s=r?.nip05,{data:c,isPending:l}=re(s,e);return(0,G.jsx)(`div`,{className:`px-4 pb-3 pt-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[n.isLoading?(0,G.jsx)(R,{className:`size-11 rounded-full shrink-0`}):(0,G.jsx)(I,{pubkey:e,asChild:!0,children:(0,G.jsx)(A,{to:o,className:`shrink-0`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(O,{shape:i,className:`size-11`,children:[(0,G.jsx)(D,{src:r?.picture,alt:a}),(0,G.jsx)(T,{className:`bg-primary/20 text-primary text-sm`,children:a[0]?.toUpperCase()})]})})}),n.isLoading?(0,G.jsxs)(`div`,{className:`min-w-0 min-h-[42px] flex flex-col justify-center space-y-1.5`,children:[(0,G.jsx)(R,{className:`h-4 w-28`}),(0,G.jsx)(R,{className:`h-3 w-36`})]}):(0,G.jsxs)(`div`,{className:`min-w-0 flex-1 min-h-[42px] flex flex-col justify-center`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(I,{pubkey:e,asChild:!0,children:(0,G.jsx)(A,{to:o,className:`font-bold text-[15px] hover:underline truncate`,onClick:e=>e.stopPropagation(),children:n.data?.event?(0,G.jsx)(j,{tags:n.data.event.tags,children:a}):a})}),r?.bot&&(0,G.jsx)(`span`,{className:`text-xs text-primary shrink-0`,title:`Bot account`,children:`🤖`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-muted-foreground min-w-0 pr-2`,children:[s&&l&&(0,G.jsx)(R,{className:`h-3 w-24`}),s&&l&&(0,G.jsx)(`span`,{className:`shrink-0`,children:`·`}),s&&c&&(0,G.jsx)(ge,{nip05:s,pubkey:e}),s&&c&&(0,G.jsx)(`span`,{className:`shrink-0`,children:`·`}),(0,G.jsx)(`span`,{className:`shrink-0 whitespace-nowrap`,children:se(t)})]})]})]})})}function Ye({group:e}){let t=e.actors[0].event,n=e.referencedEvent?.kind===0||t.tags.some(([e,t])=>e===`a`&&t?.startsWith(`0:`)),r=n?`profile`:K(e.referencedEvent?.kind);return(0,G.jsxs)(J,{isNew:e.isNew,children:[(0,G.jsx)(X,{actors:e.actors,icon:(0,G.jsx)(`span`,{className:`text-base leading-none size-4 flex items-center justify-center`,children:(0,G.jsx)(ne,{content:t.content.trim(),tags:t.tags,className:`inline-block h-4 w-4 object-contain`})}),action:(0,G.jsx)(Q,{event:t,children:`reacted to your ${r}`})}),!n&&(0,G.jsx)(Y,{item:e.actors[0]})]})}function Xe({group:e}){let t=K(e.referencedEvent?.kind);return(0,G.jsxs)(J,{isNew:e.isNew,children:[(0,G.jsx)(X,{actors:e.actors,icon:(0,G.jsx)(de,{className:`size-4 text-accent`}),action:(0,G.jsx)(Q,{event:e.actors[0].event,children:`reposted your ${t}`})}),(0,G.jsx)(Y,{item:e.actors[0]})]})}function Ze({group:e}){let t=(0,H.useMemo)(()=>{let t=0;for(let n of e.actors)t+=B(n.event);return t},[e.actors]),n=(0,H.useMemo)(()=>e.actors.map(e=>{let t=z(e.event);return t===e.event.pubkey?e:{...e,event:{...e.event,pubkey:t}}}),[e.actors]),{format:r}=h(),i=t>0?` ${r(t)}`:``;return(0,G.jsxs)(J,{isNew:e.isNew,children:[(0,G.jsx)(X,{actors:n,icon:(0,G.jsx)(u,{className:`size-4 text-amber-500 fill-amber-500`}),action:(0,G.jsx)(Q,{event:e.actors[0].event,children:`zapped you${i}`})}),(0,G.jsx)(Y,{item:e.actors[0]})]})}function Qe({item:e,isNew:t}){let n=oe(e.event);return(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:n?(0,G.jsx)(o,{className:`size-4 text-primary`}):(0,G.jsx)(r,{className:`size-4 text-primary`}),action:n?`replied to your note`:`mentioned you`})}),(0,G.jsx)(V,{event:e.event,className:`border-0`})]})}function $e({item:e,isNew:t}){let n=e.event.tags.find(([e])=>e===`k`)?.[1],r=n?parseInt(n,10):void 0,i=K(isNaN(r)?void 0:r),a=Ie.has(n??``)?`replied to your ${i}`:`commented on your ${i}`;return(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:(0,G.jsx)(o,{className:`size-4 text-primary`}),action:a})}),(0,G.jsx)(V,{event:e.event,className:`border-0`})]})}function et({item:e,isNew:t}){let n=k(),[r,i]=(0,H.useState)(!1),o=(0,H.useMemo)(()=>({event:e.event,sender:e.event.pubkey,recipient:e.event.tags.find(([e])=>e===`p`)?.[1]??``,decrypted:!1,timestamp:e.event.created_at}),[e.event]);return(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:(0,G.jsx)(a,{className:`size-4 text-primary`}),action:`sent you a letter`})}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3 px-4 pb-4 pt-2`,children:[(0,G.jsx)(`div`,{className:`w-[280px]`,children:(0,G.jsx)(Te,{letter:o,mode:`inbox`,index:0,onClick:()=>i(!0),minimal:!0})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(x,{variant:`outline`,className:`rounded-full px-5 h-9 text-sm font-medium gap-1.5 hover:bg-primary hover:text-primary-foreground transition-colors`,onClick:()=>n(`/letters`),children:[(0,G.jsx)(a,{className:`size-3.5`}),`View all letters`]}),(0,G.jsxs)(x,{variant:`default`,className:`rounded-full px-5 h-9 text-sm font-medium gap-1.5 bg-primary text-primary-foreground hover:bg-primary/90 border border-transparent`,onClick:()=>n(`/letters/compose?to=${p.npubEncode(e.event.pubkey)}`),children:[(0,G.jsx)(we,{className:`size-3.5`,strokeWidth:2}),`Reply`]})]})]}),(0,G.jsx)(Ee,{letter:r?o:null,onClose:()=>i(!1),onReply:e=>{i(!1),n(`/letters/compose?to=${e}`)}})]})})}function tt({event:e}){let t=k(),n=(0,H.useMemo)(()=>p.neventEncode({id:e.id,author:e.pubkey}),[e.id,e.pubkey]),r=e.content.trim();return r?(0,G.jsx)(`blockquote`,{role:`link`,tabIndex:0,onClick:e=>{e.stopPropagation(),t(`/${n}`)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),t(`/${n}`))},className:`mx-4 mb-3 mt-1 rounded-r-lg border-l-[3px] border-primary/70 bg-primary/5 pl-3 pr-3 py-2 cursor-pointer hover:bg-primary/10 transition-colors`,children:(0,G.jsx)(`p`,{className:`font-serif text-[14px] leading-relaxed whitespace-pre-wrap break-words line-clamp-4 text-foreground`,children:r})}):null}function nt({item:e,isNew:n}){let r=K(e.referencedEvent?.kind);return(0,G.jsxs)(J,{isNew:n,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:(0,G.jsx)(t,{className:`size-4 text-primary`}),action:`highlighted your ${r}`})}),(0,G.jsx)(tt,{event:e.event}),(0,G.jsx)(Y,{item:e})]})}function rt({group:e}){let n=K(e.referencedEvent?.kind),r=e.actors[0];return(0,G.jsxs)(J,{isNew:e.isNew,children:[(0,G.jsx)(X,{actors:e.actors,icon:(0,G.jsx)(t,{className:`size-4 text-primary`}),action:`highlighted your ${n}`}),r&&(0,G.jsx)(tt,{event:r.event}),r&&(0,G.jsx)(Y,{item:r})]})}function it({event:e}){let t=k(),n=(0,H.useMemo)(()=>p.neventEncode({id:e.id,author:e.pubkey}),[e.id,e.pubkey]),r=(0,H.useMemo)(()=>ue(e),[e]);if(!r)return null;let i=r.outcomes.length>0?r.outcomes.map(e=>e.label).join(`, `):r.scores.map(e=>`${e.label??e.dimension}: ${e.value}`).join(` · `);return i?(0,G.jsx)(`div`,{role:`link`,tabIndex:0,onClick:e=>{e.stopPropagation(),t(`/${n}`)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),t(`/${n}`))},className:`mx-4 mb-3 mt-1 rounded-lg border bg-card px-3 py-2 cursor-pointer hover:bg-secondary/50 transition-colors`,children:(0,G.jsx)(`p`,{className:`text-sm font-semibold text-foreground line-clamp-2`,children:i})}):null}function at({item:e,isNew:t}){return(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:(0,G.jsx)(l,{className:`size-4 text-primary`}),action:(0,G.jsx)(Q,{event:e.event,children:`took your quiz`})})}),(0,G.jsx)(it,{event:e.event}),(0,G.jsx)(Y,{item:e})]})}function ot({group:e}){let t=e.actors[0];return(0,G.jsxs)(J,{isNew:e.isNew,children:[(0,G.jsx)(X,{actors:e.actors,icon:(0,G.jsx)(l,{className:`size-4 text-primary`}),action:`took your quiz`}),t&&(0,G.jsx)(Y,{item:t})]})}function st(e){let t=(0,H.useMemo)(()=>N(e),[e]),{badgeMap:n}=F((0,H.useMemo)(()=>t?[t]:[],[t]));if(!t)return{name:void 0,badge:void 0,definitionEvent:void 0};let r=`${P}:${t.pubkey}:${t.identifier}`,i=n.get(r);return{name:i?.name||L(t.identifier),badge:i??void 0,definitionEvent:i?.event}}function ct({item:e,isNew:t}){let{definitionEvent:r}=st(e.event),i=(0,H.useMemo)(()=>N(e.event),[e.event]),a=(0,H.useMemo)(()=>i?p.naddrEncode({kind:P,pubkey:i.pubkey,identifier:i.identifier}):void 0,[i]);return(0,G.jsxs)(J,{isNew:t,children:[(0,G.jsx)(`div`,{className:`px-4 pt-3`,children:(0,G.jsx)($,{actorPubkey:e.event.pubkey,icon:(0,G.jsx)(n,{className:`size-4 text-primary`}),action:`awarded you a badge`})}),r&&(0,G.jsx)(A,{to:a?`/${a}`:`#`,className:`block`,children:(0,G.jsx)(me,{event:r})}),(0,G.jsx)(`div`,{className:`flex justify-center pb-4 pt-1`,children:(0,G.jsx)(he,{awardEvent:e.event,prominent:!0})})]})}function lt({group:e}){let{badgeMap:t}=F((0,H.useMemo)(()=>{let t=[];for(let n of e.actors){let e=N(n.event);e&&t.push(e)}return t},[e.actors]));return(0,G.jsxs)(J,{isNew:e.isNew,children:[(0,G.jsx)(X,{actors:e.actors,icon:(0,G.jsx)(n,{className:`size-4 text-primary`}),action:`awarded you badges`}),(0,G.jsx)(`div`,{className:`px-4 pb-3 space-y-2`,children:e.actors.map(e=>{let r=N(e.event),i=r?`${P}:${r.pubkey}:${r.identifier}`:void 0,a=i?t.get(i):void 0,o=a?.name||(r?L(r.identifier):void 0),s=r?p.naddrEncode({kind:P,pubkey:r.pubkey,identifier:r.identifier}):void 0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border/50 bg-muted/30 p-2`,children:[(0,G.jsxs)(A,{to:s?`/${s}`:`#`,className:`flex items-center gap-3 flex-1 min-w-0 transition-colors hover:opacity-80`,children:[a?(0,G.jsx)(ie,{badge:a,size:36,className:`shrink-0`}):(0,G.jsx)(`div`,{className:`shrink-0 size-9 rounded-lg border border-border bg-gradient-to-br from-primary/10 via-primary/5 to-transparent flex items-center justify-center`,children:(0,G.jsx)(n,{className:`size-4 text-primary/30`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[o&&(0,G.jsx)(`p`,{className:`text-sm font-medium truncate`,children:o}),a?.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground line-clamp-1`,children:a.description})]})]}),(0,G.jsx)(`div`,{className:`shrink-0`,children:(0,G.jsx)(he,{awardEvent:e.event})})]},e.event.id)})})]})}function $({actorPubkey:e,icon:t,action:n}){let r=v(e),i=r.data?.metadata,a=i?.name||i?.display_name||`Anonymous`,o=M(e,i);return r.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm mb-2`,children:[(0,G.jsx)(`span`,{className:`shrink-0`,children:t}),(0,G.jsx)(R,{className:`h-4 w-24`}),(0,G.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:n})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm mb-2`,children:[(0,G.jsx)(`span`,{className:`shrink-0`,children:t}),(0,G.jsx)(I,{pubkey:e,asChild:!0,children:(0,G.jsx)(A,{to:o,className:`font-bold hover:underline truncate min-w-0`,children:r.data?.event?(0,G.jsx)(j,{tags:r.data.event.tags,children:a}):a})}),(0,G.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:n})]})}function ut(){return(0,G.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(R,{className:`size-4 rounded-full`}),(0,G.jsx)(R,{className:`h-4 w-32`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,G.jsx)(R,{className:`size-11 rounded-full`}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(R,{className:`h-4 w-28`}),(0,G.jsx)(R,{className:`h-3 w-36`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2 mt-2`,children:[(0,G.jsx)(R,{className:`h-4 w-full`}),(0,G.jsx)(R,{className:`h-4 w-4/5`})]}),(0,G.jsxs)(`div`,{className:`flex gap-8 mt-3`,children:[(0,G.jsx)(R,{className:`h-4 w-8`}),(0,G.jsx)(R,{className:`h-4 w-8`}),(0,G.jsx)(R,{className:`h-4 w-8`}),(0,G.jsx)(R,{className:`h-4 w-8`})]})]})}export{ze as NotificationsPage}; // @license-end