import{a0 as b,r as n,j as e,a1 as h,a2 as y,T as a,a3 as D,aA as d,t as m,ae as w,S as T,D as v,a9 as C,Y as S,q as I,O as P}from"./main-D6SjkSWq.js";import{b as k,o as N,c as A}from"./offline-media-items-UIpHpvk8.js";import{C as B}from"./confirmation-dialog-E4zsogCz.js";import{D as M}from"./dialog-footer-es-AfbvV.js";import{p as u}from"./pretty-bytes-bO14ePu9.js";import{A as x}from"./ad-host-CDKj9Ffh.js";import{I as E}from"./Info-DJrDtfBN.js";import{T as U,a as z,b as i}from"./tabs-BwrtVGjA.js";import{T as L}from"./tab-panels-DDLnWdlJ.js";import"./extension-from-filename-O0XMuZye.js";import"./getScrollParent--OCc5gFh.js";const _=5e6,g=1e6;async function O(){const s=await navigator.storage.estimate();let t=s.usage??0,o=s.quota??0;if(t){const l=s.usageDetails;l?t=t-(l.caches+l.serviceWorkerRegistrations):t=t-_}return{used:t,available:o,usedPretty:u(t),availablePretty:u(o)}}function q(){const{close:s}=b(),[t,o]=n.useState(!1),[l,f]=n.useState(null),j=(l==null?void 0:l.used)&&l.used>g,r=n.useCallback(()=>O().then(c=>f(c)),[]);n.useEffect(()=>{r()},[]);const p=async()=>{o(!0),await Promise.allSettled([k.clear(),N.clear(),A()]),await r(),o(!1)};return e.jsxs(h,{size:"md",children:[e.jsx(y,{children:e.jsx(a,{message:"Space usage"})}),e.jsx(D,{children:l==null?e.jsx("div",{className:"flex min-h-40 items-center",children:e.jsx(d,{isIndeterminate:!0,size:"sm"})}):e.jsx(F,{usage:l})}),e.jsxs(M,{children:[j&&e.jsx(m,{variant:"outline",disabled:t,startIcon:t?e.jsx(d,{isIndeterminate:!0,size:"xs"}):null,onClick:async()=>{await w(H)&&await p()},children:e.jsx(a,{message:"Delete downloaded content"})}),e.jsx(m,{variant:"flat",color:"primary",onClick:()=>s(),children:e.jsx(a,{message:"Done"})})]})]})}function F({usage:s}){return!s||s.used<g?e.jsx(a,{message:"Music downloaded for offline playback is currently using less then 1mb of space."}):e.jsx(a,{message:"Music downloaded for offline playback is currently using approximately :used of :available availble space.",values:{used:s.usedPretty,available:s.availablePretty}})}function H(){return e.jsx(B,{isDanger:!0,title:e.jsx(a,{message:"Delete downloaded content"}),body:e.jsx(a,{message:"Are you sure you want to delete all downloaded content?"}),confirm:e.jsx(a,{message:"Delete"})})}function ae(){return e.jsxs("div",{children:[e.jsx(T,{children:e.jsx(a,{message:"Downloads - Library"})}),e.jsx(x,{slot:"general_top",className:"mb-34"}),e.jsxs("div",{className:"flex items-center justify-between gap-24",children:[e.jsx("h1",{className:"w-max whitespace-nowrap text-2xl font-semibold md:w-full",children:e.jsx(a,{message:"Downloads"})}),e.jsxs(v,{type:"modal",children:[e.jsx(C,{label:e.jsx(a,{message:"Space usage"}),children:e.jsx(S,{size:"md",className:"text-muted",children:e.jsx(E,{})})}),e.jsx(q,{})]})]}),e.jsx(R,{}),e.jsx(x,{slot:"general_bottom",className:"mt-34"})]})}function R(){const{pathname:s}=I(),[t,o]=n.useState(()=>V(s.split("/").pop()));return e.jsxs(U,{className:"mt-14",selectedTab:t,onTabChange:o,children:[e.jsxs(z,{children:[e.jsx(i,{to:"/library/downloads/songs",children:e.jsx(a,{message:"Songs"})}),e.jsx(i,{to:"/library/downloads/playlists",children:e.jsx(a,{message:"Playlists"})}),e.jsx(i,{to:"/library/downloads/albums",children:e.jsx(a,{message:"Albums"})})]}),e.jsx(L,{children:e.jsx(P,{})})]})}function V(s){switch(s){case"songs":return 0;case"playlists":return 1;case"albums":return 2;default:return 0}}export{ae as Component};
