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

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id <= 0) { http_response_code(404); echo 'Invalid event id'; exit; }

$e = null;
try {
  $stmt = $pdo->prepare("SELECT * FROM events WHERE id=?");
  $stmt->execute([$id]);
  $e = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (Throwable $ex) {}

if (!$e) { http_response_code(404); echo 'Event not found'; exit; }

function bn_date($d){ return $d ? date('d-m-Y', strtotime($d)) : ''; }
?>
<!DOCTYPE html>
<html lang="bn">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?php echo htmlspecialchars($e['title']); ?> - ইভেন্ট</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
  <style>
    body { background: #f7f8fc; }
    .card { border: 0; border-radius: 14px; box-shadow: 0 10px 25px rgba(0,0,0,0.06); }
  </style>
</head>
<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
    <div class="container">
      <a class="navbar-brand" href="index.php"><i class="fas fa-graduation-cap"></i> স্কুল ম্যানেজমেন্ট</a>
      <div class="ms-auto d-flex gap-2">
        <a class="btn btn-outline-secondary" href="events.php"><i class="fas fa-calendar"></i> সব ইভেন্ট</a>
        <a class="btn btn-primary" href="login.php"><i class="fas fa-sign-in-alt"></i> লগইন</a>
      </div>
    </div>
  </nav>

  <div class="container my-4">
    <div class="card">
      <?php if (!empty($e['cover_image'])): ?>
        <img src="<?php echo htmlspecialchars($e['cover_image']); ?>" class="card-img-top" alt="">
      <?php endif; ?>
      <div class="card-body">
        <div class="d-flex justify-content-between align-items-start">
          <div>
            <h3 class="mb-1"><?php echo htmlspecialchars($e['title']); ?></h3>
            <div class="text-muted small">
              <span class="badge bg-<?php echo $e['status']==='upcoming'?'success':($e['status']==='past'?'secondary':'danger'); ?> text-uppercase"><?php echo htmlspecialchars($e['status']); ?></span>
              <i class="far fa-calendar ms-2"></i> <?php echo bn_date($e['event_date']); ?>
              <?php if (!empty($e['location'])): ?> | <i class="fas fa-map-marker-alt"></i> <?php echo htmlspecialchars($e['location']); ?><?php endif; ?>
            </div>
          </div>
        </div>
        <hr>
        <div class="notice-content">
          <?php echo nl2br(htmlspecialchars($e['description'] ?? '')); ?>
        </div>
        <div class="mt-3">
          <a class="btn btn-outline-primary" href="events.php"><i class="fas fa-arrow-left"></i> ফিরে যান</a>
        </div>
      </div>
    </div>
  </div>
</body>
</html>