<?php

include $_SERVER['DOCUMENT_ROOT'] . "/root.class.php";
$db = new db_safeguard();
$calendar = new calendar();
$html = new html();
$html->add_styles_page();
$dash = new Dashboard();
session_start();

// Redirect to login if no session
if (empty($_SESSION['user_id'])) {
    header("Location: /login.php");
    exit;
}

$username  = strtolower(trim($_SESSION['username'] ?? ''));
$user_type = strtolower(trim($_SESSION['user_type'] ?? ''));
$allowed   = ['dev', 'admin', 'driver', 'dispatch', 'install', 'test', 'workshop'];
 
// 'test' user sees both driver and install panels
if ($username === 'test') {
    $user_type = 'combined';
}

// dispatch sees workshop stock management; workshop sees dispatch stock overview
if ($user_type === 'dispatch')  $user_type = 'workshop';
elseif ($user_type === 'workshop') $user_type = 'dispatch';
 
if (!in_array($user_type, $allowed)) {
    echo $user_type;
    die("Access denied: unknown user type.");
}

include __DIR__ . "/dashboard/dashboards/{$user_type}.php";
?>