<?php
session_start();
require 'db_connection.php';

// ---------------- AUTH CHECK ----------------
if (!isset($_SESSION['username'])) {
    header("Location: login.php");
    exit();
}

// Flash messages
$message = $_SESSION['message'] ?? '';
$message_type = $_SESSION['message_type'] ?? '';

unset($_SESSION['message'], $_SESSION['message_type']);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Add Activity | School Portal</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <style>
        body {
            background: #f4f6fb;
        }

        .navbar {
            background: #3a57e8;
        }

        .navbar-brand, .nav-link {
            color: #fff !important;
            font-weight: 500;
        }

        .card {
            border: none;
            border-radius: 12px;
            box-shadow: 0 8px 20px rgba(0,0,0,0.05);
        }

        .card-header {
            background: #3a57e8;
            color: #fff;
            font-weight: 600;
            border-radius: 12px 12px 0 0;
        }

        .btn-primary {
            background: #3a57e8;
            border: none;
        }

        .btn-primary:hover {
            background: #2c43c7;
        }
    </style>
</head>

<body>

<!-- ================= HEADER ================= -->
<nav class="navbar navbar-expand-lg px-4">
    <a class="navbar-brand" href="admin_dashboard.php">School Management</a>

    <div class="ms-auto">
        <span class="text-white me-3">
            Welcome, <?= htmlspecialchars($_SESSION['username']) ?>
        </span>
        <a href="logout.php" class="btn btn-light btn-sm">Logout</a>
    </div>
</nav>

<!-- ================= MAIN CONTENT ================= -->
<div class="container py-5">

    <div class="row justify-content-center">
        <div class="col-md-7">

            <div class="card">

                <div class="card-header">
                    Add Upcoming Activity
                </div>

                <div class="card-body">

                    <?php if ($message): ?>
                        <div class="alert alert-<?= $message_type ?> alert-dismissible fade show">
                            <?= htmlspecialchars($message) ?>
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                    <?php endif; ?>

                    <form action="process_add_activity.php" method="POST">

                        <div class="mb-3">
                            <label class="form-label">Activity Name</label>
                            <input type="text" name="activity_name" class="form-control" required>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Description</label>
                            <textarea name="description" class="form-control" rows="4" required></textarea>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Activity Date & Time</label>
                            <input type="datetime-local" name="activity_date" class="form-control" required>
                        </div>

                        <button type="submit" class="btn btn-primary w-100">
                            Save Activity
                        </button>

                        <a href="admin_dashboard.php" class="btn btn-outline-secondary w-100 mt-2">
                            Back to Dashboard
                        </a>

                    </form>

                </div>
            </div>

        </div>
    </div>

</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>