class UI_Auto extends UIBaseComponent {
	private title: eui.Label;
	private autoTips: eui.Label;
	private planEos: eui.Label;
	private planRest: eui.Label;
	private planCount: eui.Label;
	private planCont: eui.Label;
	private betEos1: eui.Label;
	private betEos2: eui.Label;
	private stopEos: eui.Label;
	private winInTotal: eui.Label;
	private gained: eui.Label;
	private reset: eui.Label;
	private detail: eui.Label;
	private period: eui.Label;
	private atLeastL1: eui.Label;
	private atLeastR1: eui.Label;
	private atLeastL2: eui.Label;
	private atLeastR2: eui.Label;
	private periodTxt: eui.Label;
	private banker: eui.Label;
	private player: eui.Label;
	private tie: eui.Label;
	private bankerPair: eui.Label;
	private playerPair: eui.Label;
	private stopTipL: eui.Label;
	private stopTipR: eui.Label;
	private multiChoice: eui.Label;
	private backTipL: eui.Label;
	private backTipR: eui.Label;

	private btnClose: eui.Button;
	private btnEosComfirm: eui.Button;
	private btnAdd: eui.Button;
	private btnBack: eui.Button;
	private btnDetail: eui.Group;
	private btnComfirm: eui.Button;
	private bankerCBox: eui.CheckBox;
	private playerCBox: eui.CheckBox;
	private tieCBox: eui.CheckBox;
	private bankerPairCBox: eui.CheckBox;
	private playerPairCBox: eui.CheckBox;
	private inputPlanEos: eui.TextInput;//计划投入
	private inputEos: eui.TextInput;//余额
	private inputCount: eui.TextInput;//期数
	private inputNomal: eui.TextInput;//筹码1
	private inputRare: eui.TextInput;//筹码2
	private inputStop: eui.TextInput;//止损线
	private planEosGroup: eui.Group;
	private eosGroup: eui.Group;
	private checkBoxFlag: Array<any> = [false, false, false, false, false]

	public constructor() {
		super();
	}

	/**
	 * 绑定事件
	 */
	protected bindEvents(): void {
		super.bindEvents();

		let cBoxArr = ["bankerCBox", "playerCBox", "tieCBox", "bankerPairCBox", "playerPairCBox"]
		let btnArr = ["btnClose", "btnEosComfirm", "btnAdd", "btnBack", "btnDetail", "btnComfirm", ...cBoxArr]
		btnArr.forEach((item) => {
			mouse.setButtonMode(this[item], true);
		})
		cBoxArr.forEach((item, index) => {
			this[item].addEventListener(eui.UIEvent.CHANGE, this[`onCheckbox${index}`], this);
		})

		this.btnClose.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnClose, this);
		this.btnEosComfirm.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnEosComfirm, this);
		this.btnAdd.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnAdd, this);
		this.btnBack.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnBack, this);
		this.btnDetail.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnDetail, this);
		this.btnComfirm.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnComfirm, this);
	}

	/**
	 * 创建完成时调用
	 */
	protected onCreate(): void {
		super.onCreate();
		this.render();
		this.onLangChange();
	}

	private onBtnClose() {
		AudiosMgr.instance.playButtonClick();

		Auto.instance.closeAutoView();
	}

	private onBtnEosComfirm() {
		AudiosMgr.instance.playButtonClick();

		this.planEosGroup.visible = false;
		this.eosGroup.visible = true;
		DEBUG && console.log("确认eos")
	}

	private onBtnAdd() {
		AudiosMgr.instance.playButtonClick();

		DEBUG && console.log("追加")
	}

	private onBtnBack() {
		AudiosMgr.instance.playButtonClick();

		this.planEosGroup.visible = true;
		this.eosGroup.visible = false;
		DEBUG && console.log("退回")
	}

	private onBtnDetail() {
		AudiosMgr.instance.playButtonClick();

		Auto.instance.openAutoDetailView();
	}

	private onBtnComfirm() {
		AudiosMgr.instance.playButtonClick();

		Auto.instance.closeAutoView();
	}

	private onCheckbox0(ev: egret.Event) {
		AudiosMgr.instance.playButtonClick();

		this.checkBoxFlag[0] = ev.target.selected;
	}
	private onCheckbox1(ev: egret.Event) {
		AudiosMgr.instance.playButtonClick();

		this.checkBoxFlag[1] = ev.target.selected;
	}
	private onCheckbox2(ev: egret.Event) {
		AudiosMgr.instance.playButtonClick();

		this.checkBoxFlag[2] = ev.target.selected;
	}
	private onCheckbox3(ev: egret.Event) {
		AudiosMgr.instance.playButtonClick();

		this.checkBoxFlag[3] = ev.target.selected;
	}
	private onCheckbox4(ev: egret.Event) {
		AudiosMgr.instance.playButtonClick();

		this.checkBoxFlag[4] = ev.target.selected;
	}

	private initFormData() {
		this.inputPlanEos.text = (0).toString();
		this.inputEos.text = (0).toString();
		this.inputCount.text = (10).toString();
		this.inputNomal.text = (0.5).toString();
		this.inputRare.text = (0.1).toString();
		this.inputStop.text = (1).toString();
	}

	/**
	 * 渲染UI时调用
	 */
	protected render(): void {
		this.initFormData();
	}

	/**
	 * 改变语言时调用
	 */
	protected onLangChange(ev?: egret.Event): void {
		let {Bet, Auto} = Lang.instance.lang();
		let isZn = Lang.instance.langEnum == 'zh';
		let backCount = 1;


		let txtArr = [
			"title", "autoTips", "planEos", "planRest", "planCount", "planCont", "stopEos",
			"winInTotal", "gained", "reset", "detail", "period", "periodTxt",
			"stopTipL", "stopTipR", "multiChoice", "backTipL"
		]; //纯label赋值
		let resultArr = ["banker", "player", "tie", "bankerPair", "playerPair"]//庄闲和赋值

		txtArr.forEach((item) => {
			this[item].text = Auto[item];
		})

		resultArr.forEach((item) => {
			this[`${item}CBox`].label = Bet[item].toUpperCase().replace(" ", "\n");
			this[`${item}CBox`].labelDisplay.size = isZn ? "30" : "18";
		})

		this.backTipR.text = `${backCount} ${Auto.backTipR}`;
		this.atLeastL1.text = `${Auto.oneBet}0.5`;
		this.atLeastR1.text = Auto.atLeast;
		this.atLeastL2.text = `${Auto.oneBet}0.1`;
		this.atLeastR2.text = Auto.atLeast;
		this.btnAdd.label = Auto.add;
		this.btnBack.label = Auto.back;
		this.btnComfirm.label = Auto.startBetting;
		this.betEos1.text = this.betEos2.text = Auto.betEos;
	}

	/**
	 * 界面关闭时调用
	 */
	public onClose(): void {
	}
}