<?php
session_start();
require_once 'includes/database.php';
require_once 'Classes/Timetable.php';

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

if(!isset($_SESSION['username']) || !isset($_POST['period_id'])) {
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
    exit();
}

$timetable = new Timetable();
$periodId = $_POST['period_id'];

try {
    if($timetable->deletePeriod($periodId)) {
        echo json_encode(['success' => true, 'message' => 'Period deleted successfully']);
    } else {
        echo json_encode(['success' => false, 'message' => 'Failed to delete period']);
    }
} catch(Exception $e) {
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}