import { IConfirmMessageData, modalObj } from "@/UIControl/ModalContext";

/** 訊息框相關 */
export default class CSMessage {
	public static Record: IConfirmMessageData[] = [];

	/** 一個按鈕的訊息框 */
	public static CreateYesMsg(content: string, yesCallback: () => void = null, enterStr: string = null, title: string = null, textAlign: "center" | "left" | "right" = null) {
		enterStr = enterStr ? enterStr : "確認";
		let data: IConfirmMessageData = {
			title: title,
			content: content,
			isShowCancel: false,
			handleConfirm: yesCallback,
			enterStr: enterStr,
			textAlign: textAlign
		};
		const { handleOpen } = modalObj;
		handleOpen(data);
	}

	/** 兩個按鈕的訊息框 */
	public static CreateYesNoMsg(content: string, yesCallback: () => void = null, noCallback: () => void = null, enterStr: string = null, title: string = null, cancelStr: string = null, textAlign: "center" | "left" | "right" = null) {
		enterStr = enterStr ? enterStr : "確認";
		cancelStr = cancelStr ? cancelStr : "取消";
		let data: IConfirmMessageData = {
			title: title,
			content: content,
			isShowCancel: true,
			handleConfirm: yesCallback,
			handleCancel: noCallback,
			enterStr: enterStr,
			cancelStr: cancelStr,
			textAlign: textAlign
		};
		const { handleOpen } = modalObj;
		handleOpen(data);
	}

	/** 網路錯誤訊息 */
	public static NetError(method: string, state: number, str: string = ""): void {
		let error = String.Format("[{0}] state:{1} {2}", method, state, str);
		console.debug("網路錯誤訊息: ", error);
	}
}