<?php
session_start();
include __DIR__ . '/includes/header.php';
include __DIR__ . '/includes/nav.php';
require_once __DIR__ . '/includes/schedule_lib.php';
$settingsFile = __DIR__ . '/data/settings.json';
$settings = (file_exists($settingsFile) ? json_decode(file_get_contents($settingsFile), true) : []);
if (!is_array($settings)) $settings = [];
$schedule = smurf_load_schedule_hourmap(__DIR__ . '/data/schedule.json', __DIR__ . '/data/schedule.txt', $SMURF_DAYS_ORDER);
$nn = smurf_schedule_now_next($schedule);
$currentDJName = $nn['now'] ?: 'Auto DJ';
$nextDJName = $nn['next'] ?: 'Auto DJ';
$isLiveNow = smurf_is_live_dj($currentDJName, $settings);


// Load DJ data
$djsFile = __DIR__ . '/data/djs.json';
$djs = file_exists($djsFile) ? json_decode(file_get_contents($djsFile), true) : [];
?>

<main class="content-area">

    <div class="smurf-divider"></div>

    <div class="content-wrapper">

        <section class="content-card center-text">
            <h1>🎙️ Meet Our DJs 🎙️</h1>
            <h2>The Heart & Soul of Radio Galaxy FX</h2>
        </section>

        <div class="dj-grid">

            <?php if (!empty($djs)): ?>
                <?php foreach ($djs as $dj): ?>
                    <div class="content-card dj-card <?php echo (strcasecmp(($dj['name'] ?? ''), $currentDJName)===0 && $isLiveNow) ? 'live' : ''; ?>">

                        <div class="dj-image">
                            <?php
                            $img = $dj['image'] ?? '';
                            $src = (preg_match('~^https?://~i', $img)) ? $img : ('/img/djs/' . $img);
                          ?>
                          <img src="<?= htmlspecialchars($src) ?>" alt="<?= htmlspecialchars($dj['name'] ?? '') ?>">
                        </div>

                        <h3 class="dj-name"><?= htmlspecialchars($dj['name']) ?></h3>
                        <p class="dj-show"><?= htmlspecialchars($dj['show']) ?></p>

                        <p class="dj-bio">
                            <?= nl2br(htmlspecialchars($dj['bio'])) ?>
                        </p>

                    </div>
                <?php endforeach; ?>
            <?php else: ?>
                <p style="text-align:center;">No DJs found.</p>
            <?php endif; ?>

        </div>

    </div>

    <div class="smurf-divider"></div>

</main>

<?php include __DIR__ . '/includes/footer.php'; ?>
