class UI_RateItem extends UIBaseItemRenderer {
	private winB: eui.Image;//庄
	private winG: eui.Image;//闲
	private winR: eui.Image;//和
	private winBr: eui.Image;//庄对
	private winRl: eui.Image;//闲对
	private winText: eui.Label;
	private fullGroup: eui.Group;

	public constructor() {
		super();
	}

	/**
	 * 创建完成时调用
	 */
	protected onCreate(): void {
		super.onCreate();
		mouse.setButtonMode(this.fullGroup, true);
		this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this)
	}

	private onTap(ev: egret.TouchEvent): void {
		AudiosMgr.instance.playButtonClick();

		// Rate.instance.openRateDetailView(this.itemIndex)
		let data = this.getValidateData(this.itemIndex);

		EOS_VUE.$showValidate(data)
	}
	private getValidateData(index: number): any {
		let history = Rate.instance.rateHistory.result[index];
		let playerPoker = history.block_info.player.map(item => item.poker);
		let bankerPoker = history.block_info.banker.map(item => item.poker);
		let playerPoint = (playerPoker.reduce((prev, cur) => { return prev + Util.pointPoker(cur) }, 0) % 10).toString();
		let bankerPoint = (bankerPoker.reduce((prev, cur) => { return prev + Util.pointPoker(cur) }, 0) % 10).toString();

		let data = {
			game_id: history.id,
			reveal_info: {
				playerPoint: playerPoint,
				bankerPoint: bankerPoint,
				win: history.winner,
				playerPair: history.player_pair === 1 ? true : false,
				bankerPair: history.banker_pair === 1 ? true : false,
				blockInfo: history.block_info,
				revealBlockNum: history.reveal_block_num,
				player:playerPoker,
				banker:bankerPoker
			}
		}

		return data;
	}
	/**
	 * 0:闲,1:庄,2:和,
	 * 10-12:闲 + 对子,
	 * 20-22:庄 + 对子,
	 * 12:和 + 闲对,22:和 + 庄对,32:和+ 闲对+ 庄对
	*/
	protected dataChanged(): void {
		let lang = Lang.instance.lang();
		let data = this.data;

		let isWinB = data.winner === 0
		let isWinR = data.winner === 1
		let isWinG = data.winner === 2
		let isWinBr = data.player_pair === 1
		let isWinRl = data.banker_pair === 1

		if (isWinB) this.winText.text = lang.Rate["player"];
		if (isWinR) this.winText.text = lang.Rate["banker"];
		if (isWinG) this.winText.text = lang.Rate["tie"];

		this.winR.visible = isWinR;
		this.winB.visible = isWinB;
		this.winG.visible = isWinG;
		this.winRl.visible = isWinRl;
		this.winBr.visible = isWinBr;
	}
}