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

const clientInstance = new Client();

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

    clientInstance.add();
});

document.addEventListener("click", async (e) => {

    const editClientBtn = e.target.closest("#modal_editClient");
    if (!editClientBtn) return;

    const clientData = editClientBtn.getAttribute("data-client");
    if (!clientData) return;

    clientInstance.edit(JSON.parse(clientData));
});

document.addEventListener("click", async (e) => {
    const deleteClientBtn = e.target.closest("#btnDeleteClient");
    if (!deleteClientBtn) return;
    
    const clientId = deleteClientBtn.getAttribute("data-client");
    if (!clientId) return;
    clientInstance.desactivate(clientId);
});