
<?php
session_start(); require __DIR__ . '/includes/header.php';
$historyFile = __DIR__ . '/../playhistory.json'; $settings = oldies_read_settings();
$history = file_exists($historyFile) ? json_decode((string)file_get_contents($historyFile), true) : []; if (!is_array($history)) $history = [];
arsort($history); $top = array_slice($history, 0, 50, true);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $CAN_EDIT) { $settings['top50_show_in_nav'] = !empty($_POST['top50_show_in_nav']); oldies_save_settings($settings); admin_redirect_self(['saved'=>1]); }
?>
<section class="content-card"><h1 class="admin-title">🎵 Top 50 Manager</h1><?php if (!empty($_GET['saved'])): ?><div class="msg success">Top 50 settings saved.</div><?php endif; ?><div class="page-builder-grid"><section class="content-card" style="text-align:left;"><form method="post" class="form"><label style="display:flex;gap:10px;align-items:center;margin:10px 0;"><input type="checkbox" name="top50_show_in_nav" <?= !empty($settings['top50_show_in_nav']) ? 'checked' : '' ?>> Show Top 50 in navigation</label><button class="admin-btn primary" type="submit" <?= !$CAN_EDIT ? 'disabled' : '' ?>>Save</button></form><p class="admin-note">This page keeps using your existing play history file so the original Oldies chart content stays intact.</p></section><section class="content-card" style="text-align:left;"><h3 style="margin-top:0;">Current chart preview</h3><?php if (!$top): ?><p>No chart data yet.</p><?php else: ?><ol><?php foreach ($top as $track => $plays): ?><li><?= admin_h($track) ?> — <strong><?= (int)$plays ?></strong></li><?php endforeach; ?></ol><?php endif; ?></section></div></section>
<?php include __DIR__ . '/includes/footer.php'; ?>
