<?php
declare(strict_types=1);

require_once __DIR__ . '/includes/bootstrap.php';

$slug = trim((string) ($_GET['s'] ?? ''));
$page = $slug !== '' ? page_find_by_slug($slug) : null;

if (!$page) {
    flash('error', 'Sayfa bulunamadı.');
    redirect(url('index.php'));
}

$pageTitle = (string) ($page['title'] ?? 'Sayfa');
// page-shop: vitrin/app header düzeni (çift header olmasın)
$pageClass = 'page-shop page-static';
$metaDescription = mb_substr(trim(preg_replace('/\s+/u', ' ', strip_tags((string) ($page['body'] ?? ''))) ?? ''), 0, 160);

require __DIR__ . '/includes/header.php';
require __DIR__ . '/includes/app_header.php';
?>

<article class="static-page">
    <h1><?= e($pageTitle) ?></h1>
    <div class="static-page-body">
        <?= page_render_body($page) ?>
    </div>
</article>

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