<?php
/**
 * Remove from Cart - AJAX Handler
 * Digital Product Store
 */

require_once __DIR__ . '/config/database.php';

header('Content-Type: application/json');

$response = ['success' => false, 'cart_count' => 0, 'cart_total' => 0];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $cart_id = (int)($_POST['cart_id'] ?? 0);
    
    if ($cart_id > 0) {
        if (remove_from_cart($cart_id)) {
            $response['success'] = true;
            $response['cart_count'] = get_cart_count();
            $response['cart_total'] = format_price(get_cart_total());
        }
    }
}

echo json_encode($response);
