function initConfirmModals() { var modal = document.getElementById("confirm-modal"); if (!modal) return; var title = document.getElementById("confirm-title"); var message = document.getElementById("confirm-message"); var actionButton = document.getElementById("confirm-action"); var backdrop = modal.querySelector("[data-confirm-backdrop]"); var cancelButton = modal.querySelector("[data-confirm-cancel]"); document.querySelectorAll("[data-confirm-trigger]").forEach(function (trigger) { if (trigger.dataset.confirmInitialized) return; trigger.dataset.confirmInitialized = "true"; trigger.addEventListener("click", function () { title.textContent = trigger.dataset.confirmTitle; message.textContent = trigger.dataset.confirmMessage; modal.classList.remove("hidden"); var cloned = actionButton.cloneNode(true); actionButton.parentNode.replaceChild(cloned, actionButton); actionButton = cloned; actionButton.addEventListener("click", function () { modal.classList.add("hidden"); htmx.ajax("DELETE", trigger.dataset.confirmAction, { target: "#content", swap: "none" }); }); }); }); function closeModal() { modal.classList.add("hidden"); } backdrop.addEventListener("click", closeModal); cancelButton.addEventListener("click", closeModal); } document.addEventListener("DOMContentLoaded", initConfirmModals); document.body.addEventListener("htmx:afterSwap", initConfirmModals);