import{q as S,ag as y,e as T,G as A,H as P,ab as j,I as E,J as I,b as O,ay as R,u as k,a0 as u,r as d,j as e,T as a,ae as $}from"./main-D6SjkSWq.js";import{C as F,b as G,c as l,t as q,d as Q,u as _,o as h}from"./share-media-button-DKcCMMvL.js";import{A as U,u as W}from"./add-to-queue-menu-button-DVWr6Cai.js";import{g as H}from"./album-link-C4KAB_gW.js";import{g as K}from"./artist-link-C48CzE2I.js";import{A as J}from"./artist-links-B9W9tkZ1.js";import{T as N,C as V}from"./toggle-in-library-menu-button-BMnh-DuO.js";import{T as z}from"./toggle-repost-menu-button-C0ryZAsI.js";import{u as X,g as Y}from"./use-should-show-radio-button-_ni_Honj.js";import{u as b}from"./use-track-permissions-thcH1McM.js";import{T as Z}from"./track-image-DHipIy5D.js";import{g as p,T as ee}from"./track-link-BvulRuhc.js";import{u as se,b as te}from"./use-player-store-_08VVZOs.js";import{C as ne}from"./confirmation-dialog-E4zsogCz.js";import{d as oe}from"./download-file-from-url-BVaKcxRP.js";function ae(){const{pathname:t}=S(),s=y(),{getRedirectUri:i}=T();return A({mutationFn:o=>ie(o),onSuccess:async(o,{trackIds:n})=>{await j.invalidateQueries({queryKey:["tracks"]}),await j.invalidateQueries({queryKey:["channel"]}),E(I("[one Track|other :count Tracks] deleted",{values:{count:n.length}})),n.some(r=>t.startsWith(`/track/${r}`))&&s(i())},onError:o=>P(o)})}function ie({trackIds:t}){return O.delete(`tracks/${t.join(",")}`).then(s=>s.data)}function le(t){return(t==null?void 0:t.src)!=null&&t.src_local}function ve({children:t,tracks:s,showAddToQueueButton:i=!0}){var f;const o=R(),n=s[0],{canEdit:r,canDelete:C}=b(s),D=X(),{player:c}=k(),{close:w}=u(),M=y(),m=se(B=>{var x;return(x=B.cuedMedia)==null?void 0:x.meta}),{play:v}=te(),g=d.useCallback(()=>Promise.resolve(s),[s]),L=s.length===1?{image:e.jsx(Z,{track:n}),title:e.jsx(ee,{track:n}),description:e.jsx(J,{artists:n.artists})}:{};return e.jsxs(F,{...L,loadTracks:g,children:[i&&e.jsx(U,{item:null,loadTracks:g}),e.jsx(N,{items:s}),t==null?void 0:t(s),e.jsx(G,{}),s.length===1?e.jsxs(d.Fragment,{children:[D&&e.jsx(l,{type:"link",to:Y(n),children:e.jsx(a,{message:"Go to song radio"})}),o&&e.jsxs(d.Fragment,{children:[((f=n.artists)==null?void 0:f[0])&&e.jsx(l,{type:"link",to:K(n.artists[0]),children:e.jsx(a,{message:"Go to artist"})}),n.album&&e.jsx(l,{type:"link",to:H(n.album),children:e.jsx(a,{message:"Go to album"})}),e.jsx(l,{type:"link",to:p(n),enableWhileOffline:!0,children:e.jsx(a,{message:"Go to track"})})]}),!(c!=null&&c.hide_lyrics)&&s.length===1&&e.jsx(l,{onClick:async()=>{w(),(m==null?void 0:m.id)!==n.id&&await v(await q(n)),M("/lyrics")},children:e.jsx(a,{message:"View lyrics"})}),!o&&e.jsx(V,{link:p(n,{absolute:!0}),children:e.jsx(a,{message:"Copy song link"})}),e.jsx(re,{tracks:s}),s.length===1&&e.jsx(Q,{item:n}),s.length===1&&e.jsx(ue,{track:n}),s.length===1?e.jsx(z,{item:s[0]}):null,s.length===1&&r&&e.jsx(l,{type:"link",to:`/backstage/tracks/${n.id}/insights`,children:e.jsx(a,{message:"Insights"})}),s.length===1&&r&&e.jsx(l,{type:"link",to:`/backstage/tracks/${n.id}/edit`,children:e.jsx(a,{message:"Edit"})})]}):null,C&&!o&&e.jsx(ce,{tracks:s})]})}function re({tracks:t}){const{close:s}=u(),i=W()&&t.every(n=>n.src),o=_(n=>t.every(r=>n.offlinedTrackIds.has(r.id)));return i?e.jsx(l,{enableWhileOffline:!0,onClick:async()=>{s(),o?h().deleteOfflinedTracks(t):h().offlineTracks(t)},children:o?e.jsx(a,{message:"Remove from this device"}):e.jsx(a,{message:"Make available offline"})}):null}function ue({track:t}){const{player:s,base_url:i}=k(),{close:o}=u(),{hasPermission:n}=T();return!(s!=null&&s.enable_download)||!t||!le(t)||!n("music.download")?null:e.jsx(l,{onClick:()=>{o(),oe(`${i}/api/v1/tracks/${t.id}/download`)},children:e.jsx(a,{message:"Download"})})}function ce({tracks:t}){const{close:s}=u(),{canDelete:i}=b(t);return i?e.jsx(l,{onClick:()=>{s(),$(me,{tracks:t})},children:e.jsx(a,{message:"Delete"})}):null}function me({tracks:t}){const s=ae(),{close:i}=u();return e.jsx(ne,{isDanger:!0,title:e.jsx(a,{message:"Delete tracks"}),body:e.jsx(a,{message:"Are you sure you want to delete selected tracks?"}),isLoading:s.isPending,confirm:e.jsx(a,{message:"Delete"}),onConfirm:()=>{s.mutate({trackIds:t.map(o=>o.id)},{onSuccess:()=>i()})}})}export{ve as T,le as t};
