/**
 * Delete a client referenced by its ID
 *
 * @param clientID The ID of the client to delete
 */
async function deleteClient(clientID) {
    if(!confirm("Do you really want to remove client " + clientID + "? The operation cannot be reverted!"))
        return;

    try {
        const res = await fetch("/", {
            method: "POST",
            headers:{
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: new URLSearchParams({
                "delete_client_id": clientID
            }),
        });

        if(res.status !== 200)
            throw new Error(`Invalid status code: ${res.status}`);

        alert("The client was successfully deleted!");
        location.reload();
    } catch (e) {
        console.error(`Failed to delete client: ${e}`);
        alert("Failed to delete client!");
    }
}