<?php

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


session_start();
include('includes/functions.php');
$table_name = "user";

$log_check = $db->select($table_name, '*', 'id = :id', '', [':id' => 1]);
$loggedinuser = !empty($log_check) ? $log_check[0]['username'] : null;

if (!empty($loggedinuser) && isset($_SESSION['name']) && $_SESSION['name'] === $loggedinuser) {
    header("Location: main.php");
    exit;
}

$data = ['id' => '1','username' => 'admin','password' => 'admin',];
$db->insertIfEmpty($table_name, $data);

$error_message = '';

if (isset($_POST["login"])) {
    if (empty($_POST["username"]) || empty($_POST["password"])) {
        $error_message = 'Por favor, preencha todos os campos!';
    } else {
        $username = trim($_POST["username"]);
        $password = trim($_POST["password"]);
        
        $userData = $db->select($table_name, '*', 'username = :username', '', [':username' => $username]);
        
        if ($userData && !empty($userData)) {
            $storedPassword = $userData[0]['password'];
            if ($password === $storedPassword) {
                session_regenerate_id();
                $_SESSION['loggedin'] = TRUE;
                $_SESSION['name'] = $username;
                
                if ($username === 'admin') {
                    header('Location: user.php');
                    exit;
                } else {
                    header('Location: main.php');
                    exit;
                }
            } else {
                $error_message = 'Usuário ou senha incorretos!';
            }
        } else {
            $error_message = 'Usuário ou senha incorretos!';
        }
    }
    
    if (!empty($error_message)) {
        $db->close();
    }
}

?>
<!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">
    <meta name="author" content="Onplay">
    <link rel="icon" type="image/x-icon" href="assets/images/logos.png">
    <link rel="apple-touch-icon" sizes="180x180" href="./img/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="./img/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="./img/favicon-16x16.png">
    <link rel="manifest" href="./img/site.webmanifest">
    <title>ADOO IPTV | PANEL ADM</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
    @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700&family=Montserrat:wght@300;400;500;600&display=swap');
    
    :root {
        --primary: #00f3ff;
        --secondary: #7700ff;
        --dark: #0a0a0f;
        --light: #f0f8ff;
        --glow: 0 0 15px rgba(0, 243, 255, 0.5);
    }
    
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    body {
        font-family: 'Montserrat', sans-serif;
        background: var(--dark);
        color: var(--light);
        min-height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        background: linear-gradient(45deg, #0a0a0f, #141421);
    }
    
    .login-box {
        width: 90%;
        max-width: 400px;
        background: rgba(15, 15, 25, 0.95);
        border-radius: 20px;
        padding: 40px 30px;
        border: 1px solid rgba(0, 243, 255, 0.2);
        box-shadow: 0 0 50px rgba(0, 243, 255, 0.1),
                    0 20px 60px rgba(0, 0, 0, 0.5);
        position: relative;
        z-index: 10;
        text-align: center;
    }
    
    .login-box::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 2px;
        background: linear-gradient(90deg, transparent, var(--primary), transparent);
        animation: scanline 3s linear infinite;
    }
    
    @keyframes scanline {
        0% { left: -100%; }
        100% { left: 100%; }
    }

    .header-image {
        width: 120px;
        height: auto;
        margin: 0 auto 20px;
        display: block;
        filter: drop-shadow(0 0 10px var(--primary));
    }
    
    .logo {
        margin-bottom: 40px;
    }
    
    .logo h1 {
        font-family: 'Orbitron', sans-serif;
        font-size: 2.2rem;
        background: linear-gradient(45deg, var(--primary), var(--secondary));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-bottom: 10px;
    }
    
    .logo p {
        color: rgba(240, 248, 255, 0.6);
        font-size: 0.9rem;
        letter-spacing: 2px;
    }
    
    .error-message {
        background: rgba(255, 0, 0, 0.1);
        border: 1px solid rgba(255, 0, 0, 0.3);
        color: #ff6b6b;
        padding: 12px 15px;
        border-radius: 8px;
        margin-bottom: 20px;
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        animation: slideDown 0.3s ease-out;
    }
    
    @keyframes slideDown {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }
    
    .input-group {
        margin-bottom: 25px;
        position: relative;
        text-align: left;
    }
    
    .input-group i {
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--primary);
        font-size: 16px;
    }
    
    .input-group input {
        width: 100%;
        padding: 15px 15px 15px 45px;
        background: rgba(0, 0, 0, 0.3);
        border: 2px solid transparent;
        border-radius: 10px;
        color: var(--light);
        font-size: 15px;
        transition: all 0.3s;
    }
    
    .input-group input:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: var(--glow);
    }
    
    .input-group input::placeholder {
        color: rgba(240, 248, 255, 0.5);
    }
    
    .login-btn {
        width: 100%;
        padding: 16px;
        background: linear-gradient(45deg, var(--primary), var(--secondary));
        border: none;
        border-radius: 10px;
        color: #000;
        font-family: 'Orbitron', sans-serif;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-top: 20px;
    }
    
    .login-btn:hover:not(:disabled) {
        transform: translateY(-2px);
        box-shadow: 0 10px 20px rgba(0, 243, 255, 0.3);
    }
    
    .login-btn:disabled {
        opacity: 0.7;
        cursor: not-allowed;
    }
    
    .play-link {
        margin-top: 25px;
    }
    
    .play-link a {
        color: var(--primary);
        text-decoration: none;
        font-size: 14px;
        transition: all 0.3s;
        padding: 8px 15px;
        border-radius: 5px;
        background: rgba(0, 243, 255, 0.1);
        display: inline-block;
    }
    
    .play-link a:hover {
        background: rgba(0, 243, 255, 0.2);
    }
    
    .floating {
        position: fixed;
        width: 100%;
        height: 100%;
        pointer-events: none;
        z-index: 1;
    }
    
    .floating div {
        position: absolute;
        width: 3px;
        height: 3px;
        background: var(--primary);
        border-radius: 50%;
        animation: float 15s infinite linear;
        opacity: 0.3;
    }
    
    @keyframes float {
        0% { transform: translate(0, 0) rotate(0deg); }
        100% { transform: translate(100px, 100px) rotate(360deg); }
    }
    </style>
</head>
<body>
    <div class="floating">
        <div style="top: 20%; left: 10%;"></div>
        <div style="top: 60%; left: 80%;"></div>
        <div style="top: 40%; left: 40%;"></div>
    </div>
    
    <div class="login-box">
        <!-- IMAGEM ACIMA DO TITULO -->
        <img src="./assets/images/logos.png" alt="Logo" class="header-image" onerror="this.style.display='none'">
        
        <div class="logo">
            <h1>SKY WAVE IPV</h1>
            <p>PANEL ADM</p>
        </div>
        
        <?php if (!empty($error_message)): ?>
            <div class="error-message">
                <i class="fas fa-exclamation-circle"></i>
                <?php echo htmlspecialchars($error_message); ?>
            </div>
        <?php endif; ?>
        
        <form method="post" action="">
            <div class="input-group">
                <i class="fas fa-user"></i>
                <input 
                    type="text" 
                    name="username" 
                    placeholder="Username" 
                    required
                    autocomplete="off"
                    value="<?php echo isset($_POST['username']) ? htmlspecialchars($_POST['username']) : ''; ?>"
                >
            </div>
            
            <div class="input-group">
                <i class="fas fa-lock"></i>
                <input 
                    type="password" 
                    name="password" 
                    placeholder="Password" 
                    required
                    autocomplete="off"
                >
            </div>
            
            <button type="submit" name="login" class="login-btn">
                <i class="fas fa-sign-in-alt"></i> LOGIN
            </button>
            
            <div class="play-link">
                <a href="https://t.me/eonbry">
                    <i class="fas fa-message"></i> Developer Contact
                </a>
                
            </div>
            <br>
            <p> Developer: eonbry _@2025</p>
        </form>
    </div>
    
    <script>
    for (let i = 0; i < 20; i++) {
        const div = document.createElement('div');
        div.style.cssText = `
            top: ${Math.random() * 100}%;
            left: ${Math.random() * 100}%;
            animation-delay: -${Math.random() * 15}s;
            width: ${1 + Math.random() * 5}px;
            height: ${1 + Math.random() * 5}px;
            opacity: ${0.1 + Math.random() * 0.2};
        `;
        document.querySelector('.floating').appendChild(div);
    }
    </script>
</body>
</html>
