<?php
session_start();

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['index'])) {
    $index = $_POST['index'];

    if (isset($_SESSION['cartz'][$index])) {
        // Remove the item from the cart
        unset($_SESSION['cartz'][$index]);
        // Re-index the array
        $_SESSION['cartz'] = array_values($_SESSION['cartz']);

        // Send a success response
        echo json_encode(['success' => true, 'message' => 'Item removed successfully']);
    } else {
        // Send an error response if the item doesn't exist
        echo json_encode(['success' => false, 'message' => 'Item not found']);
    }
} else {
    // Send an error response for invalid requests
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
}
?>
