import{j as t}from"./jsx-runtime.D_zvdyIk.js";import{u as z,r as B,P as G,M as K,a as L}from"./MediaControls.BR73DGkp.js";import{u as V,a as Q,b as q,c as J,d as U}from"./floating-ui.react.BIavrRt9.js";import{u as W}from"./useMediaQuery.CQ7x5FXM.js";import{u as X}from"./useTranslation.Dg7DwAC5.js";import{I as Y}from"./iconify.pctX9hd_.js";import{u as g}from"./index.RTTH55m1.js";import{d as Z,e as _}from"./modal.CmyA2O2l.js";import{r as o}from"./index.BIRwh3HZ.js";import{$ as ee,c as P}from"./bgm.BGD4n5gC.js";import{A as te}from"./index.BbbUxuaI.js";import{m as ae}from"./proxy.D9st1TsE.js";import"./index.3whys8t3.js";import"./utils.BZbvJs_N.js";import"./floating-ui.react-dom.Pr5t-z7H.js";import"./index.Ky-LTxRX.js";import"./_commonjsHelpers.CqkleIqs.js";import"./index.CHUzDkS6.js";import"./utils.D6Ui05B2.js";import"./site-config.CgQ_bxrG.js";import"./site.Deo0TYgJ.js";import"./index.BHh4vvK5.js";function we({audioGroups:u}){const{t:s}=X(),i=g(ee),j=g(Z),S=g(_),k=W("(max-width: 600px)"),[c,w]=o.useState([]),[M,T]=o.useState([]),[N,m]=o.useState(!1),[y,f]=o.useState(null),[O,C]=o.useState(0),[d,E]=o.useState(0),x=o.useRef(-1);o.useEffect(()=>{if(!i||x.current===d)return;x.current=d;let a=!1;m(!0),f(null);async function b(){try{const r=await Promise.all(u.map(n=>B(n.list)));if(!a){const n=[],v=[];for(let l=0;l<r.length;l++){const H=n.length;n.push(...r[l]),v.push({title:u[l].title,startIndex:H,count:r[l].length})}w(n),T(v),m(!1)}}catch(r){a||(f(r instanceof Error?r.message:"Failed to load playlist"),m(!1))}}return b(),()=>{a=!0}},[i,u,d]);const e=z(c),I=c[e.state.currentIndex]??null,h=j||S,{refs:A,context:p}=V({open:i&&!h,onOpenChange:a=>{a||P()}}),F=Q(p,{outsidePressEvent:"mousedown",outsidePress:a=>!a.target.closest("[data-bgm-toggle]")}),R=q(p,{role:"dialog"}),{getFloatingProps:$}=J([F,R]),D=()=>N?t.jsxs("output",{className:"audio-player audio-player-loading bgm-panel-player",children:[t.jsx("div",{className:"audio-player-spinner"}),t.jsx("span",{children:s("audio.loading")})]}):y?t.jsxs("div",{className:"audio-player audio-player-error bgm-panel-player",role:"alert",children:[t.jsx("span",{children:s("audio.loadError",{error:y})}),t.jsx("button",{type:"button",className:"audio-player-btn",onClick:()=>E(a=>a+1),children:s("audio.retry")})]}):c.length===0?t.jsx("div",{className:"audio-player audio-player-empty bgm-panel-player",children:t.jsx("span",{children:s("audio.empty")})}):t.jsxs("div",{className:"audio-player not-prose bgm-panel-player",children:[t.jsx(G,{track:I,playing:e.state.playing,timeStore:e.timeStore,lrcLineHeight:28,lrcContainerHeight:k?168:140}),t.jsx(K,{playing:e.state.playing,loading:e.state.loading,mode:e.state.mode,volume:e.state.volume,muted:e.state.muted,timeStore:e.timeStore,onTogglePlay:e.togglePlay,onPrev:e.prevTrack,onNext:e.nextTrack,onSeek:e.seek,onSetMode:e.setMode,onSetVolume:e.setVolume,onToggleMute:e.toggleMute}),t.jsx(L,{tracks:c,groups:M,currentIndex:e.state.currentIndex,timeStore:e.timeStore,activeTab:O,onTabChange:C,onTrackSelect:e.play,onSeek:e.seek})]});return t.jsx(te,{children:i&&!h&&t.jsx(U,{context:p,modal:!1,children:t.jsx(ae.div,{ref:A.setFloating,...$(),className:"fixed right-16 bottom-20 z-40 w-[460px] max-w-[calc(100vw-5rem)]",initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:20,scale:.95},transition:{duration:.2,ease:"easeOut"},children:t.jsxs("div",{className:"bgm-panel max-h-[85vh] overflow-y-auto overscroll-none rounded-2xl shadow-xl sm:max-h-[70vh] sm:overflow-hidden",children:[t.jsx("button",{type:"button",className:"absolute top-2 right-2 z-10 rounded-full bg-background/80 p-1.5 text-muted-foreground backdrop-blur-sm transition-colors hover:bg-background hover:text-foreground",onClick:P,"aria-label":s("audio.closePanel"),children:t.jsx(Y,{icon:"ri:close-line",className:"h-4 w-4"})}),D()]})})})})}export{we as default};
