<?php
require_once __DIR__ . '/session_bootstrap.php';

sikompro_session_bootstrap(true);

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

if (!function_exists('sikompro_role_home')) {
    function sikompro_role_home($role)
    {
        $map = [
            'admin' => '../admin/dashboard.php',
            'pelaksana' => '../pelaksana/dashboard.php',
            'teknisi' => '../teknisi/teknisi.php',
        ];

        return $map[$role] ?? '../middleware/login.php';
    }
}

if (!function_exists('sikompro_require_role')) {
    function sikompro_require_role($role)
    {
        if (($_SESSION['role'] ?? '') === $role) {
            return;
        }

        header("Location: ../middleware/login.php?required_role=" . urlencode($role) . "&role_mismatch=1");
        exit;
    }
}
?>
