<?php
session_start();
require __DIR__ . '/auth.php';
require __DIR__ . '/includes/admin_lib.php';

$settingsFile = __DIR__ . '/../data/settings.json';
$settings = smurf_load_settings($settingsFile);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  if (!$CAN_EDIT) smurf_admin_denied();
  $settings['player_show_in_nav'] = !empty($_POST['player_show_in_nav']);
  unset($settings['player_use_worker'], $settings['player_worker_url']);
  smurf_save_settings($settingsFile, $settings);
  smurf_redirect_self(['saved'=>1]);
}
include __DIR__ . '/includes/admin_header.php';
?>
<section class="content-card">
  <h1 class="admin-title">🪟 Pop Out Player</h1>
  <?php if (!empty($_GET['saved'])): ?><div class="msg success">Saved.</div><?php endif; ?>
  <section class="content-card" style="text-align:left; margin-top:12px;">
    <form method="post" class="form">
      <label style="display:block;margin:10px 0;"><input type="checkbox" name="player_show_in_nav" <?= !empty($settings['player_show_in_nav']) ? 'checked':''; ?>> Show Pop Out Player in navigation</label>
      <p style="opacity:.82;margin:10px 0 0;">The popup player now uses the same in-page stream proxy method as Thunder. No Cloudflare Worker URL is needed here.</p>
      <?php if ($CAN_EDIT): ?><button class="admin-btn primary" type="submit">Save Settings</button><?php endif; ?>
      <a class="admin-btn" href="/popout-player.php" target="_blank" rel="noopener" style="margin-left:8px;">Open Player</a>
    </form>
  </section>
</section>
<?php include __DIR__ . '/includes/admin_footer.php'; ?>
