import{r as f,j as n,a9 as g,Y as v,d as u,T as m,v as j}from"./main-D6SjkSWq.js";import{u as I,o as h}from"./share-media-button-DKcCMMvL.js";import{a as p,b,o as k}from"./offline-media-items-UIpHpvk8.js";import{u as y}from"./add-to-queue-menu-button-DVWr6Cai.js";import{C as w}from"./check-circle-filled-nHXYTdsh.js";import{D as M}from"./Download-w2QmFucW.js";function N({item:e,className:a,totalTracksCount:r}){const[s,i]=f.useState(0),c=y(),o=I(l=>e.model_type==="album"?l.offlinedAlbumIds.has(e.id):l.offlinedPlaylistIds.has(e.id));return f.useEffect(()=>{if(o){let l=0;const t=()=>{C(e,r).then(d=>{d!==l&&i(d),l=d})};return t(),p.listen("onActiveDownloadsChanged",t)}},[o,r]),c?n.jsx(O,{isOfflined:o,className:a,progress:s,onClick:()=>{o?h().deleteOfflinedMediaItem(e):h().offlineMediaItem(e)}}):null}function O({isOfflined:e,className:a,progress:r,onClick:s}){return n.jsx(g,{label:e?n.jsx(m,{message:"Remove from this device"}):n.jsx(m,{message:"Make available offline"}),children:n.jsx(v,{variant:"outline",className:u(a,e&&r>0&&r<100&&"button-with-progress"),style:{"--progress":`${r}%`},onClick:()=>s(),children:e?n.jsx(w,{}):n.jsx(M,{})})})}async function C(e,a){const r=Math.min(a,b.MAX_ITEMS)*100;let s=0;const i=await k.getTracksOfflinedBy(e),c=i.map(t=>t.id),o=i.filter(t=>t.isDownloaded).map(t=>t.id);s+=o.length*100;const l=p.getDownloadProgress().entries().reduce((t,[d,x])=>c.includes(d)?t+x:t,0);return s+=l,Math.trunc(s/r*100)}function S({children:e,showMore:a=!0,className:r}){const s=f.Children.toArray(e);if(!s.length)return null;const i=s[0].props.link,c=s[0].props.label;return n.jsxs("div",{className:u("isolate flex items-center pl-10",r),children:[s.map((o,l)=>n.jsx("div",{style:{zIndex:5-l},className:u("relative -ml-10 flex-shrink-0 overflow-hidden rounded-full border-2 border-bg-alt bg-alt"),children:o},l)),n.jsxs("div",{className:"ml-10 whitespace-nowrap text-sm",children:[i&&c?n.jsx(j,{to:i,className:"hover:underline",children:c}):null,a&&s.length>1&&n.jsxs("span",{children:[" ",n.jsx(m,{message:"+ :count more",values:{count:s.length-1}})]})]})]})}export{S as A,N as O,O as a};
