import {isMobile} from "../util/functions";
import {Dialog} from "./index";
import {Constants} from "../constants";
export const confirmDialog = (title: string, text: string,
confirm?: (dialog?: Dialog) => void,
cancel?: (dialog: Dialog) => void,
isDelete = false) => {
if (!text && !title) {
confirm();
return;
}
const dialog = new Dialog({
title,
content: `
`,
width: isMobile() ? "92vw" : "520px",
});
dialog.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
const isDispatch = typeof event.detail === "string";
while (target && !target.isSameNode(dialog.element) || isDispatch) {
if (target.id === "cancelDialogConfirmBtn" || (isDispatch && event.detail=== "Escape")) {
if (cancel) {
cancel(dialog);
}
dialog.destroy();
break;
} else if (target.id === "confirmDialogConfirmBtn" || (isDispatch && event.detail=== "Enter")) {
if (confirm) {
confirm(dialog);
}
dialog.destroy();
break;
}
target = target.parentElement;
}
});
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
};