1import{k as mt,r as x,j as e,m as z,d as q,L as U,t as B,b as W,Z as Fe,_ as pt,X as ft,z as Ie,S as Be}from"./index-DuFHDgjL.js";import{B as G}from"./button-yDjC60w6.js";import{I as Q}from"./input-BchJnEvt.js";import{S as fe,a as be,b as ge,c as we,d as X}from"./select-CTaXbays.js";import{S as Re}from"./switch-BHFRoUQ8.js";import{L as H}from"./label-DBtZhQt0.js";import{G as V,a as Le}from"./genreStyles-pQ4Esg08.js";import{C as te}from"./circle-check-big-ye-FYAvc.js";import{C as J}from"./chevron-down-Bdq-JZJg.js";import{T as Ee}from"./triangle-alert-BjdqLddS.js";import{T as ce}from"./trash-2-DGlMKV6d.js";import{P as je}from"./pause-DCPLD30Z.js";import{P as ze}from"./play-DilJhz7N.js";import{M as de}from"./monitor-nCsrNCgq.js";import{S as se}from"./smartphone-DGxPxJUv.js";import{S as kt}from"./star-BmsffQhe.js";import{U as pe}from"./upload-DZKxwZ5x.js";import{P as Se}from"./pencil-zE_nrppg.js";import{C as bt}from"./cpu-CH3f6aec.js";import{T as Ne}from"./tag-BblMJVT7.js";import{C as gt}from"./circle-x-C93ttxVe.js";import{W as _t}from"./wand-sparkles-BE1CF72a.js";import{M as Ze}from"./music-2-DiN9vkpz.js";import{S as St}from"./sliders-horizontal-D5HOIoRJ.js";import{S as Ct}from"./search-C_G_OQeo.js";import{L as $t}from"./list-fhkpZduR.js";import{L as At}from"./layout-grid-CLZKiUJW.js";import{S as xe}from"./square-check-big-Ch026B2D.js";import{S as Ce}from"./square-CLLvJoMZ.js";import"./index-DFErrfuN.js";import"./index-BKzA9_yg.js";import"./index-BdQq_4o_.js";import"./index-Byqjatey.js";import"./index-DopWwC6Z.js";import"./Combination-CvBmiCYy.js";import"./index-DxLiK4pb.js";import"./index-oxxjwFLh.js";import"./index-DNEy9Puf.js";import"./index-KNO01SsF.js";import"./index-BDQDCtFg.js";import"./chevron-up-KePEYZmq.js";/** 2 * @license lucide-react v0.475.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Dt=[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]],Mt=mt("FileAudio",Dt);/** 7 * @license lucide-react v0.475.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Tt=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]],Xe=mt("ScanSearch",Tt),Ye=W.entities.AudioTrack;function he(t){return(t||"").toLowerCase().replace(/\.[^/.]+$/,"").replace(/[-_]/g," ").replace(/\s+/g," ").trim()}function Qe(t){const s=Math.round(t||0);return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`}function Ft(t){const s=[],r=new Set;for(let g=0;g<t.length;g++){if(r.has(t[g].id))continue;const w=[t[g]];for(let u=g+1;u<t.length;u++){if(r.has(t[u].id))continue;const i=t[g],c=t[u],a=he(i.name)===he(c.name),f=he(i.artist)===he(c.artist),m=i.duration_seconds||0,A=c.duration_seconds||0,y=Math.abs(m-A)<=2;a&&f&&y&&(w.push(c),r.add(c.id))}w.length>1&&(r.add(t[g].id),s.push(w))}return s}function It({tracks:t,onComplete:s}){const[r,g]=x.useState(!1),[w,u]=x.useState(!1),[i,c]=x.useState(null),[a,f]=x.useState(new Set),[m,A]=x.useState(new Set),y=()=>{u(!0),setTimeout(()=>{const b=Ft(t);c(b),u(!1),A(new Set),b.length===0?B.success("â No duplicates found! Library is clean."):B.warning(`â Found ${b.length} duplicate group${b.length>1?"s":""}.`)},600)},F=async b=>{f(N=>new Set([...N,b]));try{await Ye.delete(b),A(N=>new Set([...N,b])),B.success("Deleted duplicate track."),s()}catch{B.error("Failed to delete track.")}finally{f(N=>{const v=new Set(N);return v.delete(b),v})}},k=async()=>{if(!(i!=null&&i.length))return;const b=i.flatMap(N=>[...N].sort((o,j)=>new Date(o.created_date)-new Date(j.created_date)).slice(1).map(o=>o.id).filter(o=>!m.has(o)));if(b.length&&confirm(`Delete ${b.length} duplicate track(s)? The oldest copy of each will be kept.`)){f(new Set(b));try{await Promise.all(b.map(N=>Ye.delete(N))),A(N=>new Set([...N,...b])),B.success(`â Deleted ${b.length} duplicates. Library is now clean!`),s()}
11catch{B.error("Some deletions failed.")}finally{f(new Set)}}},h=(i==null?void 0:i.reduce((b,N)=>b+N.filter(v=>!m.has(v.id)).length-1,0))??0,_="#f87171";return e.jsxs(z.div,{className:"mb-6 rounded-2xl overflow-hidden",style:{border:`1px solid ${_}35`,background:"linear-gradient(145deg, rgba(153,27,27,0.15), rgba(0,0,0,0.5))"},children:[e.jsxs("button",{onClick:()=>g(b=>!b),className:"w-full flex items-center justify-between p-4 hover:bg-white/[0.04] transition-all",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center",style:{background:`${_}22`,border:`1px solid ${_}40`},children:e.jsx(Xe,{className:"w-4 h-4",style:{color:_}})}),e.jsxs("div",{className:"text-left",children:[e.jsx("h2",{className:"text-base font-black text-white",children:"ð Duplicate Detector"}),e.jsx("p",{className:"text-xs text-slate-200",children:"Scans name + artist + duration to find exact duplicates"})]}),i!==null&&h>0&&e.jsxs("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full bg-red-500/20 text-red-300 border border-red-500/30",children:[h," duplicate",h>1?"s":""," found"]}),i!==null&&h===0&&e.jsxs("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3"})," Clean"]})]}),e.jsx(z.div,{animate:{rotate:r?180:0},transition:{duration:.25},children:e.jsx(J,{className:"w-5 h-5 text-slate-300"})})]}),e.jsx(q,{children:r&&e.jsxs(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.25},className:"border-t p-5 space-y-4",style:{borderColor:`${_}20`},children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 rounded-xl border",style:{background:"rgba(248,113,113,0.08)",borderColor:"rgba(248,113,113,0.25)"},children:[e.jsx(Ee,{className:"w-4 h-4 text-red-300 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-white",children:"How duplicate detection works"}),e.jsxs("p",{className:"text-xs text-slate-200 mt-0.5",children:["Two tracks are flagged as duplicates when they share the same ",e.jsx("strong",{className:"text-white",children:"normalized name"}),", ",e.jsx("strong",{className:"text-white",children:"artist"}),", and ",e.jsx("strong",{className:"text-white",children:"duration (±2s)"}),". The oldest copy is always kept when auto-deleting."]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(G,{onClick:y,disabled:w||t.length===0,className:"font-black text-white",style:{background:"linear-gradient(to right, #dc2626, #f87171)"},children:w?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-4 h-4 mr-2 animate-spin"})," Scanning ",t.length," tracksâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-4 h-4 mr-2"})," Scan Library for Duplicates"]})}),i!==null&&h>0&&e.jsxs(G,{onClick:k,variant:"outline",className:"border-red-500/50 text-red-300 hover:bg-red-500/15 font-bold",children:[e.jsx(ce,{className:"w-4 h-4 mr-2"})," Auto-Delete All Duplicates"]})]}),i!==null&&(i.length===0?e.jsxs("div",{className:"flex items-center gap-3 px-4 py-4 rounded-xl bg-emerald-500/10 border border-emerald-500/25",children:[e.jsx(te,{className:"w-5 h-5 text-emerald-400 flex-shrink-0"}),e.jsx("p",{className:"text-emerald-200 font-bold text-sm",children:"No duplicates found â your library is clean!"})]}):e.jsx("div",{className:"space-y-3",children:i.map((b,N)=>{const v=b.filter(p=>!m.has(p.id));if(v.length<=1)return null;
11const o=[...v].sort((p,C)=>new Date(p.created_date)-new Date(C.created_date)),j=o[0],d=V[j.genre]||V.ambient;return e.jsxs("div",{className:"rounded-xl overflow-hidden border border-red-500/20",children:[e.jsxs("div",{className:"px-4 py-2.5 flex items-center gap-3",style:{background:"rgba(220,38,38,0.12)"},children:[e.jsxs("span",{className:"text-sm font-black text-white flex-1 truncate",children:[d.emoji," ",j.name,j.artist&&e.jsxs("span",{className:"text-slate-300 font-normal ml-2",children:["· ",j.artist]})]}),e.jsx("span",{className:"text-xs text-slate-300 font-mono",children:Qe(j.duration_seconds)}),e.jsxs("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full bg-red-500/20 text-red-300 border border-red-500/30",children:[v.length," copies"]})]}),e.jsx("div",{className:"divide-y divide-white/[0.05]",children:o.map((p,C)=>{const l=C===0,D=a.has(p.id);return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5",style:{background:l?"rgba(52,211,153,0.06)":"rgba(248,113,113,0.04)"},children:[e.jsx("span",{className:`text-xs font-bold px-2 py-0.5 rounded-full flex-shrink-0 ${l?"bg-emerald-500/20 text-emerald-300 border border-emerald-500/30":"bg-red-500/15 text-red-300 border border-red-500/25"}`,children:l?"â Keep":"Duplicate"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-white font-semibold truncate",children:p.name}),e.jsxs("p",{className:"text-xs text-slate-300",children:["Added: ",new Date(p.created_date).toLocaleDateString()," · ",Qe(p.duration_seconds),p.artist&&` · ${p.artist}`]})]}),!l&&e.jsx(G,{size:"sm",onClick:()=>F(p.id),disabled:D,className:"bg-red-600 hover:bg-red-700 text-white font-bold h-7 px-2.5 text-xs flex-shrink-0",children:D?e.jsx(U,{className:"w-3 h-3 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-3 h-3 mr-1"}),"Delete"]})})]},p.id)})})]},N)})}))]})})]})}const $e={};async function Bt(t,s){if($e[t])return $e[t];const r=new(window.AudioContext||window.webkitAudioContext),w=await(await fetch(t)).arrayBuffer(),u=await r.decodeAudioData(w);await r.close();const i=u.getChannelData(0),c=Math.floor(i.length/s),a=new Float32Array(s);for(let m=0;m<s;m++){let A=0;const y=m*c;for(let F=0;F<c;F++){const k=Math.abs(i[y+F]);k>A&&(A=k)}a[m]=A}const f=Math.max(...a,.001);for(let m=0;m<a.length;m++)a[m]/=f;return $e[t]=a,a}function Je({trackUrl:t,isPlaying:s,audioElement:r,color:g="#22d3ee",height:w=48,numBars:u=80}){const i=x.useRef(null),c=x.useRef(null),a=x.useRef(null),f=x.useRef(null),m=x.useRef(null),A=x.useRef(null),[y,F]=x.useState(null),[k,h]=x.useState(!1),[_,b]=x.useState(!1);x.useEffect(()=>{if(t)return b(!1),h(!0),Bt(t,u).then(o=>{A.current=o,b(!0)}).catch(()=>{}).finally(()=>h(!1)),()=>{A.current=null,b(!1)}},[t,u]),x.useEffect(()=>{if(!s||!r)return;(!m.current||m.current.state==="closed")&&(m.current=new(window.AudioContext||window.webkitAudioContext));const o=m.current;if(o.state==="suspended"&&o.resume(),!f.current)try{f.current=o.createMediaElementSource(r),a.current=o.createAnalyser(),a.current.fftSize=256,f.current.connect(a.current),a.current.connect(o.destination)}catch{}return()=>{}},[s,r]),x.useEffect(()=>()=>{c.current&&cancelAnimationFrame(c.current),m.current&&m.current.state!=="closed"&&(m.current.close().catch(()=>{}),f.current=null,a.current=null,m.current=null)},[]);const N=x.useCallback(()=>{const o=i.current;if(!o)return;const j=A.current;if(!j)return;const d=window.devicePixelRatio||1,p=o.offsetWidth,C=o.offsetHeight;if(!p||!C)return;(o.width!==Math.round(p*d)||o.height!==Math.round(C*d))&&(o.width=Math.round(p*d),o.height=Math.round(C*d));const l=o.getContext("2d");l.setTransform(d,0,0,d,0,0),l.clearRect(0,0,p,C);let D=null;s&&a.current&&(D=new Uint8Array(a.current.frequencyBinCount),a.current.getByteFrequencyData(D));const I=r&&r.duration>0?r.currentTime/r.duration:0,M=p/u,T=Math.max(1,M*.18);for(let S=0;S<u;S++){const L=S*M,P=S/u<=I,E=j[S]||0;let ee=E;if(D&&s){const ue=Math.floor(S/u*D.length),O=D[ue]/255;ee=E*.5+O*.5}const ae=Math.max(2,ee*(C*.85)),ye=(C-ae)/2,K=P?1:.28;l.fillStyle=s?`rgba(${et(g)}, ${K})`:`rgba(${et(g)}, ${y!==null?.5:.3})`,s&&P?(l.shadowColor=g,l.shadowBlur=6):l.shadowBlur=0,l.fillRect(L+T/2,ye,M-T,ae)}if(l.shadowBlur=0,s&&I>0){const S=I*p;l.strokeStyle="#ffffff",l.lineWidth=1.5,l.globalAlpha=.7,l.beginPath(),l.moveTo(S,0),l.lineTo(S,C),l.stroke(),l.globalAlpha=1}y!==null&&(l.strokeStyle="rgba(255,255,255,0.5)",l.lineWidth=1,l.setLineDash([3,3]),l.beginPath(),l.moveTo(y,0),l.lineTo(y,C),l.stroke(),l.setLineDash([])),s&&(c.current=requestAnimationFrame(N))},[s,g,y,u,r]);if(x.useEffect(()=>{c.current&&cancelAnimationFrame(c.current),_&&N()},[_,N,s,y]),!t)return null;const v=[0,1,2,3,4,5,6,7];return e.jsxs("div",{className:"relative w-full",style:{height:w},children:[k&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"flex gap-0.5 items-end h-5",children:v.map(o=>e.jsx("div",{className:"w-1 rounded-full animate-pulse",style:{height:`${30+Math.sin(o)*30}%`,background:g,opacity:.4,animationDelay:`${o*80}ms`}},o))})}),e.jsx("canvas",{ref:i,className:"w-full h-full cursor-crosshair",style:{display:k?"none":"block"},onMouseMove:o=>{const j=o.currentTarget.getBoundingClientRect();F(o.clientX-j.left)},onMouseLeave:()=>F(null)})]})}function et(t){const s=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),g=parseInt(t.slice(5,7),16);return`${s},${r},${g}`}function tt(t){const s=Math.round(t||0);return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`}function st({track:t,isPlaying:s,isExpanded:r,viewMode:g,audioElement:w,onTogglePlay:u,onClick:i,onDelete:c}){const a=V[t.genre]||V.ambient,[f,m]=x.useState(!1),A=f||s;return g==="grid"?e.jsxs(z.div,{layout:!0,initial:{opacity:0,scale:.92}
11,animate:{opacity:1,scale:1},exit:{opacity:0,scale:.92},onClick:i,onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),className:`relative rounded-2xl overflow-hidden cursor-pointer group transition-all duration-300 ${r?"ring-2 ring-offset-2 ring-offset-slate-950":"hover:scale-[1.02] hover:shadow-2xl"}`,style:{background:`linear-gradient(145deg, ${a.bg}22 0%, ${a.bg}08 100%)`,border:`1px solid ${s?a.color+"70":a.color+"35"}`,boxShadow:s?`0 0 40px ${a.color}35, 0 4px 24px rgba(0,0,0,0.4)`:r?`0 0 30px ${a.color}20`:"0 4px 24px rgba(0,0,0,0.3)",ringColor:a.color},children:[e.jsx("div",{className:"h-1 w-full",style:{background:`linear-gradient(to right, ${a.color}, ${a.colorEnd||a.color})`}}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(z.button,{onClick:y=>{y.stopPropagation(),u()},whileTap:{scale:.85},className:"w-12 h-12 rounded-xl flex items-center justify-center transition-all",style:{background:s?`${a.color}30`:"rgba(0,0,0,0.4)",border:`1px solid ${s?a.color:"rgba(255,255,255,0.12)"}`,boxShadow:s?`0 0 20px ${a.color}50`:"none"},children:s?e.jsx(je,{className:"w-5 h-5",style:{color:a.color}}):e.jsx(ze,{className:"w-5 h-5 text-white/70 ml-0.5"})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[t.is_loopable&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full font-bold",style:{background:`${a.color}20`,color:a.color,border:`1px solid ${a.color}30`},children:"â"}),e.jsx("button",{onClick:y=>{y.stopPropagation(),c()},className:"opacity-0 group-hover:opacity-100 transition-opacity p-1 rounded-lg hover:bg-red-500/20",children:e.jsx(ce,{className:"w-3.5 h-3.5 text-red-400"})})]})]}),e.jsx("div",{className:"rounded-lg overflow-hidden",style:{background:"rgba(0,0,0,0.25)"},children:e.jsx(Je,{trackUrl:A?t.file_url:null,isPlaying:s,audioElement:s?w:null,color:a.color,height:40,numBars:60})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-white text-sm leading-tight truncate",children:t.name}),e.jsx("p",{className:"text-slate-300 text-xs truncate",children:t.artist||"Unknown Artist"}),t.scenario&&t.scenario!=="both"&&e.jsx("span",{className:"inline-block text-[9px] font-bold px-1.5 py-0.5 rounded-full mt-0.5",style:{background:t.scenario==="stage_one"?"rgba(245,158,11,0.2)":"rgba(96,165,250,0.2)",color:t.scenario==="stage_one"?"#fbbf24":"#93c5fd",border:`1px solid ${t.scenario==="stage_one"?"rgba(245,158,11,0.4)":"rgba(96,165,250,0.4)"}`},children:t.scenario==="stage_one"?"ð¤ Stage One":"ð¬ 3D Video"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-bold px-2.5 py-1 rounded-full",style:{background:`${a.color}18`,color:a.color,border:`1px solid ${a.color}28`},children:[a.emoji," ",a.label]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[t.gain_db!==void 0&&t.gain_db!==null&&t.gain_db!==0&&e.jsxs("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded-full ${t.gain_db<0?"bg-orange-500/20 text-orange-200 border border-orange-500/30":"bg-emerald-500/20 text-emerald-200 border border-emerald-500/30"}`,children:[t.gain_db>0?"+":"",t.gain_db," dB"]}),e.jsx("span",{className:"text-slate-200 text-xs font-mono",children:tt(t.duration_seconds)})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[t.video_3d_file_url&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold px-1.5 py-0.5 rounded-full bg-blue-500/20 text-blue-200 border border-blue-500/30",children:[e.jsx(de,{className:"w-2.5 h-2.5"})," 3D"]}),t.mobile_video_3d_file_url&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold px-1.5 py-0.5 rounded-full bg-emerald-500/20 text-emerald-200 border border-emerald-500/30",children:[e.jsx(se,{className:"w-2.5 h-2.5"})," Mobile"]})]})]})]}):e.jsx(z.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},onClick:i,onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),className:`rounded-xl overflow-hidden cursor-pointer group transition-all duration-200 ${r?"":"hover:bg-white/[0.04]"}`,style:{background:r?`linear-gradient(145deg, ${a.bg}18, rgba(0,0,0,0.3))`:"transparent",border:`1px solid ${s?a.color+"50":r?a.color+"40":"rgba(255,255,255,0.06)"}`,boxShadow:s?`0 0 20px ${a.color}15`:r?`0 0 30px ${a.color}15`:"none"},children:e.jsxs("div",{className:"p-3 flex items-center gap-3",children:[e.jsx("div",{className:"h-8 w-1 rounded-full flex-shrink-0",style:{background:`linear-gradient(to bottom, ${a.color}, ${a.colorEnd||a.color})`}}),e.jsx(z.button,{onClick:y=>{y.stopPropagation(),u()},whileTap:{scale:.85},className:"w-9 h-9 rounded-full flex items-center justify-center flex-shrink-0 transition-all",style:{background:s?`${a.color}25`:"rgba(255,255,255,0.06)",border:`1px solid ${s?a.color:"rgba(255,255,255,0.1)"}`,boxShadow:s?`0 0 12px ${a.color}40`:"none"},children:s?e.jsx(je,{className:"w-3.5 h-3.5",style:{color:a.color}}):e.jsx(ze,{className:"w-3.5 h-3.5 text-white/60 ml-0.5"})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-0.5",children:[e.jsx("div",{className:"font-semibold text-white text-sm truncate",children:t.name}),A?e.jsx(Je,{trackUrl:t.file_url,isPlaying:s,audioElement:s?w:null,color:a.color,height:28,numBars:80}):e.jsxs("div",{className:"text-xs text-slate-300 truncate",children:[t.artist||"Unknown"," · ",tt(t.duration_seconds),t.scenario&&t.scenario!=="both"?` · ${t.scenario==="stage_one"?"ð¤":"ð¬"}`:""]})]}),e.jsxs("span",{className:"text-[11px] font-bold px-2 py-0.5 rounded-full flex-shrink-0",style:{background:`${a.color}15`,color:a.color,border:`1px solid ${a.color}25`},children:[a.emoji," ",a.label]}),t.is_loopable&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full font-bold flex-shrink-0",style:{background:`${a.color}15`,color:a.color},children:"â"}),t.gain_db!==void 0&&t.gain_db!==null&&t.gain_db!==0&&e.jsxs("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded-full flex-shrink-0 ${t.gain_db<0?"bg-orange-500/20 text-orange-200 border border-orange-500/30":"bg-emerald-500/20 text-emerald-200 border border-emerald-500/30"}`,children:[t.gain_db>0?"+":"",t.gain_db," dB"]}),t.video_3d_file_url&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold px-1.5 py-0.5 rounded-full bg-blue-500/20 text-blue-200 border border-blue-500/30 flex-shrink-0",children:[e.jsx(de,{className:"w-2.5 h-2.5"})," 3D"]}),t.mobile_video_3d_file_url&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold px-1.5 py-0.5 rounded-full bg-emerald-500/20 text-emerald-200 border border-emerald-500/30 flex-shrink-0",children:[e.jsx(se,{className:"w-2.5 h-2.5"})," Mobile"]}),e.jsx("button",{onClick:y=>{y.stopPropagation(),c()},className:"opacity-0 group-hover:opacity-100 transition-opacity p-1.5 rounded-lg hover:bg-red-500/20 flex-shrink-0",children:e.jsx(ce,{className:"w-3.5 h-3.5 text-red-400"})})]})})}const zt=W.entities.AudioTrack;async function Rt(t,s,r=0){const g=t.sampleRate,w=Math.min(t.numberOfChannels,2);let u=t.getChannelData(0),i=w>1?t.getChannelData(1):u;if(r!==0){const _=Math.pow(10,r/20);
11u=new Float32Array(u.map(b=>Math.max(-1,Math.min(1,b*_)))),i=new Float32Array(i.map(b=>Math.max(-1,Math.min(1,b*_))))}const c=_=>{const b=new Int16Array(_.length);for(let N=0;N<_.length;N++){const v=Math.max(-1,Math.min(1,_[N]));b[N]=v<0?v*32768:v*32767}return b},a=c(u),f=c(i),{Mp3Encoder:m}=await pt(async()=>{const{Mp3Encoder:_}=await import("./index-C99fB1Uw.js").then(b=>b.i);return{Mp3Encoder:_}},[]),A=new m(w,g,s),y=1152,F=[];let k=0;for(;k<a.length;){const _=Math.min(k+y,a.length),b=a.subarray(k,_),N=f.subarray(k,_),v=w===2?A.encodeBuffer(b,N):A.encodeBuffer(b);v.length>0&&F.push(new Uint8Array(v)),k=_}const h=A.flush();return h.length>0&&F.push(new Uint8Array(h)),new Blob(F,{type:"audio/mpeg"})}const at=[{key:"3d_video",label:"3D Video",icon:de,color:"#60a5fa",bitrate:192,gainDb:-20,description:"192kbps · -20 dB (Mackenzie voice ducking)",urlField:"video_3d_file_url",gainField:"video_3d_gain_db"},{key:"mobile_3d",label:"Mobile 3D",icon:se,color:"#34d399",bitrate:128,gainDb:-20,description:"128kbps · -20 dB (compressed for mobile)",urlField:"mobile_video_3d_file_url",gainField:"mobile_video_3d_gain_db"}];function Lt({track:t,onComplete:s}){const[r,g]=x.useState({}),w=async i=>{g(c=>({...c,[i.key]:!0}));try{const a=await(await fetch(t.file_url)).arrayBuffer(),f=new(window.AudioContext||window.webkitAudioContext),m=await f.decodeAudioData(a);await f.close();const A=await Rt(m,i.bitrate,i.gainDb),y=new File([A],`${t.name}_${i.key}.mp3`,{type:"audio/mpeg"}),F=await W.integrations.Core.UploadFile({file:y});await zt.update(t.id,{[i.urlField]:F.file_url,[i.gainField]:i.gainDb}),B.success(`${i.label} variant generated!`),s()}catch(c){console.error(c),B.error(`Failed to generate ${i.label} variant`)}finally{g(c=>({...c,[i.key]:!1}))}},u=async()=>{for(const i of at)await w(i)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-white text-xs font-black uppercase tracking-wider",children:"Audio Variants"}),e.jsx(G,{size:"sm",onClick:u,disabled:Object.values(r).some(Boolean),className:"text-white font-bold text-xs h-7 px-3",style:{background:"linear-gradient(to right, #7c3aed, #a78bfa)"},children:Object.values(r).some(Boolean)?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-3 h-3 mr-1.5 animate-spin"})," Generatingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fe,{className:"w-3 h-3 mr-1.5"})," Generate All"]})})]}),at.map(i=>{const c=!!t[i.urlField],a=r[i.key],f=i.icon;return e.jsxs(z.div,{className:"flex items-center justify-between gap-3 px-4 py-3 rounded-xl border",style:{background:c?`${i.color}0d`:"rgba(255,255,255,0.04)",borderColor:c?`${i.color}40`:"rgba(255,255,255,0.10)"},children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0",style:{background:`${i.color}20`,border:`1px solid ${i.color}35`},children:e.jsx(f,{className:"w-4 h-4",style:{color:i.color}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-white text-sm font-bold",children:i.label}),e.jsx("p",{className:"text-slate-300 text-xs",children:i.description}),c&&e.jsx("p",{className:"text-xs font-bold mt-0.5",style:{color:i.color},children:"â Ready"})]})]}),e.jsx(G,{size:"sm",onClick:()=>w(i),disabled:a,className:"flex-shrink-0 text-white font-bold text-xs h-7 px-3",style:{background:c?"rgba(255,255,255,0.08)":`linear-gradient(to right, ${i.color}cc, ${i.color})`,border:c?`1px solid ${i.color}40`:"none",color:c?i.color:"white"},children:a?e.jsx(e.Fragment,{children:e.jsx(U,{className:"w-3 h-3 animate-spin"})}):c?"Re-generate":"Generate"})]},i.key)}),e.jsxs("p",{className:"text-slate-300 text-xs leading-relaxed",children:[e.jsx("strong",{className:"text-white",children:"Ignite Stage"})," uses the primary file (original quality). ",e.jsx("strong",{className:"text-white",children:"3D Video"})," uses 192kbps at -20 dB so Mackenzie's voice cuts through. ",e.jsx("strong",{className:"text-white",children:"Mobile 3D"})," uses 128kbps at -20 dB for faster loading on phones."]})]})}const Ae=[{label:"Stage One (Original)",db:0,icon:kt,color:"#f59e0b",description:"Full volume â Ignite presentations"},{label:"3D Video (-20 dB)",db:-20,icon:de,color:"#60a5fa",description:"Desktop 3D video background"},{label:"Mobile 3D (-20 dB)",db:-20,icon:se,color:"#34d399",description:"Phone 3D video â compressed"}];function Et(t){return Math.pow(10,t/20)}function Ut({track:t}
11){const[s,r]=x.useState(!1),[g,w]=x.useState(0),[u,i]=x.useState(-20),[c,a]=x.useState(!1),f=x.useRef(null),m=x.useRef(null),A=x.useRef(null),y=x.useRef(null),F=x.useRef(0);x.useRef(0),x.useEffect(()=>{y.current=null,r(!1),k()},[t==null?void 0:t.file_url]);const k=()=>{try{m.current&&(m.current.stop(),m.current.disconnect(),m.current=null)}catch{}r(!1)},h=()=>((!f.current||f.current.state==="closed")&&(f.current=new(window.AudioContext||window.webkitAudioContext)),f.current),_=async()=>{if(y.current)return y.current;const o=h(),d=await(await fetch(t.file_url)).arrayBuffer();return y.current=await o.decodeAudioData(d),y.current},b=async(o,j)=>{k();const d=j!==void 0?j:Ae[o].db;try{const p=h();p.state==="suspended"&&await p.resume();const C=await _(),l=p.createBufferSource();l.buffer=C,l.loop=!1;const D=p.createGain();D.gain.value=Et(d),l.connect(D),D.connect(p.destination),l.start(0),l.onended=()=>r(!1),m.current=l,A.current=D,F.current=p.currentTime,r(!0),w(o)}catch(p){console.error("Preview failed:",p)}},N=o=>{s&&g===o?k():b(o,Ae[o].db)},v=()=>{s&&c?(k(),a(!1)):(a(!0),b(99,u))};return t!=null&&t.file_url?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-slate-100 text-xs font-black uppercase tracking-wider",children:"Volume Preview"}),e.jsx("p",{className:"text-slate-300 text-xs",children:"Preview the primary audio file at simulated volume levels. The original file is not modified."}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:Ae.map((o,j)=>{const d=o.icon,p=s&&g===j&&!c;return e.jsxs("button",{onClick:()=>{a(!1),N(j)},className:"flex items-center gap-3 px-4 py-3 rounded-xl border transition-all text-left",style:{background:p?`${o.color}18`:"rgba(255,255,255,0.04)",borderColor:p?`${o.color}60`:"rgba(255,255,255,0.10)",boxShadow:p?`0 0 16px ${o.color}25`:"none"},children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0",style:{background:`${o.color}20`,border:`1px solid ${o.color}35`},children:p?e.jsx(je,{className:"w-4 h-4",style:{color:o.color}}):e.jsx(d,{className:"w-4 h-4",style:{color:o.color}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-white text-sm font-bold leading-none",children:o.label}),e.jsx("p",{className:"text-slate-300 text-xs mt-0.5",children:o.description})]}),e.jsx("span",{className:"text-xs font-mono font-bold flex-shrink-0 px-2 py-1 rounded-lg",style:{background:`${o.color}20`,color:o.color},children:o.db===0?"0 dB":`${o.db} dB`})]},j)})}),e.jsxs("div",{className:"px-4 py-3 rounded-xl border border-white/10 bg-white/[0.03] space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-slate-100 text-xs font-bold",children:"Custom Volume Test"}),e.jsxs("span",{className:"text-xs font-mono font-bold text-violet-300",children:[u," dB"]})]}),e.jsx("input",{type:"range",min:"-40",max:"0",step:"1",value:u,onChange:o=>i(parseInt(o.target.value)),className:"w-full accent-violet-400 h-1.5"}),e.jsxs("div",{className:"flex justify-between text-[10px] text-slate-300",children:[e.jsx("span",{children:"-40 dB (very quiet)"}),e.jsx("span",{children:"-20 dB"}),e.jsx("span",{children:"0 dB (full)"})]}),e.jsx("button",{onClick:v,className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs font-bold transition-all border",style:{background:s&&c?"rgba(139,92,246,0.2)":"rgba(255,255,255,0.06)",borderColor:s&&c?"rgba(139,92,246,0.6)":"rgba(255,255,255,0.12)",color:s&&c?"#a78bfa":"white"},children:s&&c?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-3.5 h-3.5"})," Stop"]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{className:"w-3.5 h-3.5"})," Play at ",u," dB"]})})]})]}):null}W.entities.AudioTrack;function Gt(t){const s=Math.round(t||0);return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`}const De=[{value:"stage_one",label:"ð¤ Stage One Only",description:"Full-volume for Ignite presentations",color:"#f59e0b"},{value:"background_video_3d",label:"ð¬ 3D Video Only",description:"Background music for 3D videos",color:"#60a5fa"},{value:"both",label:"⦠Both",description:"Used in presentations AND 3D videos",color:"#a78bfa"}];function lt({data:t,onChange:s,onSave:r,onCancel:g,onFileUpload:w,uploading:u,onVariantComplete:i}
11){const c=V[t.genre]||V.ambient,[a,f]=x.useState(!1),[m,A]=x.useState("details");De.find(h=>h.value===(t.scenario||"both"))||De[2];const y=async h=>{const _=h.target.files[0];if(!_||!_.type.startsWith("audio/")){B.error("Please upload an audio file");return}f(!0);try{const b=await W.integrations.Core.UploadFile({file:_});s({mobile_video_3d_file_url:b.file_url,mobile_video_3d_gain_db:-20}),B.success("Mobile audio uploaded! (-20 dB version ready)")}catch{B.error("Failed to upload mobile audio")}finally{f(!1)}},F=()=>{s({mobile_video_3d_file_url:null}),B.success("Mobile version cleared")},k=[{key:"details",label:"ð Details"},{key:"mobile",label:"ð± Mobile Upload"},{key:"preview",label:"ð Volume Preview"}];return e.jsxs(z.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:{duration:.25},className:"border-t",style:{borderColor:`${c.color}30`,background:`linear-gradient(145deg, ${c.bg}12, rgba(0,0,0,0.4))`},onClick:h=>h.stopPropagation(),children:[e.jsx("div",{className:"flex border-b",style:{borderColor:`${c.color}20`},children:k.map(h=>e.jsx("button",{onClick:()=>A(h.key),className:"px-4 py-2.5 text-xs font-bold transition-all",style:{color:m===h.key?c.color:"rgba(255,255,255,0.45)",borderBottom:m===h.key?`2px solid ${c.color}`:"2px solid transparent",background:m===h.key?`${c.color}10`:"transparent"},children:h.label},h.key))}),e.jsxs("div",{className:"p-5 space-y-4",children:[m==="details"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-100 mb-1.5 block text-xs font-bold uppercase tracking-wider",children:"Track Name *"}),e.jsx(Q,{value:t.name,onChange:h=>s({name:h.target.value}),className:"bg-black/40 border-white/10 text-white focus:border-white/30"})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-100 mb-1.5 block text-xs font-bold uppercase tracking-wider",children:"Artist / Composer"}),e.jsx(Q,{value:t.artist||"",onChange:h=>s({artist:h.target.value}),className:"bg-black/40 border-white/10 text-white focus:border-white/30"})]})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-100 mb-2 block text-xs font-bold uppercase tracking-wider",children:"Scenario / Use Case"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:De.map(h=>e.jsxs("button",{onClick:()=>s({scenario:h.value}),className:"text-left p-3 rounded-xl border transition-all",style:{background:(t.scenario||"both")===h.value?`${h.color}15`:"rgba(255,255,255,0.03)",borderColor:(t.scenario||"both")===h.value?`${h.color}60`:"rgba(255,255,255,0.10)",boxShadow:(t.scenario||"both")===h.value?`0 0 12px ${h.color}20`:"none"},children:[e.jsx("p",{className:"text-white text-xs font-bold leading-tight",children:h.label}),e.jsx("p",{className:"text-slate-300 text-[10px] mt-0.5 leading-tight",children:h.description})]},h.value))})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-100 mb-1.5 block text-xs font-bold uppercase tracking-wider",children:"Replace Primary Audio File"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{type:"file",accept:"audio/*",onChange:w,disabled:u,className:"bg-black/40 border-white/10 text-white h-9 text-sm"}),u&&e.jsx(U,{className:"w-4 h-4 animate-spin text-white"})]}),t.file_url&&e.jsxs("p",{className:"text-slate-300 text-xs mt-1 truncate",children:["â ",t.file_url.split("/").pop()," · ",Gt(t.duration_seconds)]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-100 mb-1.5 block text-xs font-bold uppercase tracking-wider",children:"Genre"}),e.jsxs(fe,{value:t.genre||"ambient",onValueChange:h=>s({genre:h}),children:[e.jsx(be,{className:"bg-black/40 border-white/10 text-white h-9 text-sm",children:e.jsx(ge,{})}),e.jsx(we,{className:"bg-slate-900 border-slate-700 max-h-60 overflow-y-auto",children:Le.map(h=>e.jsx(X,{value:h.value,children:h.label},h.value))})]})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-100 mb-1.5 block text-xs font-bold uppercase tracking-wider",children:"Duration (sec)"}),e.jsx(Q,{type:"number",value:t.duration_seconds||0,onChange:h=>s({duration_seconds:parseInt(h.target.value)||0}),className:"bg-black/40 border-white/10 text-white h-9 text-sm"})]}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 text-xs text-white cursor-pointer",children:[e.jsx(Re,{checked:t.is_loopable||!1,onCheckedChange:h=>s({is_loopable:h})}),e.jsx("span",{children:"Loopable"})]})})]}),t.id&&e.jsx("div",{className:"border-t pt-4",style:{borderColor:`${c.color}20`},children:e.jsx(Lt,{track:t,onComplete:i||(()=>{})})})]}),m==="mobile"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 rounded-xl border border-emerald-500/25 bg-emerald-500/05",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(se,{className:"w-4 h-4 text-emerald-400"}),e.jsx("p",{className:"text-emerald-300 text-sm font-bold",children:"Mobile 3D Video Version"})]}),e.jsx("p",{className:"text-slate-200 text-xs leading-relaxed",children:"Upload a pre-compressed, -20 dB version of this track specifically for mobile 3D video playback. This prevents audio from overpowering the video on phones. Keep the original track intact for Stage One presentations."})]}),t.mobile_video_3d_file_url?e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl border border-emerald-500/40 bg-emerald-500/10",children:[e.jsx(te,{className:"w-5 h-5 text-emerald-400 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-emerald-300 text-sm font-bold",children:"Mobile version active"}),e.jsx("p",{className:"text-slate-300 text-xs truncate",children:t.mobile_video_3d_file_url.split("/").pop()}),e.jsxs("p",{className:"text-slate-300 text-xs mt-0.5",children:["Gain: ",t.mobile_video_3d_gain_db??-20," dB"]})]}),e.jsx("button",{onClick:F,className:"p-1.5 rounded-lg hover:bg-red-500/20 transition-colors flex-shrink-0",children:e.jsx(ft,{className:"w-4 h-4 text-red-400"})})]}):e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl border border-white/10 bg-white/[0.03]",children:[e.jsx(se,{className:"w-5 h-5 text-slate-300 flex-shrink-0"}),e.jsx("p",{className:"text-slate-200 text-sm",children:"No mobile version uploaded yet"})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-100 mb-1.5 block text-xs font-bold uppercase tracking-wider",children:t.mobile_video_3d_file_url?"Replace Mobile Audio File":"Upload Mobile Audio File (-20 dB compressed)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{type:"file",accept:"audio/*",onChange:y,disabled:a,className:"bg-black/40 border-white/10 text-white h-9 text-sm"}),a&&e.jsx(U,{className:"w-4 h-4 animate-spin text-emerald-400 flex-shrink-0"})]}),e.jsx("p",{className:"text-slate-300 text-xs mt-1.5",children:"Upload your externally compressed version here. This file is served exclusively to mobile devices playing 3D video backgrounds. The Stage One primary file is preserved and untouched."})]}),e.jsxs("div",{className:"p-3 rounded-xl border border-blue-500/20 bg-blue-500/05",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(de,{className:"w-4 h-4 text-blue-400"}),e.jsx("p",{className:"text-blue-300 text-xs font-bold",children:"Desktop 3D Video"})]}),e.jsx("p",{className:"text-slate-200 text-xs",children:"For desktop, use the Auto-Generate tool in the Details tab to create a 192kbps -20 dB version from the primary file. You only need to manually upload the mobile version."})]})]}),m==="preview"&&e.jsx(Ut,{track:t}),e.jsxs("div",{className:"flex gap-2 pt-1 border-t",style:{borderColor:`${c.color}15`},children:[e.jsx(G,{onClick:r,className:"font-bold text-sm text-white",style:{background:`linear-gradient(to right, ${c.color}, ${c.colorEnd||c.color})`},children:"â Save Changes"}),e.jsx(G,{onClick:g,variant:"outline",className:"border-white/10 text-white hover:bg-white/10 text-sm",children:"Cancel"})]})]})]})}function Pt(t,s){return(t[s]&255)<<24|(t[s+1]&255)<<16|(t[s+2]&255)<<8|t[s+3]&25
115}function nt(t,s){return(t[s]&127)<<21|(t[s+1]&127)<<14|(t[s+2]&127)<<7|t[s+3]&127}function rt(t){if(!t||t.length===0)return null;const s=t[0],r=t.slice(1);try{if(s===0)return Array.from(r).map(g=>String.fromCharCode(g)).join("").replace(/\0/g,"").trim()||null;if(s===1||s===2)return new TextDecoder("utf-16").decode(r).replace(/\0/g,"").trim()||null;if(s===3)return new TextDecoder("utf-8").decode(r).replace(/\0/g,"").trim()||null}catch{}return null}async function Ot(t){const s=Math.min(262144,t.size),r=new Uint8Array(await t.slice(0,s).arrayBuffer());if(r[0]!==73||r[1]!==68||r[2]!==51)return null;const g=r[3],w=nt(r,6);let u=10;const i=Math.min(10+w,r.length),c={};for(;u+10<i;){const a=g<=2?String.fromCharCode(r[u],r[u+1],r[u+2]):String.fromCharCode(r[u],r[u+1],r[u+2],r[u+3]);if(!a.trim()||a==="\0\0\0\0")break;let f,m;if(g<=2?(f=r[u+3]<<16|r[u+4]<<8|r[u+5],m=u+6,u+=6+f):(f=g>=4?nt(r,u+4):Pt(r,u+4),m=u+10,u+=10+f),f<=0||f>1e5)break;const A=r.slice(m,m+f);(a==="TIT2"||a==="TT2")&&(c.title=rt(A)),(a==="TPE1"||a==="TP1")&&(c.artist=rt(A))}return Object.keys(c).length?c:null}async function Vt(t){if(t.size<128)return null;const s=new Uint8Array(await t.slice(t.size-128,t.size).arrayBuffer());if(s[0]!==84||s[1]!==65||s[2]!==71)return null;const r=(g,w)=>Array.from(s.slice(g,g+w)).map(u=>String.fromCharCode(u)).join("").replace(/\0/g,"").trim()||null;return{title:r(3,30),artist:r(33,30)}}async function qt(t){if(!t.name.toLowerCase().endsWith(".mp3")&&t.type!=="audio/mpeg")return{title:null,artist:null};try{const s=await Ot(t);if(s!=null&&s.title)return{title:s.title,artist:s.artist||null};const r=await Vt(t);if(r!=null&&r.title)return{title:r.title,artist:r.artist||null}}catch{}return{title:null,artist:null}}function ot(t){return t?t.trim().replace(/\s+/g," ").replace(/[<>:"/\\|?*\x00-\x1f]/g,"").replace(/\s+/g," ").trim().split(" ").map(s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()).join(" "):""}async function Wt(t){const s=t.name,r=ot(s.replace(/\.[^/.]+$/,"").replace(/[-_]/g," "));if(!(t.name.toLowerCase().endsWith(".mp3")||t.type==="audio/mpeg"))return{originalFilename:s,metadataTitle:null,finalName:r,metaStatus:"fallback"};const{title:w,artist:u}=await qt(t),i=c=>!c||c.length<2||/^[\d\s]+$/.test(c)||c.includes("/")||c.includes("\\");if(w&&!i(w)){const c=ot(w);return{originalFilename:s,metadataTitle:w,metadataArtist:u,finalName:c,metaStatus:"metadata"}}return w&&i(w)?{originalFilename:s,metadataTitle:w,metadataArtist:u,finalName:r,metaStatus:"review"}:{originalFilename:s,metadataTitle:null,metadataArtist:null,finalName:r,metaStatus:"fallback"}}const it=["ambient","cinematic","electronic","pop","rock","classical","jazz","acoustic","lofi","motivational","hip_hop","country","rnb","world","meditation"];async function Ht({filename:t,metadataTitle:s,metadataArtist:r,durationSeconds:g}){const w=[t,s,r].join(" ").toLowerCase(),u=[{keywords:["ambient","atmosphere","atmospheri","drone","pad "," pad","texture"],genre:"ambient"},{keywords:["cinema","epic","trailer","orchestr","score","film","dramatic","adventure","heroic","anthem"],genre:"cinematic"},{keywords:["lofi","lo-fi","lo fi","chill hop","chillhop","study","beats"],genre:"lofi"},{keywords:["meditat","relax","zen","mindful","healing","sleep","calm","serene","tranquil","spa"],genre:"meditation"},{keywords:["motivat","inspire","pump","energy","power","workout","hype","triumph","victory","uplift"],genre:"motivational"},{keywords:["hip hop","hiphop","hip-hop","rap","trap","beat","urban","drill","boom bap"],genre:"hip_hop"},{keywords:["jazz","swing","bebop","blues","saxophone","sax","trumpet","boogie"],genre:"jazz"},{keywords:["classical","symphony","sonata","concerto","baroque","opera","piano concerto","quartet","fugue"],genre:"classical"},{keywords:["acoustic","folk","singer songwriter","singer-songwriter","unplugged","fingerpick"],genre:"acoustic"},{keywords:["electronic","edm","techno","house","trance","dubstep","synth","electro","rave","dance","club"],genre:"electronic"},{keywords:["rock","guitar","metal","punk","grunge","riff","hard rock","alt rock","indie rock"],genre:"rock"},{keywords:["pop","catchy","upbeat","bubbly","commercial"],genre:"pop"},{keywords:["r&b","rnb","soul","funk","groove","rhythm and blues"],genre:"rnb"},{keywords:["country","bluegrass","nashville","honky","western","cowboy","twang"],genre:"country"},{keywords:["world","latin","african","celtic","tribal","ethnic","flamenco","bossa","samba","reggae","calypso"],genre:"world"}];for(const{keywords:i,genre:c}of u)if(i.some(a=>w.includes(a))){const a=Me(t,g);
11return{genre:c,is_loopable:a,confidence:"heuristic"}}try{const i=`You are a music genre classifier for a background audio library used in digital business card presentations. 12 13Given this audio track info: 14- Filename: "${t||"unknown"}" 15- ID3 Title: "${s||"none"}" 16- ID3 Artist: "${r||"none"}" 17- Duration: ${g?`${Math.round(g)}s`:"unknown"} 18 19Pick exactly ONE genre from this list: ${it.join(", ")} 20 21Rules: 22- Short tracks (< 60s) with generic names lean toward cinematic or motivational 23- Long tracks (> 120s) lean toward ambient or meditation 24- If truly ambiguous, choose "ambient" 25 26Respond ONLY with a JSON object like: {"genre": "ambient", "is_loopable": true} 27- is_loopable should be true if the track sounds like it would loop seamlessly (ambient, meditation, lofi, electronic backgrounds)`,c=await W.secureAI.InvokeLLM({prompt:i,response_json_schema:{type:"object",properties:{genre:{type:"string"},is_loopable:{type:"boolean"}}}});return{genre:it.includes(c==null?void 0:c.genre)?c.genre:"ambient",is_loopable:(c==null?void 0:c.is_loopable)??Me(t,g),confidence:"ai"}}catch{return{genre:"ambient",is_loopable:Me(t,g),confidence:"fallback"}}}function Me(t,s){const r=(t||"").toLowerCase();return!!(["loop","bg","background","ambient","bed","underscore","loop_","_loop","looped"].some(w=>r.includes(w))||s&&s>90)}const ct=W.entities.AudioTrack,dt={metadata:{label:"Metadata Found",color:"#34d399",bg:"rgba(52,211,153,0.12)",icon:Ne},fallback:{label:"Used Filename",color:"#94a3b8",bg:"rgba(148,163,184,0.10)",icon:Mt},review:{label:"Needs Review",color:"#fbbf24",bg:"rgba(251,191,36,0.12)",icon:Ee},uploading:{label:"Uploadingâ¦",color:"#60a5fa",bg:"rgba(96,165,250,0.12)",icon:U},done:{label:"Imported",color:"#34d399",bg:"rgba(52,211,153,0.10)",icon:te},error:{label:"Error",color:"#f87171",bg:"rgba(248,113,113,0.12)",icon:gt},duplicate:{label:"Duplicate",color:"#fb923c",bg:"rgba(251,146,60,0.12)",icon:Ie}};function me(t){return(t||"").replace(/\.[^/.]+$/,"").toLowerCase().replace(/[-_]/g," ").replace(/\s+/g," ").trim()}const ut={heuristic:{label:"Auto-Detected",color:"#34d399",icon:Be},ai:{label:"AI Detected",color:"#a78bfa",icon:bt},fallback:{label:"Default Genre",color:"#94a3b8",icon:Ne},manual:{label:"Manually Set",color:"#fbbf24",icon:Ne}};function oe({status:t}){const s=dt[t]||dt.fallback,r=s.icon;return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold whitespace-nowrap flex-shrink-0",style:{background:s.bg,color:s.color,border:`1px solid ${s.color}30`},children:[e.jsx(r,{className:`w-3 h-3 flex-shrink-0 ${t==="uploading"?"animate-spin":""}`}),s.label]})}function Kt({confidence:t}){if(!t)return null;const s=ut[t]||ut.fallback,r=s.icon;return e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-bold whitespace-nowrap",style:{background:`${s.color}18`,color:s.color,border:`1px solid ${s.color}30`},children:[e.jsx(r,{className:"w-2.5 h-2.5 flex-shrink-0"}),s.label]})}function Zt({onComplete:t}){const[s,r]=x.useState(!1),[g,w]=x.useState(!1),[u,i]=x.useState([]),[c,a]=x.useState(!1),[f,m]=x.useState(new Set),[A,y]=x.useState(null),F=x.useRef(null),k=(l,D)=>i(I=>I.map(M=>M.id===l?{...M,...D}:M)),h=async()=>{if(A!==null)return A;try{const l=await ct.list("-created_date",500),D=new Set(l.map(T=>me(T.name))),I=new Set(l.map(T=>{var S;return me(((S=T.file_url)==null?void 0:S.split("/").pop())||"")})),M=new Set([...D,...I]);return y(M),M}catch{return new Set}},_=async l=>{const D=Array.from(l.target.files||[]).filter(T=>T.type.startsWith("audio/"));if(!D.length)return;l.target.value="";const I=await h(),M=D.map(T=>{const S=T.name.replace(/\.[^/.]+$/,"").replace(/[-_]/g," ").trim(),L=I.has(me(S))||I.has(me(T.name));return{id:Math.random().toString(36).slice(2),file:T,originalFilename:T.name,metadataTitle:null,metadataArtist:null,finalName:S,metaStatus:"fallback",editingName:!1,uploadStatus:"pending",url:null,duration:0,genre:"ambient",is_loopable:!1,genreConfidence:null,editingGenre:!1,isDuplicate:L}});i(T=>[...T,...M]),m(T=>new Set([...T,...M.map(S=>S.id)])),await Promise.all(M.map(async T=>{const S=await Wt(T.file);i(L=>L.map(P=>P.id===T.id?{...P,originalFilename:S.originalFilename,metadataTitle:S.metadataTitle||null,metadataArtist:S.metadataArtist||null,finalName:S.finalName,metaStatus:S.metaStatus}:P))})),await Promise.all(M.map(async T=>{try{let S=T;i(P=>{const E=P.find(ee=>ee.id===T.id);return E&&(S=E),P});const L=await Ht({filename:S.originalFilename,metadataTitle:S.metadataTitle,metadataArtist:S.metadataArtist,durationSeconds:S.duration});i(P=>P.map(E=>E.id===T.id?{...E,genre:L.genre,is_loopable:L.is_loopable,genreConfidence:L.confidence}:E))}catch{}finally{m(S=>{const L=new Set(S);return L.delete(T.id),L})}}))},b=l=>i(D=>D.filter(I=>I.id!==l)),N=async()=>{const l=u.filter(D=>D.uploadStatus==="pending"&&!D.isDuplicate);if(!l.length){B.error("All pending tracks are flagged as duplicates. Remove the duplicate flag to import anyway.");return}a(!0);for(const D of l){k(D.id,{uploadStatus:"uploading"});try{const M=(await W.integrations.Core.UploadFile({file:D.file})).file_url,T=await new Promise(S=>{const L=new Audio(M);L.onloadedmetadata=()=>S(Math.round(L.duration)||0),L.onerror=()=>S(0),setTimeout(()=>S(0),5e3)});await ct.create({name:D.finalName,file_url:M,duration_seconds:T,genre:D.genre,is_loopable:D.is_loopable,artist:D.metadataArtist||""}),k(D.id,{uploadStatus:"done",url:M,duration:T})}catch{k(D.id,{uploadStatus:"error"})}}a(!1),B.success(`â ${l.length} track${l.length>
271?"s":""} imported!`),t()},v=()=>i(l=>l.filter(D=>D.uploadStatus!=="done")),o=u.filter(l=>l.uploadStatus==="pending"&&!l.isDuplicate).length,j=u.filter(l=>l.isDuplicate&&l.uploadStatus==="pending").length,d=u.filter(l=>l.metaStatus==="review"&&l.uploadStatus==="pending"&&!l.isDuplicate).length,p=f.size,C="#a78bfa";return e.jsxs(z.div,{className:"mb-6 rounded-2xl overflow-hidden",style:{border:`1px solid ${C}35`,background:"linear-gradient(145deg, rgba(76,29,149,0.15), rgba(0,0,0,0.5))"},children:[e.jsxs("button",{onClick:()=>r(!s),className:"w-full flex items-center justify-between p-4 hover:bg-white/[0.04] transition-all",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center",style:{background:`${C}25`,border:`1px solid ${C}40`},children:e.jsx(pe,{className:"w-4 h-4",style:{color:C}})}),e.jsxs("div",{className:"text-left",children:[e.jsx("h2",{className:"text-base font-black text-white",children:"â¡ Bulk Upload"}),e.jsx("p",{className:"text-xs text-slate-200",children:"Genres auto-detected · Metadata extracted · Fully hands-off"})]}),u.length>0&&e.jsxs("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full",style:{background:`${C}20`,color:C},children:[u.length," queued"]}),p>0&&e.jsxs("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full bg-violet-500/20 text-violet-200 border border-violet-500/30 flex items-center gap-1",children:[e.jsx(U,{className:"w-3 h-3 animate-spin"})," Detecting genresâ¦"]}),d>0&&e.jsxs("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full bg-yellow-500/20 text-yellow-200 border border-yellow-500/30",children:["â ",d," need review"]}),j>0&&e.jsxs("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full bg-orange-500/20 text-orange-200 border border-orange-500/30 flex items-center gap-1",children:[e.jsx(Ie,{className:"w-3 h-3"})," ",j," duplicate",j>1?"s":""]})]}),e.jsx(z.div,{animate:{rotate:s?180:0},transition:{duration:.25},children:e.jsx(J,{className:"w-5 h-5 text-slate-300"})})]}),e.jsx(q,{children:s&&e.jsxs(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.25},className:"border-t p-5 space-y-4",style:{borderColor:`${C}20`},children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl border",style:{background:"rgba(167,139,250,0.08)",borderColor:"rgba(167,139,250,0.25)"},children:[e.jsx(Be,{className:"w-4 h-4 text-violet-300 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-white",children:"Fully Automatic Mode"}),e.jsx("p",{className:"text-xs text-slate-200",children:"Genre, loopability, name & artist are all detected automatically per track. Override any field inline before importing."})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-slate-100 cursor-pointer pb-1 w-fit",children:[e.jsx(Re,{checked:g,onCheckedChange:w}),e.jsx("span",{children:"Force loopable on all tracks"})]}),e.jsxs("div",{className:"relative border-2 border-dashed rounded-xl p-8 text-center transition-all cursor-pointer hover:bg-white/[0.03]",style:{borderColor:`${C}50`},onClick:()=>{var l;return(l=F.current)==null?void 0:l.click()},children:[e.jsx(pe,{className:"w-8 h-8 mx-auto mb-3",style:{color:C}}),e.jsx("p",{className:"text-white font-bold text-sm",children:"Click to select audio files"}),e.jsx("p",{className:"text-slate-200 text-xs mt-1",children:"MP3, WAV, OGG, FLAC · Genres detected automatically per file"}),e.jsx("input",{ref:F,type:"file",accept:"audio/*",multiple:!0,className:"hidden",onChange:_})]}),u.length>0&&e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{border:"1px solid rgba(255,255,255,0.1)"},children:[e.jsxs("div",{className:"grid grid-cols-[1.2fr_1fr_1fr_auto_auto_auto] gap-2 px-4 py-2.5 text-[10px] font-black uppercase tracking-widest text-slate-200 border-b border-white/10",style:{background:"rgba(0,0,0,0.5)"},children:[e.jsx("span",{children:"Final Name"}),e.jsx("span",{children:"Artist"}),e.jsx("span",{children:"Genre"}),e.jsx("span",{children:"Loop"}),e.jsx("span",{children:"Status"}),e.jsx("span",{})]}),e.jsx("div",{className:"divide-y divide-white/[0.06] max-h-96 overflow-y-auto",children:u.map(l=>{const D=f.has(l.id),I=l.uploadStatus==="uploading",M=l.uploadStatus==="done",T=l.uploadStatus==="error",S=V[l.genre]||V.ambient,L=l.isDupl
27icate,P=M?"rgba(52,211,153,0.05)":T?"rgba(248,113,113,0.05)":L?"rgba(251,146,60,0.06)":l.metaStatus==="review"?"rgba(251,191,36,0.04)":"transparent";return e.jsxs("div",{className:"grid grid-cols-[1.2fr_1fr_1fr_auto_auto_auto] gap-2 px-4 py-3 items-center text-sm transition-colors",style:{background:P},children:[e.jsxs("div",{className:"min-w-0",children:[l.editingName?e.jsx("input",{value:l.finalName,onChange:E=>k(l.id,{finalName:E.target.value}),onBlur:()=>k(l.id,{editingName:!1}),onKeyDown:E=>E.key==="Enter"&&k(l.id,{editingName:!1}),autoFocus:!0,className:"h-7 text-xs bg-black/50 border border-white/20 rounded text-white px-2 w-full outline-none"}):e.jsxs("button",{onClick:()=>!M&&!I&&k(l.id,{editingName:!0}),className:`flex items-center gap-1.5 text-xs text-left w-full min-w-0 group ${M||I?"cursor-default":"cursor-pointer"}`,disabled:M||I,children:[e.jsx("span",{className:"font-semibold text-white truncate",children:l.finalName}),!M&&!I&&e.jsx(Se,{className:"w-3 h-3 text-slate-300 group-hover:text-white flex-shrink-0 transition-colors"})]}),l.metadataTitle&&l.metadataTitle!==l.finalName&&e.jsxs("p",{className:"text-[10px] text-slate-300 truncate mt-0.5",title:`ID3: ${l.metadataTitle}`,children:["ID3: ",l.metadataTitle]})]}),e.jsx("div",{className:"min-w-0",children:D?e.jsxs("span",{className:"text-slate-300 text-xs italic flex items-center gap-1",children:[e.jsx(U,{className:"w-3 h-3 animate-spin"})," Readingâ¦"]}):l.metadataArtist?e.jsx("p",{className:"text-emerald-200 text-xs truncate",children:l.metadataArtist}):e.jsx("p",{className:"text-slate-300 text-xs italic",children:"â"})}),e.jsx("div",{className:"min-w-0",children:D?e.jsxs("span",{className:"text-slate-300 text-xs italic flex items-center gap-1",children:[e.jsx(U,{className:"w-3 h-3 animate-spin"})," Detectingâ¦"]}):l.editingGenre?e.jsxs(fe,{value:l.genre,onValueChange:E=>k(l.id,{genre:E,genreConfidence:"manual",editingGenre:!1}),children:[e.jsx(be,{className:"h-7 text-xs bg-black/60 border-white/20 text-white w-full",children:e.jsx(ge,{})}),e.jsx(we,{className:"bg-slate-900 border-slate-700 max-h-60 overflow-y-auto",children:Le.map(E=>e.jsx(X,{value:E.value,children:E.label},E.value))})]}):e.jsxs("button",{onClick:()=>!M&&!I&&k(l.id,{editingGenre:!0}),className:`flex flex-col gap-0.5 text-left w-full ${M||I?"cursor-default":"cursor-pointer group"}`,disabled:M||I,children:[e.jsxs("span",{className:"text-xs font-bold flex items-center gap-1",style:{color:S.color},children:[S.emoji," ",S.label,!M&&!I&&e.jsx(Se,{className:"w-2.5 h-2.5 opacity-0 group-hover:opacity-100 transition-opacity"})]}),e.jsx(Kt,{confidence:l.genreConfidence})]})}),e.jsx("div",{className:"flex-shrink-0",children:!M&&!I?e.jsx("button",{onClick:()=>k(l.id,{is_loopable:!l.is_loopable}),className:"text-xs font-bold px-2 py-1 rounded-full transition-all",style:{background:l.is_loopable?`${S.color}20`:"rgba(255,255,255,0.06)",color:l.is_loopable?S.color:"#94a3b8",border:`1px solid ${l.is_loopable?S.color+"40":"rgba(255,255,255,0.12)"}`},children:"â"}):l.is_loopable?e.jsx("span",{className:"text-xs font-bold",style:{color:S.color},children:"â"}):e.jsx("span",{className:"text-slate-300 text-xs",children:"â"})}),e.jsx("div",{className:"flex-shrink-0 flex flex-col gap-1 items-start",children:D?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold bg-violet-500/15 text-violet-200 border border-violet-500/30",children:[e.jsx(U,{className:"w-3 h-3 animate-spin"})," Analyzingâ¦"]}):I?e.jsx(oe,{status:"uploading"}):M?e.jsx(oe,{status:"done"}):T?e.jsx(oe,{status:"error"}):L?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(oe,{status:"duplicate"}),e.jsx("button",{onClick:()=>k(l.id,{isDuplicate:!1}),className:"text-[10px] font-bold text-orange-300 hover:text-white underline underline-offset-2 transition-colors whitespace-nowrap",title:"Remove duplicate flag and import anyway",children:"Force Import"})]}):e.jsx(oe,{status:l.metaStatus})}),e.jsx("div",{className:"flex-shrink-0",children:!M&&!I&&e.jsx("button",{onClick:()=>b(l.id),className:"p-1 rounded hover:bg-white/10 transition-colors",children:e.jsx(ft,{className:"w-3.5 h-3.5 text-slate-200 hover:text-white"})})})]},l.id)})})]}),u.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-3 text-[11px] text-slate-200",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Be,{className:"w-3 h-3 text-emerald-300"})," Auto-Detected â keyword match"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(bt,{className:"w-3 h-3 text-violet-300"})," AI Detected â LLM analysis"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ne,{className:"w-3 h-3 text-emerald-300"})," Metadata Found â ID3 tag used"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ie,{className:"w-3 h-3 text-orange-300"})," Duplicate â already in library (skipped)"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Se,{className:"w-3 h-3 text-slate-200"})," Click any field to edit before import"]}
27)]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(G,{onClick:N,disabled:c||o===0||f.size>0,className:"font-black text-white",style:{background:"linear-gradient(to right, #7c3aed, #a78bfa)"},children:c?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-4 h-4 mr-2 animate-spin"})," Importingâ¦"]}):f.size>0?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-4 h-4 mr-2 animate-spin"})," Detecting genresâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"w-4 h-4 mr-2"})," Import ",o>0?`${o} Track${o>1?"s":""}`:"All"]})}),u.some(l=>l.uploadStatus==="done")&&e.jsx(G,{onClick:v,variant:"outline",className:"border-slate-400 text-slate-100 hover:bg-white/10 text-sm",children:"Clear Done"}),u.length>0&&!c&&e.jsx(G,{onClick:()=>i([]),variant:"ghost",className:"text-slate-200 hover:text-white text-sm",children:"Clear All"})]})]})})]})}const Xt=W.entities.AudioTrack,Yt=[{label:"320 kbps (Studio)",value:320,desc:"No loss, largest"},{label:"192 kbps (High)",value:192,desc:"Transparent quality"},{label:"128 kbps (Standard)",value:128,desc:"Good for streaming"},{label:"96 kbps (Compact)",value:96,desc:"Smaller, slight loss"},{label:"64 kbps (Podcast)",value:64,desc:"Smallest, voice ok"}];async function Qt(t,s,r=0){const g=await t.arrayBuffer(),w=new(window.AudioContext||window.webkitAudioContext),u=await w.decodeAudioData(g);await w.close();const i=u.sampleRate,c=Math.min(u.numberOfChannels,2);let a=u.getChannelData(0),f=c>1?u.getChannelData(1):a;if(r!==0){const v=Math.pow(10,r/20);a=new Float32Array(a.map(o=>o*v)),f=new Float32Array(f.map(o=>o*v))}const m=v=>{const o=new Int16Array(v.length);for(let j=0;j<v.length;j++){const d=Math.max(-1,Math.min(1,v[j]));o[j]=d<0?d*32768:d*32767}return o},A=m(a),y=m(f),{Mp3Encoder:F}=await pt(async()=>{const{Mp3Encoder:v}=await import("./index-C99fB1Uw.js").then(o=>o.i);return{Mp3Encoder:v}},[]),k=new F(c,i,s),h=1152,_=[];let b=0;for(;b<A.length;){const v=Math.min(b+h,A.length),o=A.subarray(b,v),j=y.subarray(b,v),d=c===2?k.encodeBuffer(o,j):k.encodeBuffer(o);d.length>0&&_.push(new Uint8Array(d)),b=v}const N=k.flush();return N.length>0&&_.push(new Uint8Array(N)),new Blob(_,{type:"audio/mpeg"})}function xt(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`:"â"}function Jt({tracks:t,onComplete:s}){const[r,g]=x.useState(!1),[w,u]=x.useState(128),[i,c]=x.useState(0),[a,f]=x.useState([]),[m,A]=x.useState(!1),[y,F]=x.useState(!1),[k,h]=x.useState(new Set),_=(d,p)=>f(C=>C.map(l=>l.trackId===d?{...l,...p}:l)),b=d=>{h(p=>{const C=new Set(p);return C.has(d)?C.delete(d):C.add(d),C})},N=()=>{y?(h(new Set),F(!1)):(h(new Set(t.map(d=>d.id))),F(!0))},v=async()=>{const d=t.filter(p=>k.has(p.id)).map(p=>({trackId:p.id,trackName:p.name,fileUrl:p.file_url,originalSize:null,status:"fetching",newSize:null}));f(d),await Promise.all(d.map(async p=>{try{const C=await fetch(p.fileUrl,{method:"HEAD"}),l=parseInt(C.headers.get("content-length")||"0",10);_(p.trackId,{originalSize:l||null,status:"pending"})}catch{_(p.trackId,{status:"pending"})}}))},o=async()=>{if(a.length){A(!0);for(const d of a)if(d.status==="pending"){_(d.trackId,{status:"compressing"});try{const C=await(await fetch(d.fileUrl)).blob(),l=C.size;_(d.trackId,{originalSize:l});const D=new File([C],"track.mp3",{type:"audio/mpeg"}),I=await Qt(D,w,i),M=I.size,T=new File([I],"track.mp3",{type:"audio/mpeg"}),S=await W.integrations.Core.UploadFile({file:T});await Xt.update(d.trackId,{file_url:S.file_url,gain_db:i}),_(d.trackId,{status:"done",newSize:M,newUrl:S.file_url})}catch(p){console.error("Compression failed for",d.trackName,p),_(d.trackId,{status:"error"})}}A(!1),B.success("Compression complete!"),s()}},j="#a78bfa";return e.jsxs(z.div,{className:"mb-6 rounded-2xl overflow-hidden",style:{border:`1px solid ${j}35`,background:"linear-gradient(145deg, rgba(76,29,149,0.18), rgba(0,0,0,0.5))"},children:[e.jsxs("button",{onClick:()=>g(!r),className:"w-full flex items-center justify-between p-4 hover:bg-white/[0.04] transition-all",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center",style:{background:`${j}25`,border:`1px solid ${j}40`},children:e.jsx(Fe,{className:"w-4 h-4",style:{color:j}})}),e.jsxs("div",{className:"text-left",children:[e.jsx("h2",{className:"text-base font-black text-white",children:"ð Audio Compressor"}),e.jsx("p",{className:"text-sm text-slate-300",children:"Re-encode tracks to smaller MP3 sizes â quality preserved"})]})]}),e.jsx(z.div,{animate:{rotate:r?180:0},transition:{duration:.25},children:e.jsx(J,{className:"w-5 h-5 text-white/40"})})]}),e.jsx(q,{children:r&&e.jsxs(z.div,{initial:{height:0,opacity:0}
27,animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.25},className:"border-t p-5 space-y-4",style:{borderColor:`${j}20`},children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-200 text-sm font-bold uppercase tracking-wider mb-3",children:"Target Bitrate"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Yt.map(d=>e.jsxs("button",{onClick:()=>u(d.value),className:"px-4 py-2.5 rounded-xl text-sm font-bold border transition-all",style:{background:w===d.value?`${j}30`:"rgba(255,255,255,0.06)",borderColor:w===d.value?j:"rgba(255,255,255,0.25)",color:w===d.value?j:"#f1f5f9"},children:[e.jsx("span",{className:"block",children:d.label}),e.jsx("span",{className:"block text-xs font-normal mt-0.5",style:{color:w===d.value?`${j}dd`:"#cbd5e1"},children:d.desc})]},d.value))})]}),e.jsxs("div",{className:"bg-white/[0.06] rounded-xl p-4 border border-white/10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-slate-200 text-sm font-bold uppercase tracking-wider",children:"Volume Adjustment"}),e.jsxs("span",{className:"text-sm font-mono font-bold text-violet-300",children:[i>0?"+":"",i," dB"]})]}),e.jsx("input",{type:"range",min:"-40",max:"12",step:"1",value:i,onChange:d=>c(parseInt(d.target.value)),className:"w-full accent-violet-400 h-2"}),e.jsx("p",{className:"text-xs text-slate-200 mt-2",children:"Negative values reduce volume (e.g., -20 dB for mobile playback). Positive values increase volume."})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-slate-200 text-sm font-bold uppercase tracking-wider",children:"Select Tracks"}),e.jsx("button",{onClick:N,className:"text-sm text-slate-300 hover:text-white transition-colors font-semibold",children:y?"Deselect All":`Select All (${t.length})`})]}),e.jsx("div",{className:"space-y-1 max-h-56 overflow-y-auto pr-1",children:t.map(d=>{const p=V[d.genre]||V.ambient;return e.jsxs("label",{className:"flex items-center gap-3 px-3 py-2.5 rounded-lg cursor-pointer hover:bg-white/[0.07] transition-colors",children:[e.jsx("input",{type:"checkbox",checked:k.has(d.id),onChange:()=>b(d.id),className:"accent-violet-400 w-4 h-4"}),e.jsx("span",{className:"text-sm font-bold",style:{color:p.color},children:p.emoji}),e.jsx("span",{className:"text-sm text-slate-100 flex-1 truncate font-medium",children:d.name}),d.artist&&e.jsx("span",{className:"text-sm text-slate-200 truncate",children:d.artist})]},d.id)})})]}),k.size>0&&a.length===0&&e.jsxs(G,{onClick:v,variant:"outline",className:"border-slate-500 text-slate-100 hover:bg-white/10 text-sm font-bold px-5 py-2.5 h-auto",children:["Preview ",k.size," track",k.size>1?"s":""," â"]}),a.length>0&&e.jsxs("div",{className:"rounded-xl overflow-hidden border border-white/8",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto_auto] gap-3 px-4 py-2.5 text-xs font-black uppercase tracking-widest text-slate-300 border-b border-white/10",style:{background:"rgba(0,0,0,0.5)"},children:[e.jsx("span",{children:"Track"}),e.jsx("span",{children:"Before"}),e.jsx("span",{}),e.jsx("span",{children:"After"}),e.jsx("span",{children:"Saved"})]}),e.jsx("div",{className:"divide-y divide-white/[0.06]",children:a.map(d=>{const p=d.status==="done",C=p&&d.originalSize&&d.newSize?Math.round((1-d.newSize/d.originalSize)*100):null;return e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto_auto] gap-3 px-4 py-3 items-center",style:{background:p?"rgba(52,211,153,0.06)":"transparent"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.status==="fetching"&&e.jsx(U,{className:"w-4 h-4 animate-spin flex-shrink-0 text-slate-200"}),d.status==="compressing"&&e.jsx(U,{className:"w-4 h-4 animate-spin flex-shrink-0",style:{color:j}}),d.status==="done"&&e.jsx(te,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),d.status==="error"&&e.jsx(gt,{className:"w-4 h-4 text-red-400 flex-shrink-0"}),d.status==="pending"&&e.jsx("div",{className:"w-4 h-4 rounded-full border-2 border-slate-300 flex-shrink-0"}),e.jsx("span",{className:"text-slate-100 text-sm font-medium truncate",children:d.trackName})]}),e.jsx("span",{className:`text-sm font-mono font-semibold ${p?"text-slate-300 line-through":"text-slate-100"}`,children:d.originalSize?xt(d.originalSize):"â"}),e.jsx("span",{className:`text-base font-bold ${p?"text-emerald-400":"text-slate-300"}`,children:"â"}),e.jsx("span",{className:`text-sm font-mono font-bold ${p?"text-emerald-300":"text-slate-300"}`,children:p?xt(d.newSize):"â"}),p&&C!==null?C>0?e.jsxs("span",{className:"text-sm font-bold px-2.5 py-1 rounded-full bg-emerald-500/20 text-emerald-200 border border-emerald-500/40 whitespace-nowrap",children:["â ",C,"% smaller"]}):e.jsx("span",{className:"text-sm text-slate-200",children:"No change"}):e.jsx("span",{className:"text-sm text-slate-300",children:"â"})]},d.trackId)})})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[a.length>0&&e.jsx(G,{onClick:o,disabled:m||a.every(d=>d.status!=="pending"),className:"font-black text-white",style:{background:"linear-gradient(to right, #7c3aed, #a78bfa)"},children:m?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-4 h-4 mr-2 animate-spin"})," Compressingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fe,{className:"w-4 h-4 mr-2"})," Compress & Re-upload"]})}),a.length>0&&!m&&e.jsx(G,{onClick:()=>{f([]),h(new Set),F(!1)},variant:"ghost",className:"text-white/30 hover:text-white/60 text-sm",children:"Reset"})]}),e.jsx("p",{className:"text-sm text-slate-200 leading-relaxed",children:"â Compression is destructive â the original file is replaced. 128 kbps is transparent for most music. Use 192+ for audiophile content. Files are re-encoded client-side using the Web Audio API + lamejs."})]})})]})}const es=(...t)=>W.functions.invoke("generateAudioTrackVariants",...t),ht=[{key:"video_3d_file_url"},{key:"mobile_video_3d_file_url"}];function ts({tracks:t=[],onComplete:s}
27){const[r,g]=x.useState(!1),[w,u]=x.useState(""),[i,c]=x.useState(0),[a,f]=x.useState(0),[m,A]=x.useState(""),y=x.useMemo(()=>t.filter(h=>h.file_url&&(!h.video_3d_file_url||!h.mobile_video_3d_file_url)),[t]),F=x.useMemo(()=>y.reduce((h,_)=>h+ht.filter(b=>!_[b.key]).length,0),[y]),k=async()=>{var h,_;if(!y.length){B.success("All -20 dB variants are already ready.");return}g(!0),c(0),f(0),A("");for(const b of y)try{u(b.name);const N=ht.filter(j=>!b[j.key]).length,v=await es({track_id:b.id}),o=(v==null?void 0:v.data)||v;if(!(o!=null&&o.success))throw new Error((o==null?void 0:o.error)||"Variant generation failed");c(j=>j+N)}catch(N){const v=((_=(h=N==null?void 0:N.response)==null?void 0:h.data)==null?void 0:_.error)||(N==null?void 0:N.message)||"Variant generation failed";console.error("Variant generation failed:",b.name,N),A(v),f(o=>o+1)}g(!1),u(""),B.success("Missing -20 dB variant generation finished."),s==null||s()};return e.jsx("div",{className:"rounded-2xl border border-emerald-500/30 bg-emerald-500/10 p-4 space-y-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-emerald-500/20 border border-emerald-500/35 flex items-center justify-center flex-shrink-0",children:y.length?e.jsx(_t,{className:"w-4 h-4 text-emerald-300"}):e.jsx(te,{className:"w-4 h-4 text-emerald-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-white text-sm font-black",children:"Generate Missing -20 dB Variants"}),e.jsx("p",{className:"text-slate-200 text-xs leading-relaxed",children:y.length?`${y.length} track${y.length>1?"s need":" needs"} 3D/mobile -20 dB audio files.`:"All tracks already have their 3D/mobile -20 dB audio files."}),r&&w&&e.jsxs("p",{className:"text-emerald-200 text-xs mt-1",children:["Processing: ",w]}),a>0&&e.jsxs("p",{className:"text-yellow-200 text-xs mt-1 flex items-center gap-1",children:[e.jsx(Ee,{className:"w-3 h-3"})," ",a," track",a>1?"s":""," need retry",m?` · ${m}`:"","."]})]}),e.jsx(G,{onClick:k,disabled:r||F===0,className:"bg-emerald-600 hover:bg-emerald-700 text-white font-bold text-xs",children:r?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-3 h-3 mr-1.5 animate-spin"})," ",i,"/",F]}):"Generate Now"})]})})}const ie=W.entities.AudioTrack;function ss(t){const s=Math.round(t||0);return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`}const Te={name:"",file_url:"",artist:"",duration_seconds:0,is_loopable:!1,genre:"ambient"};function Vs(){const[t,s]=x.useState([]),[r,g]=x.useState(!0),[w,u]=x.useState(!1),[i,c]=x.useState(!1),[a,f]=x.useState(Te),[m,A]=x.useState(""),[y,F]=x.useState("all"),[k,h]=x.useState("list"),[_,b]=x.useState("date_desc"),[N,v]=x.useState(null),[o,j]=x.useState(null),[d,p]=x.useState(null),C=x.useRef(null),[l,D]=x.useState(!1),[I,M]=x.useState(!1),[T,S]=x.useState(!1),[L,P]=x.useState(!1),[E,ee]=x.useState(!1),[ae,ye]=x.useState(!1),[K,ue]=x.useState(!1),[O,le]=x.useState(new Set),[Ue,Ge]=x.useState(!1);x.useEffect(()=>{Z()},[]);const Z=async()=>{g(!0);try{const n=await ie.list("-created_date",200);s(n)}catch{B.error("Failed to load audio tracks")}finally{g(!1)}},ve=async(n,$)=>{const R=n.target.files[0];if(!R||!R.type.startsWith("audio/")){B.error("Please upload an audio file");return}u(!0);try{const Ke=(await W.integrations.Core.UploadFile({file:R})).file_url,vt=await new Promise(re=>{const _e=new Audio(Ke);_e.onloadedmetadata=()=>re(Math.round(_e.duration)||0),_e.onerror=()=>re(0),setTimeout(()=>re(0),5e3)});$(re=>({...re,file_url:Ke,duration_seconds:vt})),B.success("Audio uploaded!")}catch{B.error("Failed to upload")}finally{u(!1)}},wt=async()=>{if(!a.name.trim()||!a.file_url){B.error("Name and audio file required");return}try{await ie.create(a),B.success("Track added!"),f(Te),c(!1),Z()}catch(n){B.error("Failed: "+n.message)}},Pe=async()=>{var n;if(!((n=o==null?void 0:o.name)!=null&&n.trim())){B.error("Name required");return}try{await ie.update(N,o),B.success("Track updated!"),v(null),j(null),Z()}catch($){B.error("Failed: "+$.message)}},Oe=async n=>{if(confirm("Permanently delete this track?"))try{await ie.delete(n),B.success("Deleted"),N===n&&(v(null),j(null)),Z()}catch{B.error("Failed to delete")}},jt=async()=>
27{if(O.size!==0&&confirm(`Permanently delete ${O.size} track(s)?`)){Ge(!0);try{await Promise.all([...O].map(n=>ie.delete(n))),B.success(`Deleted ${O.size} tracks`),le(new Set),ue(!1),Z()}catch{B.error("Some deletions failed")}finally{Ge(!1)}}},Ve=n=>{le($=>{const R=new Set($);return R.has(n)?R.delete(n):R.add(n),R})},Nt=()=>{O.size===Y.length?le(new Set):le(new Set(Y.map(n=>n.id)))},qe=n=>{var $;if(d===n.id)($=C.current)==null||$.pause(),p(null);else{C.current&&C.current.pause();const R=new Audio(n.file_url);R.crossOrigin="anonymous",R.onended=()=>p(null),R.play(),C.current=R,p(n.id)}},We=n=>{N===n.id?(v(null),j(null)):(v(n.id),j({...n}))},He=[...new Set(t.map(n=>n.genre).filter(Boolean))],Y=t.filter(n=>{var ne;const $=n.name.toLowerCase().includes(m.toLowerCase())||((ne=n.artist)==null?void 0:ne.toLowerCase().includes(m.toLowerCase())),R=y==="all"||n.genre===y;return $&&R}).sort((n,$)=>{switch(_){case"name_asc":return n.name.localeCompare($.name);case"name_desc":return $.name.localeCompare(n.name);case"genre_asc":return(n.genre||"").localeCompare($.genre||"");case"genre_desc":return($.genre||"").localeCompare(n.genre||"");case"date_asc":return new Date(n.created_date)-new Date($.created_date);case"date_desc":return new Date($.created_date)-new Date(n.created_date);case"duration_asc":return(n.duration_seconds||0)-($.duration_seconds||0);case"duration_desc":return($.duration_seconds||0)-(n.duration_seconds||0);default:return 0}}),yt=t.reduce((n,$)=>(n[$.genre]=(n[$.genre]||0)+1,n),{}),ke=V[a.genre]||V.ambient;return r?e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[60vh]",children:[e.jsx(Ze,{className:"w-12 h-12 text-purple-400 animate-pulse"}),e.jsx("p",{className:"mt-4 text-slate-200 text-sm animate-pulse",children:"Loading audio library..."})]}):e.jsxs("div",{className:"text-white space-y-6",children:[e.jsxs("div",{className:"rounded-2xl overflow-hidden border border-slate-600/60 bg-gradient-to-br from-slate-800/80 to-slate-900/80",children:[e.jsxs("button",{onClick:()=>D(n=>!n),className:"w-full flex items-center justify-between p-4 hover:bg-white/[0.04] transition-all",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center bg-purple-500/20 border border-purple-500/35",children:e.jsx(St,{className:"w-4 h-4 text-purple-400"})}),e.jsx("h2",{className:"text-base font-black text-white",children:"ð Control Panel"}),e.jsx("span",{className:"text-xs text-slate-200 font-semibold",children:"Bulk Upload · Duplicate Detector · Compressor · Add Track"})]}),e.jsx(z.div,{animate:{rotate:l?180:0},transition:{duration:.25},children:e.jsx(J,{className:"w-5 h-5 text-slate-300"})})]}),e.jsx(q,{children:l&&e.jsxs(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.25},className:"border-t border-slate-700/60 divide-y divide-slate-700/40",children:[e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>M(n=>!n),className:"w-full flex items-center justify-between px-5 py-3 hover:bg-white/[0.03] transition-all",children:[e.jsx("span",{className:"text-sm font-bold text-white",children:"ð¦ Bulk Upload"}),e.jsx(z.div,{animate:{rotate:I?180:0},transition:{duration:.2},children:e.jsx(J,{className:"w-4 h-4 text-white/30"})})]}),e.jsx(q,{children:I&&e.jsx(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"px-5 pb-5",children:e.jsx(Zt,{onComplete:Z})})})]}),e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>ye(n=>!n),className:"w-full flex items-center justify-between px-5 py-3 hover:bg-white/[0.03] transition-all",children:[e.jsx("span",{className:"text-sm font-bold text-white",children:"ð Duplicate Detector"}),e.jsx(z.div,{animate:{rotate:ae?180:0},transition:{duration:.2},children:e.jsx(J,{className:"w-4 h-4 text-white/30"})})]}),e.jsx(q,{children:ae&&e.jsx(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"px-5 pb-5",children:e.jsx(It,{tracks:t,onComplete:Z})})})]}),e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>S(n=>!n),className:"w-full flex items-center justify-between px-5 py-3 hover:bg-white/[0.03] transition-all",children:[e.jsx("span",{className:"text-sm font-bold text-white",children:"ð Audio Compressor"}
27),e.jsx(z.div,{animate:{rotate:T?180:0},transition:{duration:.2},children:e.jsx(J,{className:"w-4 h-4 text-white/30"})})]}),e.jsx(q,{children:T&&e.jsx(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"px-5 pb-5",children:t.length>0?e.jsx(Jt,{tracks:t,onComplete:Z}):e.jsx("p",{className:"text-white/30 text-sm py-2",children:"Upload tracks first to use the compressor."})})})]}),e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>P(n=>!n),className:"w-full flex items-center justify-between px-5 py-3 hover:bg-white/[0.03] transition-all",children:[e.jsx("span",{className:"text-sm font-bold text-white",children:"ð± Missing -20 dB Variants"}),e.jsx(z.div,{animate:{rotate:L?180:0},transition:{duration:.2},children:e.jsx(J,{className:"w-4 h-4 text-white/30"})})]}),e.jsx(q,{children:L&&e.jsx(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"px-5 pb-5",children:e.jsx(ts,{tracks:t,onComplete:Z})})})]}),e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>ee(n=>!n),className:"w-full flex items-center justify-between px-5 py-3 hover:bg-white/[0.03] transition-all",children:[e.jsx("span",{className:"text-sm font-bold text-white",children:"ðµ Add Single Track"}),e.jsx(z.div,{animate:{rotate:E?180:0},transition:{duration:.2},children:e.jsx(J,{className:"w-4 h-4 text-white/30"})})]}),e.jsx(q,{children:E&&e.jsxs(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"px-5 pb-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-200 text-xs font-bold uppercase tracking-wider mb-1.5 block",children:"Track Name *"}),e.jsx(Q,{value:a.name,onChange:n=>f($=>({...$,name:n.target.value})),placeholder:"Epic Cinematic Intro",className:"bg-black/40 border-white/10 text-white"})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-200 text-xs font-bold uppercase tracking-wider mb-1.5 block",children:"Artist / Composer"}),e.jsx(Q,{value:a.artist,onChange:n=>f($=>({...$,artist:n.target.value})),placeholder:"Hans Zimmer",className:"bg-black/40 border-white/10 text-white"})]})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-slate-200 text-xs font-bold uppercase tracking-wider mb-1.5 block",children:"Upload Audio File *"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{type:"file",accept:"audio/*",onChange:n=>ve(n,f),disabled:w,className:"bg-black/40 border-white/10 text-white"}),w&&e.jsx(U,{className:"w-5 h-5 animate-spin text-white flex-shrink-0"})]}),a.file_url&&e.jsxs("p",{className:"text-emerald-400 text-xs mt-1",children:["â Uploaded · ",ss(a.duration_seconds)]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(H,{className:"text-white/60 text-xs font-bold uppercase tracking-wider mb-1.5 block",children:"Genre"}),e.jsxs(fe,{value:a.genre,onValueChange:n=>
27f($=>({...$,genre:n})),children:[e.jsx(be,{className:"bg-black/40 border-white/10 text-white",children:e.jsx(ge,{})}),e.jsx(we,{className:"bg-slate-900 border-slate-700 max-h-60 overflow-y-auto",children:Le.map(n=>e.jsx(X,{value:n.value,children:n.label},n.value))})]})]}),e.jsxs("div",{children:[e.jsx(H,{className:"text-white/60 text-xs font-bold uppercase tracking-wider mb-1.5 block",children:"Duration (sec)"}),e.jsx(Q,{type:"number",value:a.duration_seconds,onChange:n=>f($=>({...$,duration_seconds:parseInt(n.target.value)||0})),className:"bg-black/40 border-white/10 text-white"})]}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm text-white cursor-pointer",children:[e.jsx(Re,{checked:a.is_loopable,onCheckedChange:n=>f($=>({...$,is_loopable:n}))}),"Loopable"]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(G,{onClick:wt,className:"font-black text-white",style:{background:`linear-gradient(to right, ${ke.color}, ${ke.colorEnd||ke.color})`},children:[e.jsx(pe,{className:"w-4 h-4 mr-2"})," Add Track"]}),e.jsx(G,{onClick:()=>{ee(!1),f(Te)},variant:"outline",className:"border-white/10 text-white hover:bg-white/10",children:"Cancel"})]})]})})]})]})})]}),He.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:()=>F("all"),className:`px-3 py-1.5 rounded-full text-xs font-bold transition-all border ${y==="all"?"bg-white/15 border-white/30 text-white":"border-white/10 text-white/40 hover:border-white/20 hover:text-white/60"}`,children:["ðµ All (",t.length,")"]}),He.map(n=>{const $=V[n]||V.ambient,R=y===n;return e.jsxs("button",{onClick:()=>F(n),className:"px-3 py-1.5 rounded-full text-xs font-bold transition-all border",style:{background:R?`${$.color}25`:"transparent",borderColor:R?`${$.color}60`:`${$.color}25`,color:R?$.color:`${$.color}80`},children:[$.emoji," ",$.label," (",yt[n]||0,")"]},n)})]}),e.jsxs("div",{className:"flex gap-3 items-center flex-wrap",children:[e.jsxs("div",{className:"flex-1 relative min-w-[200px]",children:[e.jsx(Ct,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/30"}),e.jsx(Q,{placeholder:"Search by name, artist...",value:m,onChange:n=>A(n.target.value),className:"pl-10 bg-black/30 border-white/10 text-white placeholder:text-slate-300"})]}),e.jsxs(fe,{value:_,onValueChange:b,children:[e.jsx(be,{className:"w-44 bg-black/30 border-white/10 text-white text-sm",children:e.jsx(ge,{})}),e.jsxs(we,{className:"bg-slate-900 border-slate-700 text-white",children:[e.jsx(X,{value:"date_desc",children:"ð
Newest First"}),e.jsx(X,{value:"date_asc",children:"ð
Oldest First"}),e.jsx(X,{value:"name_asc",children:"ð¤ Name AâZ"}),e.jsx(X,{value:"name_desc",children:"ð¤ Name ZâA"}),e.jsx(X,{value:"genre_asc",children:"ðµ Genre AâZ"}),e.jsx(X,{value:"genre_desc",children:"ðµ Genre ZâA"}),e.jsx(X,{value:"duration_asc",children:"â± Shortest First"}),e.jsx(X,{value:"duration_desc",children:"â± Longest First"})]})]}),e.jsxs("div",{className:"flex rounded-xl overflow-hidden border border-white/10",children:[e.jsx("button",{onClick:()=>h("list"),className:`px-3 py-2 transition-all ${k==="list"?"bg-white/15 text-white":"text-white/30 hover:text-white/60"}`,children:e.jsx($t,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>h("grid"),className:`px-3 py-2 transition-all ${k==="grid"?"bg-white/15 text-white":"text-white/30 hover:text-white/60"}`,children:e.jsx(At,{className:"w-4 h-4"})})]}),e.jsxs("button",{onClick:()=>{ue(n=>!n),le(new Set)},className:`flex items-center gap-1.5 px-3 py-2 rounded-xl border text-xs font-bold transition-all ${K?"bg-red-500/20 border-red-500/50 text-red-400":"border-white/10 text-white/40 hover:text-white/70 hover:border-white/20"}`,children:[e.jsx(xe,{className:"w-4 h-4"})," ",K?"Cancel":"Select"]}),e.jsxs("span",{className:"text-sm text-slate-200 whitespace-nowrap font-semibold",children:[Y.length," tracks"]})]}),e.jsx(q,{children:K&&e.jsxs(z.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"flex items-center gap-3 p-3 rounded-xl bg-red-500/10 border border-red-500/30",children:[e.jsxs("button",{onClick:Nt,className:"flex items-center gap-2 text-xs font-bold text-white/70 hover:text-white transition-colors",children:[O.size===Y.length&&Y.length>0?e.jsx(xe,{className:"w-4 h-4 text-red-400"}):e.jsx(Ce,{className:"w-4 h-4"}),O.size===Y.length&&Y.length>0?"Deselect All":"Select All"]}),e.jsxs("span",{className:"text-xs text-slate-200 flex-1",children:[O.size," selected"]}),O.size>0&&e.jsxs(G,{size:"sm",onClick:jt,disabled:Ue,className:"bg-red-600 hover:bg-red-700 text-white font-bold gap-1.5",children:[Ue?e.jsx(U,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ce,{className:"w-3.5 h-3.5"}),"Delete ",O.size]})]})}),Y.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(Ze,{className:"w-14 h-14 text-white/10 mx-auto mb-4"}),e.jsx("p",{className:"text-slate-200",children:"No tracks foun
27d. Upload some above!"})]}):k==="grid"?e.jsx(z.div,{layout:!0,className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:e.jsx(q,{children:Y.map(n=>e.jsxs("div",{className:"relative",children:[K&&e.jsx("button",{onClick:()=>Ve(n.id),className:"absolute top-2 left-2 z-10 w-6 h-6 rounded-md flex items-center justify-center bg-black/60 border border-white/20 hover:border-red-400 transition-all",children:O.has(n.id)?e.jsx(xe,{className:"w-4 h-4 text-red-400"}):e.jsx(Ce,{className:"w-4 h-4 text-white/40"})}),e.jsx(st,{track:n,isPlaying:d===n.id,isExpanded:N===n.id,viewMode:"grid",audioElement:d===n.id?C.current:null,onTogglePlay:()=>qe(n),onClick:()=>!K&&We(n),onDelete:()=>Oe(n.id)}),e.jsx(q,{children:N===n.id&&o&&!K&&e.jsx(lt,{data:o,onChange:$=>j(R=>({...R,...$})),onSave:Pe,onCancel:()=>{v(null),j(null)},onFileUpload:$=>ve($,j),uploading:w,onVariantComplete:Z})})]},n.id))})}):e.jsx(z.div,{layout:!0,className:"space-y-1",children:e.jsx(q,{children:Y.map(n=>{var $;return e.jsxs("div",{className:"rounded-xl overflow-hidden flex items-stretch gap-0",style:{border:`1px solid ${N===n.id?((($=V[n.genre])==null?void 0:$.color)||"#fff")+"35":"rgba(255,255,255,0.06)"}`},children:[K&&e.jsx("button",{onClick:()=>Ve(n.id),className:`flex-shrink-0 w-10 flex items-center justify-center transition-colors ${O.has(n.id)?"bg-red-500/15":"bg-black/20 hover:bg-white/5"}`,children:O.has(n.id)?e.jsx(xe,{className:"w-4 h-4 text-red-400"}):e.jsx(Ce,{className:"w-4 h-4 text-white/25"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(st,{track:n,isPlaying:d===n.id,isExpanded:N===n.id,viewMode:"list",audioElement:d===n.id?C.current:null,onTogglePlay:()=>qe(n),onClick:()=>!K&&We(n),onDelete:()=>Oe(n.id)}),e.jsx(q,{children:N===n.id&&o&&!K&&e.jsx(lt,{data:o,onChange:R=>j(ne=>({...ne,...R})),onSave:Pe,onCancel:()=>{v(null),j(null)},onFileUpload:R=>ve(R,j),uploading:w,onVariantComplete:Z})})]})]},n.id)})})})]})}export{Vs as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.