<?php
include 'db_connection.php';

$data = json_decode(file_get_contents('php://input'), true);

if (!isset($data['id']) || empty($data['id'])) {
    echo json_encode(['success' => false, 'message' => 'Invalid schedule ID']);
    exit();
}

try {
    $stmt = $pdo->prepare("DELETE FROM class_schedule WHERE id = :id");
    $stmt->execute([':id' => $data['id']]);

    if ($stmt->rowCount() > 0) {
        echo json_encode(['success' => true, 'message' => 'Stundu saraksta ieraksts dzēsts!']);
    } else {
        echo json_encode(['success' => false, 'message' => 'Schedule not found or already deleted']);
    }
} catch (PDOException $e) {
    echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}
?>
