<?php
$pageTitle = 'My Profile';
$role = \Core\Session::get('user')['role'] ?? '';
$dashUrl = match($role) {
    'super-admin','admin' => \Core\View::url('admin/dashboard'),
    'teacher' => \Core\View::url('teacher/dashboard'),
    'student' => \Core\View::url('student/dashboard'),
    'parent'  => \Core\View::url('parent/dashboard'),
    default   => \Core\View::url('dashboard'),
};
$sidebarNav = '<div class="nav-item"><a href="'.$dashUrl.'"><i class="bi bi-grid"></i> Dashboard</a></div>
<div class="nav-item"><a href="'.\Core\View::url('profile').'"><i class="bi bi-person-circle"></i> My Profile</a></div>';
$u = fn($p) => \Core\View::url($p);
?>
<div class="page-header"><div><h1>My Profile</h1></div></div>
<div class="grid g2">
  <div class="card">
    <div class="card-header"><h5>Personal Information</h5></div>
    <div class="card-body">
      <form method="POST" action="<?= $u('profile/update') ?>">
        <?= \Core\View::csrf() ?>
        <div class="form-group"><label>Full Name *</label><input type="text" name="name" value="<?= htmlspecialchars($user['name']) ?>" required></div>
        <div class="form-group"><label>Email</label><input type="email" value="<?= htmlspecialchars($user['email']) ?>" disabled style="background:#f8fafc;color:var(--gray)"></div>
        <div class="form-group"><label>Phone</label><input type="text" name="phone" value="<?= htmlspecialchars($user['phone'] ?? '') ?>"></div>
        <div class="form-group"><label>Role</label><input type="text" value="<?= ucfirst($user['role']) ?>" disabled style="background:#f8fafc;color:var(--gray)"></div>
        <button type="submit" class="btn btn-primary"><i class="bi bi-save"></i> Update Profile</button>
      </form>
    </div>
  </div>
  <div class="card">
    <div class="card-header"><h5>Change Password</h5></div>
    <div class="card-body">
      <form method="POST" action="<?= $u('profile/password') ?>">
        <?= \Core\View::csrf() ?>
        <div class="form-group"><label>Current Password *</label><input type="password" name="current_password" required></div>
        <div class="form-group"><label>New Password *</label><input type="password" name="new_password" required minlength="8"></div>
        <div class="form-group"><label>Confirm New Password *</label><input type="password" name="confirm_password" required></div>
        <button type="submit" class="btn btn-primary"><i class="bi bi-key"></i> Change Password</button>
      </form>
    </div>
  </div>
</div>
