// @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{Ht as t,It as n,Wr as r,Zt as i,_n as a,qi as o}from"./lucide-icons-BdRF0moN.js";import{t as s}from"./jsx-runtime-By8HlURe.js";import{t as c}from"./dist-DQ82bf9M.js";import{u as l}from"./esm-CRVqHnq2.js";import{t as u}from"./useQuery-rCAlChE8.js";import{o as d,r as f}from"./react-intl-eZirkCBg.js";import{l as p,t as m}from"./useCurrentUser-C6OJJlWo.js";import{t as h}from"./utils-BFSTDHdM.js";import{n as g}from"./useFollowActions-cve70R08.js";import{n as _,o as v,r as y,t as b}from"./avatar--oX_CTF4.js";import{n as x}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{n as S}from"./CustomEmoji-DRcU63lJ.js";import{t as C}from"./skeleton-CVls4GW9.js";import{a as w,i as T,n as E,r as D,s as O}from"./musicHelpers-B271Bg0t.js";import{t as k}from"./timeAgo-BXjjbyXp.js";import{t as A}from"./formatTime-CT4ZmnVr.js";import{t as j}from"./DecryptedImage-DLbW5kmn.js";import{s as M}from"./index-CYEZWNq6.js";var N=e(o(),1),P=s();function F(){let{nostr:e}=c(),{user:t}=m(),{data:n}=g(),{data:r}=M(),i=n?.pubkeys,a=t&&i?.length?i:r,{data:o,isLoading:s}=u({queryKey:[`widget-music`,t?`follows`:`curator`],queryFn:async()=>(await e.query([{kinds:[36787],limit:1,...a?{authors:a}:{}}]))[0]??null,staleTime:5*6e4,enabled:t?i!==void 0:r!==void 0});return s?(0,P.jsxs)(`div`,{className:`space-y-2 p-1`,children:[(0,P.jsx)(C,{className:`w-full aspect-square rounded-lg`}),(0,P.jsx)(C,{className:`h-4 w-3/4`}),(0,P.jsx)(C,{className:`h-3 w-1/2`}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(C,{className:`size-5 rounded-full`}),(0,P.jsx)(C,{className:`h-3 w-24`})]})]}):o?(0,P.jsx)(I,{event:o}):(0,P.jsx)(`p`,{className:`text-sm text-muted-foreground p-1`,children:(0,P.jsx)(f,{id:`widgets.music.empty`,defaultMessage:`No music yet.`})})}function I({event:e}){let o=d(),s=O(),c=p(e.pubkey),u=c.data?.metadata,f=v(u),m=u?.name||u?.display_name||o.formatMessage({id:`common.anonymous`,defaultMessage:`Anonymous`}),g=(0,N.useMemo)(()=>E(e),[e]),C=w(e.id),M=(0,N.useMemo)(()=>{let t=e.tags.find(([e])=>e===`d`)?.[1]??``;return l.naddrEncode({kind:e.kind,pubkey:e.pubkey,identifier:t})},[e]);if(!g)return null;let F=s.currentTrack?.id===e.id,I=C.status===`decrypting`,L=g.duration?A(g.duration):void 0;return(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsxs)(`div`,{className:h(`relative rounded-lg overflow-hidden cursor-pointer`,F?`ring-2 ring-primary`:``),onClick:t=>{if(t.preventDefault(),t.stopPropagation(),F&&s.isPlaying)s.pause();else if(F)s.resume();else{let t=D(e,g);t.artwork??=u?.picture,s.playTrack(t)}},children:[g.artwork?(0,P.jsx)(j,{url:g.artwork,encryption:g.artworkEncryption,alt:g.title,className:`w-full aspect-square object-cover`,loading:`lazy`,decoding:`async`,noticeClassName:`aspect-square`}):(0,P.jsx)(`div`,{className:`w-full aspect-square bg-gradient-to-br from-primary/10 via-primary/5 to-transparent flex items-center justify-center`,children:(0,P.jsx)(i,{className:`size-12 text-primary/20`})}),(0,P.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/0 hover:bg-black/15 transition-colors`,children:(0,P.jsx)(`div`,{className:h(`size-12 rounded-full flex items-center justify-center transition-colors`,F&&s.isPlaying||I?`bg-primary text-primary-foreground`:`bg-primary/15 text-primary hover:bg-primary/25 backdrop-blur-sm`),children:I?(0,P.jsx)(a,{className:`size-5 animate-spin`}):F&&s.isPlaying?(0,P.jsx)(t,{className:`size-5`,fill:`currentColor`}):(0,P.jsx)(n,{className:`size-5 ml-0.5`,fill:`currentColor`})})})]}),(0,P.jsxs)(x,{to:`/${M}`,className:`block px-0.5 space-y-1 group`,children:[(0,P.jsx)(`p`,{className:`text-sm font-semibold leading-snug truncate group-hover:text-primary transition-colors`,children:g.title}),g.artist&&(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:g.artist}),(0,P.jsx)(T,{trackId:e.id}),L&&(0,P.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,P.jsx)(r,{className:`size-3 shrink-0`}),(0,P.jsx)(`span`,{children:L})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5 pt-0.5`,children:[(0,P.jsxs)(b,{shape:f,className:`size-4`,children:[(0,P.jsx)(y,{src:u?.picture,alt:m}),(0,P.jsx)(_,{className:`bg-primary/20 text-primary text-[8px]`,children:m[0]?.toUpperCase()})]}),(0,P.jsx)(`span`,{className:`text-xs font-semibold truncate`,children:c.data?.event?(0,P.jsx)(S,{tags:c.data.event.tags,children:m}):m}),(0,P.jsxs)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[`· `,k(e.created_at)]})]})]})]})}export{F as MusicWidget};
// @license-end
