<?php
// /elms/index.php — minimal, safe entrypoint
declare(strict_types=1);
if (session_status() === PHP_SESSION_NONE) session_start();

require_once __DIR__ . '/includes/helpers.php';
require_once __DIR__ . '/includes/auth.php';

// If a user is already logged in, send them to their dashboard
$role = $_SESSION['user']['role'] ?? ($_SESSION['role_code'] ?? '');
switch (strtolower((string)$role)) {
  case 'super_admin':
  case 'admin':
  case 'branch_admin':
    header('Location: ' . app_url('/admin/dashboard.php')); exit;
  case 'coordinator':
    header('Location: ' . app_url('/admin/dashboard.php')); exit;
  case 'lecturer':
    header('Location: ' . app_url('/lecturer/dashboard.php')); exit;
  case 'student':
    header('Location: ' . app_url('/student/modules.php')); exit;
}

// Otherwise go to unified login
header('Location: ' . app_url('/auth/login.php')); 
exit;
