import{Dt as e,I as t,bt as n,x as r}from"./_plugin-vue_export-helper-BVhEvvHC.js";import{n as i}from"./events-Bc6cZn5G.js";import{Kn as a}from"./src-CD6Jsigc.js";import{t as o}from"./axios-DSyjHw-i.js";import{n as s,r as c}from"./sessionSettingStore-ZHUB-lwo.js";import{t as l}from"./matchDatabaseUpdateType-C351fm7X.js";var u=a(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),d=a(`video-off`,[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]);t(),n();var f=e(null),p=!1;function m(e){return e?.lifecycleState===s.Active||e?.isActive===!0}async function h(){try{f.value=(await o.get(`/match/current`)).data}catch{f.value=null}}function g(){i.on(`ws:match-database-update`,e=>{if(e)switch(e.updateType){case l.Start:e.match&&(f.value=e.match);break;case l.Add:case l.Update:m(e.match)?f.value=e.match:f.value?.matchId===e.match.matchId&&(f.value=null);break;case l.End:case l.Remove:f.value?.matchId===e.match.matchId&&(f.value=null)}}),i.on(`ws:game-database-update`,()=>{h()}),i.on(`ws:game-sides-swapped`,()=>{h()}),i.on(`ws:database-reloaded`,()=>{h()})}function _(){p||(p=!0,g(),h());let e=r(()=>f.value?.games.find(e=>e.isActive)),t=r(()=>{if(f.value)return e.value??f.value.games.find(e=>!e.isComplete)??f.value.games[0]}),n=r(()=>t.value?.teams[0]??f.value?.teams[0]),i=r(()=>t.value?.teams[1]??f.value?.teams[1]),a=e=>!e||!f.value?0:f.value.games.filter(t=>t.gameWinnerId===e).length,s=r(()=>a(n.value?.teamId)),l=r(()=>a(i.value?.teamId)),u=r(()=>f.value?.games.filter(e=>e.isComplete).length??0),d=r(()=>{if(e.value)return e.value.gameNumber+1;let t=f.value?.games.find(e=>!e.isComplete);return t?t.gameNumber+1:f.value?.games.length}),m=r(()=>f.value&&Number(f.value.type)||1),_=r(()=>f.value?.ruleSet===c.Fearless);function v(e){if(!e)return;let t=e.teams[0];e.teams[0]=e.teams[1],e.teams[1]=t,o.put(`/game/${e.gameId}/teams`,e.teams.map(e=>e.teamId))}async function y(e,t){t===null?(e.gameWinnerId=void 0,e.isComplete=!1,await o.delete(`/game/${e.gameId}/winner`)):(e.gameWinnerId=t,e.isComplete=!0,await o.put(`/game/${e.gameId}/winner/${t}`))}async function b(e=!1){await o.post(`/match/current`,void 0,{params:e?{force:!0}:void 0}),f.value=null}return{currentMatch:f,refresh:h,currentGame:e,sideReferenceGame:t,leftTeam:n,rightTeam:i,leftWins:s,rightWins:l,completedGames:u,currentGameNumber:d,seriesGameCount:m,isFearless:_,swapTeamSides:v,setGameWinner:y,endMatch:b}}export{d as n,u as r,_ as t};