<?php
declare(strict_types=1);
require __DIR__ . '/_common.php';
ec_require_coordinator();

$PAGE_TITLE = 'My Profile';
$ACTIVE     = '';

$user = $_SESSION['user'] ?? [];
$name = $user['name'] ?? ($user['username'] ?? 'Coordinator');
$email= $user['email'] ?? '';
$role = $_SESSION['role'] ?? ($user['role'] ?? 'coordinator');
?>
<!doctype html><html lang="en"><head>
  <meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My Profile</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
</head><body>
<div class="ec-shell">
  <?php include __DIR__ . '/partials/sidebar.php'; ?>
  <div class="ec-content">
    <?php include __DIR__ . '/partials/topbar.php'; ?>
    <div class="wrap container-fluid">
      <div class="row g-3">
        <div class="col-12 col-lg-6">
          <div class="card section-card">
            <div class="card-header bg-white"><strong>Profile</strong></div>
            <div class="card-body">
              <dl class="row mb-0">
                <dt class="col-sm-4">Name</dt><dd class="col-sm-8"><?php echo h($name); ?></dd>
                <dt class="col-sm-4">Email</dt><dd class="col-sm-8"><?php echo h($email ?: '—'); ?></dd>
                <dt class="col-sm-4">Role</dt><dd class="col-sm-8"><?php echo h(is_array($role)?implode(',',$role):(string)$role); ?></dd>
              </dl>
            </div>
          </div>
        </div>
        <div class="col-12 col-lg-6">
          <div class="card section-card">
            <div class="card-header bg-white"><strong>Security</strong></div>
            <div class="card-body">
              <a href="/elms/admin/change_password.php" class="btn btn-outline-primary">
                <i class="bi bi-shield-lock"></i> Change Password
              </a>
              <a href="/elms/admin/logout.php" class="btn btn-outline-danger ms-2">
                <i class="bi bi-box-arrow-right"></i> Sign out
              </a>
              <p class="text-muted small mt-3">Links above use your existing endpoints.</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</body></html>
