<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <?php $assetsUrl = $assetsUrl ?? rtrim($baseUrl, '/'); ?>
    <title>Your profile · <?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?></title>
    <?php include constant('BASE_PATH') . '/core/views/favicon.php'; ?>
    <link href="<?= $assetsUrl ?>/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?= $assetsUrl ?>/icons/bootstrap-icons.css" rel="stylesheet">
    <script src="<?= $assetsUrl ?>/bootstrap/js/bootstrap.bundle.min.js" defer></script>
    <?php include constant('BASE_PATH') . '/core/views/theme-head.php'; ?>
    <link href="<?= $assetsUrl ?>/css/account.css?v=<?= (int) @filemtime(constant('BASE_PATH') . '/public/assets/css/account.css') ?>" rel="stylesheet">
    <style>body { padding-top: 56px; }</style>
</head>
<body class="acct-body">
<?php
    $__uname = (string)($user['username'] ?? 'User');
    $__parts = preg_split('/[^A-Za-z0-9]+/', $__uname, -1, PREG_SPLIT_NO_EMPTY) ?: [$__uname];
    $__initials = strtoupper(substr($__parts[0], 0, 1) . (isset($__parts[1]) ? substr($__parts[1], 0, 1) : substr($__parts[0], 1, 1)));
    $__initials = $__initials !== '' ? $__initials : 'U';
?>
<?php
    $user = $user ?? \PpPhp\Core\Security::CurrentUserData();
    $navBrandLabel = 'Your profile';
    $navBrandIcon  = 'person-circle';
    $navBack = ['url' => rtrim($baseUrl, '/') . '/projects', 'label' => 'Projects', 'icon' => 'arrow-left'];
    include constant('BASE_PATH') . '/core/views/console-navbar.php';
?>

    <main class="acct-main">
        <div class="acct-card">
            <div class="acct-head">
                <div class="acct-avatar"><?= htmlspecialchars($__initials) ?></div>
                <div class="acct-head-copy">
                    <div class="acct-eyebrow">Account</div>
                    <h1 class="acct-title">Your profile</h1>
                    <p class="acct-sub">Manage the email tied to your <?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?> account.</p>
                </div>
            </div>

            <?php if (!empty($success)): ?>
                <div class="acct-alert is-success"><i class="bi bi-check-circle-fill"></i><span><?= htmlspecialchars($success) ?></span></div>
            <?php endif; ?>
            <?php if (!empty($error)): ?>
                <div class="acct-alert is-error"><i class="bi bi-exclamation-triangle-fill"></i><span><?= htmlspecialchars($error) ?></span></div>
            <?php endif; ?>

            <form method="post" action="<?= rtrim($baseUrl, '/') ?>/profile">
                <div class="acct-field">
                    <label class="acct-label">Username</label>
                    <input type="text" class="acct-input" value="<?= htmlspecialchars($__uname) ?>" disabled>
                    <div class="acct-hint"><i class="bi bi-lock-fill"></i> Your username can't be changed.</div>
                </div>
                <div class="acct-field">
                    <label class="acct-label" for="acct-email">Email address</label>
                    <input id="acct-email" type="email" name="email" class="acct-input" value="<?= htmlspecialchars($user['email'] ?? '') ?>" placeholder="you@example.com" required>
                    <div class="acct-hint"><i class="bi bi-envelope"></i> Used for sign-in recovery and account notices.</div>
                </div>
                <div class="acct-actions">
                    <button type="submit" class="acct-btn acct-btn-primary"><i class="bi bi-check-lg"></i> Update email</button>
                    <a href="<?= rtrim($baseUrl, '/') ?>/change-password" class="acct-btn acct-btn-ghost"><i class="bi bi-key"></i> Change password</a>
                    <a href="<?= rtrim($baseUrl, '/') ?>/account/security" class="acct-btn acct-btn-ghost"><i class="bi bi-shield-lock"></i> Two-factor auth</a>
                </div>
            </form>
        </div>
    </main>

    <footer class="acct-foot"><?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?><?php $__tg = \PpPhp\Core\Brand::tagline(); if ($__tg !== ''): ?> · <?= htmlspecialchars($__tg) ?><?php endif; ?></footer>
    <script src="<?= $assetsUrl ?>/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>
