import{c as N}from"./createLucideIcon-Bp-vR5YK.js";import{a as o,o as t,L as E}from"./chunk-NL6KNZEE-DfxmOBHd.js";import{R as w}from"./index-0dO883bS.js";import{i as u}from"./api-BuTqLiNI.js";/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const C=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],R=N("check",C);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const _=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}]],F=N("trash",_);function T({isOpen:s,onClose:i,children:x,maxW:d,h:f}){const l=o.useRef(null),[c,m]=o.useState(s),[e,n]=o.useState(!1);return o.useEffect(()=>{if(s)m(!0),n(!1);else if(c){n(!0);const r=setTimeout(()=>{m(!1)},100);return()=>clearTimeout(r)}},[s,c]),o.useEffect(()=>{const r=a=>{if(a.key==="Escape")i();else if(a.key==="Tab"&&l.current){const h=l.current.querySelectorAll('button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])'),g=h[0],b=h[h.length-1],j=document.activeElement;a.shiftKey&&j===g?(a.preventDefault(),b.focus()):!a.shiftKey&&j===b?(a.preventDefault(),g.focus()):Array.from(h).find(k=>k.isEqualNode(j))||(a.preventDefault(),g.focus())}};return s&&document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[s,i]),o.useEffect(()=>{const r=a=>{l.current&&!l.current.contains(a.target)&&i()};return s&&document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[s,i]),c?w.createPortal(t.jsx("div",{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 transition-opacity duration-100 ${e?"animate-fade-out":"animate-fade-in"}`,children:t.jsxs("div",{ref:l,className:`bg-secondary rounded-lg shadow-md p-6 w-full relative max-h-3/4 overflow-y-auto transition-all duration-100 ${e?"animate-fade-out-scale":"animate-fade-in-scale"}`,style:{maxWidth:d??600,height:f??""},children:[x,t.jsx("button",{onClick:i,className:"absolute top-2 right-2 color-fg-tertiary hover:cursor-pointer",children:"🞪"})]})}),document.body):null}function v(s){return t.jsxs(E,{to:s.to,className:"px-3 py-2 flex gap-3 items-center hover:text-(--color-fg-secondary)",onClick:s.onClick,children:[t.jsx("img",{src:s.img,alt:s.text}),t.jsxs("div",{children:[s.text,s.subtext?t.jsxs(t.Fragment,{children:[t.jsx("br",{}),t.jsx("span",{className:"color-fg-secondary",children:s.subtext})]}):""]})]})}function y(s){return t.jsxs("button",{className:"px-3 py-2 flex gap-3 items-center hover:text-(--color-fg-secondary) hover:cursor-pointer w-full",style:{border:s.active?"1px solid var(--color-fg-tertiary":""},onClick:s.onClick,children:[t.jsx("img",{src:s.img,alt:s.text}),t.jsxs("div",{className:"flex justify-between items-center w-full",children:[t.jsxs("div",{className:"flex flex-col items-start text-start",children:[s.text,s.subtext?t.jsxs(t.Fragment,{children:[t.jsx("br",{}),t.jsx("span",{className:"color-fg-secondary",children:s.subtext})]}):""]}),s.active?t.jsx("div",{className:"px-2",children:t.jsx(R,{size:24})}):""]})]})}function $({data:s,onSelect:i,selectorMode:x}){const[d,f]=o.useState(0),l="flex flex-col items-start bg rounded w-full",c="pt-4 pb-2",m=(e,n)=>{d===n?(f(0),i({id:0,title:""})):(f(n),i({id:n,title:e}))};return s?t.jsxs("div",{className:"w-full",children:[s.artists&&s.artists.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:c,children:"Artists"}),t.jsx("div",{className:l,children:s.artists.map(e=>x?t.jsx(y,{id:e.id,onClick:()=>m(e.name,e.id),text:e.name,img:u(e.image,"small"),active:d===e.id}):t.jsx(v,{to:`/artist/${e.id}`,onClick:()=>i(e.id),text:e.name,img:u(e.image,"small")}))})]}),s.albums&&s.albums.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:c,children:"Albums"}),t.jsx("div",{className:l,children:s.albums.map(e=>x?t.jsx(y,{id:e.id,onClick:()=>m(e.title,e.id),text:e.title,subtext:e.is_various_artists?"Various Artists":e.artists[0].name,img:u(e.image,"small"),active:d===e.id}):t.jsx(v,{to:`/album/${e.id}`,onClick:()=>i(e.id),text:e.title,subtext:e.is_various_artists?"Various Artists":e.artists[0].name,img:u(e.image,"small")}))})]}),s.tracks&&s.tracks.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:c,children:"Tracks"}),t.jsx("div",{className:l,children:s.tracks.map(e=>x?t.jsx(y,{id:e.id,onClick:()=>m(e.title,e.id),text:e.title,subtext:e.artists.map(n=>n.name).join(", "),img:u(e.image,"small"),active:d===e.id}):t.jsx(v,{to:`/track/${e.id}`,onClick:()=>i(e.id),text:e.title,subtext:e.artists.map(n=>n.name).join(", "),img:u(e.image,"small")}))})]})]}):t.jsx(t.Fragment,{})}export{T as M,$ as S,F as T};
