import{p as L,b as y,l as c,z as b,o as C,A as h,B as m,C as g,T as I,D as k,s as x,u as l,q as R,E as H,F as n,G as V,H as p,I as A,J as B,v as P,x as D,y as M}from"./style-C-kEPrZO.js";import{w as U,h as d,S as N}from"./response-f_1ttBSN.js";import{c as W}from"./chartRoutes-BpysR4jZ.js";function q(s){var o;const t={};for(let r of((o=s.meta)==null?void 0:o.params)??[]){const a=s.query[r.prop];if(a!==void 0&&typeof a=="string")switch(r.type){case"boolean":t[r.prop]=a==="true"||a==="1";break;case"int":t[r.prop]=parseInt(a);break;case"float":t[r.prop]=parseFloat(a);break;default:t[r.prop]=a;break}}return t}const E={class:"w-full h-full"},F={key:0,class:"fixed w-full h-full left-0 top-0 error-cover"},T={class:"flex flex-col items-center justify-center h-full"},j={class:"text-xl font-semibold text-white"},z=L({__name:"ViewerApp",setup(s){const t=y({strength:0,randomStrength:0,strengthLimit:50,tempStrength:0,realStrength:0,clientId:"",gameStarted:!1,error:null});let o,r;const a=k(),u=c(()=>q(a)),i=c(()=>({valLow:Math.min(t.strength+t.tempStrength,t.strengthLimit),valHigh:Math.min(t.strength+t.tempStrength+t.randomStrength,t.strengthLimit),valLimit:t.strengthLimit})),f=async()=>{try{let e=await U.getServerInfo();d(e),o=e}catch(e){console.error("Cannot get server info:",e),t.error="无法获取服务器信息"}},S=async()=>{r=new N(o.server.wsUrl),r.on("open",()=>{console.log("WebSocket connected or re-connected"),t.clientId&&v()}),r.on("strengthChanged",e=>{t.strengthLimit=e.limit,t.tempStrength=e.tempStrength,t.realStrength=e.strength}),r.on("strengthConfigUpdated",e=>{t.strength=e.strength,t.randomStrength=e.randomStrength,t.strength=Math.min(t.strength,t.strengthLimit)}),r.on("gameStarted",()=>{t.gameStarted=!0}),r.on("gameStopped",()=>{t.gameStarted=!1}),r.connect()},v=async()=>{try{let e=await r.bindClient(t.clientId);d(e)}catch(e){console.error("Cannot bind client:",e),t.error="绑定客户端失败"+e.message}};return b(()=>{r.close()}),C(async()=>{const e=new URLSearchParams(window.location.search);if(!e.has("clientId")){t.error="缺少 clientId 参数";return}t.clientId=e.get("clientId"),await f(),await S()}),(e,J)=>{const w=x("RouterView");return l(),h("div",E,[m(w,null,{default:g(({Component:_})=>[(l(),R(V(_),H(n(u),{valLimit:n(i).valLimit,valLow:n(i).valLow,valHigh:n(i).valHigh,strength:n(t).strength,randomStrength:n(t).randomStrength,tempStrength:n(t).tempStrength,realStrength:n(t).realStrength,strengthLimit:n(t).strengthLimit,running:n(t).gameStarted}),null,16,["valLimit","valLow","valHigh","strength","randomStrength","tempStrength","realStrength","strengthLimit","running"]))]),_:1}),m(I,{name:"fade"},{default:g(()=>[n(t).error?(l(),h("div",F,[p("div",T,[p("p",j,A(n(t).error),1)])])):B("",!0)]),_:1})])}}}),G=P({history:D(),routes:W});M(z).use(G).mount("#app");
