import Scene from "../views/Scene";
import MyImage from "./MyImage";
import PanelCtrl from "../ctrls/panelCtrl";
import { ModuleTypes } from "../types/sceneTypes";
import { NetManager } from "../../libs/tw/manager/NetManager";
import { DataManager } from "../../libs/tw/manager/DataManager";
import { GTime } from "../../libs/tc/util/GTime";
import { TimeFormat } from "../../libs/tc/enum/TimeFormat";
import Panel from "../views/Panel";
import { GDispatcher } from "../../libs/tc/util/GDispatcher";
import { Buried } from "../../libs/tw/util/Buried";
import ComponentBase from "../components/ComponentBase";
import GuidePanel from "../guidePanel/GuidePanel";
import { GCache } from "../../libs/tc/util/GCache";
import Loading from "../loading/Loading";
import { GetPrizeInfoData } from "../../libs/tw/data/plug/getPrizeInfo/GetPrizeInfoData";
import { ABNetManager } from "../../libs/tc/manager/ABNetManager";
import FriendItem from "./FriendItem";
import { NetName } from "../../libs/tw/enum/NetName";

export default class MainScene extends Scene {

	public topGroup:eui.Group;
	public team_0:eui.Group;
	public team_1:eui.Group;
	public team_2:eui.Group;
	public team_3:eui.Group;
	public team_4:eui.Group;
	public team_5:eui.Group;
	public bottomGroup:eui.Group;
	public doglist_0:eui.Group;
	public doglist_1:eui.Group;
	public doglist_2:eui.Group;
	public doglist_3:eui.Group;
	public doglist_4:eui.Group;
	public doglist_5:eui.Group;
	public doglist_6:eui.Group;
	public doglist_7:eui.Group;
	public doglist_8:eui.Group;
	public doglist_9:eui.Group;
	public doglist_10:eui.Group;
	public doglist_11:eui.Group;



	public get skinKey() { return 'MainScene' }
	public get groupName() { return 'main_scene' }

	private teams=[];
	constructor(data?) {
		super(data);
		if (data) {
		
		}
		this.percentHeight = 100;
	}

	initEvents() {
		GDispatcher.addEvent(ABNetManager.ERROR, this.onError, this);

		for(let i=0;i<6;i++){
			this.teams[i]=new FriendItem()
			this.teams[i].x=0;
			this.teams[i].y=0;
			this["team_"+i].addChild(this.teams[i])
			/* this.teams[i].setLoadVal(50)
			this.teams[i].setState(true) */
		}
	}

	private onError(net: any, code: any): void {
		console.log(code);
		var msg: string;
		var msgArr: any = window['errorMessage'];
		if (!isNaN(code)) {
			msg = msgArr[code] ? msgArr[code] : '额哦，一个未知的错误';
		} else {
			msg = code;
		}

		PanelCtrl.instance.show(ModuleTypes.MSG_PANEL, [msg], false);
	}
	removeEvents() {
		this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
		GDispatcher.removeEvent(ABNetManager.ERROR, this.onError, this);
	}

	protected onSkinComplete(): void {
		super.onSkinComplete();
		NetManager.ins.getHome((succuss)=>{
			if(!succuss){
				return;
			}
			this.updateIndex()
		},"")
	}

    teamData

	updateIndex(){

		
		console.log(DataManager.ins.getData(NetName.GET_HOME))
		let data=DataManager.ins.getData(NetName.GET_HOME).data;
		if(data){
			this.teamData=data.team
		}
	}

	updateTeam(){
		for(let i=0;i<6;i++){
			this.teams[i].setLoadVal(50)
			this.teams[i].setState(true)
		}
	}

	start(data?) {

	}

	protected onLoad(): void {
		this.initUI();

		this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
	}

	private initUI(): void {
		//初始化数据
		this.initData();

	}
	private initData(): void {
	}


	private onEnterFrame(): void{

	}

}