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

/*
|--------------------------------------------------------------------------
| DUYURULAR SAYFASI
|--------------------------------------------------------------------------
| announcements.php
| RadyoHost Okey Premium Duyuru Listeleme Sayfası
| Developed By VoLKaN75
|--------------------------------------------------------------------------
*/

declare(strict_types=1);

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

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

function site_short($text, int $limit = 150): string
{
    $text = trim(strip_tags((string)$text));

    if ($text === '') {
        return 'Duyuru içeriği yakında yayınlanacaktır.';
    }

    if (mb_strlen($text, 'UTF-8') <= $limit) {
        return $text;
    }

    return mb_substr($text, 0, $limit, 'UTF-8') . '...';
}

function site_val(array $row, array $keys, string $default = ''): string
{
    foreach ($keys as $key) {
        if (isset($row[$key]) && trim((string)$row[$key]) !== '') {
            return (string)$row[$key];
        }
    }

    return $default;
}

function site_date(array $row): string
{
    $date = site_val($row, ['created_at', 'updated_at', 'date'], '');

    if ($date === '') {
        return date('d.m.Y');
    }

    $time = strtotime($date);

    return $time ? date('d.m.Y', $time) : date('d.m.Y');
}

function announcement_image(array $row): string
{
    $image = site_val($row, ['image', 'image_path', 'photo', 'banner'], '');

    if ($image === '') {
        return 'uploads/site/announcement-default.webp';
    }

    $image = trim(str_replace('\\', '/', $image));

    if (str_starts_with($image, 'http://') || str_starts_with($image, 'https://')) {
        return $image;
    }

    $imageName = basename($image);

    $paths = [
        [
            'disk' => __DIR__ . '/uploads/announcements/' . $imageName,
            'url'  => 'uploads/announcements/' . $imageName,
        ],
        [
            'disk' => __DIR__ . '/uploads/site/' . $imageName,
            'url'  => 'uploads/site/' . $imageName,
        ],
        [
            'disk' => __DIR__ . '/uploads/' . $imageName,
            'url'  => 'uploads/' . $imageName,
        ],
    ];

    foreach ($paths as $path) {
        if (is_file($path['disk'])) {
            return $path['url'];
        }
    }

    return $image;
}

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

$announcements = [];
$totalAnnouncements = 0;

try {
    if (isset($pdo) && $pdo instanceof PDO) {
        $columns = [];

        try {
            $columnQuery = $pdo->query("SHOW COLUMNS FROM announcements");
            while ($row = $columnQuery->fetch(PDO::FETCH_ASSOC)) {
                $columns[] = (string)$row['Field'];
            }
        } catch (Throwable $e) {}

        $where = '';
        if (in_array('status', $columns, true)) {
            $where = "WHERE status IN ('active','aktif','1')";
        }

        $totalAnnouncements = (int)$pdo->query("
            SELECT COUNT(*)
            FROM announcements
            {$where}
        ")->fetchColumn();

        $stmt = $pdo->query("
            SELECT *
            FROM announcements
            {$where}
            ORDER BY id DESC
            LIMIT 50
        ");

        $announcements = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
    }
} catch (Throwable $e) {
    $announcements = [];
}

$featured = $announcements[0] ?? null;
?>
<!doctype html>
<html lang="tr">
<head>
<meta charset="utf-8">
<title>Duyurular | RadyoHost Okey</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="RadyoHost Okey duyuruları, kampanyalar, güncellemeler ve platform haberleri.">

<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;gap:14px;min-width:240px;font-weight:900;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}
.kicker{display:inline-flex;padding:10px 16px;border-radius:999px;background:rgba(245,182,66,.13);border:1px solid rgba(245,182,66,.35);color:#f5b642;font-weight:1000;margin-bottom:18px}
.page-hero h1{margin:0;font-size:clamp(42px,6vw,74px);line-height:1.02;text-transform:uppercase;letter-spacing:-1.7px}
.page-hero h1 span{color:#f5b642}
.page-hero p{margin:18px 0 0;max-width:720px;color:#dce3ef;font-size:18px;font-weight:800;line-height:1.7}

.stats{display:grid;grid-template-columns:repeat(3,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}
.section-head{display:flex;align-items:flex-end;justify-content:space-between;gap:20px;margin-bottom:25px}
.section-head h2{margin:0;font-size:36px}
.section-head p{margin:8px 0 0;color:#9aa3b2;font-weight:800;line-height:1.6}

.featured{display:grid;grid-template-columns:1.15fr .85fr;gap:24px;align-items:stretch;margin-bottom:34px}
.featured-image{position:relative;overflow:hidden;border-radius:32px;border:1px solid rgba(245,182,66,.30);background:#070911;min-height:360px;box-shadow:0 32px 95px rgba(0,0,0,.45)}
.featured-image img{width:100%;height:100%;display:block;object-fit:cover;filter:saturate(1.08) contrast(1.05)}
.featured-image:after{content:"";position:absolute;inset:0;background:linear-gradient(180deg,rgba(0,0,0,.04),rgba(0,0,0,.74))}
.featured-content{position:relative;overflow:hidden;border-radius:32px;padding:34px;background:radial-gradient(circle at top right,rgba(245,182,66,.18),transparent 40%),linear-gradient(145deg,rgba(255,255,255,.075),rgba(255,255,255,.035));border:1px solid rgba(245,182,66,.24);box-shadow:0 24px 72px rgba(0,0,0,.28)}
.featured-content:before{content:"";position:absolute;inset:0;background:radial-gradient(circle at 12% 12%,rgba(185,0,0,.12),transparent 32%);pointer-events:none}
.featured-content>*{position:relative;z-index:2}
.badge{display:inline-flex;align-items:center;gap:7px;padding:8px 12px;border-radius:999px;background:rgba(245,182,66,.13);color:#ffd47d;border:1px solid rgba(245,182,66,.28);font-size:12px;font-weight:1000;text-transform:uppercase}
.featured-content h2{margin:18px 0 14px;font-size:34px;line-height:1.15}
.featured-content p{margin:0 0 24px;color:#cbd3df;font-size:16px;font-weight:800;line-height:1.8}
.meta{display:flex;gap:10px;flex-wrap:wrap;margin-bottom:24px}
.meta span{padding:8px 11px;border-radius:999px;color:#dce3ef;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.10);font-size:12px;font-weight:900}
.read-btn{min-height:52px;padding:0 20px;border-radius:15px;display:inline-flex;align-items:center;justify-content:center;font-weight:1000;color:#111;background:linear-gradient(135deg,#f5b642,#ffcf6a);box-shadow:0 16px 38px rgba(245,182,66,.24);transition:.25s}
.read-btn:hover{transform:translateY(-3px)}

.announcement-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:24px}
.announcement-card{position:relative;overflow:hidden;border-radius:28px;background:linear-gradient(145deg,rgba(255,255,255,.075),rgba(255,255,255,.035));border:1px solid rgba(245,182,66,.18);box-shadow:0 24px 72px rgba(0,0,0,.25);transition:.25s}
.announcement-card:hover{transform:translateY(-7px);border-color:rgba(245,182,66,.55);box-shadow:0 34px 95px rgba(0,0,0,.45)}
.card-image{position:relative;height:190px;overflow:hidden;background:#070911}
.card-image img{width:100%;height:100%;display:block;object-fit:cover;transition:.35s}
.announcement-card:hover .card-image img{transform:scale(1.06)}
.card-image:after{content:"";position:absolute;inset:0;background:linear-gradient(180deg,rgba(0,0,0,.06),rgba(0,0,0,.72))}
.card-label{position:absolute;left:16px;top:15px;z-index:3;display:inline-flex;align-items:center;gap:7px;min-height:32px;padding:0 12px;border-radius:999px;background:rgba(0,0,0,.58);border:1px solid rgba(245,182,66,.32);color:#f5b642;font-size:11px;font-weight:1000;text-transform:uppercase}
.card-body{padding:22px}
.card-body h3{margin:0 0 12px;color:#fff;font-size:23px;line-height:1.25}
.card-body p{min-height:82px;margin:0 0 20px;color:#aeb7c7;font-size:14px;font-weight:750;line-height:1.7}
.card-meta{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:18px}
.card-date{font-size:12px;font-weight:900;color:#dce3ef}
.card-views{font-size:12px;font-weight:900;color:#f5b642}
.empty{padding:40px;border-radius:28px;text-align:center;color:#9aa3b2;font-weight:900;background:rgba(255,255,255,.045);border:1px solid rgba(255,255,255,.09);grid-column:1 / -1}

.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:980px){
    .stats,.featured,.announcement-grid{grid-template-columns:1fr}
    .featured-image{min-height:280px}
}

@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}
    .section-head{display:block}
    .footer{grid-template-columns:1fr;text-align:center}
    .footer-right{justify-content:center}
    .page-hero{padding:54px 0 46px}
    .featured-content{padding:26px}
    .featured-content h2{font-size:28px}
}

@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}
    .section-head 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" class="active">📢 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="kicker">📢 Platform Duyuruları</div>
        <h1>Son <span>Duyurular</span></h1>
        <p>101 Batman Okey platformundaki güncellemeler, kampanyalar, turnuvalar ve önemli haberleri buradan takip edebilirsiniz.</p>
    </div>
</section>

<section>
    <div class="container">
        <div class="stats">
            <div class="stat">
                <strong><?= site_e((string)$totalAnnouncements) ?></strong>
                <span>Toplam Duyuru</span>
            </div>
            <div class="stat">
                <strong><?= site_e((string)count($announcements)) ?></strong>
                <span>Yayındaki Duyuru</span>
            </div>
            <div class="stat">
                <strong>7/24</strong>
                <span>Güncel Bilgilendirme</span>
            </div>
        </div>
    </div>
</section>

<section class="section">
    <div class="container">

        <?php if ($featured): ?>
            <div class="section-head">
                <div>
                    <h2>⭐ Öne Çıkan Duyuru</h2>
                    <p>En son yayınlanan önemli duyuru.</p>
                </div>
            </div>

            <div class="featured">
                <div class="featured-image">
                    <img src="<?= site_e(announcement_image($featured)) ?>" alt="<?= site_e(site_val($featured, ['title'], 'Duyuru')) ?>">
                </div>

                <article class="featured-content">
                    <span class="badge">📢 <?= site_e(site_val($featured, ['category'], 'Duyuru')) ?></span>

                    <h2><?= site_e(site_val($featured, ['title'], 'Duyuru')) ?></h2>

                    <p><?= site_e(site_short(site_val($featured, ['summary', 'description', 'content', 'message'], ''), 260)) ?></p>

                    <div class="meta">
                        <span>📅 <?= site_e(site_date($featured)) ?></span>
                        <span>👁️ <?= site_e(site_val($featured, ['views', 'view_count'], '0')) ?> görüntülenme</span>
                    </div>

                    <a href="announcements.php" class="read-btn">Duyuruları Gör</a>
                </article>
            </div>
        <?php endif; ?>

        <div class="section-head">
            <div>
                <h2>📢 Tüm Duyurular</h2>
                <p>Admin panelden eklenen aktif duyurular burada listelenir.</p>
            </div>
        </div>

        <div class="announcement-grid">
            <?php if ($announcements): ?>
                <?php foreach ($announcements as $item): ?>
                    <article class="announcement-card">
                        <div class="card-image">
                            <img src="<?= site_e(announcement_image($item)) ?>" alt="<?= site_e(site_val($item, ['title'], 'Duyuru')) ?>">
                            <span class="card-label">📢 <?= site_e(site_val($item, ['category'], 'Duyuru')) ?></span>
                        </div>

                        <div class="card-body">
                            <div class="card-meta">
                                <span class="card-date">📅 <?= site_e(site_date($item)) ?></span>
                                <span class="card-views">👁️ <?= site_e(site_val($item, ['views', 'view_count'], '0')) ?></span>
                            </div>

                            <h3><?= site_e(site_val($item, ['title'], 'Duyuru')) ?></h3>

                            <p><?= site_e(site_short(site_val($item, ['summary', 'description', 'content', 'message'], ''), 150)) ?></p>

                            <a href="announcements.php" class="read-btn">Devamını Oku</a>
                        </div>
                    </article>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="empty">
                    Henüz yayınlanmış duyuru bulunamadı.
                </div>
            <?php endif; ?>
        </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 () {
            this.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>