<?php
session_start();
$IIIIIIIllIII = file_get_contents('./includes/eggzie.json');
$IIIIIIIllIIl = json_decode($IIIIIIIllIII, true);
$IIIIIIIllII1 = $IIIIIIIllIIl['info'];
$IIIIIIIllIlI = $IIIIIIIllII1['aa'];

$IIIIIIIl1I1I = new SQLite3('./a/.eggziepanels.db');
$IIIIIIIl1I1I->exec('CREATE TABLE IF NOT EXISTS USERS(id INT PRIMARY KEY,NAME TEXT,USERNAME TEXT,PASSWORD TEXT,LOGO TEXT)');
$IIIIIIIl1I1l = $IIIIIIIl1I1I->query('SELECT COUNT(*) as count FROM USERS');
$IIIIIIIIII1l = $IIIIIIIl1I1l->fetchArray();
$IIIIIIIl1I11 = $IIIIIIIIII1l['count'];

if ($IIIIIIIl1I11 == 0) {
    $IIIIIIIl1I1I->exec('INSERT INTO USERS(id,NAME,USERNAME,PASSWORD,LOGO) VALUES(\'1\',\'Your Name\',\'admin\',\'admin\',\'img/logo.png\')');
}

$IIIIIIIl1lII = $IIIIIIIl1I1I->query('SELECT * FROM USERS WHERE id=\'1\'');
$IIIIIIIl1lIl = $IIIIIIIl1lII->fetchArray();
$IIIIIIIl1lI1 = $IIIIIIIl1lIl['NAME'];
$IIIIIIIl1llI = $IIIIIIIl1lIl['LOGO'];

if (isset($_POST['login'])) {
    $query = 'SELECT * FROM USERS WHERE USERNAME="' . $_POST['username'] . '"';
    $result = $IIIIIIIl1I1I->query($query);
    $user = $result->fetchArray();

    if (!$user) {
        $msg = '<div class="alert alert-danger text-center mt-2">❌ Usuário inválido!</div>';
    } else if ($user['PASSWORD'] == $_POST['password']) {
        $_SESSION['eggzie_iboPlayer'] = true;
        $_SESSION['id'] = $user['id'];
        header('Location: users.php');
        exit();
    } else {
        $msg = '<div class="alert alert-danger text-center mt-2">❌ Senha incorreta!</div>';
    }
}
?>

<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>IBO PRO - Login</title>
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,300,400,600,700,800,900" rel="stylesheet">
<link href="css/sb-admin-<?= $IIIIIIIllIlI ?>.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">

<style>
html, body {
    height: 100%;
    margin: 0;
    font-family: 'Nunito', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1e3c72, #2a5298);
}
.login-wrapper {
    width: 100%;
    max-width: 500px;
    padding: 40px;
    border-radius: 15px;
    background: rgba(0,0,0,0.7);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    color: #fff;
    text-align: center;
}
.login-wrapper img {
    width: 120px;
    height: 120px;
    margin-bottom: 20px;
    border-radius: 50%;
    object-fit: cover;
}
.login-wrapper h2 {
    margin-bottom: 25px;
}
.login-wrapper form input {
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 10px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 1em;
}
.login-wrapper form input::placeholder {
    color: rgba(255,255,255,0.7);
}
.login-wrapper form button {
    width: 100%;
    padding: 15px;
    border-radius: 10px;
    background-color: #ff9800;
    border: none;
    color: #fff;
    font-weight: bold;
    font-size: 1.1em;
}
.login-wrapper form button:hover {
    background-color: #e68900;
}
.login-wrapper .time-display {
    margin-top: 20px;
    font-size: 0.95em;
    color: #fdd835;
}
@media (max-width: 576px) {
    .login-wrapper {
        padding: 30px 20px;
    }
    .login-wrapper img {
        width: 100px;
        height: 100px;
    }
}
</style>
</head>
<body>

<div class="login-wrapper">
    <?php if($IIIIIIIl1llI): ?>
        <img src="<?= $IIIIIIIl1llI ?>" alt="Logo">
    <?php else: ?>
        <img src="img/logo.png" alt="Logo">
    <?php endif; ?>

    <h2><strong>IBO PRO</strong></h2>

    <?php if(isset($msg)) echo $msg; ?>

    <form method="post">
        <input type="text" name="username" placeholder="Usuário" required autofocus>
        <input type="password" name="password" placeholder="Senha" required>
        <button type="submit" name="login">ENTRAR</button>
    </form>

    <div class="time-display">
        Hora de acesso: <i><?= date('d-m-Y H:i:s') ?></i>
    </div>
</div>

<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>