<?php
include ('includes/header.php');

$table_name = 'users';
$res = $db->select($table_name, '*', '', '');

if(isset($_POST['submit'])){
    unset($_POST['submit']);
    $updateData = $_POST;
    $db->update($table_name, $updateData, 'id = :id',[':id' => 1]);
    session_regenerate_id();
    $_SESSION['loggedin'] = true;
    $_SESSION['name'] = $_POST['username'];
    echo "<script>window.location.href='". basename($_SERVER["SCRIPT_NAME"])."?status=1'</script>";
}
?>

<!-- Adicione a classe CSS no <head> ou no arquivo de estilo -->
<style>
.imagem-alerta {
    width: 120%;  /* Ajusta a largura para 100% do contêiner */
    max-width: 300px;  /* Define a largura máxima */
    height: auto;  /* A altura será proporcional */
    margin: 0 auto;  /* Centraliza a imagem */
}
.card {
    margin-top: 20px;
}
</style>

<!-- Container com o Bootstrap para garantir o layout responsivo -->
<div class="col-md-8 col-lg-6 col-xl-4 mx-auto">
    <div class="card-body">
        <div class="card bg-primary text-white">
            <div class="card-header card-header-warning">
                <center>
                    <h2><i class="icon icon-user"></i> Atualizar Credenciais</h2>
                </center>
            </div>
            <div class="alert alert-info alert-dismissible" role="alert">
                <center>
                    <!-- Substitua a mensagem de texto pela imagem -->
                    <img src="img/perfil.png" alt="Aviso Importante" class="imagem-alerta">
                </center>
            </div>

            <div class="card-body">
                <form method="post">
                    <div class="form-group">
                        <div class="form-group form-float form-group-lg">
                            <div class="form-line">
                                <label class="form-label">Nome de usuário</label>
                                <input type="text" class="form-control" name="username" value="<?=$res[0]['username'] ?>">
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="form-group form-float form-group-lg">
                            <div class="form-line">
                                <label class="form-label">Senha</label>
                                <input type="text" class="form-control" name="password" value="<?=$res[0]['password'] ?>">
                            </div>
                        </div>
                    </div>

                    <hr>

                    <center>
                        <button type="submit" name="submit" class="btn btn-info btn-lg">
                            <i class="icon icon-check"></i> Atualizar Credenciais
                        </button>
                    </center>
                </form>
            </div>
        </div>
    </div>
</div>

<?php include ('includes/footer.php'); ?>

</body>
</html>
