<?php
// Include your database connection file
include('shikanisha.kts.php'); // Update with your actual database connection file

// Get the beverage ID from the POST request
$beverage_id = isset($_POST['beverage_id']) ? intval($_POST['beverage_id']) : 0;

if ($beverage_id > 0) {
    // Prepare the SQL query to delete the beverage
    $query = "DELETE FROM beverages WHERE beverage_id = ?";

    // Create a prepared statement
    if ($stmt = $conn->prepare($query)) {
        // Bind parameters
        $stmt->bind_param('i', $beverage_id);

        // Execute the query
        if ($stmt->execute()) {
            $response = [
                'status' => 'success',
                'message' => 'Beverage deleted successfully.'
            ];
        } else {
            $response = [
                'status' => 'error',
                'message' => 'Failed to delete beverage.'
            ];
        }

        // Close the statement
        $stmt->close();
    } else {
        $response = [
            'status' => 'error',
            'message' => 'Failed to prepare the SQL query.'
        ];
    }
} else {
    $response = [
        'status' => 'error',
        'message' => 'Invalid beverage ID.'
    ];
}

// Close the database connection
$conn->close();

// Output the response in JSON format
header('Content-Type: application/json');
echo json_encode($response);
?>
