<?php
/*
|--------------------------------------------------------------------------
| RadyoHost.BiZ / Profesyonel Radyo Hosting ve Web Tasarım Hizmetleri
|--------------------------------------------------------------------------
*/

/*
|--------------------------------------------------------------------------
| KAYIT SAYFASI
|--------------------------------------------------------------------------
| register.php
| RadyoHost Okey Premium Yeni Üye Kayıt Sayfası
| Developed By VoLKaN75
|--------------------------------------------------------------------------
*/

declare(strict_types=1);

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

require_once __DIR__ . '/config/db.php';

function site_e($value): string
{
    return htmlspecialchars((string)$value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

$message = '';
$messageType = '';
$isRegistered = false;

$userCount = 0;
$packageCount = 0;
$announcementCount = 0;

$logoImage = 'uploads/site/logo.png';
$heroBgImage = 'uploads/site/register-hero.webp';

try {
    if (isset($pdo) && $pdo instanceof PDO) {
        try {
            $userCount = (int)$pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
        } catch (Throwable $e) {}

        try {
            $packageCount = (int)$pdo->query("SELECT COUNT(*) FROM packages WHERE status IN ('active','aktif','1')")->fetchColumn();
        } catch (Throwable $e) {}

        try {
            $announcementCount = (int)$pdo->query("SELECT COUNT(*) FROM announcements")->fetchColumn();
        } catch (Throwable $e) {}
    }
} catch (Throwable $e) {}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($pdo) && $pdo instanceof PDO) {
    $name      = trim((string)($_POST['name'] ?? ''));
    $username  = trim((string)($_POST['username'] ?? ''));
    $email     = trim((string)($_POST['email'] ?? ''));
    $phone     = trim((string)($_POST['phone'] ?? ''));
    $password  = trim((string)($_POST['password'] ?? ''));
    $password2 = trim((string)($_POST['password_confirm'] ?? ''));
    $agreement = isset($_POST['agreement']);

    if ($name === '' || $username === '' || $email === '' || $password === '') {
        $message = 'Ad soyad, kullanıcı adı, e-posta ve şifre zorunludur.';
        $messageType = 'error';
    } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $message = 'Geçerli bir e-posta adresi yazınız.';
        $messageType = 'error';
    } elseif ($password !== $password2) {
        $message = 'Şifre tekrar alanı eşleşmiyor.';
        $messageType = 'error';
    } elseif (strlen($password) < 6) {
        $message = 'Şifre en az 6 karakter olmalıdır.';
        $messageType = 'error';
    } elseif (!$agreement) {
        $message = 'Kullanım şartlarını ve üyelik kurallarını kabul etmelisiniz.';
        $messageType = 'error';
    } else {
        try {
            $check = $pdo->prepare("
                SELECT COUNT(*)
                FROM users
                WHERE username = ? OR email = ?
            ");
            $check->execute([$username, $email]);

            if ((int)$check->fetchColumn() > 0) {
                throw new RuntimeException('Bu kullanıcı adı veya e-posta zaten kayıtlı.');
            }

            $stmt = $pdo->prepare("
                INSERT INTO users
                (name, username, email, phone, password, role, status, created_at)
                VALUES (?, ?, ?, ?, ?, 'user', 'active', NOW())
            ");

            $stmt->execute([
                $name,
                $username,
                $email,
                $phone,
                password_hash($password, PASSWORD_DEFAULT)
            ]);

            $message = 'Üyelik başarıyla oluşturuldu. 3 saniye sonra giriş sayfasına yönlendiriliyorsunuz.';
            $messageType = 'success';
            $isRegistered = true;
            $_POST = [];
        } catch (Throwable $e) {
            $message = $e->getMessage();
            $messageType = 'error';
        }
    }
}
?>
<!doctype html>
<html lang="tr">
<head>
<meta charset="utf-8">
<title>RadyoHost Okey | Kayıt Ol</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="RadyoHost Okey premium üyelik kayıt sayfası. Hemen kayıt ol, oyuna katıl.">

<?php if ($isRegistered): ?>
<meta http-equiv="refresh" content="3;url=login.php">
<?php endif; ?>

<style>
*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{margin:0;font-family:Arial,Helvetica,sans-serif;background:#070911;color:#fff}
a{text-decoration:none;color:inherit}
.site-wrap{min-height:100vh;background:radial-gradient(circle at top left,rgba(245,182,66,.24),transparent 34%),radial-gradient(circle at top right,rgba(185,0,0,.26),transparent 36%),linear-gradient(180deg,#070911,#10131f 48%,#070911)}
.container{width:min(1180px,92%);margin:auto}

.topbar{position:sticky;top:0;z-index:999;backdrop-filter:blur(22px);background:linear-gradient(135deg,rgba(7,9,17,.94),rgba(16,19,31,.88));border-bottom:1px solid rgba(255,255,255,.09);box-shadow:0 18px 60px rgba(0,0,0,.25)}
.nav{min-height:88px;display:flex;align-items:center;justify-content:space-between;gap:22px;position:relative}
.logo{display:flex;align-items:center;min-width:240px;position:relative;z-index:1001}
.logo-img{max-width:250px;max-height:76px;object-fit:contain;display:block;filter:drop-shadow(0 10px 22px rgba(245,182,66,.18))}
.menu{flex:1;display:flex;justify-content:center;align-items:center;gap:8px;padding:8px;border-radius:24px;background:rgba(255,255,255,.045);border:1px solid rgba(255,255,255,.07)}
.menu a{height:46px;display:inline-flex;align-items:center;justify-content:center;gap:7px;padding:0 15px;border-radius:17px;color:#dce3ef;font-size:14px;font-weight:900;transition:.25s;white-space:nowrap}
.menu a:hover{color:#fff;background:rgba(245,182,66,.12);transform:translateY(-2px)}
.menu a.active{color:#111;background:linear-gradient(135deg,#f5b642,#ffcf6a);box-shadow:0 12px 28px rgba(245,182,66,.22)}
.actions{display:flex;gap:10px}
.btn{min-height:48px;padding:0 20px;border-radius:17px;display:inline-flex;align-items:center;justify-content:center;gap:8px;font-weight:1000;border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.06);color:#fff;transition:.25s}
.btn:hover{transform:translateY(-2px)}
.btn-gold{color:#111;background:linear-gradient(135deg,#f5b642,#ffcf6a);box-shadow:0 15px 34px rgba(245,182,66,.22)}

.mobile-menu-btn{display:none;width:52px;height:52px;border:none;border-radius:16px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.12);cursor:pointer;padding:0;align-items:center;justify-content:center;flex-direction:column;gap:5px;position:relative;z-index:1001;transition:.25s}
.mobile-menu-btn span{width:25px;height:3px;background:#fff;border-radius:20px;transition:.3s}
.mobile-menu-btn.active{background:linear-gradient(135deg,#f5b642,#ffcf6a)}
.mobile-menu-btn.active span{background:#111}
.mobile-menu-btn.active span:nth-child(1){transform:translateY(8px) rotate(45deg)}
.mobile-menu-btn.active span:nth-child(2){opacity:0}
.mobile-menu-btn.active span:nth-child(3){transform:translateY(-8px) rotate(-45deg)}

.page-hero{
    position:relative;
    overflow:hidden;
    padding:74px 0 54px;
    border-bottom:1px solid rgba(245,182,66,.18);
    background:
        linear-gradient(90deg,rgba(0,0,0,.88) 0%,rgba(0,0,0,.70) 44%,rgba(0,0,0,.48) 100%),
        url('<?= site_e($heroBgImage) ?>') center center/cover no-repeat;
}
.page-hero:before{
    content:"";
    position:absolute;
    inset:0;
    background:
        radial-gradient(circle at 18% 28%,rgba(245,182,66,.18),transparent 30%),
        linear-gradient(90deg,rgba(0,0,0,.30),rgba(0,0,0,.08));
}
.page-hero .container{position:relative;z-index:2}
.badge{display:inline-flex;padding:10px 15px;border-radius:999px;background:rgba(245,182,66,.13);border:1px solid rgba(245,182,66,.25);color:#f5b642;font-weight:1000;margin-bottom:18px}
.page-hero h1{font-size:clamp(42px,6vw,74px);line-height:1.02;margin:0;letter-spacing:-1.7px;text-transform:uppercase}
.page-hero h1 span{color:#f5b642;text-shadow:0 0 35px rgba(245,182,66,.35)}
.page-hero p{margin:18px 0 0;max-width:760px;color:#dce3ef;font-size:18px;font-weight:800;line-height:1.7}
.hero-buttons{display:flex;gap:14px;flex-wrap:wrap;margin-top:26px}

.stats{display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin-top:-32px;position:relative;z-index:5}
.stat{padding:23px 22px;border-radius:22px;background:rgba(10,10,10,.92);border:1px solid rgba(255,255,255,.13);box-shadow:0 24px 70px rgba(0,0,0,.35)}
.stat strong{display:block;color:#f5b642;font-size:31px;margin-bottom:6px}
.stat span{color:#cfd6e3;font-size:13px;font-weight:900}

.section{padding:58px 0}
.register-card{max-width:980px;margin:auto;padding:34px;border-radius:38px;background:rgba(255,255,255,.055);border:1px solid rgba(255,255,255,.08);box-shadow:0 24px 80px rgba(0,0,0,.22)}
.register-card h2{margin:0 0 10px;font-size:36px;color:#fff}
.register-card p{margin:0 0 24px;color:#aeb7c7;line-height:1.7;font-weight:700}

.alert{padding:15px 18px;border-radius:17px;font-weight:900;margin-bottom:18px}
.alert.error{background:rgba(185,0,0,.20);border:1px solid rgba(255,80,80,.30);color:#ffdede}
.alert.success{background:rgba(0,150,70,.20);border:1px solid rgba(0,255,120,.30);color:#d8ffe8}

.form-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:16px}
.form-group label{display:block;margin-bottom:8px;color:#dce3ef;font-size:14px;font-weight:900}
.form-control{width:100%;height:56px;border:1px solid rgba(255,255,255,.12);border-radius:18px;background:rgba(0,0,0,.25);color:#fff;padding:0 16px;outline:none;font-weight:800}
.form-control:focus{border-color:#f5b642;box-shadow:0 0 0 4px rgba(245,182,66,.12)}
.check-row{display:flex;align-items:flex-start;gap:10px;color:#cbd2df;font-size:14px;font-weight:800;line-height:1.5;margin:18px 0}
.submit-btn{width:100%;border:0;cursor:pointer;font-size:15px}

.package-mini{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;margin-top:18px}
.mini-card{padding:14px;border-radius:19px;background:rgba(0,0,0,.24);border:1px solid rgba(255,255,255,.08);text-align:center}
.mini-card em{display:block;font-style:normal;font-size:24px;margin-bottom:6px}
.mini-card strong{display:block;color:#f5b642;font-size:12px}

.login-box{margin-top:18px;padding:20px;border-radius:24px;background:linear-gradient(135deg,rgba(245,182,66,.10),rgba(185,0,0,.08)),rgba(255,255,255,.045);border:1px solid rgba(255,255,255,.08)}
.login-box strong{display:block;color:#f5b642;font-size:20px;margin-bottom:8px}
.login-box span{display:block;color:#cbd2df;line-height:1.6;font-weight:700;margin-bottom:14px}

.register-extra{display:grid;grid-template-columns:repeat(3,1fr);gap:18px}
.extra-card{position:relative;overflow:hidden;min-height:175px;padding:24px;border-radius:28px;background:rgba(255,255,255,.055);border:1px solid rgba(255,255,255,.08);box-shadow:0 22px 65px rgba(0,0,0,.18);transition:.25s}
.extra-card:hover{transform:translateY(-5px);border-color:rgba(245,182,66,.35)}
.extra-card:before{content:"";position:absolute;width:160px;height:160px;border-radius:50%;right:-70px;top:-70px;background:rgba(245,182,66,.12)}
.extra-icon{position:relative;width:56px;height:56px;border-radius:20px;display:flex;align-items:center;justify-content:center;background:linear-gradient(135deg,rgba(245,182,66,.25),rgba(185,0,0,.18));border:1px solid rgba(255,255,255,.10);font-size:26px;margin-bottom:16px}
.extra-card strong{position:relative;display:block;color:#f5b642;font-size:19px;margin-bottom:9px}
.extra-card span{position:relative;display:block;color:#aeb7c7;font-size:14px;line-height:1.7;font-weight:700}

.cta-box{padding:34px;border-radius:36px;background:radial-gradient(circle at top right,rgba(245,182,66,.23),transparent 36%),linear-gradient(135deg,rgba(255,255,255,.08),rgba(255,255,255,.035));border:1px solid rgba(255,255,255,.10);display:flex;justify-content:space-between;align-items:center;gap:22px}
.cta-box h2{margin:0;color:#fff;font-size:30px}
.cta-box p{margin:8px 0 0;color:#aeb7c7;font-weight:800}

.footer{margin-top:40px;padding:22px 30px;border-top:1px solid rgba(255,255,255,.08);display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:18px;color:#9aa3b2;font-size:13px;font-weight:900}
.footer a{color:#f5b642}
.footer-center{color:#f5b642}
.footer-right{display:flex;justify-content:flex-end;align-items:center;color:#ff5db1}
.footer-right img{width:52px;height:52px;object-fit:contain;margin-left:-2px;filter:drop-shadow(0 0 10px rgba(37,211,102,.8))}

@media(max-width:1100px){
    .nav{padding:14px 0}
    .actions{gap:8px}
    .btn{padding:0 15px;font-size:13px}
    .menu a{padding:0 12px;font-size:13px}
}

@media(max-width:980px){
    .stats,.register-extra{grid-template-columns:repeat(2,1fr)}
    .cta-box{display:block}
    .cta-box .btn{margin-top:18px}
}

@media(max-width:768px){
    .topbar{overflow:visible}
    .nav{min-height:82px;padding:12px 0;gap:12px;flex-wrap:nowrap}
    .logo{min-width:auto;flex:1}
    .logo-img{max-width:210px;max-height:68px}
    .mobile-menu-btn{display:flex}
    .menu{position:absolute;top:100%;left:0;right:0;width:100%;flex-direction:column;justify-content:flex-start;align-items:stretch;gap:8px;padding:16px;border-radius:0 0 24px 24px;background:linear-gradient(180deg,rgba(7,9,17,.99),rgba(16,19,31,.98));border:1px solid rgba(245,182,66,.20);border-top:none;box-shadow:0 28px 70px rgba(0,0,0,.55);display:none;z-index:1000}
    .menu.active{display:flex}
    .menu a{width:100%;height:54px;justify-content:flex-start;padding:0 18px;font-size:15px;border-radius:16px}
    .actions{display:none}
    .footer{grid-template-columns:1fr;text-align:center}
    .footer-right{justify-content:center}
    .page-hero{padding:54px 0 46px}
    .form-grid{grid-template-columns:1fr}
}

@media(max-width:560px){
    .stats,.package-mini,.register-extra{grid-template-columns:1fr}
}

@media(max-width:480px){
    .container{width:min(100% - 24px,1180px)}
    .logo-img{max-width:185px;max-height:62px}
    .mobile-menu-btn{width:48px;height:48px;border-radius:14px}
    .page-hero h1{font-size:40px}
    .hero-buttons .btn{width:100%}
    .register-card{padding:24px}
    .register-card h2{font-size:30px}
}
</style>
</head>

<body>
<div class="site-wrap">

<header class="topbar">
    <div class="container nav">
        <a href="index.php" class="logo">
            <img src="<?= site_e($logoImage) ?>" alt="101 Batman Okey" class="logo-img">
        </a>

        <button class="mobile-menu-btn" id="mobileMenuBtn" type="button" aria-label="Menüyü Aç / Kapat" aria-expanded="false">
            <span></span><span></span><span></span>
        </button>

        <nav class="menu" id="mainMenu">
            <a href="index.php">🏠 Ana Sayfa</a>
            <a href="announcements.php">📢 Duyurular</a>
            <a href="downloads.php">⬇️ İndir</a>
            <a href="packages.php">👑 Paketler</a>
            <a href="contact.php">☎️ İletişim</a>
        </nav>

        <div class="actions">
            <a href="login.php" class="btn">Giriş Yap</a>
            <a href="register.php" class="btn btn-gold">Kayıt Ol</a>
        </div>
    </div>
</header>

<main>

<section class="page-hero">
    <div class="container">
        <div class="badge">📝 Premium Üyelik Merkezi</div>

        <h1>Hemen <span>Kayıt Ol</span></h1>

        <p>101 Batman Okey dünyasına katıl, sohbet et, oyna, Gold / Premium / VIP ayrıcalıklarından yararlan.</p>

        <div class="hero-buttons">
            <a href="#registerForm" class="btn btn-gold">Üyelik Oluştur</a>
            <a href="login.php" class="btn">Zaten Üyeyim</a>
        </div>
    </div>
</section>

<section>
    <div class="container">
        <div class="stats">
            <div class="stat">
                <strong><?= $userCount > 0 ? site_e((string)$userCount) : '500+' ?></strong>
                <span>Kayıtlı Üye</span>
            </div>

            <div class="stat">
                <strong><?= $packageCount > 0 ? site_e((string)$packageCount) : '3+' ?></strong>
                <span>Aktif Paket</span>
            </div>

            <div class="stat">
                <strong><?= $announcementCount > 0 ? site_e((string)$announcementCount) : '7+' ?></strong>
                <span>Duyuru</span>
            </div>

            <div class="stat">
                <strong>7/24</strong>
                <span>Aktif Platform</span>
            </div>
        </div>
    </div>
</section>

<section class="section" id="registerForm">
    <div class="container">
        <div class="register-card">
            <h2>Kayıt Ol</h2>
            <p>Yeni hesap oluştur, 101 Batman Okey dünyasına giriş yap.</p>

            <?php if ($message !== ''): ?>
                <div class="alert <?= site_e($messageType) ?>">
                    <?= site_e($message) ?>
                </div>
            <?php endif; ?>

            <?php if (!$isRegistered): ?>
                <form method="post">
                    <div class="form-grid">
                        <div class="form-group">
                            <label>Ad Soyad</label>
                            <input type="text" name="name" class="form-control" value="<?= site_e($_POST['name'] ?? '') ?>" required>
                        </div>

                        <div class="form-group">
                            <label>Kullanıcı Adı</label>
                            <input type="text" name="username" class="form-control" value="<?= site_e($_POST['username'] ?? '') ?>" required>
                        </div>

                        <div class="form-group">
                            <label>E-Posta</label>
                            <input type="email" name="email" class="form-control" value="<?= site_e($_POST['email'] ?? '') ?>" required>
                        </div>

                        <div class="form-group">
                            <label>Telefon</label>
                            <input type="text" name="phone" class="form-control" value="<?= site_e($_POST['phone'] ?? '') ?>">
                        </div>

                        <div class="form-group">
                            <label>Şifre</label>
                            <input type="password" name="password" class="form-control" required>
                        </div>

                        <div class="form-group">
                            <label>Şifre Tekrar</label>
                            <input type="password" name="password_confirm" class="form-control" required>
                        </div>
                    </div>

                    <label class="check-row">
                        <input type="checkbox" name="agreement" value="1" <?= isset($_POST['agreement']) ? 'checked' : '' ?>>
                        Kullanım şartlarını ve üyelik kurallarını kabul ediyorum.
                    </label>

                    <button type="submit" class="btn btn-gold submit-btn">Üyeliği Oluştur</button>
                </form>
            <?php else: ?>
                <a href="login.php" class="btn btn-gold">Giriş Sayfasına Git</a>
            <?php endif; ?>

            <div class="package-mini">
                <div class="mini-card"><em>🥇</em><strong>GOLD</strong></div>
                <div class="mini-card"><em>👑</em><strong>PREMIUM</strong></div>
                <div class="mini-card"><em>💎</em><strong>VIP</strong></div>
            </div>

            <div class="login-box">
                <strong>Zaten hesabın var mı?</strong>
                <span>Hesabına giriş yaparak oyuna devam edebilirsin.</span>
                <a href="login.php" class="btn">Giriş Yap</a>
            </div>
        </div>
    </div>
</section>

<section class="section">
    <div class="container">
        <div class="register-extra">
            <div class="extra-card">
                <div class="extra-icon">🎮</div>
                <strong>Okey Masaları</strong>
                <span>Premium masa deneyimiyle kaliteli oyuncularla oyuna katıl.</span>
            </div>

            <div class="extra-card">
                <div class="extra-icon">👑</div>
                <strong>Gold Üyelik</strong>
                <span>Gold, Premium ve VIP paketlerle profilini daha güçlü göster.</span>
            </div>

            <div class="extra-card">
                <div class="extra-icon">💬</div>
                <strong>Sohbetli Oyun</strong>
                <span>Oyuncularla canlı sohbet ederek sosyal okey keyfi yaşa.</span>
            </div>

            <div class="extra-card">
                <div class="extra-icon">🛡️</div>
                <strong>Güvenli Hesap</strong>
                <span>Şifren güvenli şekilde saklanır ve hesabın aktif olarak korunur.</span>
            </div>

            <div class="extra-card">
                <div class="extra-icon">⬇️</div>
                <strong>Kolay Başlangıç</strong>
                <span>Oyunu indir, hesabını oluştur ve masaya hızlıca katıl.</span>
            </div>

            <div class="extra-card">
                <div class="extra-icon">🎁</div>
                <strong>Yeni Üye Avantajı</strong>
                <span>Yeni üyeler için hazırlanmış premium oyun deneyimine dahil ol.</span>
            </div>
        </div>
    </div>
</section>

<section class="section">
    <div class="container">
        <div class="cta-box">
            <div>
                <h2>Hesabını oluştur, masadaki yerini al.</h2>
                <p>101 Batman Okey dünyasına katılmak için kayıt işlemini tamamla.</p>
            </div>
            <a href="downloads.php" class="btn btn-gold">Oyunu İndir</a>
        </div>
    </div>
</section>

<footer class="footer">
    <div>Powered By <?= date('Y') ?> <a href="https://www.radyohost.biz" target="_blank">🌐RadyoHost.BiZ</a><span> Web Teknolojileri</span></div>
    <div class="footer-center">Premium Okey ve Sohbet Platformu</div>
    <div class="footer-right">
        Developed By VoLKaN75
        <a href="https://wa.me/905415917536" target="_blank">
            <img src="uploads/footer/whatsapp.png" alt="WhatsApp">
        </a>
    </div>
</footer>

</main>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
    const mobileMenuBtn = document.getElementById('mobileMenuBtn');
    const mainMenu = document.getElementById('mainMenu');

    if (mobileMenuBtn && mainMenu) {
        mobileMenuBtn.addEventListener('click', function () {
            const isOpen = mainMenu.classList.toggle('active');
            mobileMenuBtn.classList.toggle('active', isOpen);
            mobileMenuBtn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
        });

        mainMenu.querySelectorAll('a').forEach(function (link) {
            link.addEventListener('click', function () {
                mainMenu.classList.remove('active');
                mobileMenuBtn.classList.remove('active');
                mobileMenuBtn.setAttribute('aria-expanded', 'false');
            });
        });

        window.addEventListener('resize', function () {
            if (window.innerWidth > 768) {
                mainMenu.classList.remove('active');
                mobileMenuBtn.classList.remove('active');
                mobileMenuBtn.setAttribute('aria-expanded', 'false');
            }
        });
    }
});
</script>

</body>
</html>