<?php
/**
 * Student Profile — Gmind Institute
 *
 * Allows students to view and update their profile information.
 */

$basePath = defined('BASE_PATH') ? BASE_PATH : '/gmind';
$user = $user ?? null;
$student = $student ?? null;
$settings = $settings ?? [];
include __DIR__ . '/../layouts/header.php';

?>
<section class="inner-page-section">
    <div class="container">
        <div class="inner-page-header">
            <h1><?= __('profile.title') ?></h1>
            <p><?= __('profile.subtitle') ?></p>
        </div>

        <?php if ($flash_error): ?>
        <div class="alert alert-error"><?= htmlspecialchars($flash_error, ENT_QUOTES, 'UTF-8') ?></div>
        <?php endif; ?>
        <?php if ($flash_success): ?>
        <div class="alert alert-success"><?= htmlspecialchars($flash_success, ENT_QUOTES, 'UTF-8') ?></div>
        <?php endif; ?>

        <div class="profile-card">
            <form method="POST" action="<?= $basePath ?>/profile">
                <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(generateCsrfToken(), ENT_QUOTES, 'UTF-8') ?>">

                <div class="profile-form-grid">
                    <div class="form-group">
                        <label for="name"><?= __('auth.full_name') ?></label>
                        <input type="text" id="name" name="name" value="<?= htmlspecialchars($user['name'] ?? '', ENT_QUOTES, 'UTF-8') ?>" required>
                    </div>

                    <div class="form-group">
                        <label for="email"><?= __('auth.email') ?></label>
                        <input type="email" id="email" name="email" value="<?= htmlspecialchars($user['email'] ?? '', ENT_QUOTES, 'UTF-8') ?>" disabled>
                        <small><?= __('profile.email_cannot_change') ?></small>
                    </div>

                    <div class="form-group">
                        <label for="phone"><?= __('auth.phone') ?></label>
                        <input type="tel" id="phone" name="phone" value="<?= htmlspecialchars($user['phone'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
                    </div>

                    <?php if ($student): ?>
                    <div class="form-group">
                        <label><?= __('dashboard.enrollment_no') ?></label>
                        <input type="text" value="<?= htmlspecialchars($student['enrollment_no'] ?? 'N/A', ENT_QUOTES, 'UTF-8') ?>" disabled>
                    </div>
                    <?php endif; ?>
                </div>

                <div class="profile-actions">
                    <button type="submit" class="btn-primary"><?= __('profile.save') ?></button>
                    <a href="<?= $basePath ?>/dashboard" class="btn-outline"><?= __('profile.back_to_dashboard') ?></a>
                </div>
            </form>
        </div>
    </div>
</section>

<style>
.profile-card { background:#fff; border-radius:12px; padding:2rem; box-shadow:0 2px 8px rgba(0,0,0,.08); max-width:700px; }
.profile-form-grid { display:grid; grid-template-columns:1fr 1fr; gap:1.5rem; }
.form-group { display:flex; flex-direction:column; gap:.5rem; }
.form-group label { font-weight:600; color:#0d2b6e; font-size:.9rem; }
.form-group input { padding:.75rem 1rem; border:1px solid #ddd; border-radius:8px; font-size:1rem; transition:border-color .2s; }
.form-group input:focus { border-color:#1a4fa0; outline:none; box-shadow:0 0 0 3px rgba(26,79,160,.15); }
.form-group input:disabled { background:#f5f5f5; color:#888; cursor:not-allowed; }
.form-group small { color:#888; font-size:.8rem; }
.profile-actions { display:flex; gap:1rem; margin-top:2rem; }
.alert { padding:1rem; border-radius:8px; margin-bottom:1.5rem; }
.alert-error { background:#f8d7da; color:#721c24; }
.alert-success { background:#d4edda; color:#155724; }
@media (max-width:600px) { .profile-form-grid { grid-template-columns:1fr; } }
</style>

<?php include __DIR__ . '/../layouts/footer.php'; ?>
