<?php
// Layout + page dispatch. Rendered by index.php.
$flashes = take_flashes();
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>NADIPLAY · Admin Panel</title>
<link rel="stylesheet" href="assets/style.css">
</head>
<body class="<?= $page === 'login' ? 'page-login' : 'page-app' ?>">

<?php if ($page === 'login'): ?>
    <?php require __DIR__ . '/login.php'; ?>
<?php else: ?>
<div class="app-shell">
    <aside class="sidebar">
        <div class="brand">
            <div class="brand-logo">N</div>
            <div>
                <div class="brand-title">NADIPLAY</div>
                <div class="brand-sub">Admin Panel</div>
            </div>
        </div>
        <nav class="nav">
            <a class="nav-item <?= $page === 'dashboard' ? 'active' : '' ?>" href="?page=dashboard">
                <span class="nav-ico">■</span> Dashboard
            </a>
            <a class="nav-item <?= $page === 'update' ? 'active' : '' ?>" href="?page=update">
                <span class="nav-ico">↑</span> Update Popup
            </a>
            <a class="nav-item <?= $page === 'settings' ? 'active' : '' ?>" href="?page=settings">
                <span class="nav-ico">&#x2699;</span> Settings
            </a>
            <a class="nav-item <?= $page === 'users' ? 'active' : '' ?>" href="?page=users">
                <span class="nav-ico">&#x2630;</span> Users
            </a>
            <a class="nav-item <?= $page === 'broadcast' ? 'active' : '' ?>" href="?page=broadcast">
                <span class="nav-ico">📣</span> Notifications
            </a>
            <a class="nav-item <?= $page === 'ads' ? 'active' : '' ?>" href="?page=ads">
                <span class="nav-ico">📢</span> Ads
            </a>
            <a class="nav-item <?= $page === 'worldcup' ? 'active' : '' ?>" href="?page=worldcup">
                <span class="nav-ico">⚽</span> World Cup
            </a>
            <a class="nav-item <?= $page === 'ads_control' ? 'active' : '' ?>" href="?page=ads_control">
                <span class="nav-ico">📊</span> Ads &amp; Analytics
            </a>
            <a class="nav-item <?= $page === 'sports' ? 'active' : '' ?>" href="?page=sports">
                <span class="nav-ico">🔌</span> Sports API (legacy)
            </a>
        </nav>
        <div class="sidebar-foot">
            <div class="who"><?= h($_SESSION['admin_user'] ?? '') ?></div>
            <a class="logout-btn" href="?page=logout">Logout</a>
        </div>
    </aside>

    <main class="main">
        <?php if ($flashes): ?>
            <div class="flash-stack">
            <?php foreach ($flashes as $f): ?>
                <div class="flash flash-<?= h($f['type']) ?>"><?= h($f['msg']) ?></div>
            <?php endforeach; ?>
            </div>
        <?php endif; ?>

        <?php
        switch ($page) {
            case 'update':    require __DIR__ . '/update.php';    break;
            case 'settings':  require __DIR__ . '/settings.php';  break;
            case 'users':     require __DIR__ . '/users.php';     break;
            case 'broadcast': require __DIR__ . '/broadcast.php'; break;
            case 'ads':       require __DIR__ . '/ads.php';       break;
            case 'sports':    require __DIR__ . '/sports.php';    break;
            case 'worldcup':  require __DIR__ . '/worldcup.php';  break;
            case 'ads_control': require __DIR__ . '/ads_control.php'; break;
            case 'dashboard':
            default:          require __DIR__ . '/dashboard.php'; break;
        }
        ?>
    </main>
</div>
<?php endif; ?>

</body>
</html>
