const fs=require("fs"),vm=require("vm");function E(){return{innerHTML:"",textContent:"",children:[],appendChild(x){this.children.push(x)},prepend(x){this.children.unshift(x)},remove(){},onclick:null,value:"",files:[]}}const els={},store={},ctx={console,Math,Date,Blob:function(){},URL:{createObjectURL(){return"blob:x"}},FileReader:function(){},localStorage:{setItem(k,v){store[k]=v},getItem(k){return store[k]??null}},document:{getElementById(id){return els[id]||(els[id]=E())},createElement(){return E()}},window:{}};ctx.window=ctx;vm.createContext(ctx);vm.runInContext(fs.readFileSync(__dirname+"/data.js","utf8")+";globalThis.__D=FOOTBALL_DATA",ctx);for(const x of ["tournaments.js","engine.js","game.js"])vm.runInContext(fs.readFileSync(__dirname+"/"+x,"utf8"),ctx);vm.runInContext("globalThis.__E=Engine",ctx);const D=ctx.__D,T=ctx.FOOTBALL_TOURNAMENTS,Q=ctx.__FIFA_CUP_QA,E2=ctx.__E;function A(c,m){if(!c)throw Error(m)}const groups={GK:new Set(["GK"]),DF:new Set(["CB","LB","RB","LWB","RWB"]),MF:new Set(["DM","CDM","CM","CAM","AM","LM","RM"]),FW:new Set(["LW","RW","CF","ST","SS"])};let bad=[];for(const c of D.clubs.filter(x=>x.national)){const ps=E2.squad(c.id),cnt={GK:0,DF:0,MF:0,FW:0};for(const p of ps)for(const k of Object.keys(groups))if(groups[k].has(p.pos)){cnt[k]++;break}if(ps.length<23||cnt.GK<3||E2.autoXI(c.id,"4-3-3").length!==11)bad.push({team:c.name,total:ps.length,cnt})}A(bad.length===0,"national squads incomplete "+JSON.stringify(bad));A(T.find(x=>x.id==="worldcup").teams.length===48,"world count");A(T.find(x=>x.id==="euro").teams.length===24,"euro count");let tid=T.find(x=>x.id==="ucl").teams[0];Q.startTournament("ucl",tid);let s=Q.getState();s.tournament.champion=tid;Q.grantTournamentReward(s.tournament);A(s.legacy.trophies.length===1,"ucl trophy");A(s.legacy.prestige===60,"ucl prestige");A(s.legacy.pendingBudget===25000000,"ucl reward bank");let legacy=s.legacy;Q.startCareer(tid);s=Q.getState();A(s.legacy===legacy,"legacy preserved");A(s.legacy.pendingBudget===0,"reward applied");let ids=Object.keys(s.table);ids.forEach((id,i)=>{s.table[id].pts=100-i;s.table[id].gf=60-i;s.table[id].ga=i});if(ids[0]!==tid){const me=s.table[tid],top=s.table[ids[0]];me.pts=200;me.gf=100;me.ga=0;top.pts=50}let before=s.budget;Q.nextSeason();s=Q.getState();A(s.season===2,"season 2");A(s.legacy.trophies.length>=2,"league trophy");A(s.budget>before,"champion budget reward");A(s.legacy.consequences.some(x=>x.includes("champion en titre")),"next season consequence");console.log(JSON.stringify({nationalTeams:D.clubs.filter(x=>x.national).length,incomplete:bad.length,worldCupTeams:48,euroTeams:24,uclReward:true,seasonCarry:true,prestige:s.legacy.prestige,trophies:s.legacy.trophies.length}));