class UI_UserHeader extends UIBaseComponent {
	private group:eui.Group;
	private eosText: eui.Label;
	private gtText: eui.Label;
	private eosSurplusText: eui.Label;
	private eosSurplusImg:eui.Image;
	private eosSurplusLangText: eui.Label;
	private btnGtQuestion: eui.Button;
	private btnEosQuestion: eui.Button;
	private btnWithdraw: eui.Button;
	private btnFair: eui.Button;
	public constructor() {
		super();
	}

	/**
	 * 绑定事件
	 */
	protected bindEvents(): void {
		super.bindEvents();
		mouse.setButtonMode(this.btnWithdraw, true);
		mouse.setButtonMode(this.btnFair, true);
		mouse.setButtonMode(this.btnGtQuestion, true);
		mouse.setButtonMode(this.btnEosQuestion, true);
		this.btnWithdraw.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnWithdraw, this);
		this.btnFair.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnFair, this);
		this.btnGtQuestion.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnGtQuestion, this);
		this.btnEosQuestion.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnEosQuestion, this);
	}

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

	/**
	 * 渲染UI时调用
	 */
	protected render(): void {
		this.group.removeChild(this.eosSurplusLangText);
		this.group.removeChild(this.eosSurplusImg);
		this.group.removeChild(this.eosSurplusText);
		this.group.removeChild(this.btnEosQuestion);
		this.group.removeChild(this.btnWithdraw);

		this.renderBalance(UserMgr.instance.balance);
		this.renderGt(UserMgr.instance.gt);
		this.renderMoney(UserMgr.instance.money);
		EOS_VUE.$getCoinData();
	}

	/**
	 * 改变语言时调用
	 */
	protected onLangChange(ev?: egret.Event): void {
		let lang = Lang.instance.lang();

		this.eosSurplusLangText.text = lang.Userinfo.eosSurplus;
		this.btnWithdraw.label = lang.Userinfo.withdraw;
		this.btnFair.label = lang.Userinfo.fair;
		this.btnWithdraw.width = (GAME_ISMOBILE ? 40 : 23) + this.btnWithdraw.labelDisplay['width'];
	}

	//eos数量
	renderBalance(balance: number): void {
		if (balance != null) {
			this.eosText.text = (balance / 10000).toString();
		}
	}

	renderGt(gt: number): void {
		if (gt != null) {
			this.gtText.text = gt.toString();
		}
	}

	renderMoney(money: number): void {
		if (money != null) {
			this.eosSurplusText.text = money.toString();
		}
	}



	//TODO user withdraw
	private onBtnWithdraw(ev: egret.TouchEvent): void {
		AudiosMgr.instance.playButtonClick();
		if (UserMgr.instance.isLogin()) {
			EOS_VUE.$showWallet();
		}

	}

	//TODO show fair
	private onBtnFair(ev: egret.TouchEvent): void {
		AudiosMgr.instance.playButtonClick();
		EOS_VUE.$showFair();
	}

	//TODO show fair
	private onBtnGtQuestion(ev: egret.TouchEvent): void {
		AudiosMgr.instance.playButtonClick();
		EOS_VUE.$showGt();
	}

	//TODO show fair
	private onBtnEosQuestion(ev: egret.TouchEvent): void {
		AudiosMgr.instance.playButtonClick();
		EOS_VUE.$showCount();
	}

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