<!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">
    <?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">
</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';
?>
    <header class="acct-top">
        <a class="acct-brand-min" href="<?= rtrim($baseUrl, '/') ?>/projects" aria-label="Home">
            <?= \PpPhp\Core\Brand::lockup(30) ?>
        </a>
        <div class="acct-top-actions">
            <a href="<?= rtrim($baseUrl, '/') ?>/projects" class="acct-back"><i class="bi bi-arrow-left"></i> Projects</a>
            <?php include constant('BASE_PATH') . '/core/views/theme-toggle.php'; ?>
        </div>
    </header>

    <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>
