// @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{C as t,Ci as n,D as r,Et as i,Kn as a,P as o,S as s,T as ee,Wr as te,_n as c,bt as ne,cr as l,li as u,mt as d,nt as re,qi as f}from"./lucide-icons-BdRF0moN.js";import{t as p}from"./jsx-runtime-By8HlURe.js";import{t as ie}from"./dist-DQ82bf9M.js";import{u as m}from"./esm-CRVqHnq2.js";import{t as ae}from"./useQuery-rCAlChE8.js";import{t as oe}from"./useAppContext-Ughdk2-Z.js";import{r as h}from"./react-intl-eZirkCBg.js";import{l as g,t as _}from"./useCurrentUser-C6OJJlWo.js";import{n as v,t as y}from"./utils-BFSTDHdM.js";import{i as b,n as x,r as se,t as S}from"./NewPostsPill-BQIcBVZE.js";import{t as ce}from"./nostrId-DuqQCAdJ.js";import{n as le}from"./useFollowActions-cve70R08.js";import{r as ue}from"./appRelays-Clm5NPIe.js";import{n as C,o as w,r as T,t as E}from"./avatar--oX_CTF4.js";import{d as D,n as O}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{n as k}from"./CustomEmoji-DRcU63lJ.js";import{t as A}from"./input-CM5Fnyvy.js";import{i as j,r as M,t as N}from"./popover-Dw5E1auH.js";import{t as P}from"./skeleton-CVls4GW9.js";import{a as F,i as de,l as I,r as L}from"./ComposeDialogContent-YxhSZA-Y.js";import{k as R}from"./EmbeddedPost-Bb-ngBHS.js";import{a as z}from"./extraKinds-BydAXtVV.js";import{t as fe}from"./badge-eEdLlpTp.js";import{c as pe}from"./LayoutContext-CjQBLGO-.js";import{t as me}from"./useInView-DAJQSIvc.js";import{nt as he,r as ge}from"./NoteCard-COwLfrJJ.js";import{t as _e}from"./useSearchProfiles-uU0NOVhy.js";import{t as B}from"./useFeedSettings-DkFDaYIY.js";import{t as ve}from"./SubHeaderBar-BYwNp4Nc.js";import{t as ye}from"./switch-B6lxwP1L.js";import{t as be}from"./separator-CWY6Ovdb.js";import{i as xe,n as Se,t as Ce}from"./useUserLists-zSWA8dQn.js";import{t as we}from"./useMutedAuthorFilter-CTggZCaG.js";import{C as Te,j as Ee,m as De,o as Oe,w as ke,y as V}from"./index-CYEZWNq6.js";import{t as Ae}from"./HelpTip-BJyejkTU.js";import{t as je}from"./PageHeader-CMi4aeE4.js";import{i as H,n as Me,o as Ne,s as Pe,t as Fe}from"./select-DRTcxeFR.js";import{i as Ie,n as Le,r as Re,s as ze,t as Be}from"./SavedFeedFiltersEditor-BBv6Rhov.js";import{n as Ve,t as He}from"./usePublishProfileTabs-BSCCnTr9.js";var U=e(f(),1);function Ue(e){return e.tags.some(e=>e[0]===`imeta`&&e.slice(1).some(e=>e.startsWith(`m `)&&e.split(` `)[1]?.startsWith(`image/`)))}function We(e){return e.tags.some(e=>e[0]===`imeta`&&e.slice(1).some(e=>e.startsWith(`m `)&&e.split(` `)[1]?.startsWith(`video/`)))}function Ge(e,t,n){let r=Math.floor(Date.now()/1e3);if(e.created_at>r)return!1;let i=t.protocols??[`nostr`];if(!i.includes(`nostr`)||i.length>1){let t=e.tags.find(([e])=>e===`proxy`);if(i.includes(`nostr`)&&!i.some(e=>e!==`nostr`)){if(t)return!1}else{let e=!!t;if(!e&&!i.includes(`nostr`))return!1;if(e){let e=t?.[2]?.toLowerCase();if(!i.filter(e=>e!==`nostr`).some(t=>e?.includes(t)))return!1}}}if((e.kind===1||e.kind===1111)&&!t.includeReplies&&R(e))return!1;if(t.clientTags&&t.clientTags.length>0){let n=e.tags.find(([e])=>e===`client`)?.[1];if(!n||!t.clientTags.includes(n))return!1}if(n.trim()){let t=n.toLowerCase(),r=e.content.toLowerCase(),i=[`title`,`summary`,`subject`,`alt`].flatMap(t=>e.tags.filter(([e])=>e===t).map(([,e])=>e??``)).join(` `).toLowerCase();if(!r.includes(t)&&!i.includes(t))return!1}if(t.mediaType!==`all`){let n=Ue(e),r=We(e);switch(t.mediaType){case`images`:if(!n||r)return!1;break;case`videos`:if(!r)return!1;break;case`vines`:if(e.kind===1||e.kind===1111)return!1;break;case`none`:if(n||r)return!1;break}}return!0}var Ke=40;function qe(e,t){let{nostr:n}=ie(),{feedSettings:r}=B(),{isMuted:i}=V(),{shouldFilterEvent:a}=x(),[o,s]=(0,U.useState)([]),[ee,te]=(0,U.useState)(!0),c=(0,U.useRef)([]),[ne,l]=(0,U.useState)(0),u=(0,U.useRef)(!1),d=(0,U.useRef)(!1),[re,f]=(0,U.useState)(new Set),p=(0,U.useRef)(void 0),[ae,oe]=(0,U.useState)(!1),h=(0,U.useRef)(!1),[g,_]=(0,U.useState)(!0),v=(0,U.useRef)(null),y=(0,U.useCallback)(()=>{if(c.current.length===0)return;let e=new Set(c.current.map(e=>e.id));s(e=>{let t=[...e,...c.current];return t.sort((e,t)=>t.created_at-e.created_at),t}),c.current=[],l(0),f(e),clearTimeout(p.current),p.current=setTimeout(()=>f(new Set),1500)},[]);(0,U.useEffect)(()=>()=>clearTimeout(p.current),[]),(0,U.useEffect)(()=>{function e(){d.current=window.scrollY>200,!d.current&&c.current.length>0&&y()}return window.addEventListener(`scroll`,e,{passive:!0}),()=>window.removeEventListener(`scroll`,e)},[y]);let b=(0,U.useMemo)(()=>{if(!t.authorPubkeys||t.authorPubkeys.length===0)return;let e=[];for(let n of t.authorPubkeys){let t=n.trim();if(ce(t))e.push(t);else try{let n=m.decode(t);n.type===`npub`&&e.push(n.data)}catch{}}return e.length>0?e:void 0},[t.authorPubkeys]),se=!t.kindsOverride&&(t.mediaType===`vines`||t.mediaType===`images`||t.mediaType===`videos`),S=z(r),le=[...S].sort().join(`,`),C=[...t.protocols??[`nostr`]].sort().join(`,`),w=t.kindsOverride?[...t.kindsOverride].sort().join(`,`):``,T=t.authorPubkeys?[...t.authorPubkeys].sort().join(`,`):``,E=t.clientTags?[...t.clientTags].sort().join(`,`):``,D=(0,U.useMemo)(()=>{let n;n=t.kindsOverride&&t.kindsOverride.length>0?[...t.kindsOverride]:t.mediaType===`vines`?[22,34236]:t.mediaType===`videos`?[21,22,...S.filter(e=>!I(e))]:t.mediaType===`images`?[20,...S.filter(e=>!I(e))]:S.filter(e=>!I(e)),n=[...new Set(n)];let r={kinds:n},i=(t.protocols??[`nostr`]).filter(e=>e!==`nostr`).map(e=>`protocol:${e}`);e.trim()&&i.push(e.trim()),t.language&&t.language!==`global`&&i.push(`language:${t.language}`),se||(t.mediaType===`images`?(i.push(`media:true`),i.push(`video:false`)):t.mediaType===`videos`?i.push(`video:true`):t.mediaType===`none`&&i.push(`media:false`)),t.sort===`hot`?i.push(`sort:hot`):t.sort===`trending`?i.push(`sort:trending`):i.length>0&&i.push(`sort:recent`);let a={...r};return i.length>0&&(a.search=i.join(` `)),b&&b.length>0&&(a.authors=b,r.authors=b),t.clientTags&&t.clientTags.length>0&&(a[`#client`]=t.clientTags,r[`#client`]=t.clientTags),{searchFilter:a,streamFilter:r}},[e,se,le,t.language,t.mediaType,C,w,T,E,t.sort]),O=(0,U.useRef)(new Map),k=(0,U.useRef)(new Set),A=(0,U.useCallback)(()=>{s(Array.from(O.current.values()).sort((e,t)=>t.created_at-e.created_at))},[]),j=(0,U.useCallback)((e,t)=>{let n=Math.floor(Date.now()/1e3);if(e.created_at>n)return!1;let r;if(e.kind>=3e4&&e.kind<4e4){let t=e.tags.find(([e])=>e===`d`)?.[1]??``;r=`${e.pubkey}:${e.kind}:${t}`}else r=e.id;if(t&&u.current&&d.current)return k.current.has(r)?!1:(k.current.add(r),c.current=[...c.current,e],!1);if(e.kind>=3e4&&e.kind<4e4){let t=O.current.get(r);if(t&&t.created_at>=e.created_at)return!1;O.current.set(r,e)}else{if(O.current.has(r))return!1;O.current.set(r,e)}return k.current.add(r),!0},[]),M=(0,U.useRef)(!1),N=(0,U.useRef)(void 0),P=(0,U.useCallback)(e=>{j(e,!0)&&(M.current=!0),N.current===void 0&&(N.current=setTimeout(()=>{N.current=void 0,l(c.current.length),M.current&&(M.current=!1,A())},1e3))},[j,A]);(0,U.useEffect)(()=>{let e=new AbortController,t=!0;s([]),te(!0),_(!0),h.current=!1,v.current=null,u.current=!1,c.current=[],l(0),O.current=new Map,k.current=new Set,clearTimeout(N.current),N.current=void 0,M.current=!1;let{searchFilter:r,streamFilter:i}=D;return(async()=>{try{let t=await n.query([{...r,limit:Ke}],{signal:e.signal});for(let e of t)j(e,!1);if(A(),t.length>0){let e=Math.min(...t.map(e=>e.created_at));v.current=e}t.length===0&&_(!1)}catch{}t&&(u.current=!0,te(!1))})(),(async()=>{try{let r=Math.floor(Date.now()/1e3),a=n.group(ue);for await(let n of a.req([{...i,since:r,limit:0}],{signal:e.signal})){if(!t)break;if(n[0]===`EVENT`)P(n[2]);else if(n[0]===`CLOSED`)break}}catch{}})(),()=>{t=!1,e.abort(),clearTimeout(N.current),N.current=void 0}},[n,D]);let F=(0,U.useCallback)(async()=>{if(!(h.current||!g||v.current===null)){h.current=!0,oe(!0);try{let{searchFilter:e}=D,t=v.current,r=await n.query([{...e,until:t-1,limit:Ke}]);for(let e of r)j(e,!1);if(A(),r.length>0){let e=Math.min(...r.map(e=>e.created_at));v.current=e}(r.length===0||v.current>=t)&&_(!1)}catch{}finally{h.current=!1,oe(!1)}}},[g,D,n,j,A]),de=y,L=(0,U.useMemo)(()=>b?new Set(b):void 0,[b]),R=(0,U.useCallback)(n=>i(n)||a(n)||L&&!L.has(n.pubkey)?!1:Ge(n,t,e),[t.includeReplies,t.mediaType,C,e,i,L,a,T,E]);return{posts:(0,U.useMemo)(()=>o.filter(R),[o,R]),isLoading:ee,newPostCount:(0,U.useMemo)(()=>c.current.filter(R).length,[ne,R]),flushStreamBuffer:de,flushedIds:re,fetchNextPage:F,hasNextPage:g,isFetchingNextPage:ae}}var W=p(),Je=[`posts`,`accounts`];function Ye(e){return Je.includes(e)?e:`posts`}var Xe=[`anyone`,`follows`,`people`],Ze=[`recent`,`hot`,`trending`],G={includeReplies:!0,onlyDitto:!1,mediaType:`all`,language:`global`,platform:`nostr`,kindFilter:`all`,customKindText:``,authorScope:`anyone`,sort:`recent`};function Qe(e,t){return e===null?t:e!==`false`}function $e(){let{config:e}=oe();ke({title:`Search | ${e.appName}`,description:`Search Nostr`}),pe({hasSubHeader:!0});let[r,d]=D(),f=Ye(r.get(`tab`)),p=r.get(`q`)??``,[m,h]=(0,U.useState)(!1),g=Qe(r.get(`replies`),G.includeReplies),x=Qe(r.get(`ditto`),G.onlyDitto),ce=[`all`,`images`,`videos`,`vines`,`none`],ue=r.get(`media`)??G.mediaType,C=ce.includes(ue)?ue:G.mediaType,w=r.get(`lang`)??G.language,T=[`nostr`,`activitypub`,`atproto`],E=r.get(`platform`)??G.platform,O=T.includes(E)?E:G.platform,k=r.get(`kind`)??G.kindFilter,P=r.get(`customKind`)??G.customKindText,I=r.get(`authorScope`)??G.authorScope,R=Xe.includes(I)?I:G.authorScope,z=(0,U.useMemo)(()=>r.getAll(`author`),[r]),he=r.get(`sort`)??G.sort,B=Ze.includes(he)?he:G.sort,V=(0,U.useCallback)((e,t,n)=>{d(r=>{let i=new URLSearchParams(r);return t===n?i.delete(e):i.set(e,t),i},{replace:!0})},[d]),Ue=(0,U.useCallback)(e=>V(`replies`,String(e),String(G.includeReplies)),[V]),We=(0,U.useCallback)(e=>V(`ditto`,String(e),String(G.onlyDitto)),[V]),Ge=(0,U.useCallback)(e=>V(`media`,e,G.mediaType),[V]),Ke=(0,U.useCallback)(e=>V(`lang`,e,G.language),[V]),Je=(0,U.useCallback)(e=>V(`platform`,e,G.platform),[V]),$e=(0,U.useCallback)(e=>V(`sort`,e,G.sort),[V]),tt=(0,U.useCallback)(e=>{d(t=>{let n=new URLSearchParams(t);return e===G.kindFilter?n.delete(`kind`):n.set(`kind`,e),e!==`custom`&&n.delete(`customKind`),n},{replace:!0})},[d]),rt=(0,U.useCallback)(e=>V(`customKind`,e,G.customKindText),[V]),ut=(0,U.useCallback)(e=>{d(t=>{let n=new URLSearchParams(t);return e===G.authorScope?n.delete(`authorScope`):n.set(`authorScope`,e),e!==`people`&&n.delete(`author`),n},{replace:!0})},[d]),dt=(0,U.useCallback)(e=>{d(t=>{let n=new URLSearchParams(t);return n.delete(`author`),e.forEach(e=>n.append(`author`,e)),n.set(`authorScope`,`people`),n},{replace:!0})},[d]),ft=(0,U.useCallback)(e=>{d(t=>{let n=new URLSearchParams(t);return e===`posts`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[d]),pt=(0,U.useCallback)(e=>{let t=e.trim();d(e=>{let n=e.get(`q`)??``;if(t===n)return e;let r=new URLSearchParams(e);return t?r.set(`q`,t):r.delete(`q`),r},{replace:!0})},[d]),mt=(0,U.useMemo)(()=>[O],[O]),ht=(0,U.useMemo)(()=>x?[e.clientName??e.appName]:void 0,[x,e.clientName,e.appName]),K=(0,U.useMemo)(()=>ze(),[]),gt=(0,U.useMemo)(()=>K.map(e=>Number(e.value)),[K]),q=(0,U.useMemo)(()=>k===`all`?gt:v(k,P)??gt,[k,P,gt]),_t=!g||x||C!==G.mediaType||w!==G.language||O!==G.platform||k!==G.kindFilter||R!==G.authorScope||B!==G.sort||z.length>0,vt=(0,U.useCallback)(()=>{d(e=>{let t=new URLSearchParams(e);return t.delete(`replies`),t.delete(`ditto`),t.delete(`media`),t.delete(`lang`),t.delete(`platform`),t.delete(`kind`),t.delete(`customKind`),t.delete(`authorScope`),t.delete(`author`),t.delete(`sort`),t},{replace:!0})},[d]),yt=(0,U.useMemo)(()=>{let e=[];if(g||e.push(`No replies`),x&&e.push(`Ditto users only`),C!==`all`&&e.push({images:`Images`,videos:`Videos`,vines:`Shorts`,none:`No media`}[C]??C),w!==`global`&&e.push(w.toUpperCase()),O!==`nostr`&&e.push({activitypub:`Mastodon`,atproto:`Bluesky`}[O]??O),B!==`recent`&&e.push(B===`hot`?`Hot`:`Trending`),k!==`all`&&k!==`custom`){let t=k.split(`,`).filter(Boolean);if(t.length===1){let n=K.find(e=>e.value===t[0]);n?e.push(n.label):e.push(`Kind ${t[0]}`)}else t.length>1&&e.push(`${t.length} kinds`)}else k===`custom`&&P&&e.push(`Kind: ${P}`);return R===`follows`&&e.push(`My follows`),R===`people`&&z.length>0&&e.push(`${z.length} author${z.length>1?`s`:``}`),e},[g,x,C,w,O,B,k,P,R,z,K]),{user:J}=_(),{data:bt}=le(),xt=(0,U.useMemo)(()=>bt?.pubkeys??[],[bt?.pubkeys]),{excludeMuted:St}=we(),Ct=(0,U.useMemo)(()=>St(xt),[xt,St]),{lists:wt}=Se(),{data:Tt=[]}=xe(),{savedFeeds:Et,addSavedFeed:Dt,isPending:Ot}=De(),kt=Ve(J?.pubkey),{publishProfileTabs:At,isPending:jt}=He(),[Mt,Nt]=(0,U.useState)(!1),[Y,X]=(0,U.useState)(``),[Pt,Ft]=(0,U.useState)(!1),Z=Ce(z),It=R===`people`&&z.length>0,Lt=(0,U.useMemo)(()=>{let e={};return p.trim()&&(e.search=p.trim()),q&&q.length>0&&(e.kinds=q),R===`people`&&z.length>0&&(e.authors=z),e},[p,q,R,z]),Rt=Et.some(e=>JSON.stringify(e.filter)===JSON.stringify(Lt)),zt=async()=>{if(!Y.trim()||Ot)return;let e=R===`follows`&&J?[{name:`$follows`,tagName:`p`,pointer:`a:3:${J.pubkey}:`}]:[];await Dt(Y,Lt,e),Nt(!1),X(``),Ft(!0),setTimeout(()=>Ft(!1),2e3)},Bt=async()=>{if(!Y.trim()||jt||!J)return;let e=kt.data??{tabs:[],vars:[]};await At({tabs:[...e.tabs,{label:Y.trim(),filter:Lt}],vars:e.vars}),Nt(!1),X(``),Ft(!0),setTimeout(()=>Ft(!1),2e3)},{posts:Q,isLoading:Vt,newPostCount:Ht,flushStreamBuffer:Ut,flushedIds:Wt,fetchNextPage:Gt,hasNextPage:Kt,isFetchingNextPage:qt}=qe(p,{includeReplies:g,mediaType:C,language:w,protocols:mt,kindsOverride:q,authorPubkeys:R===`follows`?Ct:R===`people`&&z.length>0?z:void 0,sort:B,clientTags:ht}),{data:Jt,isLoading:Yt,followedPubkeys:Xt}=_e(f===`accounts`?p:``),{nostr:Zt}=ie(),Qt=(0,U.useMemo)(()=>Q.map(e=>e.id).join(`,`),[Q]),$t=(0,U.useRef)(new Map),{data:$=[]}=ae({queryKey:[`search-feed-items`,Qt],queryFn:async({signal:e})=>{let t=$t.current,n=Q.filter(e=>!t.has(e.id));if(n.length>0){let r=await L(n,Zt,e);if(e.aborted)throw Error(`aborted`);let i=new Map(n.map(e=>[e.id,[]]));for(let e of r){let t=e.repostEvent?.id??e.reactedBy?.event.id??e.zappedBy?.event.id??e.event.id,n=i.get(t);n&&n.push(e)}for(let[e,n]of i)t.set(e,n)}return de(Q.flatMap(e=>t.get(e.id)??[]))},enabled:Q.length>0,staleTime:6e4,placeholderData:e=>e}),{floodIds:en}=Ee(),tn=(0,U.useMemo)(()=>$.map(e=>e.event),[$]),nn=(0,U.useMemo)(()=>en(tn),[en,tn]),rn=(0,U.useMemo)(()=>{if(nn.size===0)return $.map(e=>({type:`item`,item:e}));let e=[];for(let t of $){if(!nn.has(t.event.id)){e.push({type:`item`,item:t});continue}let n=e[e.length-1];n?.type===`flood`?n.items.push(t):e.push({type:`flood`,key:`flood:${t.event.id}`,items:[t]})}return e},[$,nn]),an=(0,U.useCallback)(async()=>{Ut(),window.scrollTo({top:0,behavior:`smooth`})},[Ut]),{ref:on,inView:sn}=me({threshold:0,rootMargin:`400px`});return(0,U.useEffect)(()=>{sn&&Kt&&!qt&&f===`posts`&&Gt()},[sn,Kt,qt,Gt,f]),(0,W.jsxs)(`main`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(je,{title:`Search`,icon:(0,W.jsx)(ne,{className:`size-5`})}),(0,W.jsxs)(ve,{children:[(0,W.jsx)(Oe,{label:`Posts`,active:f===`posts`,onClick:()=>ft(`posts`)}),(0,W.jsx)(Oe,{label:`Accounts`,active:f===`accounts`,onClick:()=>ft(`accounts`)})]}),(0,W.jsx)(`div`,{style:{height:20}}),(0,W.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(ct,{initialValue:p,onDebouncedChange:pt}),f===`posts`&&J&&(0,W.jsx)(`div`,{className:y(!p.trim()&&!_t?`hidden`:void 0),children:(0,W.jsxs)(N,{open:Mt,onOpenChange:e=>{if(Nt(e),e&&!Y){if(p.trim())X(p.trim());else if(Z){let e=Z.startsWith(`set:`)?wt.find(e=>e.id===Z.slice(4))?.title:Tt.find(e=>e.id===Z.slice(5))?.title;e&&X(e)}}},children:[(0,W.jsx)(j,{asChild:!0,children:(0,W.jsx)(`button`,{className:y(`shrink-0 h-10 w-10 rounded-full border flex items-center justify-center transition-colors`,Rt||Pt?`border-primary bg-primary/10 text-primary`:`border-border bg-secondary/50 hover:bg-secondary text-muted-foreground hover:text-foreground`),style:{outline:`none`},"aria-label":`Add to feed`,children:Pt?(0,W.jsx)(u,{className:`size-4`}):(0,W.jsx)(n,{className:`size-4`})})}),(0,W.jsxs)(M,{align:`end`,className:`w-64 p-3 space-y-3`,children:[(0,W.jsx)(`p`,{className:`font-semibold text-sm`,children:`Save as tab`}),Rt?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Already saved.`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(A,{placeholder:`Tab name…`,value:Y,onChange:e=>X(e.target.value),onKeyDown:e=>{e.key===`Enter`&&zt()},className:`bg-secondary/50 border-border focus-visible:ring-1 text-base md:text-sm`,autoFocus:!0}),(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsx)(lt,{icon:(0,W.jsx)(n,{className:`size-4 text-muted-foreground`}),label:`Home feed`,description:`Tab on your home page`,onClick:()=>zt(),disabled:!Y.trim()||Ot||jt,loading:Ot}),!It&&(0,W.jsx)(lt,{icon:(0,W.jsx)(t,{className:`size-4 text-muted-foreground`}),label:`Profile tab`,description:`Your posts matching this search`,onClick:()=>Bt(),disabled:!Y.trim()||Ot||jt,loading:jt})]})]})]})]})}),f===`posts`&&(0,W.jsxs)(N,{open:m,onOpenChange:h,children:[(0,W.jsx)(j,{asChild:!0,children:(0,W.jsx)(`button`,{className:y(`shrink-0 h-10 w-10 rounded-full border bg-secondary/50 hover:bg-secondary flex items-center justify-center transition-colors`,m?`border-2 border-primary bg-secondary text-primary`:_t?`border-primary text-primary`:`border-border`),style:{outline:`none`},"aria-label":`Search filters`,children:(0,W.jsx)(re,{className:`size-4`})})}),(0,W.jsxs)(M,{align:`end`,className:`w-80 p-3 space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`font-semibold text-sm`,children:`Filters`}),_t&&(0,W.jsxs)(`button`,{className:`text-xs text-muted-foreground hover:text-foreground flex items-center gap-1 transition-colors`,onClick:vt,children:[(0,W.jsx)(i,{className:`size-3`}),`Reset`]})]}),(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`From`}),(0,W.jsx)(`div`,{className:`flex rounded-lg border border-border overflow-hidden`,children:[[`anyone`,`Anyone`,a],[`follows`,`Follows`,s],[`people`,`People`,ee]].map(([e,t,n])=>(0,W.jsxs)(`button`,{onClick:()=>ut(e),className:y(`flex-1 py-1.5 flex items-center justify-center gap-1 text-xs font-medium transition-colors`,R===e?`bg-primary text-primary-foreground`:`bg-secondary/40 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[(0,W.jsx)(n,{className:`size-3.5 shrink-0`}),t]},e))}),R===`people`&&(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[z.length>0&&(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:z.map(e=>(0,W.jsx)(Be,{pubkey:e,onRemove:()=>{let t=z.filter(t=>t!==e);d(e=>{let n=new URLSearchParams(e);return n.delete(`author`),t.forEach(e=>n.append(`author`,e)),t.length===0&&n.delete(`authorScope`),n},{replace:!0})}},e))}),(0,W.jsx)(Le,{onCommit:e=>{z.includes(e)||d(t=>{let n=new URLSearchParams(t);return n.append(`author`,e),n.set(`authorScope`,`people`),n},{replace:!0})}}),(0,W.jsx)(Ie,{lists:wt,followPacks:Tt,value:Z,onSelectPubkeys:dt})]})]}),(0,W.jsx)(be,{}),(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Sort`}),(0,W.jsx)(`div`,{className:`flex rounded-lg border border-border overflow-hidden`,children:[[`recent`,`Recent`,te],[`hot`,`Hot`,l],[`trending`,`Trending`,o]].map(([e,t,n])=>(0,W.jsxs)(`button`,{onClick:()=>$e(e),className:y(`flex-1 py-1.5 flex items-center justify-center gap-1 text-xs font-medium transition-colors`,B===e?`bg-primary text-primary-foreground`:`bg-secondary/40 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[(0,W.jsx)(n,{className:`size-3.5 shrink-0`}),t]},e))})]}),(0,W.jsx)(be,{}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-1`,children:`Media`}),(0,W.jsxs)(Fe,{value:C,onValueChange:e=>Ge(e),children:[(0,W.jsx)(Ne,{className:`w-full bg-secondary/50 h-8 text-base md:text-xs`,children:(0,W.jsx)(Pe,{})}),(0,W.jsxs)(Me,{children:[(0,W.jsx)(H,{value:`all`,children:`All`}),(0,W.jsx)(H,{value:`images`,children:`Images`}),(0,W.jsx)(H,{value:`videos`,children:`Videos`}),(0,W.jsx)(H,{value:`vines`,children:`Shorts`}),(0,W.jsx)(H,{value:`none`,children:`No media`})]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-1`,children:[`Protocol `,(0,W.jsx)(Ae,{faqId:`vs-mastodon-bluesky`,iconSize:`size-3`})]}),(0,W.jsxs)(Fe,{value:O,onValueChange:e=>Je(e),children:[(0,W.jsx)(Ne,{className:`w-full bg-secondary/50 h-8 text-base md:text-xs`,children:(0,W.jsx)(Pe,{})}),(0,W.jsxs)(Me,{children:[(0,W.jsx)(H,{value:`nostr`,children:`Nostr`}),(0,W.jsx)(H,{value:`activitypub`,children:`Mastodon`}),(0,W.jsx)(H,{value:`atproto`,children:`Bluesky`})]})]})]})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-1`,children:`Language`}),(0,W.jsxs)(Fe,{value:w,onValueChange:e=>Ke(e),children:[(0,W.jsx)(Ne,{className:`w-full bg-secondary/50 h-8 text-base md:text-xs`,children:(0,W.jsx)(Pe,{})}),(0,W.jsxs)(Me,{children:[(0,W.jsx)(H,{value:`global`,children:`Global`}),(0,W.jsx)(H,{value:`en`,children:`English`}),(0,W.jsx)(H,{value:`es`,children:`Spanish`}),(0,W.jsx)(H,{value:`fr`,children:`French`}),(0,W.jsx)(H,{value:`de`,children:`German`}),(0,W.jsx)(H,{value:`ja`,children:`Japanese`}),(0,W.jsx)(H,{value:`zh`,children:`Chinese`})]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-1`,children:`Kind`}),(0,W.jsx)(Re,{value:k,options:K,onChange:e=>tt(e)})]})]}),k===`custom`&&(0,W.jsx)(A,{type:`text`,inputMode:`numeric`,placeholder:`e.g. 1, 30023`,value:P,onChange:e=>rt(e.target.value),className:`bg-secondary/50 border-border focus-visible:ring-1 rounded-lg text-base md:text-xs h-8`}),(0,W.jsx)(be,{}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`Include replies`}),(0,W.jsx)(ye,{checked:g,onCheckedChange:Ue,className:`scale-90`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1.5`,children:[(0,W.jsx)(b,{size:14,className:`shrink-0`}),e.appName,` users only`]}),(0,W.jsx)(ye,{checked:x,onCheckedChange:We,className:`scale-90`})]})]})]})]}),f===`posts`&&yt.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mt-2`,children:[yt.map(e=>(0,W.jsx)(fe,{variant:`secondary`,className:`text-xs font-normal`,children:e},e)),(0,W.jsx)(`button`,{onClick:vt,className:`text-xs text-muted-foreground hover:text-foreground underline underline-offset-2 transition-colors`,children:`Clear`})]})]}),(0,W.jsxs)(Te,{onRefresh:an,children:[f===`posts`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(S,{count:Ht,onClick:()=>{Ut(),window.scrollTo({top:0,behavior:`smooth`})}}),Vt&&Q.length===0?(0,W.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:5}).map((e,t)=>(0,W.jsx)(ot,{},t))}):$.length>0?(0,W.jsxs)(`div`,{children:[rn.map((e,t)=>{if(e.type===`flood`)return(0,W.jsx)(at,{items:e.items},e.key);let{item:n}=e,r=Wt.has(n.event.id);return(0,W.jsx)(se,{cacheKey:F(n),className:`cv-feed-item`,initialInView:t<10,children:(0,W.jsx)(ge,{event:n.event,repostedBy:n.repostedBy,repostEvent:n.repostEvent,reactedBy:n.reactedBy,zappedBy:n.zappedBy,profileZapRecipient:n.profileZapRecipient,highlight:r})},F(n))}),Kt&&(0,W.jsx)(`div`,{ref:on,className:`py-4`,children:qt&&(0,W.jsx)(`div`,{className:`flex justify-center`,children:(0,W.jsx)(c,{className:`size-5 animate-spin text-muted-foreground`})})})]}):Q.length>0?(0,W.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:5}).map((e,t)=>(0,W.jsx)(ot,{},t))}):p.trim()?(0,W.jsx)(it,{message:`No posts found matching your search.`,activeFilters:yt,onResetFilters:_t?vt:void 0}):(0,W.jsx)(it,{message:`Enter a search query to find posts.`})]}),f===`accounts`&&(0,W.jsx)(W.Fragment,{children:(0,W.jsx)(`div`,{children:p.trim()?Yt?(0,W.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:5}).map((e,t)=>(0,W.jsx)(st,{},t))}):Jt&&Jt.length>0?(0,W.jsx)(`div`,{className:`divide-y divide-border`,children:Jt.map(e=>(0,W.jsx)(et,{profile:e,isFollowed:Xt.has(e.pubkey)},e.pubkey))}):(0,W.jsx)(it,{message:`No accounts found matching your search.`}):(0,W.jsx)(nt,{})})})]})]})}function et({profile:e,isFollowed:t}){let n=(0,U.useMemo)(()=>m.npubEncode(e.pubkey),[e.pubkey]),i=e.metadata,a=i?.name||i?.display_name||`Anonymous`,o=w(i),s=e.event?.tags??[];return(0,W.jsxs)(O,{to:`/${n}`,className:`flex items-center gap-3 px-4 py-3 hover:bg-secondary/30 transition-colors`,children:[(0,W.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,W.jsxs)(E,{shape:o,className:`size-11`,children:[(0,W.jsx)(T,{src:i?.picture,alt:a}),(0,W.jsx)(C,{className:`bg-primary/20 text-primary text-sm`,children:a[0]?.toUpperCase()||`?`})]}),t&&(0,W.jsx)(`span`,{className:`absolute -bottom-0.5 -right-0.5 size-[18px] rounded-full bg-primary flex items-center justify-center ring-2 ring-background`,title:`Following`,children:(0,W.jsx)(r,{className:`size-2.5 text-primary-foreground`,strokeWidth:3})})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(`p`,{className:`font-bold text-[15px] truncate`,children:(0,W.jsx)(k,{tags:s,children:a})}),i?.bot&&(0,W.jsx)(`span`,{className:`text-xs`,title:`Bot account`,children:`🤖`})]}),i?.nip05&&(0,W.jsx)(he,{nip05:i.nip05,pubkey:e.pubkey,className:`text-sm text-muted-foreground truncate block`}),i?.about&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5 line-clamp-2`,children:(0,W.jsx)(k,{tags:s,children:i.about})})]})]})}var tt=30;function nt(){let{data:e}=le(),t=(0,U.useMemo)(()=>e?.pubkeys??[],[e]),[n,r]=(0,U.useState)(tt),{ref:i,inView:a}=me({threshold:0,rootMargin:`300px`}),o=(0,U.useMemo)(()=>t.slice(0,n),[t,n]),s=n{a&&s&&r(e=>Math.min(e+tt,t.length))},[a,s,t.length]),t.length===0?(0,W.jsx)(it,{message:`Search for people by name or NIP-05 address.`}):(0,W.jsxs)(`div`,{className:`divide-y divide-border`,children:[o.map(e=>(0,W.jsx)(rt,{pubkey:e},e)),s&&(0,W.jsx)(`div`,{ref:i,className:`divide-y divide-border`,children:Array.from({length:3}).map((e,t)=>(0,W.jsx)(st,{},t))})]})}function rt({pubkey:e}){let t=g(e),n=t.data?.metadata,i=w(n),a=(0,U.useMemo)(()=>m.npubEncode(e),[e]),o=n?.name||n?.display_name||`Anonymous`,s=t.data?.event?.tags??[];return t.isLoading?(0,W.jsx)(st,{}):(0,W.jsxs)(O,{to:`/${a}`,className:`flex items-center gap-3 px-4 py-3 hover:bg-secondary/30 transition-colors`,children:[(0,W.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,W.jsxs)(E,{shape:i,className:`size-11`,children:[(0,W.jsx)(T,{src:n?.picture,alt:o}),(0,W.jsx)(C,{className:`bg-primary/20 text-primary text-sm`,children:o[0]?.toUpperCase()||`?`})]}),(0,W.jsx)(`span`,{className:`absolute -bottom-0.5 -right-0.5 size-[18px] rounded-full bg-primary flex items-center justify-center ring-2 ring-background`,title:`Following`,children:(0,W.jsx)(r,{className:`size-2.5 text-primary-foreground`,strokeWidth:3})})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(`p`,{className:`font-bold text-[15px] truncate`,children:(0,W.jsx)(k,{tags:s,children:o})}),n?.bot&&(0,W.jsx)(`span`,{className:`text-xs`,title:`Bot account`,children:`🤖`})]}),n?.nip05&&(0,W.jsx)(he,{nip05:n.nip05,pubkey:e,className:`text-sm text-muted-foreground truncate block`}),n?.about&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5 line-clamp-2`,children:(0,W.jsx)(k,{tags:s,children:n.about})})]})]})}function it({message:e,activeFilters:t,onResetFilters:n}){return(0,W.jsxs)(`div`,{className:`py-16 px-8 text-center`,children:[(0,W.jsx)(`p`,{className:`text-muted-foreground`,children:e}),t&&t.length>0&&(0,W.jsxs)(`div`,{className:`mt-3`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground/70 mb-2`,children:`Active filters:`}),(0,W.jsx)(`div`,{className:`flex flex-wrap justify-center gap-1.5`,children:t.map(e=>(0,W.jsx)(fe,{variant:`secondary`,className:`text-xs font-normal`,children:e},e))}),n&&(0,W.jsx)(`button`,{onClick:n,className:`mt-3 text-xs text-primary hover:underline underline-offset-2 transition-colors`,children:`Clear all filters`})]})]})}function at({items:e}){let[t,n]=(0,U.useState)(!1);return e.length===0?null:(0,W.jsxs)(`div`,{children:[(0,W.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,W.jsx)(d,{className:`size-4 shrink-0`}),(0,W.jsx)(`span`,{className:`group-hover:underline`,children:t?(0,W.jsx)(h,{id:`search.floodHide`,defaultMessage:`Hide {count} {count, plural, one {post} other {posts}} marked as spam`,values:{count:e.length}}):(0,W.jsx)(h,{id:`search.floodShow`,defaultMessage:`{count} {count, plural, one {post} other {posts}} marked as spam`,values:{count:e.length}})})]}),t&&(0,W.jsx)(`div`,{children:e.map(e=>(0,W.jsx)(ge,{event:e.event,repostedBy:e.repostedBy,repostEvent:e.repostEvent,reactedBy:e.reactedBy,zappedBy:e.zappedBy,profileZapRecipient:e.profileZapRecipient},F(e)))})]})}function ot(){return(0,W.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(P,{className:`size-11 rounded-full shrink-0`}),(0,W.jsxs)(`div`,{className:`min-w-0 space-y-1.5`,children:[(0,W.jsx)(P,{className:`h-4 w-28`}),(0,W.jsx)(P,{className:`h-3 w-36`})]})]}),(0,W.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[(0,W.jsx)(P,{className:`h-4 w-full`}),(0,W.jsx)(P,{className:`h-4 w-4/5`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-6 mt-3 -ml-2`,children:[(0,W.jsx)(P,{className:`h-4 w-8`}),(0,W.jsx)(P,{className:`h-4 w-8`}),(0,W.jsx)(P,{className:`h-4 w-8`})]})]})}function st(){return(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,W.jsx)(P,{className:`size-11 rounded-full shrink-0`}),(0,W.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,W.jsx)(P,{className:`h-4 w-28`}),(0,W.jsx)(P,{className:`h-3 w-36`})]})]})}function ct({initialValue:e,onDebouncedChange:t,className:n}){let[r,i]=(0,U.useState)(e),a=(0,U.useRef)(t);return a.current=t,(0,U.useEffect)(()=>{i(e)},[e]),(0,U.useEffect)(()=>{let e=setTimeout(()=>a.current(r),300);return()=>clearTimeout(e)},[r]),(0,W.jsxs)(`div`,{className:y(`relative flex-1`,n),children:[(0,W.jsx)(A,{type:`text`,placeholder:`Search`,value:r,onChange:e=>i(e.target.value),className:`pr-10 bg-secondary/50 border-border focus-visible:ring-1 rounded-full`}),(0,W.jsx)(ne,{className:`absolute right-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none`})]})}function lt({icon:e,label:t,description:n,onClick:r,disabled:i,loading:a}){return(0,W.jsxs)(`button`,{onClick:r,disabled:i,className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg hover:bg-secondary/60 disabled:opacity-40 disabled:pointer-events-none transition-colors text-left`,children:[(0,W.jsx)(`span`,{className:`shrink-0`,children:a?(0,W.jsx)(c,{className:`size-4 animate-spin text-muted-foreground`}):e}),(0,W.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`span`,{className:`block text-sm font-medium`,children:t}),(0,W.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n})]})]})}export{$e as SearchPage}; // @license-end