/**
 * 用于显示错误信息以及其他提示
 */
class AlertMgr {
	private static _instance: AlertMgr;

	static get instance(): AlertMgr {
		if (!this._instance) {
			this._instance = new AlertMgr();
		}
		return this._instance;
	}


	private alertMsg: string[] = [];
	private uiAlert: UI_Alert;
	private uiFairAlert: UI_FairAlert;
	private constructor() {
	}

	register(): void {

	}


	private onReceived(ev: SocketEvent): void {

	}

	showAlert(msg: string, always: boolean = false): void {
		if (!this.uiAlert) {
			this.uiAlert = UIController.instance.alertView<UI_Alert>(UI_Alert);
		} else {
			if (this.uiAlert.visible) {
				return;
			}
		}

		this.uiAlert.visible = true;
		this.uiAlert.showAlert(msg);

		!always && setTimeout(() => {
			this.hideAlert();
		}, 2000);
	}

	hideAlert(): void {
		this.uiAlert && (this.uiAlert.visible = false);
	}

	showFairAlert(block: { blockId: string, poker: number }, imageUrl: string): void {
		if (!this.uiFairAlert) {
			this.uiFairAlert = UIController.instance.alertView<UI_FairAlert>(UI_FairAlert);
		}

		this.uiFairAlert.visible = true;
		this.uiFairAlert.showAlert(block, imageUrl);
	}

	hideFairAlert(): void {
		this.uiFairAlert && this.uiFairAlert.hideAlert();
	}

	release(): void {

	}
}