import Helper from "./helper.js";
import Modals from "./modals.js";

export default function confirmPopup(text, confirmedCb, canceledCb) {
	Modals.create("confirm-popup", {
		title: `Requires confirmation`,
		body: () => {
			const paragraph = document.createElement("p");
			paragraph.textContent = text ?? "";
			return paragraph;
		},
		actions: modal => {
			const buttonNO = Helper.template.createElement("button", { class: "btn btn-primary" }, "NO");
			const buttonYES = Helper.template.createElement("button", { class: "btn btn-warning" }, "YES");

			buttonNO.addEventListener("click", e => {
				modal.close();
				canceledCb?.();
			});

			buttonYES.addEventListener("click", e => {
				modal.close();
				confirmedCb?.();
			});

			return [ buttonNO, buttonYES ];
		}
	}).show();
}
