/**
 * 主页逻辑  
 */
class Userinfo {
	private static _instance: Userinfo;
	static get instance(): Userinfo {
		if (!this._instance) {
			this._instance = new Userinfo();
		}
		return this._instance;
	}
	private balance: number = 0;
	private gt: number = 0;
	private uiUserHeader: UI_UserHeader;
	public constructor() {
	}

	getUserHeaderView(): UI_UserHeader {
		return this.uiUserHeader = UIController.instance.createView<UI_UserHeader>(UI_UserHeader);
	}

	renderUserData(data: { balance?: number, money?: number, gt?: number }): void {
		data.balance && (this.balance = data.balance);
		data.gt && (this.gt = data.gt);

		if (this.uiUserHeader) {
			this.uiUserHeader.renderBalance(data.balance);
			this.uiUserHeader.renderMoney(data.money);
			this.uiUserHeader.renderGt(data.gt);
		}
	}

	updateBalance(eosNum: number): void {
		eosNum = NP.times(eosNum, 1e4);
		this.balance = NP.plus(this.balance, eosNum);
		this.uiUserHeader && this.uiUserHeader.renderBalance(this.balance);
	}

	updateGt(gtNum: number): void {
		this.gt = NP.plus(this.gt, gtNum);
		this.uiUserHeader && this.uiUserHeader.renderGt(this.gt);
	}

	addOffer(data: { win: string }): void {
		if (parseInt(data.win)) {
			this.balance = NP.plus(this.balance, parseInt(data.win));
			this.uiUserHeader && this.uiUserHeader.renderBalance(this.balance);
		}
	}
}