import{u as E,r as a,c as S,g as b,j as e,a as R,s as C}from"./index-yD-5hMZV.js";function O(){const{settings:u}=E(),[t,g]=a.useState(null),[y,h]=a.useState(!0),[o,l]=a.useState(null),[f,N]=a.useState(!1),[m,d]=a.useState(""),[r,x]=a.useState(!1),i=a.useRef(null);a.useEffect(()=>{if(!u.backstageCoordination){h(!1);return}(async()=>{try{h(!0),l(null);const n=await b();n?(g(n),d((n.onStage||0).toString())):(g(null),d("0"))}catch(n){console.error("Error loading entrant readiness:",n),l("Failed to load entrant readiness data")}finally{h(!1)}})();try{const n=S.entrantReadiness.subscribe("*",p=>{console.log("Entrant readiness updated:",p),(p.action==="update"||p.action==="create")&&b().then(c=>{g(c),d(c?(c.onStage||0).toString():"0")}).catch(c=>{console.error("Error refreshing entrant readiness:",c)})});i.current=n}catch(n){console.error("Error setting up entrant readiness subscription:",n),i.current=null}return()=>{i.current&&typeof i.current=="function"&&i.current()}},[u.backstageCoordination]);const j=async()=>{if(!(!t||r))try{x(!0),await R(t.id,!t.entrant_ready)}catch(s){console.error("Error toggling entrant ready:",s),l("Failed to update entrant ready status")}finally{x(!1)}},w=async()=>{if(!t||r)return;const s=parseInt(m);if(isNaN(s)||s<0){l("Please enter a valid number");return}try{x(!0),l(null),await C(t.id,s)}catch(n){console.error("Error updating on stage:",n),l("Failed to update on stage number")}finally{x(!1)}};if(!u.backstageCoordination)return e.jsx("div",{className:"text-center p-6 flex flex-col items-center justify-center h-screen bg-gray-900 text-white text-4xl",children:"Backstage coordination is not enabled"});if(y)return e.jsx("div",{className:"p-4 flex flex-col items-center justify-center h-screen bg-gray-900 text-center",children:e.jsx("div",{className:"text-white text-2xl",children:"Loading entrant readiness..."})});if(o&&!t)return e.jsx("div",{className:"p-4 flex flex-col items-center justify-center h-screen bg-gray-900 text-center",children:e.jsxs("div",{className:"text-red-400 text-2xl",children:["Error: ",o]})});if(!t)return e.jsx("div",{className:"p-4 flex flex-col items-center justify-center h-screen text-center bg-gray-900 mx-auto",children:e.jsx("h1",{className:"text-3xl font-bold text-white mb-4",children:"No current group"})});const v=t.entrant_name?`${t.entrant_name}`:"Unknown Group";return e.jsx("div",{className:"p-4 flex flex-col items-center justify-center h-screen text-center bg-gray-900",children:e.jsxs("div",{className:"text-center max-w-2xl w-full",children:[e.jsxs("h1",{className:"text-4xl font-bold text-white mb-8",children:[e.jsx("span",{className:"text-gray-400 text-2xl",children:"Next Group:"}),e.jsx("br",{}),v]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-2xl text-white mb-3",children:"Panel Ready:"}),e.jsx("div",{className:`px-8 py-4 rounded-lg text-2xl font-bold w-full max-w-sm ${t.panel_ready?"bg-green-600 text-white":"bg-red-600 text-white"}`,children:t.panel_ready?"READY":"NOT READY"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-2xl text-white mb-3",children:"Group Ready:"}),e.jsx("button",{onClick:j,disabled:r,className:`px-8 py-4 rounded-lg text-2xl font-bold w-full max-w-sm transition-colors duration-200 ${t.entrant_ready?"bg-green-600 text-white hover:bg-green-700":"bg-red-600 text-white hover:bg-red-700"} ${r?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:r?"UPDATING...":t.entrant_ready?"READY":"NOT READY"})]})]}),e.jsxs("div",{className:"mt-8",children:[e.jsxs("button",{onClick:()=>N(!f),className:"text-white text-lg underline hover:text-gray-300 transition-colors",children:[f?"Hide":"Show"," Stage Controls"]}),f&&e.jsx("div",{className:"mt-4 p-4 bg-gray-800 rounded-lg",children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("label",{className:"text-white text-xl",children:"On Stage Number:"}),e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("input",{type:"number",value:m,onChange:s=>d(s.target.value),className:"px-4 py-2 text-xl text-center bg-gray-700 text-white rounded border border-gray-600 focus:border-blue-500 focus:outline-none w-24",min:"0",disabled:r}),e.jsx("button",{onClick:w,disabled:r||m===(t.onStage||0).toString(),className:"px-6 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:r?"Updating...":"Update"})]}),o&&e.jsx("div",{className:"text-red-400 text-sm",children:o})]})})]})]})})}export{O as default};
