<div class="content-box">
    <h1><i class="fas fa-user-edit"></i> Editar Usuário</h1>
    
    <div class="page-actions">
        <a href="<?= BASE_URL ?>/paineladmin/usuarios" class="btn btn-secondary">
            <i class="fas fa-arrow-left"></i> Voltar para Usuários
        </a>
    </div>

    <?php if (isset($_SESSION['error_message'])): ?>
        <div class="alert alert-error">
            <i class="fas fa-exclamation-triangle"></i>
            <?= $_SESSION['error_message'] ?>
        </div>
        <?php unset($_SESSION['error_message']); ?>
    <?php endif; ?>

    <?php if (isset($_SESSION['success_message'])): ?>
        <div class="alert alert-success">
            <i class="fas fa-check-circle"></i>
            <?= $_SESSION['success_message'] ?>
        </div>
        <?php unset($_SESSION['success_message']); ?>
    <?php endif; ?>

    <form action="<?= BASE_URL ?>/paineladmin/atualizarUsuario" method="POST" class="user-form">
        <input type="hidden" name="usuario_id" value="<?= htmlspecialchars($usuario['id']) ?>">
        <div class="form-group">
            <label for="nome">Nome Completo:</label>
            <input type="text" id="nome" name="nome" required value="<?= htmlspecialchars($usuario['nome']) ?>">
        </div>

        <div class="form-group">
            <label for="email">Email:</label>
            <input type="email" id="email" name="email" required value="<?= htmlspecialchars($usuario['email']) ?>">
            <small>O email deve ser único no sistema.</small>
        </div>

        <div class="form-group">
            <label for="senha">Senha (opcional):</label>
            <input type="password" id="senha" name="senha" minlength="6">
            <small>Preencha apenas se desejar alterar a senha.</small>
        </div>

        <div class="form-group">
            <label for="nivel_acesso">Nível de Acesso:</label>
            <select id="nivel_acesso" name="nivel_acesso" required>
                <?php foreach ($niveisAcesso as $nivel => $descricao): ?>
                    <option value="<?= htmlspecialchars($nivel) ?>" <?= ($usuario['nivel_acesso'] === $nivel) ? 'selected' : '' ?>>
                        <?= htmlspecialchars($descricao) ?>
                    </option>
                <?php endforeach; ?>
            </select>
        </div>

        <div class="form-actions">
            <button type="submit" class="btn btn-success">
                <i class="fas fa-save"></i> Salvar Alterações
            </button>
            <a href="<?= BASE_URL ?>/paineladmin/usuarios" class="btn btn-secondary">
                Cancelar
            </a>
        </div>
    </form>
</div>

<style>
.user-form {
    max-width: 500px;
    margin: 20px auto;
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
    box-sizing: border-box;
}

.form-group small {
    color: #666;
    font-size: 0.9em;
    margin-top: 5px;
    display: block;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 30px;
}
</style>