<?php
require_once 'config/config.php';

$slug = $_GET['slug'] ?? '';

if (empty($slug)) {
    header('HTTP/1.0 404 Not Found');
    include '404.php';
    exit;
}

$stmt = $pdo->prepare("SELECT * FROM pages WHERE slug = ? AND status = 'published'");
$stmt->execute([$slug]);
$page = $stmt->fetch();

if (!$page) {
    header('HTTP/1.0 404 Not Found');
    include '404.php';
    exit;
}

$page_title = $page['meta_title'] ?: $page['title'];
$meta_description = $page['meta_description'] ?: excerpt(strip_tags($page['content']), 160);
$meta_keywords = $page['meta_keywords'] ?: '';

include 'includes/header.php';
?>

<div class="container mt-4 mb-5">
    <div class="row">
        <div class="col-lg-12">
            <article>
                <h1 class="mb-4"><?= e($page['title']) ?></h1>
                <div class="page-content">
                    <?= $page['content'] ?>
                </div>
            </article>
        </div>
    </div>
</div>

<style>
.page-content {
    line-height: 1.8;
    font-size: 1.1rem;
}

.page-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 20px 0;
}

.page-content h1,
.page-content h2,
.page-content h3,
.page-content h4,
.page-content h5,
.page-content h6 {
    margin-top: 30px;
    margin-bottom: 15px;
    font-weight: 600;
}

.page-content p {
    margin-bottom: 15px;
}

.page-content ul,
.page-content ol {
    margin-bottom: 15px;
    padding-left: 30px;
}

.page-content blockquote {
    border-left: 4px solid #007bff;
    padding-left: 20px;
    margin: 20px 0;
    font-style: italic;
    color: #666;
}

.page-content table {
    width: 100%;
    margin: 20px 0;
    border-collapse: collapse;
}

.page-content table th,
.page-content table td {
    padding: 10px;
    border: 1px solid #ddd;
}

.page-content table th {
    background-color: #f8f9fa;
    font-weight: 600;
}
</style>

<?php include 'includes/footer.php'; ?>



