<?php
require_once __DIR__ . '/config/database.php'; // Veritabanı ve temel ayarlar
require_once __DIR__ . '/includes/header.php'; // Header'ı dahil et

global $db, $translations, $settings;

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

// Sayfa içeriğini veritabanından çek
$page = null;
$page_title = $settings['site_title'] ?? 'StockPanel';
$page_content = '<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
    <strong class="font-bold">Hata!</strong>
    <span class="block sm:inline">Sayfa bulunamadı.</span>
</div>';

if (!empty($slug) && $db) {
    try {
        $stmt = $db->prepare("SELECT title, content FROM pages WHERE slug = ? AND is_visible = 1");
        $stmt->execute([$slug]);
        $page = $stmt->fetch(PDO::FETCH_ASSOC);
        
        if ($page) {
            $page_title = $page['title'] . ' - ' . ($settings['site_title'] ?? 'StockPanel');
            $page_content = $page['content'];
        }
    } catch (PDOException $e) {
        error_log("Sayfa verileri alınamadı: " . $e->getMessage());
    }
}
?>

<!-- Sayfa İçerik Kartı -->
<div class="bg-white dark:bg-gray-800 shadow-lg rounded-lg overflow-hidden">
    <!-- Sayfa İçeriği -->
    <div class="p-6">
        <div class="prose prose-lg prose-indigo dark:prose-invert max-w-none 
                    prose-headings:text-gray-800 dark:prose-headings:text-gray-100
                    prose-p:text-gray-600 dark:prose-p:text-gray-300
                    prose-a:text-primary-600 dark:prose-a:text-primary-400 prose-a:no-underline hover:prose-a:underline
                    prose-strong:text-gray-800 dark:prose-strong:text-white
                    prose-img:rounded-lg prose-img:shadow-md
                    prose-pre:bg-gray-50 dark:prose-pre:bg-gray-900 prose-pre:border prose-pre:border-gray-200 dark:prose-pre:border-gray-700
                    prose-blockquote:text-gray-500 dark:prose-blockquote:text-gray-400 prose-blockquote:border-l-4 prose-blockquote:border-primary-500
                    prose-ul:text-gray-600 dark:prose-ul:text-gray-300
                    prose-ol:text-gray-600 dark:prose-ol:text-gray-300
                    prose-li:text-gray-600 dark:prose-li:text-gray-300">
            <?php echo $page_content; ?>
        </div>
    </div>
</div>

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