import { Modal } from "antd";

/** 訊息框相關 */
export default class CSMessage {
	/** 一個按鈕的訊息框 */
	public static CreateYesMsg(content: string, yesCallback: (() => void) | null = null, enterStr: string | null = null, title: string | null = null, textAlign: "center" | "left" | "right" | null = null) {
		Modal.info({
			title: title || "訊息",
			content: <div style={{ textAlign: textAlign || "center" }}> {content} </div>,
			okText: enterStr || "確認",
			onOk: yesCallback || (() => { }),
		});
	}

	/** 兩個按鈕的訊息框 */
	public static CreateYesNoMsg(content: string, yesCallback: (() => void) | null = null, noCallback: (() => void) | null = null, enterStr: string | null = null, title: string | null = null, cancelStr: string | null = null, textAlign: "center" | "left" | "right" | null = null) {
		Modal.confirm({
			title: title || "確認",
			content: <div style={{ textAlign: textAlign || "center" }}> {content} </div>,
			okText: enterStr || "確認",
			cancelText: cancelStr || "取消",
			onOk: yesCallback || (() => { }),
			onCancel: noCallback || (() => { }),
		});
	}

	/** 網路錯誤訊息 */
	public static NetError(method: string, state: number, str: string = ""): void {
		const error = String.Format("[{0}] state:{1} {2}", method, state, str);
		console.debug("網路錯誤訊息: ", error);
		// 同時彈出訊息
		this.CreateYesMsg(error, null, "關閉", "網路錯誤");
	}
}
