// @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{It as t,br as n,dr as r,jt as i,qi as a}from"./lucide-icons-BdRF0moN.js";import{t as o}from"./jsx-runtime-By8HlURe.js";import{t as s}from"./dist-DQ82bf9M.js";import{u as c}from"./esm-CRVqHnq2.js";import{t as l}from"./useQuery-rCAlChE8.js";import{F as u,L as d,R as f,et as p}from"./EmbeddedNote-BKfkvcrg.js";import{t as m}from"./useAppContext-Ughdk2-Z.js";import{n as h}from"./encryptedFile-DKFYUsvG.js";import{l as g,t as _}from"./useCurrentUser-C6OJJlWo.js";import{t as v}from"./utils-BFSTDHdM.js";import{n as y}from"./useFollowActions-cve70R08.js";import{n as b,o as x,r as S,t as C}from"./avatar--oX_CTF4.js";import{n as w}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as T}from"./useProfileUrl-DoFhqUUR.js";import{t as E}from"./skeleton-CVls4GW9.js";import{t as D}from"./timeAgo-BXjjbyXp.js";import{t as O}from"./getDisplayName-B6lnEGRj.js";import{s as k}from"./extraKinds-BydAXtVV.js";import{g as A}from"./sidebarItems-BFr7FKBa.js";import{o as j,t as M}from"./imeta-83Lqxs5-.js";import{c as N}from"./LayoutContext-CjQBLGO-.js";import{t as P}from"./SubHeaderBar-BYwNp4Nc.js";import{t as F}from"./useFeed-DtXzJkqY.js";import{t as ee}from"./usePageRefresh-BuJEOs2u.js";import{t as I}from"./contentWarning-CNDzjeMP.js";import{t as L}from"./ContentWarningGuard-BQGV-Ggw.js";import{t as R}from"./useOpenPost-DKpHsp1A.js";import{n as te}from"./useTrending-DsL3v2RN.js";import{t as ne}from"./useMutedAuthorFilter-CTggZCaG.js";import{C as re,S as ie,o as z,w as ae,x as oe,y as B}from"./index-CYEZWNq6.js";import{t as V}from"./PageHeader-CMi4aeE4.js";import{t as H}from"./KindInfoButton-BL9_-Fdi.js";import{VineCard as U}from"./VinesFeedPage-Drr5IS4B.js";var W=e(a(),1),G=o(),K=k(`videos`),se=12;function q(e,t){return e.find(([e])=>e===t)?.[1]}function J(e){let t=q(e,`thumb`)??q(e,`image`),n=M(e);return n?{url:n.url,thumbnail:n.thumbnail??t,duration:n.duration,blurhash:n.blurhash,encryption:n.encryption}:{url:q(e,`url`),thumbnail:t}}function ce(e){let t=parseFloat(e??``);if(isNaN(t)||t<=0)return;let n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=Math.floor(t%60);return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`}var Y=64,le=8;function X(){let e=(0,W.useRef)(null),t=(0,W.useRef)(!1),n=(0,W.useRef)(0),r=(0,W.useRef)(0),i=(0,W.useRef)(null),a=(0,W.useRef)(0),o=(0,W.useCallback)(()=>{if(i.current!==null)return;let t=()=>{let n=e.current;n&&a.current!==0?(n.scrollLeft+=a.current*le,i.current=requestAnimationFrame(t)):i.current=null};i.current=requestAnimationFrame(t)},[]),s=(0,W.useCallback)(()=>{a.current=0,i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[]),c=(0,W.useCallback)(i=>{let a=e.current;a&&(t.current=!0,n.current=i.pageX-a.offsetLeft,r.current=a.scrollLeft,a.style.cursor=`grabbing`,a.style.userSelect=`none`,s())},[s]),l=(0,W.useCallback)(i=>{let c=e.current;if(!c)return;if(t.current){i.preventDefault();let e=i.pageX-c.offsetLeft;c.scrollLeft=r.current-(e-n.current);return}let l=c.getBoundingClientRect(),u=i.clientX-l.left;ul.width-Y?(a.current=1,o()):s()},[o,s]),u=(0,W.useCallback)(()=>{t.current=!1,e.current&&(e.current.style.cursor=`grab`,e.current.style.userSelect=``)},[]),d=(0,W.useCallback)(()=>{t.current=!1,e.current&&(e.current.style.cursor=`grab`,e.current.style.userSelect=``),s()},[s]);return(0,W.useEffect)(()=>()=>s(),[s]),{ref:e,onMouseDown:c,onMouseMove:l,onMouseUp:u,onMouseLeave:d}}function ue({event:e}){let{url:n,thumbnail:r,duration:i,blurhash:a,encryption:o}=J(e.tags),s=q(e.tags,`title`)??(e.content.slice(0,120)||`Untitled`),l=ce(i),p=j(r??``,r&&o?h(o):void 0),m=r?p.src:void 0,_=u(o?``:n??``,r),v=m??(o?void 0:_),y=g(e.pubkey),k=y.data?.metadata,A=x(k),M=O(k,e.pubkey),N=T(e.pubkey,k),{onClick:P,onAuxClick:F}=R(`/${c.noteEncode(e.id)}`);return(0,G.jsx)(`div`,{className:`cursor-pointer group`,onClick:P,onAuxClick:F,role:`button`,tabIndex:0,onKeyDown:e=>e.key===`Enter`&&P(),children:(0,G.jsxs)(L,{event:e,children:[(0,G.jsxs)(`div`,{className:`relative aspect-video overflow-hidden rounded-xl bg-muted`,children:[d(a)&&(0,G.jsx)(f,{hash:a,width:`100%`,height:`100%`,resolutionX:32,resolutionY:32,punch:1,className:`absolute inset-0`,style:{width:`100%`,height:`100%`}}),v?(0,G.jsx)(`img`,{src:v,alt:s,className:`absolute inset-0 w-full h-full object-cover transition-transform duration-300 group-hover:scale-[1.03]`,loading:`lazy`,decoding:`async`}):(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(t,{className:`size-8 text-muted-foreground/20`})}),l&&(0,G.jsx)(`div`,{className:`absolute bottom-1.5 right-1.5 bg-black/80 text-white text-[10px] px-1.5 py-0.5 rounded font-medium pointer-events-none`,children:l})]}),(0,G.jsxs)(`div`,{className:`mt-2.5 flex gap-2.5`,children:[(0,G.jsx)(w,{to:N,className:`shrink-0 mt-0.5`,onClick:e=>e.stopPropagation(),children:y.isLoading?(0,G.jsx)(E,{className:`size-8 rounded-full`}):(0,G.jsxs)(C,{shape:A,className:`size-8`,children:[(0,G.jsx)(S,{src:k?.picture,alt:M}),(0,G.jsx)(b,{className:`bg-primary/20 text-primary text-[10px]`,children:M[0]?.toUpperCase()})]})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-xs font-medium leading-snug line-clamp-2 mb-1`,children:s}),y.isLoading?(0,G.jsx)(E,{className:`h-2.5 w-20 mb-1`}):(0,G.jsx)(w,{to:N,className:`text-[11px] text-muted-foreground hover:text-foreground transition-colors block truncate`,onClick:e=>e.stopPropagation(),children:M}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:D(e.created_at)})]})]})]})})}function de(){return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(E,{className:`w-full aspect-video rounded-xl`}),(0,G.jsxs)(`div`,{className:`mt-2.5 flex gap-2.5`,children:[(0,G.jsx)(E,{className:`size-8 rounded-full shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`flex-1 space-y-1.5 pt-0.5`,children:[(0,G.jsx)(E,{className:`h-3 w-full`}),(0,G.jsx)(E,{className:`h-3 w-4/5`}),(0,G.jsx)(E,{className:`h-2.5 w-20`})]})]})]})}function fe(){let{nostr:e}=s(),t=l({queryKey:[`all-streams`],queryFn:async({signal:t})=>{let n=await e.query([{kinds:[30311],limit:200}],{signal:AbortSignal.any([t,AbortSignal.timeout(8e3)])}),r=new Map;for(let e of n){let t=e.tags.find(([e])=>e===`d`)?.[1]??``,n=`${e.pubkey}:${t}`,i=r.get(n);(!i||e.created_at>i.created_at)&&r.set(n,e)}return Array.from(r.values())},staleTime:30*1e3,refetchInterval:60*1e3});return{data:t.data??[],isLoading:t.isLoading}}function Z(e){let t={live:[],planned:[],past:[]},n=(e,t)=>t.created_at-e.created_at;for(let n of e){let e=p(n);e===`live`?t.live.push(n):e===`planned`?t.planned.push(n):t.past.push(n)}return t.live.sort(n),t.planned.sort(n),t.past.sort(n),t}function Q(e){let{user:t}=_(),{data:n}=y(),r=n?.pubkeys,{mutedPubkeys:i,excludeMuted:a}=ne(),{data:o,isLoading:s}=fe();return{data:(0,W.useMemo)(()=>{if(e===`global`)return Z(o);if(!r||!t)return{live:[],planned:[],past:[]};let n=a(r),s=new Set([...n,t.pubkey]);return Z(o.filter(e=>i.has(e.pubkey)?!1:s.has(e.pubkey)?!0:e.tags.some(([e,t])=>e===`p`&&s.has(t))))},[o,e,r,t,i,a]),isLoading:s}}function pe({status:e}){switch(e){case`live`:return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-bold bg-red-600 text-white px-1.5 py-0.5 rounded`,children:[(0,G.jsx)(`span`,{className:`size-1.5 rounded-full bg-white animate-pulse`}),`LIVE`]});case`planned`:return(0,G.jsx)(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-bold bg-blue-600/90 text-white px-1.5 py-0.5 rounded`,children:`PLANNED`});default:return(0,G.jsx)(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-bold bg-black/60 text-white/80 px-1.5 py-0.5 rounded`,children:`ENDED`})}}function $({event:e}){let t=q(e.tags,`title`)||`Untitled Stream`,r=q(e.tags,`image`),a=q(e.tags,`current_participants`),o=p(e),{onClick:s,onAuxClick:l}=R(`/${(0,W.useMemo)(()=>{let t=q(e.tags,`d`)||``;return c.naddrEncode({kind:e.kind,pubkey:e.pubkey,identifier:t})},[e])}`),u=g(e.pubkey).data?.metadata,d=O(u,e.pubkey);return(0,G.jsxs)(`div`,{className:`cursor-pointer group shrink-0 w-40`,onClick:s,onAuxClick:l,role:`button`,tabIndex:0,onKeyDown:e=>e.key===`Enter`&&s(),children:[(0,G.jsxs)(`div`,{className:`relative aspect-video overflow-hidden rounded-lg bg-muted`,children:[r?(0,G.jsx)(`img`,{src:r,alt:t,className:`w-full h-full object-cover transition-transform duration-300 group-hover:scale-[1.03]`,loading:`lazy`,decoding:`async`}):(0,G.jsx)(`div`,{className:v(`w-full h-full flex items-center justify-center bg-gradient-to-br to-muted`,o===`live`?`from-red-950/40`:o===`planned`?`from-blue-950/40`:`from-muted-foreground/10`),children:(0,G.jsx)(i,{className:v(`size-5`,o===`live`?`text-red-400/60`:`text-muted-foreground/40`)})}),(0,G.jsx)(`div`,{className:`absolute top-1.5 left-1.5`,children:(0,G.jsx)(pe,{status:o})}),a&&o===`live`&&(0,G.jsxs)(`div`,{className:`absolute bottom-1.5 right-1.5 flex items-center gap-0.5 bg-black/70 text-white text-[10px] px-1 py-0.5 rounded`,children:[(0,G.jsx)(n,{className:`size-2.5`}),a]})]}),(0,G.jsx)(`p`,{className:`mt-1.5 text-xs font-medium line-clamp-2 leading-snug group-hover:text-primary transition-colors`,children:t}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground truncate mt-0.5`,children:d})]})}function me({tab:e}){let{data:t}=Q(e),[n,r]=(0,W.useState)(`live`),i=X();if(t.live.length+t.planned.length+t.past.length===0)return null;let a=t[n].length>0?n:t.live.length>0?`live`:t.planned.length>0?`planned`:`past`,o=t[a];return(0,G.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2.5`,children:[t.live.length>0&&(0,G.jsxs)(`button`,{onClick:()=>r(`live`),className:v(`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold transition-colors`,a===`live`?`bg-red-600 text-white`:`bg-secondary/60 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`size-1.5 rounded-full bg-current animate-pulse shrink-0`}),`Live (`,t.live.length,`)`]}),t.planned.length>0&&(0,G.jsxs)(`button`,{onClick:()=>r(`planned`),className:v(`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold transition-colors`,a===`planned`?`bg-blue-600 text-white`:`bg-secondary/60 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[`Planned (`,t.planned.length,`)`]}),t.past.length>0&&(0,G.jsxs)(`button`,{onClick:()=>r(`past`),className:v(`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold transition-colors`,a===`past`?`bg-muted text-foreground`:`bg-secondary/60 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[`Past (`,t.past.length,`)`]})]}),(0,G.jsx)(`div`,{ref:i.ref,className:`flex gap-3 overflow-x-auto pb-1 cursor-grab`,style:{scrollbarWidth:`none`},onMouseDown:i.onMouseDown,onMouseMove:i.onMouseMove,onMouseUp:i.onMouseUp,onMouseLeave:i.onMouseLeave,children:o.map(e=>(0,G.jsx)($,{event:e},e.id))})]})}function he({event:e,onClick:n}){let{url:r,thumbnail:i,blurhash:a,encryption:o}=J(e.tags),s=q(e.tags,`title`)??(e.content.slice(0,60)||`Short`),c=j(i??``,i&&o?h(o):void 0),l=u(o?``:r??``,i),p=(i?c.src:void 0)??(o?void 0:l);return(0,G.jsx)(`button`,{className:`group block w-full text-left focus:outline-none`,onClick:n,"aria-label":s,children:(0,G.jsxs)(L,{event:e,children:[(0,G.jsxs)(`div`,{className:`relative w-full aspect-[9/16] overflow-hidden rounded-xl bg-muted`,children:[d(a)&&!p&&(0,G.jsx)(f,{hash:a,width:`100%`,height:`100%`,resolutionX:32,resolutionY:32,punch:1,className:`absolute inset-0`,style:{width:`100%`,height:`100%`}}),p?(0,G.jsx)(`img`,{src:p,alt:s,className:`absolute inset-0 w-full h-full object-cover transition-transform duration-300 group-hover:scale-[1.03]`,loading:`lazy`,decoding:`async`}):a?null:(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(t,{className:`size-8 text-muted-foreground/30`})}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-black/25`,children:(0,G.jsx)(`div`,{className:`size-12 rounded-full bg-black/60 flex items-center justify-center`,children:(0,G.jsx)(t,{className:`size-6 text-white fill-white ml-0.5`})})})]}),(0,G.jsx)(`p`,{className:`mt-1.5 text-xs font-medium line-clamp-2 leading-snug group-hover:text-primary transition-colors w-full overflow-hidden`,children:s})]})})}function ge({events:e,startIndex:t,onClose:n}){let[i,a]=(0,W.useState)(t),o=(0,W.useRef)(null);return(0,W.useEffect)(()=>{let e=o.current;e&&e.scrollTo({top:t*e.clientHeight,behavior:`instant`})},[]),(0,W.useEffect)(()=>{let e=o.current;if(!e)return;let t=new IntersectionObserver(t=>{for(let n of t)if(n.isIntersecting&&n.intersectionRatio>=.5){let t=Array.from(e.children).indexOf(n.target);t!==-1&&a(t)}},{root:e,threshold:.5});return Array.from(e.children).forEach(e=>t.observe(e)),()=>t.disconnect()},[e]),(0,W.useEffect)(()=>{let t=t=>{let r=o.current;if(t.key===`Escape`){n();return}if(r){if(t.key===`ArrowDown`){t.preventDefault();let n=Math.min(i+1,e.length-1);r.scrollTo({top:n*r.clientHeight,behavior:`smooth`}),a(n)}else if(t.key===`ArrowUp`){t.preventDefault();let e=Math.max(i-1,0);r.scrollTo({top:e*r.clientHeight,behavior:`smooth`}),a(e)}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[n,i,e.length]),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col`,children:[(0,G.jsx)(V,{title:`Videos`,icon:(0,G.jsx)(r,{className:`size-5`}),onBack:n,alwaysShowBack:!0}),(0,G.jsx)(`div`,{ref:o,className:`vine-slide-height sidebar:h-[calc(100vh-3rem)] snap-y snap-mandatory overflow-y-scroll`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`,overscrollBehavior:`none`},children:e.map((e,t)=>(0,G.jsx)(`div`,{className:`w-full vine-slide-height sidebar:h-[calc(100vh-3rem)] snap-start snap-always flex-shrink-0`,children:(0,G.jsx)(U,{event:e,isActive:t===i,isNearActive:Math.abs(t-i)<=1,onCommentClick:()=>{}})},e.id))})]})}function _e({events:e,onOpen:t}){let n=X();return e.length===0?null:(0,G.jsxs)(`section`,{children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3 px-4`,children:`Shorts`}),(0,G.jsx)(`div`,{ref:n.ref,className:`flex gap-2.5 overflow-x-auto px-4 pb-2 cursor-grab`,style:{scrollbarWidth:`none`},onMouseDown:n.onMouseDown,onMouseMove:n.onMouseMove,onMouseUp:n.onMouseUp,onMouseLeave:n.onMouseLeave,children:e.map((e,n)=>(0,G.jsx)(`div`,{className:`shrink-0 w-32`,children:(0,G.jsx)(he,{event:e,onClick:()=>t(n)})},e.id))})]})}function ve(){let{config:e}=m(),{user:t}=_(),{isMuted:n}=B(),[i,a]=oe(`videos`,[`follows`,`global`]);ae({title:`Videos | ${e.appName}`,description:`Videos and live streams on Nostr`});let[o,s]=(0,W.useState)(null);N({showFAB:!1,noOverscroll:!0,hasSubHeader:o===null}),(0,W.useEffect)(()=>{y(!1)},[i]);let c=F(`follows`,{kinds:[21,22]}),l=te([21,22],i===`global`,se),{data:u,isPending:d,isLoading:f}=i===`follows`?c:l,p=(0,W.useMemo)(()=>{if(!u?.pages)return[];let t=new Set,r=i===`follows`?u.pages.flatMap(e=>e.items).map(e=>e.event):u.pages.flat(),a=e.contentWarningPolicy===`hide`;return r.filter(e=>t.has(e.id)||(t.add(e.id),![21,22].includes(e.kind))||n(e)||a&&I(e)!==void 0?!1:!!J(e.tags).url)},[u?.pages,n,i,e.contentWarningPolicy]),h=(0,W.useMemo)(()=>p.filter(e=>e.kind===21),[p]),g=(0,W.useMemo)(()=>p.filter(e=>e.kind===22),[p]),[v,y]=(0,W.useState)(!1),{data:b}=Q(i),x=b.live.length+b.planned.length+b.past.length>0?4:6,S=v?h:h.slice(0,x),C=d||f&&!u,w=ee([`feed`]);return o===null?(0,G.jsxs)(`main`,{className:``,children:[(0,G.jsx)(V,{title:`Videos`,icon:(0,G.jsx)(r,{className:`size-5`}),children:(0,G.jsx)(H,{kindDef:K,icon:A(`videos`,`size-5`)})}),(0,G.jsxs)(P,{children:[(0,G.jsx)(z,{label:`Follows`,active:i===`follows`,onClick:()=>a(`follows`),disabled:!t}),(0,G.jsx)(z,{label:`Global`,active:i===`global`,onClick:()=>a(`global`)})]}),(0,G.jsx)(`div`,{style:{height:20}}),(0,G.jsx)(me,{tab:i}),(0,G.jsx)(re,{onRefresh:w,children:C?(0,G.jsxs)(`div`,{className:`pt-3 pb-8 px-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3`,children:`Videos`}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-6`,children:Array.from({length:4}).map((e,t)=>(0,G.jsx)(de,{},t))})]}):p.length===0?(0,G.jsx)(ie,{message:i===`follows`?`No videos yet. Follow some creators to see their videos here.`:`No videos found. Check your relay connections or come back soon.`,onSwitchToGlobal:i===`follows`?()=>a(`global`):void 0}):(0,G.jsxs)(`div`,{className:`pt-3 pb-8`,children:[h.length>0&&(0,G.jsxs)(`div`,{className:`px-4 mb-8`,children:[(0,G.jsx)(`p`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3`,children:`Videos`}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-6`,children:S.map(e=>(0,G.jsx)(ue,{event:e},e.id))}),!v&&h.length>x&&(0,G.jsxs)(`button`,{className:`mt-5 w-full text-sm text-muted-foreground hover:text-foreground transition-colors py-2 border border-border rounded-lg`,onClick:()=>y(!0),children:[`Show `,h.length-x,` more`]})]}),g.length>0&&(0,G.jsx)(_e,{events:g,onOpen:s})]})})]}):(0,G.jsx)(ge,{events:g,startIndex:o,onClose:()=>s(null)})}export{ve as VideosFeedPage}; // @license-end