// @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{On as t,Ot as n,Ri as r,Sr as i,_n as a,a as o,bt as s,ht as c,ln as l,lr as u,qi as d}from"./lucide-icons-BdRF0moN.js";import{t as f}from"./jsx-runtime-By8HlURe.js";import{t as p}from"./useQuery-rCAlChE8.js";import{t as m}from"./useInfiniteQuery-BFtb_-3K.js";import{t as h}from"./useAppContext-Ughdk2-Z.js";import{s as g}from"./useCurrentUser-C6OJJlWo.js";import{t as _}from"./utils-BFSTDHdM.js";import{c as v,n as y}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as b}from"./input-CM5Fnyvy.js";import{i as x,r as S,t as C}from"./popover-Dw5E1auH.js";import{t as w}from"./skeleton-CVls4GW9.js";import{t as T}from"./BlueskyIcon-BZ9o1lYL.js";import{F as E,d as D,p as O,u as k}from"./EmbeddedPost-Bb-ngBHS.js";import{t as A}from"./useInView-DAJQSIvc.js";import{t as j}from"./useShareOrigin-04gGNDPW.js";import{w as M}from"./index-CYEZWNq6.js";var N=e(d(),1),P=`https://api.bsky.app/xrpc`,F=`at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot`,I=25;async function L(e,t){let n=new URLSearchParams({feed:F,limit:String(I)});e&&n.set(`cursor`,e);let r=await fetch(`${P}/app.bsky.feed.getFeed?${n}`,{signal:t,headers:{Accept:`application/json`}});if(!r.ok)return{posts:[]};let i=await r.json();return i.feed?{posts:i.feed.map(e=>e.post),cursor:i.cursor}:{posts:[]}}function R(){return m({queryKey:[`bluesky-trending`],queryFn:({pageParam:e,signal:t})=>L(e,t),getNextPageParam:e=>e.cursor,initialPageParam:void 0,staleTime:1e3*60*15,gcTime:1e3*60*60,retry:2})}var z=`https://api.bsky.app/xrpc`;async function B(e,t){let n=new URLSearchParams({q:e,limit:`8`}),r=await fetch(`${z}/app.bsky.actor.searchActorsTypeahead?${n}`,{signal:t,headers:{Accept:`application/json`}});if(!r.ok)return[];let i=await r.json();return i.actors?i.actors.map(e=>({did:e.did,handle:e.handle,displayName:e.displayName,avatar:e.avatar,description:e.description,url:`https://bsky.app/profile/${e.handle}`})):[]}function V(e){return p({queryKey:[`bluesky-actor-search`,e],queryFn:({signal:t})=>B(e,t),enabled:e.trim().length>=1,staleTime:1e3*60*5,gcTime:1e3*60*30,retry:1,placeholderData:e=>e})}var H=f();function U(e,t){let n=e.split(`/`);return`https://bsky.app/profile/${t}/post/${n[n.length-1]}`}function W(e){return`/i/${encodeURIComponent(e)}`}function G(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function K(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m`;let r=Math.floor(n/60);if(r<24)return`${r}h`;let i=Math.floor(r/24);return i<30?`${i}d`:`${Math.floor(i/30)}mo`}function q({post:e}){let t=v(),{toast:r}=g(),i=j(),a=U(e.uri,e.author.handle),o=W(a),s=W(`https://bsky.app/profile/${e.author.handle}`),u=e.embed?.$type===`app.bsky.embed.images#view`?e.embed.images??[]:[],d=e.embed?.$type===`app.bsky.embed.external#view`?e.embed.external:void 0,f=(0,N.useMemo)(()=>E(a),[a]),[p,m]=(0,N.useState)(!1),[h,b]=(0,N.useState)(!1),x=(0,N.useCallback)(e=>{e.stopPropagation(),b(!0)},[]),S=(0,N.useCallback)(e=>{e.stopPropagation(),m(!0)},[]),C=(0,N.useCallback)(async e=>{e.stopPropagation(),await k(`${i}${o}`)===`copied`&&r({title:`Link copied`})},[o,r,i]);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`article`,{onClick:(0,N.useCallback)(()=>{t(o)},[t,o]),className:`px-4 py-3 border-b border-border hover:bg-secondary/30 transition-colors cursor-pointer`,children:(0,H.jsxs)(`div`,{className:`flex gap-3`,children:[(0,H.jsx)(y,{to:s,onClick:e=>e.stopPropagation(),className:`shrink-0`,children:e.author.avatar?(0,H.jsx)(`img`,{src:e.author.avatar,alt:``,className:`size-11 rounded-full object-cover`,loading:`lazy`,onError:e=>{e.currentTarget.style.display=`none`},decoding:`async`}):(0,H.jsx)(`div`,{className:`size-11 rounded-full bg-gradient-to-br from-sky-400 to-blue-500 flex items-center justify-center text-white text-sm font-bold`,children:(e.author.displayName??e.author.handle).charAt(0).toUpperCase()})}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,H.jsx)(y,{to:s,onClick:e=>e.stopPropagation(),className:`font-semibold text-[15px] truncate leading-tight hover:underline`,children:e.author.displayName??e.author.handle}),(0,H.jsxs)(y,{to:s,onClick:e=>e.stopPropagation(),className:`text-muted-foreground text-sm truncate leading-tight hover:underline`,children:[`@`,e.author.handle]}),(0,H.jsx)(`span`,{className:`text-muted-foreground text-sm shrink-0`,children:`ยท`}),(0,H.jsx)(`span`,{className:`text-muted-foreground text-sm shrink-0`,children:K(e.record.createdAt)})]}),(0,H.jsx)(`p`,{className:`mt-1 text-[15px] leading-relaxed whitespace-pre-wrap break-words`,children:e.record.text}),u.length>0&&(0,H.jsx)(`div`,{className:_(`mt-3 rounded-xl overflow-hidden border border-border`,u.length===1&&`grid grid-cols-1`,u.length===2&&`grid grid-cols-2 gap-0.5`,u.length===3&&`grid grid-cols-2 gap-0.5`,u.length>=4&&`grid grid-cols-2 gap-0.5`),children:u.slice(0,4).map((e,t)=>(0,H.jsx)(`div`,{className:_(`relative overflow-hidden bg-secondary`,u.length===1?`aspect-video`:`aspect-square`,u.length===3&&t===0&&`row-span-2 aspect-auto`),children:(0,H.jsx)(`img`,{src:e.thumb,alt:e.alt||``,loading:`lazy`,className:`absolute inset-0 w-full h-full object-cover`,onError:e=>{e.currentTarget.style.display=`none`},decoding:`async`})},t))}),d&&(0,H.jsxs)(`div`,{className:`mt-3 rounded-xl border border-border overflow-hidden bg-secondary/30`,children:[d.thumb&&(0,H.jsx)(`div`,{className:`aspect-[2/1] overflow-hidden bg-secondary`,children:(0,H.jsx)(`img`,{src:d.thumb,alt:``,loading:`lazy`,className:`w-full h-full object-cover`,onError:e=>{e.currentTarget.style.display=`none`},decoding:`async`})}),(0,H.jsxs)(`div`,{className:`px-3 py-2.5 space-y-0.5`,children:[(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:(()=>{try{return new URL(d.uri).hostname}catch{return d.uri}})()}),d.title&&(0,H.jsx)(`p`,{className:`text-sm font-semibold leading-tight line-clamp-2`,children:d.title}),d.description&&(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:d.description})]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-5 mt-3 -ml-2`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:x,className:`inline-flex items-center gap-1.5 p-2 rounded-full text-muted-foreground hover:text-sky-500 hover:bg-sky-500/10 transition-colors`,title:`Comment`,children:[(0,H.jsx)(l,{className:`size-[18px]`}),e.replyCount>0&&(0,H.jsx)(`span`,{className:`text-sm tabular-nums`,children:G(e.replyCount)})]}),(0,H.jsxs)(`button`,{type:`button`,onClick:S,className:`inline-flex items-center gap-1.5 p-2 rounded-full text-muted-foreground hover:text-green-500 hover:bg-green-500/10 transition-colors`,title:`Share to feed`,children:[(0,H.jsx)(n,{className:`size-[18px]`}),e.repostCount>0&&(0,H.jsx)(`span`,{className:`text-sm tabular-nums`,children:G(e.repostCount)})]}),(0,H.jsx)(O,{content:f,iconSize:`size-[18px]`,count:e.likeCount}),(0,H.jsx)(`button`,{type:`button`,onClick:C,className:`inline-flex items-center p-2 rounded-full text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,title:`Share link`,children:(0,H.jsx)(c,{className:`size-[18px]`})})]})]})]})}),h&&(0,H.jsx)(D,{open:h,onOpenChange:b,event:new URL(a)}),p&&(0,H.jsx)(D,{open:p,onOpenChange:m,initialContent:a,title:`Share to feed`})]})}function J(){let e=v(),t=(0,N.useRef)(null),n=(0,N.useRef)(null),[r,i]=(0,N.useState)(``),[c,l]=(0,N.useState)(``),[u,d]=(0,N.useState)(!1),f=(0,N.useRef)(void 0),{data:p,isFetching:m}=V(c),h=(0,N.useCallback)(e=>{i(e),clearTimeout(f.current),f.current=setTimeout(()=>{l(e.trim())},300)},[]);(0,N.useEffect)(()=>()=>clearTimeout(f.current),[]),(0,N.useEffect)(()=>{(c.length>=1&&p&&p.length>0||c.length>=1&&p&&p.length===0&&!m)&&d(!0)},[c,p,m]),(0,N.useEffect)(()=>{function e(e){n.current&&!n.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let g=(0,N.useCallback)(n=>{i(``),l(``),d(!1),t.current?.blur(),e(W(n.url))},[e]),_=(0,N.useCallback)(()=>{i(``),l(``),d(!1),t.current?.focus()},[]),y=(0,N.useCallback)(e=>{e.key===`Escape`&&(d(!1),t.current?.blur()),e.key===`Enter`&&p&&p.length>0&&(e.preventDefault(),g(p[0]))},[p,g]);return(0,H.jsxs)(`div`,{ref:n,className:`relative px-4 pb-3`,children:[(0,H.jsxs)(`div`,{className:`relative`,children:[(0,H.jsx)(s,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none`}),(0,H.jsx)(b,{ref:t,type:`text`,placeholder:`Search Bluesky users...`,value:r,onChange:e=>h(e.target.value),onFocus:()=>{c.length>=1&&d(!0)},onKeyDown:y,className:`pl-9 pr-9 h-9 text-base md:text-sm rounded-full`}),r?(0,H.jsx)(`button`,{type:`button`,onClick:_,className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded-full text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors`,children:(0,H.jsx)(o,{className:`size-3.5`})}):null]}),u&&c.length>=1&&(0,H.jsxs)(`div`,{className:`absolute left-4 right-4 top-full mt-1 z-50 bg-popover border border-border rounded-lg shadow-lg overflow-hidden`,children:[m&&(!p||p.length===0)?(0,H.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:4}).map((e,t)=>(0,H.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,H.jsx)(w,{className:`size-10 rounded-full shrink-0`}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-1`,children:[(0,H.jsx)(w,{className:`h-3.5 w-3/4`}),(0,H.jsx)(w,{className:`h-3 w-1/2`})]})]},t))}):p&&p.length>0?(0,H.jsx)(`div`,{className:`divide-y divide-border max-h-80 overflow-y-auto`,children:p.map(e=>(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-3 px-3 py-2.5 w-full text-left hover:bg-secondary/60 transition-colors`,onClick:()=>g(e),children:[e.avatar?(0,H.jsx)(`img`,{src:e.avatar,alt:``,className:`size-10 rounded-full object-cover bg-secondary shrink-0`,loading:`lazy`,decoding:`async`}):(0,H.jsx)(`div`,{className:`size-10 rounded-full bg-gradient-to-br from-sky-500/20 to-blue-500/20 flex items-center justify-center shrink-0`,children:(0,H.jsx)(T,{className:`size-4 text-muted-foreground/50`})}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium truncate`,children:e.displayName||e.handle}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground truncate`,children:[`@`,e.handle]})]})]},e.did))}):(0,H.jsxs)(`div`,{className:`px-4 py-6 text-center text-sm text-muted-foreground`,children:[`No users found for โ€œ`,c,`โ€`]}),m&&p&&p.length>0&&(0,H.jsx)(`div`,{className:`flex justify-center py-2 border-t border-border`,children:(0,H.jsx)(a,{className:`size-4 animate-spin text-muted-foreground`})})]})]})}function Y(){return(0,H.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:5}).map((e,t)=>(0,H.jsx)(`div`,{className:`px-4 py-3`,children:(0,H.jsxs)(`div`,{className:`flex gap-3`,children:[(0,H.jsx)(w,{className:`size-11 rounded-full shrink-0`}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(w,{className:`h-4 w-28`}),(0,H.jsx)(w,{className:`h-3.5 w-20`})]}),(0,H.jsx)(w,{className:`h-4 w-full`}),(0,H.jsx)(w,{className:`h-4 w-4/5`}),(0,H.jsx)(w,{className:`h-40 w-full rounded-xl`}),(0,H.jsxs)(`div`,{className:`flex gap-6 pt-1`,children:[(0,H.jsx)(w,{className:`h-4 w-10`}),(0,H.jsx)(w,{className:`h-4 w-10`}),(0,H.jsx)(w,{className:`h-4 w-10`})]})]})]})},t))})}function X(){let{config:e}=h(),{data:n,isLoading:o,isError:s,fetchNextPage:c,hasNextPage:l,isFetchingNextPage:d}=R(),{ref:f,inView:p}=A();M({title:`Bluesky | ${e.appName}`,description:`Explore popular posts from Bluesky โ€” trending discussions, images, and links.`});let m=(0,N.useMemo)(()=>{if(!n?.pages)return[];let e=new Set;return n.pages.flatMap(e=>e.posts).filter(t=>e.has(t.uri)?!1:(e.add(t.uri),!0))},[n?.pages]);return(0,N.useEffect)(()=>{p&&l&&!d&&c()},[p,l,d,c]),(0,H.jsxs)(`main`,{className:`pb-16 sidebar:pb-0`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-4 px-4 pt-4 pb-2`,children:[(0,H.jsx)(y,{to:`/`,className:`p-2 -ml-2 rounded-full hover:bg-secondary transition-colors sidebar:hidden`,children:(0,H.jsx)(r,{className:`size-5`})}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2.5 flex-1 min-w-0`,children:[(0,H.jsx)(`div`,{className:`size-8 rounded-lg bg-gradient-to-br from-sky-500/20 to-blue-500/10 flex items-center justify-center`,children:(0,H.jsx)(T,{className:`size-4 text-sky-500 dark:text-sky-400`})}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-xl font-bold leading-tight`,children:`Bluesky`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Popular posts from the ATmosphere`})]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsxs)(C,{children:[(0,H.jsx)(x,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:`p-2 rounded-full hover:bg-secondary transition-colors text-muted-foreground hover:text-foreground`,title:`About`,children:(0,H.jsx)(t,{className:`size-4`})})}),(0,H.jsxs)(S,{side:`bottom`,align:`end`,className:`w-72 text-xs text-muted-foreground`,children:[`Content provided by`,` `,(0,H.jsx)(`a`,{href:`https://bsky.app`,target:`_blank`,rel:`noopener noreferrer`,className:`underline underline-offset-2 hover:text-foreground transition-colors`,children:`Bluesky`}),`, a decentralized social network built on the AT Protocol. All posts are public and belong to their respective authors.`]})]}),(0,H.jsx)(`a`,{href:`https://bsky.app`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-full hover:bg-secondary transition-colors text-muted-foreground hover:text-foreground`,title:`Visit Bluesky`,children:(0,H.jsx)(i,{className:`size-4`})})]})]}),(0,H.jsx)(J,{}),o?(0,H.jsx)(Y,{}):s?(0,H.jsxs)(`div`,{className:`px-4 pt-8 pb-16 text-center`,children:[(0,H.jsx)(u,{className:`size-10 mx-auto mb-3 text-muted-foreground/30`}),(0,H.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Couldn't load Bluesky posts. Try again later.`})]}):m.length===0?(0,H.jsxs)(`div`,{className:`py-16 text-center`,children:[(0,H.jsx)(T,{className:`size-10 mx-auto mb-3 text-muted-foreground/20`}),(0,H.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No posts found.`})]}):(0,H.jsxs)(`div`,{children:[m.map(e=>(0,H.jsx)(q,{post:e},e.uri)),l&&(0,H.jsx)(`div`,{ref:f,className:`py-6`,children:d&&(0,H.jsx)(`div`,{className:`flex justify-center`,children:(0,H.jsx)(a,{className:`size-5 animate-spin text-muted-foreground`})})})]})]})}export{X as BlueskyPage}; // @license-end