import User from "../../modules/User.js";

const userInstance = new User();

document.addEventListener("click", async (e) => {
    const addUserBtn = e.target.closest("#modal_createUser");
    if (!addUserBtn) return;

    userInstance.add();
});

document.addEventListener("click", async (e) => {
    const editUserBtn = e.target.closest("#modal_editUser");
    if (!editUserBtn) return;

    const userData = editUserBtn.getAttribute("data-user");
    if (!userData) return;

    userInstance.edit(JSON.parse(userData));
});

document.addEventListener("click", async (e) => {
    const desactivateUserBtn = e.target.closest("#desactivateUserBtn");
    if (!desactivateUserBtn) return;

    const userId = desactivateUserBtn.getAttribute("data-user-id");
    if (!userId) return;

    userInstance.desactivate(userId);
});