import{Dt as e,bt as t}from"./_plugin-vue_export-helper-BVhEvvHC.js";import{t as n}from"./axios-DSyjHw-i.js";var r=function(e){return e[e.Scheduled=0]=`Scheduled`,e[e.Active=1]=`Active`,e[e.Completed=2]=`Completed`,e[e.Abandoned=3]=`Abandoned`,e}({});t();function i(){let t=e([]),i=e([]),a=e(null),o=e(!1);return{matches:t,seasons:i,selectedSeasonId:a,isLoading:o,fetchMatches:async()=>{o.value=!0;try{let e=(await n.get(`match`)).data,o=(await n.get(`season`)).data,s=new Map;o.forEach(e=>{s.set(e.seasonId,e.seasonName||`Season ${e.seasonId}`)});let c=e.map(e=>{if(!e||!e.games)return null;let t=e.lifecycleState;if(t===r.Abandoned)return null;let n=e.teams?.find(e=>e.teamId===1)?.name,i=e.teams?.find(e=>e.teamId===2)?.name,a=e.games.filter(t=>t.isComplete||t.isActive?!0:!e.isActive||t.gameTime!==void 0&&t.gameTime>0).map(e=>({gameId:e.gameId,gameNumber:e.gameNumber,isComplete:e.isComplete,isUpcoming:!e.isComplete&&!e.isActive})).sort((e,t)=>e.gameNumber-t.gameNumber);if(a.length===0&&!e.isActive)return null;let o=t===void 0?!e.isActive&&e.winnerId===null&&a.some(e=>!e.isComplete):t===r.Scheduled;return{matchId:e.matchId.toString(),name:e.name||`Match ${e.matchId}`,date:(typeof e.date==`string`?e.date:e.date?.toLocaleString())||``,isActive:e.isActive,isComplete:e.winnerId!==null,isUpcoming:o,blueTeam:n,redTeam:i,patch:e.games[0]?.patch,seasonId:e.seasonId||0,seasonName:s.get(e.seasonId||0),games:a}}).filter(e=>e!==null);if(t.value=c.sort((e,t)=>Number(t.matchId)-Number(e.matchId)),i.value=o.sort((e,t)=>t.seasonId-e.seasonId),o.length>0&&!a.value){let e=o.find(e=>e.isActive);a.value=e?.seasonId??o[0]?.seasonId??null}}catch(e){console.error(`Error loading matches:`,e)}finally{o.value=!1}}}}export{i as t};