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

$slug = isset($_GET['slug']) ? $_GET['slug'] : '';

$stmt = $pdo->prepare("SELECT * FROM articles WHERE slug = :slug AND is_published = 1 AND (publish_start IS NULL OR publish_start <= CURDATE()) AND (publish_end IS NULL OR publish_end >= CURDATE())");
$stmt->execute(['slug' => $slug]);
$article = $stmt->fetch();

if (!$article) {
    // Rediriger ou afficher une erreur
    header("Location: actualites.php");
    exit;
}

include 'includes/header.php';
?>

<main class="min-h-screen py-16 bg-gray-50">
    <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
        
        <a href="actualites.php" class="inline-flex items-center text-alsace-red hover:underline mb-8 font-medium">
            <i data-lucide="arrow-left" class="w-4 h-4 mr-2"></i> Retour aux actualités
        </a>

        <article class="bg-white rounded-2xl shadow-lg overflow-hidden border border-gray-100">
            <?php if ($article['image']): ?>
                <img src="uploads/<?php echo htmlspecialchars($article['image']); ?>" alt="<?php echo htmlspecialchars($article['title']); ?>" class="w-full h-64 md:h-96 object-cover">
            <?php endif; ?>
            
            <div class="p-8 md:p-12">
                <div class="flex items-center space-x-4 mb-6">
                    <span class="text-sm font-bold text-alsace-red bg-red-50 px-3 py-1 rounded-full"><?php echo htmlspecialchars($article['category']); ?></span>
                    <span class="text-sm text-gray-500 font-medium flex items-center">
                        <i data-lucide="calendar" class="w-4 h-4 mr-2"></i>
                        Publié le <?php echo date('d/m/Y', strtotime($article['created_at'])); ?>
                    </span>
                </div>
                
                <h1 class="font-serif text-3xl md:text-5xl font-bold text-gray-900 mb-8 leading-tight">
                    <?php echo htmlspecialchars($article['title']); ?>
                </h1>
                
                <div class="prose max-w-none text-gray-700 text-lg leading-relaxed">
                    <?php echo $article['content']; ?>
                </div>
            </div>
        </article>

    </div>
</main>

<script>
    if(typeof lucide !== 'undefined') {
        lucide.createIcons();
    }
</script>

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