const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DoqVxf1H.js","assets/index-dbebx5u2.js","assets/index-CgA3Z5Y5.css"])))=>i.map(i=>d[i]);
import{a as n,j as e,_ as A}from"./index-dbebx5u2.js";let u=null;const E=async()=>{if(typeof window>"u")throw new Error("abcjs requires a browser environment");if(u)return u;try{const t=await A(()=>import("./index-DoqVxf1H.js").then(a=>a.i),__vite__mapDeps([0,1,2])),r=t.default||t;if(!r)throw new Error("abcjs module is empty");if(typeof r.renderAbc!="function")throw new Error(`renderAbc is not a function. Available methods: ${Object.keys(r).join(", ")}`);return u=r,u}catch(t){const r=window;if(typeof window<"u"&&r.ABCJS)return u=r.ABCJS,u;const a=t instanceof Error?t.message:"Failed to load abcjs";throw new Error(`Failed to load abcjs: ${a}`)}},R=t=>{const r=t.trim();return/^[XMTLK]:/m.test(r)||/^X:\d+/m.test(r)},S=t=>{const r=t.trim();if(!r.includes("X:")||!/^K:/m.test(r))return!0;const i=r.split(`
`),s=i[i.length-1].trim();return!!(s.match(/^[A-Z]:?\s*$/)&&s.length<3||s.endsWith("|")&&!s.endsWith("|]")&&!s.endsWith("||")&&s.replace(/\|/g,"").trim().length<2)},T=({code:t})=>{const r=n.useRef(null),[a,i]=n.useState(null),[s,c]=n.useState(!0),[l,f]=n.useState(!1),[p,j]=n.useState(!1),[x,k]=n.useState(!1),b=n.useRef(""),w=n.useRef(0),m=n.useRef(null);return n.useEffect(()=>{const g=t.trim();if(!g)return;const o=Date.now(),d=o-w.current,y=t!==b.current;b.current=t,w.current=o;const h=S(g),C=y&&d<500&&d>0,v=h||C;if(h){setTimeout(()=>{f(!0),c(!0),i(null)},0);return}R(t)?setTimeout(()=>{j(!0),i(null),v&&f(!0)},0):setTimeout(()=>{j(!1),v?(f(!0),i(null)):(i("Unable to detect ABC notation. Expected ABC notation starting with headers like X:, T:, M:, L:, or K:"),c(!1),f(!1))},0)},[t]),n.useEffect(()=>!p||!t.trim()?void 0:(l&&(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{f(!1)},400)),(async()=>{try{c(!0);let o=0;const d=10;for(;!r.current&&o<d;)await new Promise(h=>setTimeout(h,50)),o++;if(!r.current)throw new Error("Container element not found after waiting");const y=await E();r.current.innerHTML="",y.renderAbc(r.current,t,{responsive:"resize",staffwidth:740,paddingleft:0,paddingright:0,paddingtop:15,paddingbottom:15,scale:1}),i(null),c(!1)}catch(o){const d=o instanceof Error?o.message:"Failed to render ABC notation";i(d),c(!1)}})(),()=>{m.current&&clearTimeout(m.current)}),[t,p,l]),t.trim()?a?e.jsxs("div",{className:"graph-error",children:[e.jsxs("div",{className:"graph-error-header",children:[e.jsx("div",{className:"graph-error-icon",children:"⚠️"}),e.jsxs("div",{className:"graph-error-content",children:[e.jsx("div",{className:"graph-error-title",children:"ABC Notation Rendering Error"}),e.jsx("div",{className:"graph-error-message",children:a})]})]}),e.jsxs("button",{className:"graph-error-toggle",onClick:()=>k(!x),type:"button",children:[x?"Hide":"Show"," Details"]}),x&&e.jsxs("details",{className:"graph-error-details",open:!0,children:[e.jsx("summary",{style:{cursor:"pointer",marginBottom:"8px",fontWeight:500},children:"ABC Notation Code"}),e.jsx("pre",{style:{marginTop:"8px",fontSize:"0.8em",opacity:.8,padding:"8px",background:"rgba(0, 0, 0, 0.05)",borderRadius:"4px",overflow:"auto",maxHeight:"200px"},children:e.jsx("code",{children:t})})]})]}):(s||l)&&!p?e.jsx("div",{className:"graph-container music-container abc-container",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"30px 20px",color:"var(--md-text-secondary, #6b7280)",minHeight:"120px"},children:[e.jsx("svg",{style:{animation:"spin 1s linear infinite",marginBottom:"10px",width:"28px",height:"28px"},viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"32",strokeLinecap:"round"})}),e.jsx("span",{style:{fontWeight:500,fontSize:"14px"},children:l?"Receiving music notation...":"Loading music notation..."}),e.jsx("style",{children:`
            @keyframes spin {
              from { transform: rotate(0deg); }
              to { transform: rotate(360deg); }
            }
          `})]})}):p?e.jsxs("div",{className:"graph-container music-container abc-container",style:{padding:"16px",position:"relative"},children:[l&&e.jsxs("div",{style:{position:"absolute",top:"8px",right:"8px",display:"flex",alignItems:"center",padding:"4px 8px",backgroundColor:"rgba(59, 130, 246, 0.1)",borderRadius:"4px",fontSize:"12px",color:"#3b82f6",zIndex:10},children:[e.jsx("svg",{style:{animation:"spin 1s linear infinite",marginRight:"4px",width:"12px",height:"12px"},viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"32",strokeLinecap:"round"})}),"Updating...",e.jsx("style",{children:`
              @keyframes spin {
                from { transform: rotate(0deg); }
                to { transform: rotate(360deg); }
              }
            `})]}),s&&!l&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"20px",color:"var(--md-text-secondary, #6b7280)",minHeight:"80px"},children:[e.jsx("svg",{style:{animation:"spin 1s linear infinite",marginBottom:"8px",width:"24px",height:"24px"},viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"32",strokeLinecap:"round"})}),e.jsx("span",{style:{fontSize:"13px"},children:"Rendering notation..."}),e.jsx("style",{children:`
              @keyframes spin {
                from { transform: rotate(0deg); }
                to { transform: rotate(360deg); }
              }
            `})]}),e.jsx("div",{ref:r,style:{display:"flex",justifyContent:"center",overflow:"auto"}})]}):null:null};export{T as MusicRenderer};
