<?php
require __DIR__ . '/../vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->safeLoad();

use App\Auth;
Auth::init();
Auth::requireRole(['admin','manager','user']);
$user = Auth::user();
if (session_status() === PHP_SESSION_NONE) session_start();
// ensure topbar can read these
$_SESSION['full_name'] = $user['full_name'] ?? ($user['name'] ?? $user['email'] ?? 'User');
$_SESSION['role'] = $user['role_name'] ?? ($user['role'] ?? 'staff');
include __DIR__ . '/header.php';

// main content wrapper
echo '<main class="container" style="padding:26px 12px">';
?>
<h2>Dashboard</h2>
<p>Welcome, <?=htmlspecialchars($user['name'])?>. Your role is <strong><?=htmlspecialchars($user['role_name'])?></strong>.</p>
<?php if ($user['role_name'] === 'admin'): ?>
  <h3>Admin Panel</h3>
  <ul>
    <li><a href="/admin/users.php">Pending user approvals</a></li>
    <li><a href="#">Site settings (not implemented)</a></li>
  </ul>
<?php elseif ($user['role_name'] === 'manager'): ?>
  <h3>Manager Panel</h3>
  <p>Manager-specific overview (placeholder)</p>
<?php else: ?>
  <h3>User Panel</h3>
  <p>Regular user area (placeholder)</p>
<?php endif; ?>

<?php
echo '</main>'; 
include __DIR__ . '/footer.php'; 
?>