<?php include app()->basePath('app/Views/partials/header.php'); ?>

<section class="panel narrow">
    <p class="eyebrow">Utilizador</p>
    <h1><?= e($managedUser['name']) ?></h1>

    <div class="detail-list">
        <div>
            <span>Email</span>
            <strong><?= e($managedUser['email']) ?></strong>
        </div>
        <div>
            <span>Telefone</span>
            <strong><?= e($managedUser['phone'] ?: '-') ?></strong>
        </div>
        <div>
            <span>Perfil</span>
            <strong><?= e(role_label($managedUser['role'])) ?></strong>
        </div>
        <div>
            <span>Estado</span>
            <strong><?= e(status_label($managedUser['status'])) ?></strong>
        </div>
        <div>
            <span>Provincia</span>
            <strong><?= e($managedUser['profile']['province'] ?? '-') ?></strong>
        </div>
        <div>
            <span>Cidade</span>
            <strong><?= e($managedUser['profile']['city'] ?? '-') ?></strong>
        </div>
        <div>
            <span>Ultimo login</span>
            <strong><?= e(format_date($managedUser['last_login_at'] ?? '')) ?></strong>
        </div>
        <div>
            <span>Registado em</span>
            <strong><?= e(format_date($managedUser['created_at'] ?? '')) ?></strong>
        </div>
    </div>

    <?php if (!empty($managedUser['profile']['bio'])): ?>
        <div class="bio-box">
            <span>Bio</span>
            <p><?= e($managedUser['profile']['bio']) ?></p>
        </div>
    <?php endif; ?>

    <div class="actions">
        <a class="ghost-button" href="/admin/users">Voltar</a>

        <?php if ($managedUser['status'] === 'pending'): ?>
            <form method="post" action="/admin/users/approve">
                <?= csrf_field() ?>
                <input type="hidden" name="user_id" value="<?= e((string) $managedUser['id']) ?>">
                <button class="button" type="submit">Aprovar conta</button>
            </form>
        <?php elseif ($managedUser['status'] === 'active' && $managedUser['role'] !== 'admin'): ?>
            <form method="post" action="/admin/users/suspend">
                <?= csrf_field() ?>
                <input type="hidden" name="user_id" value="<?= e((string) $managedUser['id']) ?>">
                <button class="danger-button" type="submit">Suspender conta</button>
            </form>
        <?php elseif (in_array($managedUser['status'], ['suspended', 'rejected'], true)): ?>
            <form method="post" action="/admin/users/activate">
                <?= csrf_field() ?>
                <input type="hidden" name="user_id" value="<?= e((string) $managedUser['id']) ?>">
                <button class="button" type="submit">Activar conta</button>
            </form>
        <?php endif; ?>
    </div>
</section>

<?php include app()->basePath('app/Views/partials/footer.php'); ?>
