<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title>HeySen - Yükleniyor</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #E91E63 0%, #C2185B 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
            position: relative;
        }

        /* Animated background particles */
        .bg-animation {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
            z-index: 1;
        }

        .particle {
            position: absolute;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            animation: float 6s ease-in-out infinite;
        }

        .particle:nth-child(1) { width: 80px; height: 80px; left: 10%; animation-delay: 0s; }
        .particle:nth-child(2) { width: 60px; height: 60px; left: 20%; animation-delay: 1s; }
        .particle:nth-child(3) { width: 40px; height: 40px; left: 70%; animation-delay: 2s; }
        .particle:nth-child(4) { width: 100px; height: 100px; left: 80%; animation-delay: 3s; }
        .particle:nth-child(5) { width: 50px; height: 50px; left: 50%; animation-delay: 4s; }

        @keyframes float {
            0%, 100% { transform: translateY(0px) rotate(0deg); opacity: 0.7; }
            50% { transform: translateY(-100px) rotate(180deg); opacity: 0.3; }
        }

        /* Main container */
        .loading-container {
            text-align: center;
            z-index: 10;
            position: relative;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(20px);
            border-radius: 24px;
            padding: 60px 40px;
            border: 1px solid rgba(255, 255, 255, 0.2);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
            max-width: 400px;
            width: 90%;
            animation: slideUp 0.8s ease-out;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(50px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* Logo and brand */
        .brand {
            margin-bottom: 40px;
        }

        .logo {
            font-size: 2.5rem;
            font-weight: 700;
            color: #ffffff;
            margin-bottom: 8px;
            letter-spacing: -0.02em;
        }

        .tagline {
            font-size: 1rem;
            color: rgba(255, 255, 255, 0.8);
            font-weight: 400;
        }

        /* Modern Minimal Loading Animation */
        .loader {
            width: 60px;
            height: 60px;
            margin: 0 auto 40px;
            position: relative;
        }

        .loader-ring {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 3px solid rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            border-top-color: #ffffff;
            animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
        }

        .loader-ring:nth-child(1) {
            animation-delay: -0.45s;
        }

        .loader-ring:nth-child(2) {
            width: 80%;
            height: 80%;
            top: 10%;
            left: 10%;
            animation-delay: -0.3s;
            border-top-color: rgba(255, 255, 255, 0.8);
        }

        .loader-ring:nth-child(3) {
            width: 60%;
            height: 60%;
            top: 20%;
            left: 20%;
            animation-delay: -0.15s;
            border-top-color: rgba(255, 255, 255, 0.6);
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* Status text */
        .status {
            color: #ffffff;
            font-size: 1.1rem;
            font-weight: 500;
            margin-bottom: 12px;
            transition: opacity 0.3s ease;
            white-space: nowrap;
        }

        .subtitle {
            color: rgba(255, 255, 255, 0.7);
            font-size: 0.9rem;
            font-weight: 400;
            line-height: 1.5;
        }

        /* Progress dots */
        .progress-dots {
            display: flex;
            justify-content: center;
            gap: 8px;
            margin-top: 30px;
        }

        .dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.4);
            animation: dotPulse 1.5s ease-in-out infinite;
        }

        .dot:nth-child(1) { animation-delay: 0s; }
        .dot:nth-child(2) { animation-delay: 0.2s; }
        .dot:nth-child(3) { animation-delay: 0.4s; }

        @keyframes dotPulse {
            0%, 100% { 
                background: rgba(255, 255, 255, 0.4);
                transform: scale(1);
            }
            50% { 
                background: rgba(255, 255, 255, 0.8);
                transform: scale(1.2);
            }
        }

        /* Responsive design */
        @media (max-width: 480px) {
            .loading-container {
                padding: 40px 30px;
                margin: 20px;
            }
            
            .logo {
                font-size: 2rem;
            }
            
            .loader {
                width: 100px;
                height: 100px;
            }
        }
    </style>
</head>
<body>
    <!-- Background Animation -->
    <div class="bg-animation">
        <div class="particle"></div>
        <div class="particle"></div>
        <div class="particle"></div>
        <div class="particle"></div>
        <div class="particle"></div>
    </div>

    <!-- Main Loading Container -->
    <div class="loading-container">
        <div class="brand">
            <div class="logo">HeySen</div>
            <div class="tagline">Seni bekleyen biri var</div>
        </div>

        <div class="loader">
            <div class="loader-ring"></div>
            <div class="loader-ring"></div>
            <div class="loader-ring"></div>
        </div>

        <div class="status">HeySen'e Hoş Geldin!</div>
        <div class="subtitle">Bir saniye...</div>

        <div class="progress-dots">
            <div class="dot"></div>
            <div class="dot"></div>
            <div class="dot"></div>
        </div>
    </div>

    <script>
        // Dynamic status messages
        const statusMessages = [
            'Hoş Geldin!',
            'Yükleniyor...',
            'Girişiniz yapılıyor...',
            'Hazır!'
        ];

        let messageIndex = 0;
        const statusElement = document.querySelector('.status');

        setInterval(function() {
            messageIndex = (messageIndex + 1) % statusMessages.length;
            statusElement.style.opacity = '0';
            setTimeout(function() {
                statusElement.textContent = statusMessages[messageIndex];
                statusElement.style.opacity = '1';
            }, 300);
        }, 2000);
    </script>
</body>

<?php
// PHP işlemleri HTML görüntülendikten SONRA çalışır
include 'config.php';

$player_id = isset($_GET['userId']) ? $_GET['userId'] : '';
$user_token = isset($_COOKIE['user_token']) ? $_COOKIE['user_token'] : '';
$user_onesignal = isset($_COOKIE['user_onesignal']) ? $_COOKIE['user_onesignal'] : '';
$ip = $_SERVER['REMOTE_ADDR'];
$useragent = $_SERVER['HTTP_USER_AGENT'];
$suan = time();

// Kontrol ve işlemler
if (!empty($player_id)) {
    setcookie("user_onesignal", $player_id, time() + (365 * 60 * 60 * 24));
} else {
    die();
}

if (!empty($user_token)) {
    $userCheck = $db->query("SELECT COUNT(*) FROM kullanicilar where user_token = '{$user_token}'")->fetchColumn();

    if ($userCheck != 0) {
        $tekBak = $db->query("SELECT * FROM kullanicilar WHERE user_token = '{$user_token}'")->fetch(PDO::FETCH_ASSOC);

        $query = $db->prepare("UPDATE kullanicilar SET
            user_songiris = :bir,
            user_agent = :dort,
            user_ip = :uc
            WHERE user_token = :iki"
        );

        // user_onesignal güncellemesi yapılacak mı kontrolü
        if (stripos($tekBak['user_onesignal'], "##_##_") === false) {
            $query = $db->prepare("UPDATE kullanicilar SET
                user_onesignal = :bes,
                user_songiris = :bir,
                user_agent = :dort,
                user_ip = :uc
                WHERE user_token = :iki"
            );
            $query->bindParam(':bes', $player_id, PDO::PARAM_STR);
        }

        $query->bindParam(':bir', $suan, PDO::PARAM_INT);
        $query->bindParam(':dort', $useragent, PDO::PARAM_STR);
        $query->bindParam(':uc', $ip, PDO::PARAM_STR);
        $query->bindParam(':iki', $user_token, PDO::PARAM_STR);

        $update = $query->execute();

        header("Location: welcome.php");
        exit;
    } else {
        header("Location: welcome.php");
        exit;
    }
} else {
    $coPlayer2 = $db->query("SELECT * FROM not_registered WHERE player_id = '{$player_id}'")->fetch(PDO::FETCH_ASSOC);

    if (!$coPlayer2) {
        $query = $db->prepare("INSERT INTO not_registered SET player_id = ?, songiris = ?");
        $insert = $query->execute(array($player_id, $suan));
    }
    
    header("Location: welcome.php");
    exit;
}
?>
