<?php
/**
 * SMM Paket Satış Scripti - Dinamik Sayfa Görüntüleme
 * @version 1.0.0
 */

require_once __DIR__ . '/config.php';

// Slug al
$slug = isset($_GET['s']) ? trim($_GET['s']) : '';

if (empty($slug)) {
    // Slug yoksa ana sayfaya yönlendir
    redirect(SITE_URL);
    exit;
}

// Sayfayı veritabanından çek
try {
    $stmt = $db->prepare("SELECT * FROM pages WHERE slug = ? AND is_active = 1");
    $stmt->execute([$slug]);
    $page = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $page = null;
}

// Sayfa bulunamadıysa 404
if (!$page) {
    http_response_code(404);
    $pageTitle = 'Sayfa Bulunamadı';
    require_once __DIR__ . '/header.php';
    ?>
    <div class="container py-5">
        <div class="text-center py-5">
            <div style="font-size: 120px; color: var(--primary); opacity: 0.3; margin-bottom: 20px;">
                <i class="fas fa-exclamation-triangle"></i>
            </div>
            <h1 style="font-size: 48px; font-weight: 800; margin-bottom: 15px;">404</h1>
            <h2 style="font-size: 24px; margin-bottom: 15px; color: var(--text-secondary);">Sayfa Bulunamadı</h2>
            <p style="color: var(--text-secondary); margin-bottom: 30px;">Aradığınız sayfa mevcut değil veya kaldırılmış olabilir.</p>
            <a href="<?php echo SITE_URL; ?>" class="btn-primary-custom">
                <i class="fas fa-home me-2"></i> Ana Sayfaya Dön
            </a>
        </div>
    </div>
    <?php
    require_once __DIR__ . '/footer.php';
    exit;
}

// Sayfa başlığı
$pageTitle = $page['title'];

require_once __DIR__ . '/header.php';
?>

<style>
.page-hero {
    background: var(--gradient);
    padding: 60px 0;
    margin-bottom: 50px;
    text-align: center;
}

.page-hero h1 {
    font-size: 36px;
    font-weight: 800;
    color: #fff;
    margin: 0;
}

.page-breadcrumb {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    font-size: 14px;
}

.page-breadcrumb a {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
}

.page-breadcrumb a:hover {
    color: #fff;
}

.page-breadcrumb span {
    color: rgba(255,255,255,0.5);
}

.page-breadcrumb .current {
    color: #fff;
}

.page-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

.page-content-inner {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
}

.page-content-inner h1,
.page-content-inner h2,
.page-content-inner h3,
.page-content-inner h4,
.page-content-inner h5,
.page-content-inner h6 {
    color: var(--text-primary);
    margin-top: 30px;
    margin-bottom: 15px;
}

.page-content-inner h1:first-child,
.page-content-inner h2:first-child,
.page-content-inner h3:first-child {
    margin-top: 0;
}

.page-content-inner p {
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 15px;
}

.page-content-inner ul,
.page-content-inner ol {
    color: var(--text-secondary);
    padding-left: 25px;
    margin-bottom: 15px;
}

.page-content-inner li {
    margin-bottom: 8px;
    line-height: 1.7;
}

.page-content-inner a {
    color: var(--primary);
}

.page-content-inner a:hover {
    text-decoration: underline;
}

.page-content-inner blockquote {
    border-left: 4px solid var(--primary);
    padding: 15px 20px;
    margin: 20px 0;
    background: var(--bg-hover);
    border-radius: 0 10px 10px 0;
    color: var(--text-secondary);
    font-style: italic;
}

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

.page-content-inner hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 30px 0;
}

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

.page-content-inner table th,
.page-content-inner table td {
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.page-content-inner table th {
    background: var(--bg-hover);
    font-weight: 600;
}

@media (max-width: 768px) {
    .page-hero { padding: 40px 0; }
    .page-hero h1 { font-size: 28px; }
    .page-content-inner { padding: 25px; }
}
</style>

<!-- Hero -->
<div class="page-hero">
    <div class="container">
        <h1><?php echo clean($page['title']); ?></h1>
        <div class="page-breadcrumb">
            <a href="<?php echo SITE_URL; ?>"><i class="fas fa-home"></i> Ana Sayfa</a>
            <span><i class="fas fa-chevron-right"></i></span>
            <span class="current"><?php echo clean($page['title']); ?></span>
        </div>
    </div>
</div>

<!-- Content -->
<div class="page-content">
    <div class="page-content-inner">
        <?php echo $page['content']; ?>
    </div>
</div>

<?php require_once __DIR__ . '/footer.php'; ?>