1import{e as xe,k as we,f as J,s as q,T as re,r as d,j as e,m as k,A as F,a as M,C as W,b as A,aN as K,L as he,t as te,ah as me,a2 as se,Q as ae,X as ne,a1 as ge,aa as je,u as ye,a4 as ve,aL as oe,aT as Ne,J as ke}from"./index-TfVn0xSy.js";import{P as Ce}from"./pause-8i5Yiuu0.js";const ce={staff_tower:0,rhythm_arena:30,interval_observatory:80,ear_training:150,chord_city:250,sight_reading:400,composition_studio:600,practice_field:0};function _e(){const{user:n}=xe(),a=we(),{data:s,isLoading:i}=J({queryKey:["music-profile",n==null?void 0:n.id],enabled:!!n,queryFn:async()=>{const{data:o}=await q.from("music_profiles").select("*").eq("user_id",n.id).maybeSingle();return o}}),{data:x=[]}=J({queryKey:["music-lessons"],queryFn:async()=>{const{data:o}=await q.from("music_lessons").select("*").order("zone").order("sort_order");return o??[]}}),{data:r=[]}=J({queryKey:["music-progress",n==null?void 0:n.id],enabled:!!n,queryFn:async()=>{const{data:o}=await q.from("music_lesson_progress").select("*").eq("user_id",n.id);return o??[]}}),l=re({mutationFn:async o=>{const{error:m}=await q.from("music_profiles").upsert({user_id:n.id,...o,onboarded:!0});if(m)throw m},onSuccess:()=>a.invalidateQueries({queryKey:["music-profile"]})}),g=re({mutationFn:async o=>{const m=x.find(C=>C.id===o.lessonId);if(!m||!n)return;await q.from("music_lesson_progress").upsert({user_id:n.id,lesson_id:o.lessonId,status:"completed",score:o.score,accuracy:o.accuracy,best_accuracy:o.accuracy,attempts:1,completed_at:new Date().toISOString(),last_attempted_at:new Date().toISOString()},{onConflict:"user_id,lesson_id"}),await q.from("music_practice_sessions").insert({user_id:n.id,zone:m.zone,lesson_id:o.lessonId,duration_seconds:60,exercises_completed:1,accuracy:o.accuracy,xp_earned:m.xp_reward});const c=new Date().toISOString().slice(0,10),t=((s==null?void 0:s.total_xp)??0)+m.xp_reward,y=(s==null?void 0:s.last_practice_date)!==c?((s==null?void 0:s.current_streak)??0)+1:(s==null?void 0:s.current_streak)??1,w=Object.entries(ce).filter(([,C])=>t>=C).map(([C])=>C);await q.from("music_profiles").update({total_xp:t,current_streak:y,longest_streak:Math.max(y,(s==null?void 0:s.longest_streak)??0),last_practice_date:c,zones_unlocked:w,updated_at:new Date().toISOString()}).eq("user_id",n.id)},onSuccess:()=>{a.invalidateQueries({queryKey:["music-profile"]}),a.invalidateQueries({queryKey:["music-progress"]})}});return{profile:s,profileLoading:i,lessons:x,progress:r,createProfile:l,completeLesson:g,zoneLessons:o=>x.filter(m=>m.zone===o),lessonProgress:o=>r.find(m=>m.lesson_id===o),isZoneUnlocked:o=>((s==null?void 0:s.zones_unlocked)??["staff_tower"]).includes(o),zoneXpRequired:o=>ce[o]??0}}const U=[{title:"Welcome to Music Planet",subtitle:"Learn to read, hear, and create music",icon:"ðµ"},{title:"What's your experience?",subtitle:"We'll tailor lessons to your level",field:"skill_level",options:[{value:"beginner",label:"Complete Beginner",desc:"Never read music before",icon:"ð±"},{value:"elementary",label:"Some Basics",desc:"Know a few notes",icon:"ð¿"},{value:"intermediate",label:"Intermediate",desc:"Can read simple melodies",icon:"ð³"},{value:"advanced",label:"Advanced",desc:"Comfortable with notation",icon:"ðï¸"}]},{title:"Which clef first?",subtitle:"You can always switch later",field:"preferred_clef",options:[{value:"treble",label:"Treble Clef ð",desc:"Piano right hand, guitar, voice",icon:"ð¹"},{value:"bass",label:"Bass Clef ð¢",desc:"Piano left hand, bass guitar",icon:"ð¸"}]},{title:"How will you practice?",subtitle:"Input method for exercises",field:"preferred_instrument",options:[{value:"piano",label:"On-screen Keyboard",desc:"Click or tap notes",icon:"ð±ï¸"},{value:"midi",label:"MIDI Keyboard",desc:"Connect a MIDI device",icon:"ð¹"}]}];function Se({onComplete:n}){const[a,s]=d.useState(0),[i,x]=d.useState({preferred_clef:"treble",preferred_instrument:"piano",skill_level:"beginner"}),r=U[a],l=(f,j)=>{x(u=>({...u,[f]:j}))},g=()=>{a<U.length-1?s(a+1):n(i)};return e.jsxs(k.div,{className:"fixed inset-0 z-50 flex items-center justify-center",style:{background:"linear-gradient(135deg, hsl(260 30% 10%), hsl(240 20% 15%))"},initial:{opacity:0}
1,animate:{opacity:1},children:[e.jsx(F,{mode:"wait",children:e.jsxs(k.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"max-w-md w-full mx-4",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-5xl mb-4",children:r.icon??"ðµ"}),e.jsx("h1",{className:"text-2xl font-bold text-white mb-2",children:r.title}),e.jsx("p",{className:"text-white/50 text-sm",children:r.subtitle})]}),r.options&&e.jsx("div",{className:"space-y-3 mb-8",children:r.options.map(f=>{const j=i[r.field]===f.value;return e.jsxs("button",{onClick:()=>l(r.field,f.value),className:M("w-full flex items-center gap-3 p-4 rounded-xl border transition-all text-left",j?"border-purple-400 bg-purple-500/10 text-white":"border-white/10 bg-white/5 text-white/70 hover:bg-white/10"),children:[e.jsx("span",{className:"text-2xl",children:f.icon}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium",children:f.label}),e.jsx("div",{className:"text-xs opacity-60",children:f.desc})]}),j&&e.jsx(W,{className:"w-5 h-5 text-purple-400"})]},f.value)})}),e.jsxs(A,{onClick:g,className:"w-full bg-purple-600 hover:bg-purple-500 text-white h-12",children:[a===U.length-1?"Start Learning":"Continue",e.jsx(K,{className:"w-4 h-4 ml-2"})]})]},a)}),e.jsx("div",{className:"absolute bottom-8 flex gap-2",children:U.map((f,j)=>e.jsx("div",{className:M("w-2 h-2 rounded-full transition-all",j<=a?"bg-purple-400":"bg-white/20")},j))})]})}const ue=[{id:"staff_tower",name:"Staff Tower",icon:"ð°",description:"Learn to read notes on the staff",color:"hsl(260, 70%, 60%)",position:{x:50,y:30}},{id:"rhythm_arena",name:"Rhythm Arena",icon:"ð¥",description:"Master rhythm and timing",color:"hsl(20, 80%, 55%)",position:{x:80,y:50}},{id:"interval_observatory",name:"Interval Observatory",icon:"ð",description:"Recognize interval distances",color:"hsl(200, 70%, 55%)",position:{x:25,y:55}},{id:"ear_training",name:"Ear Training Cavern",icon:"ð",description:"Sharpen your listening skills",color:"hsl(160, 60%, 45%)",position:{x:65,y:72}},{id:"chord_city",name:"Chord City",icon:"ðï¸",description:"Build and hear harmonies",color:"hsl(300, 60%, 55%)",position:{x:35,y:78}},{id:"sight_reading",name:"Sight Reading River",icon:"ð",description:"Read music in real-time",color:"hsl(180, 60%, 50%)",position:{x:70,y:25}},{id:"composition_studio",name:"Composition Studio",icon:"âï¸",description:"Write your own music",color:"hsl(45, 80%, 55%)",position:{x:20,y:35}},{id:"practice_field",name:"Practice Field",icon:"ð¯",description:"Free play and drills",color:"hsl(120, 50%, 50%)",position:{x:50,y:55}}];function Te({unlockedZones:n,currentZone:a,completedLessons:s,totalLessons:i,onSelectZone:x}){return e.jsxs("div",{className:"relative w-full aspect-[16/9] max-w-3xl mx-auto",children:[e.jsx("div",{className:"absolute inset-4 rounded-[50%] overflow-hidden",style:{background:"radial-gradient(ellipse at 40% 35%, hsl(260 40% 25%), hsl(240 30% 12%))",boxShadow:"0 0 60px hsla(260, 60%, 40%, 0.3), inset 0 -20px 40px rgba(0,0,0,0.4)"},children:e.jsx("div",{className:"absolute inset-0 opacity-10",style:{backgroundImage:"radial-gradient(circle at 20% 30%, white 1px, transparent 1px), radial-gradient(circle at 70% 60%, white 1px, transparent 1px), radial-gradient(circle at 45% 80%, white 1px, transparent 1px)",backgroundSize:"80px 80px, 120px 120px, 60px 60px"}})}),ue.map(r=>{const l=n.includes(r.id),g=a===r.id,f=s[r.id]??0,j=i[r.id]??0;return e.jsxs(k.button,{className:M("absolute flex flex-col items-center gap-1 -translate-x-1/2 -translate-y-1/2",l?"cursor-pointer":"cursor-not-allowed opacity-40"),style:{left:`${r.position.x}%`,top:`${r.position.y}%`},whileHover:l?{scale:1.1}:{},whileTap:l?{scale:.95}:{},onClick:()=>l&&x(r.id),children:[l&&e.jsx(k.div,{className:"absolute w-16 h-16 rounded-full -z-10",style:{background:`radial-gradient(circle, ${r.color}33, transparent)`},animate:g?{scale:[1,1.3,1],opacity:[.5,.8,.5]}:{},transition:{duration:2,repeat:1/0}}),e.jsx("div",{className:M("w-12 h-12 rounded-full flex items-center justify-center text-xl",g&&"ring-2 ring-white/50"),style:{background:l?r.color:"hsl(var(--muted))"},children:l?r.icon:e.jsx(he,{className:"w-4 h-4 text-white/50"})}),e.jsx("span",{className:"text-[10px] font-medium text-white/80 whitespace-nowrap max-w-[80px] truncate",children:r.name}),l&&j>0&&e.jsx("div",{className:"flex gap-0.5",children:Array.from({length:Math.min(j,5)}).map((u,b)=>e.jsx("div",{className:"w-1.5 h-1.5 rounded-full",style:{background:b<f?r.color:"hsl(var(--muted))"}},b))})]},r.id)})]})}const de=70;function Me({zone:n,lessons:a,progress:s,explorerMode:i,onSelectLesson:x,onBack:r}){const l=ue.find(o=>o.id===n),g=o=>{const m=s.find(c=>c.lesson_id===o);return(m==null?void 0:m.status)??"available"},f=o=>{const m=s.find(c=>c.lesson_id===o);return(m==null?void 0:m.score)??0},j=o=>{const m=s.find(c=>c.lesson_id===o);return(m==null?void 0:m.best_accuracy)??0},u=o=>{if(i||o===0)return!1;const m=a[o-1],c=g(m.id),t=f(m.id);return!(c==="completed"&&t>=de||g(a[o].id)==="completed")},b=o=>{const m=g(o),c=f(o);return m==="completed"&&c<de};return e.jsxs("div",{className:"max-w-lg mx-auto",children:[e.jsx("button",{onClick:r,className:"text-white/50 text-sm mb-4 hover:text-white/70",children:"â Back to Planet"}),e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center text-xl",style:{background:(l==null?void 0:l.color)??"hsl(var(--primary))"},children:l==null?void 0:l.icon}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-white",children:l==null?void 0:l.name}),e.jsx("p",{className:"text-sm text-white/50",children:l==null?void 0:l.description})]})]}),e.jsx("div",{className:"space-y-3",children:a.map((o,m)=>{const c=g(o.id),t=j(o.id),h=c==="completed",y=u(m),w=b(o.id);return e.jsxs(k.button,{className:M("w-full flex items-center gap-4 p-4 rounded-xl border text-left transition-all",y?"border-white/5 bg-white/2 opacity-40 cursor-not-allowed":h?"border-emerald-500/30 bg-emerald-500/5 hover:bg-emerald-500/10":"border-white/10 bg-white/5 hover:bg-white/10 cursor-pointer"),onClick:()=>!y&&x(o),whileHover:y?{}:{x:4},children:[e.jsx("div",{className:M("w-10 h-10 rounded-full flex items-center justify-center shrink-0",h?"bg-emerald-500/20":y?"bg-white/5":"bg-white/10"),children:h&&!i?e.jsx(W,{className:"w-5 h-5 text-emerald-400"}):y?e.jsx(he,{className:"w-4 h-4 text-white/30"}):i&&!h?e.jsx(te,{className:"w-4 h-4 text-cyan-400"}):h?e.jsx(W,{className:"w-5 h-5 text-emerald-400"}):e.jsx(me,{className:"w-4 h-4 text-white/60"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:o.title}),e.jsx("div",{className:"text-xs text-white/40",children:o.description}),i&&!h&&e.jsx("div",{className:"text-[10px] text-cyan-400/70 mt-0.5",children:"Explorer Mode"}),w&&!i&&e.jsx("div",{className:"text-[10px] text-amber-400/70 mt-0.5",children:"Practice again to unlock the next lesson."})]}),e.jsxs("div",{className:"text-right shrink-0",children:[h&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-400",children:[e.jsx(se,{className:"w-3 h-3"}),t,"%"]}),e.jsxs("div",{className:M("text-[10px]",i?"text-white/20 line-through":"text-white/30"),children:["+",o.xp_reward," XP",i&&e.jsx("span",{className:"no-underline ml-1 text-white/15",children:"(disabled)"})]})]})]},o.id)})})]})}const Ee=["C","D","E","F","G","A","B"];function Ae(n,a){const s=n.match(/^([A-G]#?)(\d)$/);if(!s)return 0;const[,i,x]=s,r=i.replace("#",""),l=parseInt(x),g=Ee.indexOf(r);return a==="treble"?(l-4)*7+g-2:(l-2)*7+g-5}function ie({notes:n,clef:a="treble",width:s=600,height:i=180,showNoteNames:x=!1,highlightedNote:r,onNoteClick:l,interactive:g=!1,className:f}){const u=(i-80)/4,b=40+u*4,o=40+u*2,m=d.useMemo(()=>{const h=Math.min(60,(s-80-40)/Math.max(n.length,1));return n.map((y,w)=>{const C=Ae(y.note,a),v=b-C*u/2,N=80+w*h+h/2;return{...y,x:N,y:v,pos:C}})},[n,a,s,i,u,b]),c=a==="treble"?"ð":"ð¢";return e.jsxs("svg",{width:s,height:i,viewBox:`0 0 ${s} ${i}`,className:M("select-none",f),children:[[0,1,2,3,4].map(t=>e.jsx("line",{x1:10,y1:40+t*u,x2:s-10,y2:40+t*u,stroke:"hsl(var(--foreground) / 0.3)",strokeWidth:1},t)),e.jsx("text",{x:20,y:o+(a==="treble"?12:8),fontSize:a==="treble"?52:42,fill:"hsl(var(--foreground) / 0.7)",fontFamily:"serif",children:c}),m.map((t,h)=>{const y=r===t.note||t.highlighted,w=t.color??(y?"hsl(var(--primary))":"hsl(var(--foreground))"),C=!t.duration||t.duration==="quarter"||t.duration==="eighth"||t.duration==="sixteenth",v=[];if(t.pos<0)for(let N=-2;N>=t.pos;N-=2)v.push(b-N*u/2);if(t.pos>8)for(let N=10;N<=t.pos;N+=2)v.push(b-N*u/2);return e.jsxs("g",{className:M(g&&"cursor-pointer"),onClick:()=>l==null?void 0:l(t.note),children:[v.map((N,T)=>e.jsx("line",{x1:t.x-14,y1:N,x2:t.x+14,y2:N,stroke:"hsl(var(--foreground) / 0.3)",strokeWidth:1},T)),e.jsx("ellipse",{cx:t.x,cy:t.y,rx:8,ry:6,fill:C?w:"none",stroke:w,strokeWidth:2,transform:`rotate(-10 ${t.x} ${t.y})`,opacity:y?1:.8}),t.duration!=="whole"&&e.jsx("line",{x1:t.pos<4?t.x+7:t.x-7,y1:t.y,x2:t.pos<4?t.x+7:t.x-7,y2:t.pos<4?t.y-u*1.5:t.y+u*1.5,stroke:w,strokeWidth:1.5}),y&&e.jsx("ellipse",{cx:t.x,cy:t.y,rx:14,ry:12,fill:"hsl(var(--primary) / 0.15)",transform:`rotate(-10 ${t.x} ${t.y})`}),x&&e.jsx("text",{x:t.x,y:t.y+u+14,textAnchor:"middle",fontSize:10,fill:"hsl(var(--primary))",fontWeight:600,children:t.note.replace(/\d/,"")})]},h)})]})}const fe={},V=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];for(let n=2;n<=7;n++)for(let a=0;a<V.length;a++){const s=(n+1)*12+a,i=440*Math.pow(2,(s-69)/12);fe[`${V[a]}${n}`]=i}let Z=null;function pe(){return Z||(Z=new AudioContext),Z.state==="suspended"&&Z.resume(),Z}function O(n,a=.5,s="triangle"){const i=pe(),x=fe[n];if(!x)return;const r=i.createOscillator(),l=i.createGain();r.type=s,r.frequency.value=x,l.gain.setValueAtTime(.3,i.currentTime),l.gain.exponentialRampToValueAtTime(.001,i.currentTime+a),r.connect(l),l.connect(i.destination),r.start(i.currentTime),r.stop(i.currentTime+a)}
1function Pe(n,a=1){n.forEach(s=>O(s,a,"sine"))}function Le(){const n=pe(),a=n.createOscillator(),s=n.createGain();a.type="square",a.frequency.value=1e3,s.gain.setValueAtTime(.1,n.currentTime),s.gain.exponentialRampToValueAtTime(.001,n.currentTime+.05),a.connect(s),s.connect(n.destination),a.start(n.currentTime),a.stop(n.currentTime+.05)}function G(n){const a=n.match(/^([A-G]#?)(\d)$/);return a?a[1]:n}const z={m2:{semitones:1,name:"Minor 2nd"},M2:{semitones:2,name:"Major 2nd"},m3:{semitones:3,name:"Minor 3rd"},M3:{semitones:4,name:"Major 3rd"},P4:{semitones:5,name:"Perfect 4th"},TT:{semitones:6,name:"Tritone"},P5:{semitones:7,name:"Perfect 5th"},m6:{semitones:8,name:"Minor 6th"},M6:{semitones:9,name:"Major 6th"},m7:{semitones:10,name:"Minor 7th"},M7:{semitones:11,name:"Major 7th"},P8:{semitones:12,name:"Octave"}};function Re(n){const a=n.match(/^([A-G]#?)(\d)$/);if(!a)return 60;const s=V.indexOf(a[1]);return(parseInt(a[2])+1)*12+s}function Be(n){const a=Math.floor(n/12)-1,s=n%12;return`${V[s]}${a}`}function be(n,a){const s=Re(n);return Be(s+a)}function De(n){const a=[...n];for(let s=a.length-1;s>0;s--){const i=Math.floor(Math.random()*(s+1));[a[s],a[i]]=[a[i],a[s]]}return a}function ee({lesson:n,onComplete:a,onBack:s}){var P,D;const i=((P=n.content_json)==null?void 0:P.notes)??["C4","D4","E4","F4","G4"],x=((D=n.content_json)==null?void 0:D.type)==="timed",r=x?15:8,[l,g]=d.useState(0),[f,j]=d.useState(""),[u,b]=d.useState(null),[o,m]=d.useState(0),[c,t]=d.useState(0),[h,y]=d.useState(x?60:0),[w,C]=d.useState(!1),v=d.useCallback(()=>{const E=i[Math.floor(Math.random()*i.length)];j(E),b(null)},[i]);d.useEffect(()=>{v()},[]),d.useEffect(()=>{if(!x||w)return;const E=setInterval(()=>{y(L=>L<=1?(C(!0),0):L-1)},1e3);return()=>clearInterval(E)},[x,w]);const N=d.useCallback(E=>{if(u||w)return;const L=G(E),p=G(f),_=L===p;t(R=>R+1),_?(m(R=>R+1),b("correct"),O(f,.4)):b("wrong"),setTimeout(()=>{l+1>=r&&!x?C(!0):(g(R=>R+1),v())},800)},[u,w,f,l,r,x,v]),T=c>0?Math.round(o/c*100):0,B=o*10,S=d.useMemo(()=>{const E=[...new Set(i.map(L=>G(L)))];return De(E).slice(0,Math.min(E.length,7))},[i,l]);return w?e.jsxs(k.div,{className:"flex flex-col items-center justify-center gap-6 py-12",initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},children:[e.jsx("div",{className:"text-6xl",children:T>=80?"ð":T>=50?"ð":"ðª"}),e.jsx("h2",{className:"text-2xl font-bold text-white",children:T>=80?"Excellent!":T>=50?"Good job!":"Keep practicing!"}),e.jsxs("div",{className:"flex gap-8 text-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-3xl font-bold text-purple-400",children:o}),e.jsx("div",{className:"text-xs text-white/50",children:"Correct"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-3xl font-bold text-white",children:[T,"%"]}),e.jsx("div",{className:"text-xs text-white/50",children:"Accuracy"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-3xl font-bold text-amber-400",children:B}),e.jsx("div",{className:"text-xs text-white/50",children:"Score"})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(A,{variant:"outline",onClick:s,className:"border-white/20 text-white",children:"Back to Zone"}),e.jsxs(A,{onClick:()=>a(B,T),className:"bg-purple-600 hover:bg-purple-500 text-white",children:["Complete ",e.jsx(K,{className:"w-4 h-4 ml-1"})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between w-full max-w-lg",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:s,className:"text-white/60",children:"â Back"}),e.jsxs("div",{className:"flex items-center gap-4",children:[x&&e.jsxs("span",{className:M("text-sm font-mono font-bold",h<10?"text-red-400":"text-white/60"),children:[h,"s"]}),e.jsxs("span",{className:"text-sm text-white/60",children:[o,"/",x?"â":r]})]})]}),!x&&e.jsx("div",{className:"w-full max-w-lg h-1.5 bg-white/10 rounded-full overflow-hidden",children:e.jsx(k.div,{className:"h-full bg-purple-500 rounded-full",animate:{width:`${l/r*100}%`}})}),e.jsxs("div",{className:"bg-white/5 rounded-2xl p-4 border border-white/10",children:[e.jsx("h3",{className:"text-sm text-white/50 text-center mb-2",children:"Identify this note:"}),e.jsx(ie,{notes:[{note:f,duration:"quarter"}],clef:"treble",width:300,height:160}),e.jsxs("button",{onClick:()=>O(f,.5),className:"flex items-center gap-1 mx-auto mt-2 text-xs text-purple-400 hover:text-purple-300",children:[e.jsx(ae,{className:"w-3 h-3"})," Hear note"]})]}),e.jsx(F,{children:u&&e.jsxs(k.div,{initial:{opacity:0,y:-10}
1,animate:{opacity:1,y:0},exit:{opacity:0},className:M("flex items-center gap-2 px-4 py-2 rounded-full text-sm font-medium",u==="correct"?"bg-emerald-500/20 text-emerald-400":"bg-red-500/20 text-red-400"),children:[u==="correct"?e.jsx(W,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"}),u==="correct"?"Correct!":`That was ${G(f)}`]})}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center max-w-sm",children:S.map(E=>e.jsx("button",{onClick:()=>N(`${E}4`),className:M("w-12 h-12 rounded-xl border text-sm font-bold transition-all","border-white/20 bg-white/5 text-white hover:bg-white/10 active:scale-95"),children:E},E))})]})}const Q={whole:{symbol:"ð
",beats:4},half:{symbol:"ð
ð
¥",beats:2},quarter:{symbol:"â©",beats:1},eighth:{symbol:"âª",beats:.5},sixteenth:{symbol:"ð
ð
¥ð
¯",beats:.25}};function Oe(n,a){var x;const s=[];let i=0;for(;i<a;){const r=n[Math.floor(Math.random()*n.length)],l=((x=Q[r])==null?void 0:x.beats)??1;i+l<=a&&(s.push(r),i+=l)}return s}function $e({lesson:n,onComplete:a,onBack:s}){var D,E;const i=((D=n.content_json)==null?void 0:D.values)??["quarter","half"],x=((E=n.content_json)==null?void 0:E.bpm)??80,r=5,[l,g]=d.useState(0),[f,j]=d.useState([]),[u,b]=d.useState("listen"),[o,m]=d.useState([]),[c,t]=d.useState(0),[h,y]=d.useState([]),[w,C]=d.useState(-1),[v,N]=d.useState(!1),T=d.useRef(0),B=6e4/x;d.useEffect(()=>{j(Oe(i,4)),b("listen"),m([]),C(-1)},[l]),d.useEffect(()=>{if(u!=="listen"||f.length===0)return;let L=0;const p=[];return f.forEach((_,R)=>{var Y;const I=((Y=Q[_])==null?void 0:Y.beats)??1,X=L*B;p.push(window.setTimeout(()=>{Le(),C(R)},X)),L+=I}),p.push(window.setTimeout(()=>{b("tap"),C(-1),T.current=Date.now()},L*B+400)),()=>p.forEach(clearTimeout)},[u,f,B]);const S=d.useCallback(()=>{if(u!=="tap")return;const L=Date.now()-T.current;m(p=>{const _=[...p,L];if(_.length>=f.length){const R=[];let I=0;f.forEach($=>{var H;R.push(I*B),I+=((H=Q[$])==null?void 0:H.beats)??1});let X=0;_.forEach(($,H)=>{X+=Math.abs($-R[H])});const le=X/_.length<B*.4;y($=>[...$,le]),le&&t($=>$+20),b("result"),setTimeout(()=>{l+1>=r?N(!0):g($=>$+1)},1200)}return _})},[u,f,B,l,r]),P=h.length>0?Math.round(h.filter(Boolean).length/h.length*100):0;return v?e.jsxs(k.div,{className:"flex flex-col items-center gap-6 py-12",initial:{opacity:0}
1,animate:{opacity:1},children:[e.jsx("div",{className:"text-6xl",children:P>=80?"ð¥":"ðª"}),e.jsx("h2",{className:"text-2xl font-bold text-white",children:P>=80?"Great Rhythm!":"Keep Tapping!"}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-3xl font-bold text-orange-400",children:[P,"%"]}),e.jsx("div",{className:"text-xs text-white/50",children:"Accuracy"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-3xl font-bold text-amber-400",children:c}),e.jsx("div",{className:"text-xs text-white/50",children:"Score"})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(A,{variant:"outline",onClick:s,className:"border-white/20 text-white",children:"Back"}),e.jsxs(A,{onClick:()=>a(c,P),className:"bg-orange-600 hover:bg-orange-500 text-white",children:["Complete ",e.jsx(K,{className:"w-4 h-4 ml-1"})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between w-full max-w-lg",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:s,className:"text-white/60",children:"â Back"}),e.jsxs("span",{className:"text-sm text-white/60",children:["Round ",l+1,"/",r]})]}),e.jsx("div",{className:"w-full max-w-lg h-1.5 bg-white/10 rounded-full overflow-hidden",children:e.jsx(k.div,{className:"h-full bg-orange-500 rounded-full",animate:{width:`${l/r*100}%`}})}),e.jsxs("div",{className:"bg-white/5 rounded-2xl p-6 border border-white/10",children:[e.jsx("h3",{className:"text-sm text-white/50 text-center mb-4",children:u==="listen"?"Listen to the pattern...":u==="tap"?"Tap the rhythm!":"Result"}),e.jsx("div",{className:"flex gap-4 justify-center items-end",children:f.map((L,p)=>{var _;return e.jsxs(k.div,{className:M("flex flex-col items-center gap-1 p-3 rounded-xl",w===p?"bg-orange-500/30":"bg-white/5",p<o.length&&"opacity-50"),animate:w===p?{scale:1.1}:{scale:1},children:[e.jsx("span",{className:"text-3xl",children:((_=Q[L])==null?void 0:_.symbol)??"â©"}),e.jsx("span",{className:"text-[10px] text-white/40 capitalize",children:L})]},p)})})]}),u==="tap"&&e.jsx(k.button,{className:"w-32 h-32 rounded-full bg-orange-600 hover:bg-orange-500 text-white font-bold text-lg active:scale-90 transition-transform shadow-lg shadow-orange-600/30",onClick:S,whileTap:{scale:.85},children:"TAP"}),u==="result"&&e.jsxs(k.div,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},className:M("flex items-center gap-2 px-4 py-2 rounded-full text-sm font-medium",h[h.length-1]?"bg-emerald-500/20 text-emerald-400":"bg-red-500/20 text-red-400"),children:[h[h.length-1]?e.jsx(W,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"}),h[h.length-1]?"Great timing!":"Try to match the rhythm"]})]})}function Ie({lesson:n,onComplete:a,onBack:s}){var w,C;const i=((w=n.content_json)==null?void 0:w.intervals)??["m2","M2","m3","M3"],x=8,r=["C4","D4","E4","F4","G4"],[l,g]=d.useState(0),[f,j]=d.useState(0),[u,b]=d.useState(null),[o,m]=d.useState(!1),c=d.useMemo(()=>{const v=r[Math.floor(Math.random()*r.length)],N=i[Math.floor(Math.random()*i.length)],T=z[N],B=be(v,T.semitones);return{base:v,second:B,answer:N}},[l,i]),t=d.useCallback(()=>{O(c.base,.4),setTimeout(()=>O(c.second,.4),500)},[c]),h=d.useCallback(v=>{if(u)return;const N=v===c.answer;N&&j(T=>T+1),b(N?"correct":"wrong"),t(),setTimeout(()=>{b(null),l+1>=x?m(!0):g(T=>T+1)},1e3)},[u,c,l,x,t]),y=o?Math.round(f/x*100):0;return o?e.jsxs(k.div,{className:"flex flex-col items-center gap-6 py-12",initial:{opacity:0}
1,animate:{opacity:1},children:[e.jsx("div",{className:"text-6xl",children:"ð"}),e.jsx("h2",{className:"text-2xl font-bold text-white",children:y>=80?"Interval Pro!":"Keep at it!"}),e.jsxs("div",{className:"text-3xl font-bold text-blue-400",children:[y,"%"]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(A,{variant:"outline",onClick:s,className:"border-white/20 text-white",children:"Back"}),e.jsxs(A,{onClick:()=>a(f*12,y),className:"bg-blue-600 hover:bg-blue-500 text-white",children:["Complete ",e.jsx(K,{className:"w-4 h-4 ml-1"})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between w-full max-w-lg",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:s,className:"text-white/60",children:"â Back"}),e.jsxs("span",{className:"text-sm text-white/60",children:[l+1,"/",x]})]}),e.jsx("div",{className:"w-full max-w-lg h-1.5 bg-white/10 rounded-full overflow-hidden",children:e.jsx(k.div,{className:"h-full bg-blue-500 rounded-full",animate:{width:`${l/x*100}%`}})}),e.jsxs("div",{className:"bg-white/5 rounded-2xl p-4 border border-white/10",children:[e.jsx("h3",{className:"text-sm text-white/50 text-center mb-2",children:"What interval is this?"}),e.jsx(ie,{notes:[{note:c.base,duration:"half"},{note:c.second,duration:"half"}],clef:"treble",width:280,height:150}),e.jsx("button",{onClick:t,className:"flex items-center gap-1 mx-auto mt-2 text-xs text-blue-400 hover:text-blue-300",children:"ð Play"})]}),e.jsx(F,{children:u&&e.jsx(k.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:M("px-4 py-2 rounded-full text-sm",u==="correct"?"bg-emerald-500/20 text-emerald-400":"bg-red-500/20 text-red-400"),children:u==="correct"?"â Correct!":`â It was ${(C=z[c.answer])==null?void 0:C.name}`})}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center max-w-md",children:i.map(v=>{var N;return e.jsx("button",{onClick:()=>h(v),className:"px-4 py-3 rounded-xl border border-white/20 bg-white/5 text-white text-sm font-medium hover:bg-white/10 active:scale-95 transition-all",children:((N=z[v])==null?void 0:N.name)??v},v)})})]})}function qe({lesson:n,onComplete:a,onBack:s}){var v,N,T,B;const i=n.lesson_type==="ear"&&((v=n.content_json)==null?void 0:v.intervals),x=((N=n.content_json)==null?void 0:N.notes)??["C4","D4","E4","F4","G4"],r=((T=n.content_json)==null?void 0:T.intervals)??["M2","M3","P4","P5"],l=8,[g,f]=d.useState(0),[j,u]=d.useState(0),[b,o]=d.useState(null),[m,c]=d.useState(!1),t=d.useMemo(()=>{if(i){const S=x.length>0?x[Math.floor(Math.random()*x.length)]:"C4",P=r[Math.floor(Math.random()*r.length)],D=z[P],E=be(S,D.semitones);return{type:"interval",base:S,second:E,answer:P,label:D.name}}else{const S=x[Math.floor(Math.random()*x.length)];return{type:"note",note:S,answer:G(S)}}},[g,i,x,r]),h=d.useCallback(()=>{t.type==="interval"?(O(t.base,.5),setTimeout(()=>O(t.second,.5),600)):O(t.note,.6)},[t]),y=d.useCallback(S=>{if(b)return;const P=S===t.answer;P&&u(D=>D+1),o(P?"correct":"wrong"),setTimeout(()=>{o(null),g+1>=l?c(!0):f(D=>D+1)},1e3)},[b,t,g,l]),w=m?Math.round(j/l*100):0;if(m)return e.jsxs(k.div,{className:"flex flex-col items-center gap-6 py-12",initial:{opacity:0}
1,animate:{opacity:1},children:[e.jsx("div",{className:"text-6xl",children:w>=80?"ð":"ðª"}),e.jsx("h2",{className:"text-2xl font-bold text-white",children:w>=80?"Sharp Ears!":"Keep Listening!"}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-3xl font-bold text-teal-400",children:[j,"/",l]}),e.jsx("div",{className:"text-xs text-white/50",children:"Correct"})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-3xl font-bold text-white",children:[w,"%"]}),e.jsx("div",{className:"text-xs text-white/50",children:"Accuracy"})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(A,{variant:"outline",onClick:s,className:"border-white/20 text-white",children:"Back"}),e.jsxs(A,{onClick:()=>a(j*10,w),className:"bg-teal-600 hover:bg-teal-500 text-white",children:["Complete ",e.jsx(K,{className:"w-4 h-4 ml-1"})]})]})]});const C=i?r.map(S=>{var P;return{key:S,label:((P=z[S])==null?void 0:P.name)??S}}):[...new Set(x.map(G))].map(S=>({key:S,label:S}));return e.jsxs("div",{className:"flex flex-col items-center gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between w-full max-w-lg",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:s,className:"text-white/60",children:"â Back"}),e.jsxs("span",{className:"text-sm text-white/60",children:[g+1,"/",l]})]}),e.jsx("div",{className:"w-full max-w-lg h-1.5 bg-white/10 rounded-full overflow-hidden",children:e.jsx(k.div,{className:"h-full bg-teal-500 rounded-full",animate:{width:`${g/l*100}%`}})}),e.jsxs("div",{className:"bg-white/5 rounded-2xl p-8 border border-white/10 text-center",children:[e.jsx("h3",{className:"text-white/50 text-sm mb-4",children:i?"What interval do you hear?":"What note do you hear?"}),e.jsx(k.button,{onClick:h,className:"w-20 h-20 rounded-full bg-teal-600 hover:bg-teal-500 flex items-center justify-center mx-auto text-white shadow-lg shadow-teal-600/30",whileTap:{scale:.9},children:e.jsx(ae,{className:"w-8 h-8"})}),e.jsx("p",{className:"text-xs text-white/30 mt-2",children:"Tap to listen"})]}),e.jsx(F,{children:b&&e.jsxs(k.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0},className:M("flex items-center gap-2 px-4 py-2 rounded-full text-sm font-medium",b==="correct"?"bg-emerald-500/20 text-emerald-400":"bg-red-500/20 text-red-400"),children:[b==="correct"?e.jsx(W,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"}),b==="correct"?"Correct!":`It was ${i?(B=z[t.answer])==null?void 0:B.name:t.answer}`]})}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center max-w-md",children:C.map(S=>e.jsx("button",{onClick:()=>y(S.key),className:"px-4 py-3 rounded-xl border border-white/20 bg-white/5 text-white text-sm font-medium hover:bg-white/10 active:scale-95 transition-all",children:S.label},S.key))})]})}const Fe={C:["C4","E4","G4"],F:["F4","A4","C5"],G:["G4","B4","D5"],Am:["A4","C5","E5"],Dm:["D4","F4","A4"],Em:["E4","G4","B4"]};function Ge({lesson:n,onComplete:a,onBack:s}){var y;const i=((y=n.content_json)==null?void 0:y.chords)??["C","F","G"],x=6,[r,l]=d.useState(0),[g,f]=d.useState(0),[j,u]=d.useState(null),[b,o]=d.useState(!1),m=d.useMemo(()=>i[Math.floor(Math.random()*i.length)],[r,i]),c=d.useCallback(()=>{const w=Fe[m];w&&Pe(w,1)},[m]),t=d.useCallback(w=>{if(j)return;const C=w===m;C&&f(v=>v+1),u(C?"correct":"wrong"),setTimeout(()=>{u(null),r+1>=x?o(!0):l(v=>v+1)},1e3)},[j,m,r,x]),h=b?Math.round(g/x*100):0;return b?e.jsxs(k.div,{className:"flex flex-col items-center gap-6 py-12",initial:{opacity:0}
1,animate:{opacity:1},children:[e.jsx("div",{className:"text-6xl",children:"ð¹"}),e.jsx("h2",{className:"text-2xl font-bold text-white",children:h>=80?"Chord Master!":"Keep Building!"}),e.jsx("div",{className:"flex gap-8",children:e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-3xl font-bold text-fuchsia-400",children:[g,"/",x]}),e.jsx("div",{className:"text-xs text-white/50",children:"Correct"})]})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(A,{variant:"outline",onClick:s,className:"border-white/20 text-white",children:"Back"}),e.jsxs(A,{onClick:()=>a(g*15,h),className:"bg-fuchsia-600 hover:bg-fuchsia-500 text-white",children:["Complete ",e.jsx(K,{className:"w-4 h-4 ml-1"})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between w-full max-w-lg",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:s,className:"text-white/60",children:"â Back"}),e.jsxs("span",{className:"text-sm text-white/60",children:[r+1,"/",x]})]}),e.jsxs("div",{className:"bg-white/5 rounded-2xl p-8 border border-white/10 text-center",children:[e.jsx("h3",{className:"text-white/50 text-sm mb-4",children:"Listen and identify the chord"}),e.jsx(k.button,{onClick:c,className:"w-20 h-20 rounded-full bg-fuchsia-600 hover:bg-fuchsia-500 flex items-center justify-center mx-auto text-white shadow-lg shadow-fuchsia-600/30",whileTap:{scale:.9},children:e.jsx(ae,{className:"w-8 h-8"})})]}),e.jsx(F,{children:j&&e.jsx(k.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:M("px-4 py-2 rounded-full text-sm font-medium",j==="correct"?"bg-emerald-500/20 text-emerald-400":"bg-red-500/20 text-red-400"),children:j==="correct"?"â Correct!":`â It was ${m}`})}),e.jsx("div",{className:"flex flex-wrap gap-3 justify-center",children:i.map(w=>e.jsx("button",{onClick:()=>t(w),className:"px-6 py-4 rounded-xl border border-white/20 bg-white/5 text-white font-bold text-lg hover:bg-white/10 active:scale-95 transition-all",children:w},w))})]})}const ze=["C","D","E","F","G","A","B"],We={"C#":.65,"D#":1.75,"F#":3.6,"G#":4.7,"A#":5.8};function Ke({startOctave:n=4,octaves:a=2,highlightedNotes:s=[],onKeyPress:i,compact:x=!1}){const r=x?28:36,l=x?100:140,g=x?18:22,f=x?60:85,j=[];let u=0;for(let c=n;c<n+a;c++){for(const t of ze)j.push({note:`${t}${c}`,isBlack:!1,x:u*r}),u++;for(const[t,h]of Object.entries(We)){const y=(c-n)*7;j.push({note:`${t}${c}`,isBlack:!0,x:(y+h)*r-g/2})}}const b=j.filter(c=>!c.isBlack),o=j.filter(c=>c.isBlack),m=u*r;return e.jsx("div",{className:"relative overflow-x-auto pb-2",children:e.jsxs("svg",{width:m,height:l+10,viewBox:`0 0 ${m} ${l+10}`,children:[b.map(c=>{const t=s.includes(c.note);return e.jsx("rect",{x:c.x,y:0,width:r-1,height:l,rx:3,fill:t?"hsl(var(--primary))":"hsl(var(--background))",stroke:"hsl(var(--border))",strokeWidth:1,className:"cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>i==null?void 0:i(c.note)},c.note)}),o.map(c=>{const t=s.includes(c.note);return e.jsx("rect",{x:c.x,y:0,width:g,height:f,rx:2,fill:t?"hsl(var(--primary))":"hsl(var(--foreground))",className:"cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>i==null?void 0:i(c.note)},c.note)}),b.map(c=>e.jsx("text",{x:c.x+r/2-.5,y:l-8,textAnchor:"middle",fontSize:9,fill:"hsl(var(--muted-foreground))",className:"pointer-events-none",children:c.note.replace(/\d/,"")},`label-${c.note}`))]})})}function Ze({onBack:n,onSave:a}){const[s,i]=d.useState([]),[x,r]=d.useState("quarter"),[l,g]=d.useState(!1),[f,j]=d.useState(-1),u=d.useCallback(t=>{O(t,.3),i(h=>[...h,{note:t,duration:x}])},[x]),b=d.useCallback(t=>{i(h=>h.filter((y,w)=>w!==t))},[]),o=d.useCallback(async()=>{if(s.length===0)return;g(!0);const t={whole:1600,half:800,quarter:400,eighth:200};for(let h=0;h<s.length;h++){j(h);const y=s[h];O(y.note,t[y.duration]/1e3),await new Promise(w=>setTimeout(w,t[y.duration]))}j(-1),g(!1)},[s]),m=["whole","half","quarter","eighth"],c={whole:"ð
",half:"ð
ð
¥",quarter:"â©",eighth:"âª"};return e.jsxs("div",{className:"flex flex-col gap-4 max-w-2xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:n,className:"text-white/60",children:"â Back"}),e.jsx("h2",{className:"text-lg font-bold text-white",children:"Composition Studio"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{size:"sm",variant:"outline",onClick:()=>i([]),className:"border-white/20 text-white",children:e.jsx(ge,{className:"w-3 h-3"})}),a&&e.jsxs(A,{size:"sm",onClick:()=>a(s),className:"bg-amber-600 hover:bg-amber-500 text-white",children:[e.jsx(je,{className:"w-3 h-3 mr-1"})," Save"]})]})]}),e.jsx("div",{className:"bg-white/5 rounded-2xl p-4 border border-white/10 overflow-x-auto",children:s.length>0?e.jsx(ie,{notes:s.map((t,h)=>({note:t.note,duration:t.duration,highlighted:h===f})),clef:"treble",width:Math.max(600,s.length*50+100),height:160,showNoteNames:!0,interactive:!0,onNoteClick:()=>{}}):e.jsx("div",{className:"h-40 flex items-center justify-center text-white/30 text-sm",children:"Tap the keyboard below to add notes"})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex gap-2",children:m.map(t=>e.jsx("button",{onClick:()=>r(t),className:M("w-10 h-10 rounded-lg border text-xl flex items-center justify-center transition-all",x===t?"border-amber-400 bg-amber-500/20 text-amber-400":"border-white/20 bg-white/5 text-white/60 hover:bg-white/10"),children:c[t]},t))}),e.jsxs(A,{onClick:l?()=>g(!1):o,className:"bg-amber-600 hover:bg-amber-500 text-white",disabled:s.length===0,children:[l?e.jsx(Ce,{className:"w-4 h-4 mr-1"}):e.jsx(me,{className:"w-4 h-4 mr-1"}),l?"Stop":"Play"]})]}),e.jsx(Ke,{startOctave:4,octaves:2,onKeyPress:u,compact:!0}),s.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:s.map((t,h)=>e.jsxs(k.button,{className:M("px-2 py-1 rounded text-xs border transition-all",h===f?"border-amber-400 bg-amber-500/20 text-amber-400":"border-white/10 bg-white/5 text-white/60 hover:bg-red-500/20 hover:border-red-500/30 hover:text-red-400"),onClick:()=>b(h),title:"Click to remove",children:[t.note," ",c[t.duration]]},h))})]})}function Ue(){const n=ye();xe();const{profile:a,profileLoading:s,lessons:i,progress:x,createProfile:r,completeLesson:l,zoneLessons:g,lessonProgress:f,isZoneUnlocked:j}=_e(),[u,b]=d.useState("planet"),[o,m]=d.useState("staff_tower"),[c,t]=d.useState(null),[h,y]=d.use
1State(!1),[w,C]=d.useState(!1);d.useEffect(()=>{const p=_=>{var R;_.shiftKey&&_.key==="E"&&!["INPUT","TEXTAREA"].includes((R=_.target)==null?void 0:R.tagName)&&y(I=>!I)};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[]);const v=d.useCallback(p=>{r.mutate(p)},[r]),N=d.useCallback(p=>{m(p),b(p==="composition_studio"?"composition":"zone")},[]),T=d.useCallback(p=>{t(p),b("lesson")},[]),B=d.useCallback((p,_)=>{c&&!h&&l.mutate({lessonId:c.id,score:p,accuracy:_}),b("zone"),t(null)},[c,l,h]),S=d.useCallback(()=>{b("zone"),t(null)},[]),P=d.useCallback(()=>{b("planet"),m("staff_tower"),t(null)},[]),D=d.useMemo(()=>{const p={};for(const _ of i){p[_.zone]||(p[_.zone]=0);const R=x.find(I=>I.lesson_id===_.id);(R==null?void 0:R.status)==="completed"&&p[_.zone]++}return p},[i,x]),E=d.useMemo(()=>{const p={};for(const _ of i)p[_.zone]=(p[_.zone]??0)+1;return p},[i]);if(s)return e.jsx("div",{className:"fixed inset-0 flex items-center justify-center",style:{background:"linear-gradient(135deg, hsl(260 30% 10%), hsl(240 20% 15%))"},children:e.jsx(ve,{className:"w-8 h-8 animate-spin text-purple-400"})});if(!(a!=null&&a.onboarded))return e.jsx(Se,{onComplete:v});const L=()=>
1{if(!c)return null;const p={lesson:c,onComplete:B,onBack:S};switch(c.lesson_type){case"note_reading":return e.jsx(ee,{...p});case"rhythm":return e.jsx($e,{...p});case"interval":return e.jsx(Ie,{...p});case"ear":return e.jsx(qe,{...p});case"chord":return e.jsx(Ge,{...p});case"sight_reading":return e.jsx(ee,{...p});default:return e.jsx(ee,{...p})}};return e.jsxs("div",{className:"fixed inset-0 flex flex-col overflow-hidden",style:{background:"linear-gradient(135deg, hsl(260 30% 10%), hsl(240 20% 15%))"},children:[e.jsxs("header",{className:"flex items-center justify-between px-4 py-3 border-b border-white/5 shrink-0",children:[e.jsx("button",{onClick:()=>n("/universe"),className:"text-white/50 hover:text-white/70 text-sm",children:"â Universe"}),e.jsx("h1",{className:"text-lg font-bold text-white flex items-center gap-2",children:"ðµ Music Academy"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>y(p=>!p),className:M("flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium transition-all border",h?"bg-cyan-500/15 border-cyan-500/30 text-cyan-400":"bg-white/5 border-white/10 text-white/40 hover:text-white/60 hover:bg-white/8"),title:"Toggle Explorer Mode (Shift+E)",children:[e.jsx(te,{className:"w-3.5 h-3.5"}),e.jsxs("span",{className:"hidden sm:inline",children:["Explorer ",h?"ON":"OFF"]})]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-400",children:[e.jsx(se,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"font-bold",children:a.total_xp}),e.jsx("span",{className:"text-white/30",children:"XP"})]}),a.current_streak>0&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-orange-400",children:[e.jsx(oe,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"font-bold",children:a.current_streak})]})]})]}),e.jsx(F,{children:h&&e.jsx(k.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-2 bg-cyan-500/10 border-b border-cyan-500/20",children:[e.jsx(te,{className:"w-4 h-4 text-cyan-400"}),e.jsx("span",{className:"text-xs text-cyan-300",children:"Explorer Mode â All lessons unlocked. XP and progress are not saved."}),e.jsxs("button",{onClick:()=>C(p=>!p),className:M("ml-3 flex items-center gap-1 px-2 py-0.5 rounded text-[10px] border transition-all",w?"border-amber-500/30 bg-amber-500/10 text-amber-400":"border-white/10 bg-white/5 text-white/30 hover:text-white/50"),title:"Developer: Unlock all lessons permanently for this session",children:[e.jsx(Ne,{className:"w-3 h-3"}),"Unlock All"]})]})})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsxs(F,{mode:"wait",children:[u==="planet"&&e.jsxs(k.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},children:[e.jsxs("div",{className:"flex items-center justify-center gap-6 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-white/5 border border-white/10",children:[e.jsx(se,{className:"w-4 h-4 text-amber-400"}),e.jsxs("span",{className:"text-sm text-white font-bold",children:[a.total_xp," XP"]})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-white/5 border border-white/10",children:[e.jsx(oe,{className:"w-4 h-4 text-orange-400"}),e.jsxs("span",{className:"text-sm text-white",children:[a.current_streak," day streak"]})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-white/5 border border-white/10",children:[e.jsx(ke,{className:"w-4 h-4 text-blue-400"}),e.jsxs("span",{className:"text-sm text-white",children:[x.filter(p=>p.status==="completed").length," lessons"]})]})]}),e.jsx("h2",{className:"text-center text-white/50 text-sm mb-4",children:"Select a zone to begin"}),e.jsx(Te,{unlockedZones:h||w?Object.keys(E):a.zones_unlocked??["staff_tower"],currentZone:a.current_zone,completedLessons:D,totalLessons:E,onSelectZone:N})]},"planet"),u==="zone"&&e.jsx(k.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},children:e.jsx(Me,{zone:o,lessons:g(o),progress:x,explorerMode:h||w,onSelectLesson:T,onBack:P})},"zone"),u==="lesson"&&e.jsx(k.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},children:L()},"lesson"),u==="composition"&&e.jsx(k.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},children:e.jsx(Ze,{onBack:P})},"composition")]})})]})}export{Ue 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.