(function () { async function apiRequest(url, method) { const res = await fetch(url, { method, credentials: "include", headers: { "Content-Type": "application/json" }, }); const data = await res.json().catch(() => ({})); if (!res.ok) { throw new Error(data.error || "Request failed"); } return data; } document.body.addEventListener("click", async (e) => { const cancelBtn = e.target.closest("[data-cancel-job]"); const deleteBtn = e.target.closest("[data-delete-job]"); if (!cancelBtn && !deleteBtn) return; try { if (cancelBtn) { const id = cancelBtn.getAttribute("data-cancel-job"); if (!confirm("Cancel this job?")) return; await apiRequest(`/api/jobs/${id}`, "DELETE"); } if (deleteBtn) { const id = deleteBtn.getAttribute("data-delete-job"); if (!confirm("Delete this job permanently?")) return; await apiRequest(`/api/jobs/${id}/delete`, "POST"); } if (window.htmx) { htmx.trigger("#jobs-fragment", "refresh"); htmx.ajax("GET", "/ui/fragments/jobs", "#jobs-fragment"); } else { window.location.reload(); } } catch (err) { alert(err.message); } }); })();