<?php

//<----------------------------------------------------------->
//<-------------------COPIA AI BRUXÃO------------------------->
//<-------------CONTATO: https://t.me/eonbry------------------>
//<-------------DEVELOPER: EMANUEL NASCIMENTO----------------->
//<----------------------------------------------------------->


include ('includes/header.php');

$table_name = 'user';
$page = 'user.php';
$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='".$page."?status=1'</script>";
}
?>

<style>
    :root {
        --deep-blue: #0a0f1a;
        --dark-gray: #1e293b;
        --accent-blue: #3b82f6;
        --text-main: #e2e8f0;
        --text-muted: #94a3b8;
        --glass-bg: rgba(30, 41, 59, 0.7);
        --glass-border: rgba(255, 255, 255, 0.08);
    }

    body {
        background-color: var(--deep-blue);
        background-image: linear-gradient(135deg, #0a0f1a 0%, #111827 100%);
        color: var(--text-main);
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
        min-height: 100vh;
        margin: 0;
    }

    .futuristic-container {
        padding: 60px 20px;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .glass-card {
        background: var(--glass-bg);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border: 1px solid var(--glass-border);
        border-radius: 20px;
        padding: 45px;
        width: 100%;
        max-width: 480px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    }

    .header-section {
        text-align: center;
        margin-bottom: 35px;
    }

    .header-section h2 {
        font-size: 1.75rem;
        font-weight: 700;
        color: #ffffff;
        margin-bottom: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
    }

    .header-section p {
        color: var(--text-muted);
        font-size: 0.95rem;
    }

    .warning-banner {
        background: rgba(245, 158, 11, 0.05);
        border: 1px solid rgba(245, 158, 11, 0.2);
        padding: 12px;
        border-radius: 10px;
        margin-bottom: 30px;
        font-size: 0.85rem;
        color: #d1d5db;
        text-align: center;
    }

    .warning-banner strong {
        color: #fbbf24;
    }

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

    .form-label {
        display: block;
        color: var(--text-muted);
        margin-bottom: 10px;
        font-size: 0.8rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    .form-control {
        background: rgba(15, 23, 42, 0.6);
        border: 1px solid var(--glass-border);
        border-radius: 10px;
        padding: 14px 18px;
        color: #ffffff;
        width: 100%;
        transition: all 0.2s ease;
        outline: none;
        font-size: 1rem;
    }

    .form-control:focus {
        border-color: var(--accent-blue);
        background: rgba(15, 23, 42, 0.8);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    }

    .btn-submit {
        background: #3b82f6;
        color: white;
        border: none;
        border-radius: 10px;
        padding: 16px;
        width: 100%;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
    }

    .btn-submit:hover {
        background: #2563eb;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    }

    .btn-submit:active {
        transform: translateY(0);
    }

    .icon-style {
        color: var(--accent-blue);
        font-size: 1.2rem;
    }

    hr {
        border: 0;
        border-top: 1px solid var(--glass-border);
        margin: 25px 0;
    }
</style>

<div class="futuristic-container">
    <div class="glass-card">
        <div class="header-section">
            <h2>
                <i class="icon icon-user icon-style"></i> 
                <span>Segurança da Conta</span>
            </h2>
            <p>Gerencie suas credenciais de acesso</p>
        </div>

        <div class="warning-banner">
            Atenção: Evite usar <strong>admin</strong> como usuário ou senha.
        </div>

        <form method="post">
            <div class="form-group">
                <label class="form-label">Nome de Usuário</label>
                <input type="text" class="form-control" name="username" value="<?=$res[0]['username'] ?>" autocomplete="off">
            </div>

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

            <hr>

            <button type="submit" name="submit" class="btn-submit">
                <i class="icon icon-check"></i>
                Salvar Alterações
            </button>
        </form>
    </div>
</div>
<script>
    // Função para criar e exibir alertas que desaparecem sozinhos
function createAlert(title, message, type) {
    const container = document.getElementById('pageMessages');
    if (!container) return;

    // Criar o elemento do alerta
    const alertDiv = document.createElement('div');
    alertDiv.className = `alert alert-${type} alert-dismissible fade show`;
    alertDiv.role = 'alert';
    alertDiv.style.boxShadow = '0 10px 30px rgba(0,0,0,0.3)';
    alertDiv.style.borderRadius = '12px';
    alertDiv.style.border = 'none';
    alertDiv.style.background = type === 'success' ? 'rgba(16, 185, 129, 0.9)' : 'rgba(239, 68, 68, 0.9)';
    alertDiv.style.color = '#fff';
    alertDiv.style.backdropFilter = 'blur(10px)';
    alertDiv.style.marginBottom = '10px';

    alertDiv.innerHTML = `
        <strong>${title}</strong> ${message}
        <button type="button" class="close" data-dismiss="alert" aria-label="Close" style="color: #fff; opacity: 0.8;">
            <span aria-hidden="true">&times;</span>
        </button>
    `;

    // Adicionar ao container
    container.appendChild(alertDiv);

    // AUTO-OCULTAR APÓS 2 SEGUNDOS (2000ms)
    setTimeout(function() {
        $(alertDiv).fadeTo(500, 0).slideUp(500, function(){
            $(this).remove(); 
        });
    }, 1000);
}

// Verificar se existe status na URL ao carregar a página
$(document).ready(function() {
    const urlParams = new URLSearchParams(window.location.search);
    if (urlParams.has('status')) {
        const status = urlParams.get('status');
        if (status == '1') {
            createAlert('Sucesso!', 'As credenciais foram atualizadas com êxito.', 'success');
        } else if (status == '0') {
            createAlert('Erro!', 'Ocorreu um problema ao atualizar os dados.', 'danger');
        }
        
        // Limpar o parâmetro da URL sem recarregar a página
        const newUrl = window.location.pathname;
        window.history.replaceState({}, document.title, newUrl);
    }
});

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