
<?php
session_start();
$pageTitle = 'Custom Page — Oldies And More Radio';
include __DIR__ . '/includes/header.php';
include __DIR__ . '/includes/sidebar.php';
require_once __DIR__ . '/includes/app_lib.php';
$slug = preg_replace('/[^a-z0-9\-]/i', '', trim((string)($_GET['slug'] ?? '')));
$pages = oldies_read_json(__DIR__ . '/data/pages.json', []);
$page = $slug !== '' && isset($pages[$slug]) ? $pages[$slug] : null;
?>
<div class="main-wrap"><div class="content-panel">
  <div class="content-box custom-page-shell">
    <?php if (!$page): ?>
      <h1 class="section-title">Page Not Found</h1><p>This page does not exist.</p>
    <?php elseif (empty($page['published'])): ?>
      <h1 class="section-title"><?= oldies_h($page['title'] ?? 'Page') ?></h1><p>This page is not published.</p>
    <?php else: ?>
      <?php if (!empty($page['image'])): ?><div class="hero-image"><img src="<?= oldies_h($page['image']) ?>" alt=""></div><?php endif; ?>
      <h1 class="section-title"><?= oldies_h($page['title'] ?? 'Page') ?></h1>
      <?php if (!empty($page['summary'])): ?><p class="about-text"><?= nl2br(oldies_h($page['summary'])) ?></p><?php endif; ?>
      <div class="rich-content"><?= $page['content'] ?? '' ?></div>
      <?php if (!empty($page['button_text']) && !empty($page['button_url'])): ?><div class="page-cta"><a class="button radio-static" href="<?= oldies_h($page['button_url']) ?>"><?= oldies_h($page['button_text']) ?></a></div><?php endif; ?>
    <?php endif; ?>
  </div>
<?php include __DIR__ . '/includes/footer.php'; ?>
</div></div>
