<?php
$page = db_one('SELECT * FROM pages WHERE slug = ? AND status = 1', [get('slug', '')]);
if (!$page) {
    not_found();
}

$sections = db_value('SELECT COUNT(*) FROM sections WHERE page = ? AND status = 1', ['page-' . $page['id']]);

view_header(seo_title($page, $page['title']), ['description' => $page['meta_description'] ?: $page['content']]);
?>

<?php if (trim((string) $page['content']) !== '' || !$sections): ?>
    <article class="container-x pt-8">
        <?php breadcrumb([$page['title'] => null]) ?>
        <div class="mx-auto max-w-3xl py-12 sm:py-16">
            <h1 class="heading text-4xl <?= heading_weight_class() ?> sm:text-5xl"><?= e($page['title']) ?></h1>
            <?php if ($page['updated_at']): ?>
                <p class="mt-4 text-sm text-zinc-500">Son güncelleme: <?= date_tr($page['updated_at']) ?></p>
            <?php endif ?>
            <div class="rich mt-10 text-[17px] leading-8 text-zinc-700">
                <?php foreach (preg_split('/\n\s*\n/', trim((string) $page['content'])) as $paragraph): ?>
                    <p><?= nl2br(e($paragraph)) ?></p>
                <?php endforeach ?>
            </div>
        </div>
    </article>
<?php endif ?>

<?php render_sections('page-' . $page['id']) ?>

<?php view_footer() ?>
