'use strict';

/**
 * Deletes a book by ID and the corresponding element from the DOM
 * 
 * @param {number} id - The ID of the book to delete
 */
function trash(id, element) {
    // Sending a POST request to the server 
    fetch(`books/${id}/delete`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: 'identifier=' + id
    })
    
        // Checking the success of the request
        .then((response) => {
            if (response.ok) {
            
                // Removing an element from the DOM
                element.remove();
            }

        })
        .catch((error) => {
            console.error('Ошибка:', error);
        });
}