<?php
session_start();
header('Content-Type: application/json');
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/auth.php';

if (!isLoggedIn()) { echo json_encode(['status'=>'error','message'=>'Silakan login.']); exit; }

$kelasId = (int)($_POST['kelas_id'] ?? 0);
$userId = $_SESSION['user_id'];

$pdo->prepare("DELETE FROM keranjang WHERE kelas_id = ? AND user_id = ?")->execute([$kelasId, $userId]);

$cnt = $pdo->prepare("SELECT COUNT(*) FROM keranjang WHERE user_id = ?");
$cnt->execute([$userId]);
$cartCount = (int)$cnt->fetchColumn();

echo json_encode(['status'=>'success','cart_count'=>$cartCount]);
