{"size": 1605, "ext": "js", "max_stars_repo_path": "public/js/burgers.js", "max_stars_repo_name": "cynthiwu/eat-burger", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/js/burgers.js", "max_issues_repo_name": "cynthiwu/eat-burger", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/js/burgers.js", "max_forks_repo_name": "cynthiwu/eat-burger", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.6029411765, "max_line_length": 62, "alphanum_fraction": 0.4535825545}
$(function() {
    
    // Adding event listener to devour button
    $(".devour-button").on("click", function(event){
        const id = $(this).data("id");
        const newDevour = "true";

        console.log(id);
        console.log(newDevour);

        const newDevourState = {
            devoured: newDevour
        };

        // Send the PUT request.

        $.ajax("/api/burgers/" + id, {
            type: "PUT",
            data: newDevourState
        }).then(
            function() {
                console.log("Changed devoured to", newDevour);

                location.reload();
            }
        );   
    });

    // Adding event listener to the submit form button
    $("#form-button").on("click", function(event) {
        event.preventDefault();
        const newBurger = {
            burger_name: $("#bu").val().trim(),
        };

        // Send the PUT request.
        $.ajax("api/burgers", {
            type: "POST",
            data: newBurger
        }).then(
            function() {
                console.log("Created new burger");
                location.reload();
            }
        );
    });

    // Adding event listener to the close buttons
    $(".close-button").on("click", function(event) {
        event.preventDefault();

        const id = $(this).data("id");

        // Send the DELETE request.

        $.ajax("/api/burgers/" + id, {
            type: "DELETE",
        }).then(
            function() {
                console.log("Deleted burger with ID" + id);
                location.reload();
            }
        );
    });
    
});

