<?php
require_once 'db/config.php';
session_start();
$db = db();

$logs = $db->query("SELECT * FROM project_logs ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Journal du Projet - Galaxy Manager</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Rajdhani:wght@300;500;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-color: #2e3440;
            --panel-bg: rgba(46, 52, 64, 0.9);
            --text-color: #eceff4;
            --accent-color: #88c0d0;
            --accent-glow: rgba(136, 192, 208, 0.4);
            --border-color: #4c566a;
        }

        body {
            margin: 0;
            font-family: 'Rajdhani', sans-serif;
            background: #1a1c23 url('https://www.transparenttextures.com/patterns/stardust.png');
            color: var(--text-color);
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        header {
            background: rgba(0, 0, 0, 0.6);
            padding: 20px;
            text-align: center;
            border-bottom: 2px solid var(--accent-color);
            box-shadow: 0 0 15px var(--accent-glow);
        }

        header h1 {
            margin: 0;
            font-family: 'Orbitron', sans-serif;
            letter-spacing: 3px;
            color: var(--accent-color);
            text-transform: uppercase;
        }

        .container {
            max-width: 800px;
            margin: 40px auto;
            padding: 0 20px;
            flex-grow: 1;
        }

        .log-entry {
            background: var(--panel-bg);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 25px;
            margin-bottom: 30px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.3);
            transition: transform 0.2s;
        }

        .log-entry:hover {
            transform: translateY(-3px);
            border-color: var(--accent-color);
        }

        .log-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
            border-bottom: 1px solid var(--border-color);
            padding-bottom: 10px;
        }

        .version-badge {
            background: var(--accent-color);
            color: #2e3440;
            padding: 4px 12px;
            border-radius: 20px;
            font-weight: bold;
            font-family: 'Orbitron', sans-serif;
            font-size: 14px;
        }

        .log-date {
            color: #81a1c1;
            font-size: 14px;
        }

        .log-title {
            font-size: 22px;
            color: #fff;
            margin: 0 0 10px 0;
            font-weight: 700;
        }

        .log-content {
            line-height: 1.6;
            color: #d8dee9;
            white-space: pre-line;
        }

        .back-btn {
            display: inline-block;
            margin-bottom: 20px;
            color: var(--accent-color);
            text-decoration: none;
            font-weight: bold;
            transition: 0.2s;
        }

        .back-btn:hover {
            color: #fff;
            text-shadow: 0 0 5px var(--accent-color);
        }

        footer {
            text-align: center;
            padding: 20px;
            font-size: 12px;
            color: #4c566a;
            background: rgba(0,0,0,0.4);
        }
    </style>
</head>
<body>
    <header>
        <h1>Journal de Bord du Projet</h1>
    </header>

    <div class="container">
        <a href="index.php" class="back-btn"><i class="fa-solid fa-arrow-left"></i> Retour au Secteur</a>

        <?php if (empty($logs)): ?>
            <div class="log-entry">
                <p>Aucun log disponible pour le moment.</p>
            </div>
        <?php else: ?>
            <?php foreach ($logs as $log): ?>
                <div class="log-entry">
                    <div class="log-header">
                        <span class="version-badge">v<?php echo htmlspecialchars($log['version']); ?></span>
                        <span class="log-date"><?php echo date('d/m/Y H:i', strtotime($log['created_at'])); ?></span>
                    </div>
                    <h2 class="log-title"><?php echo htmlspecialchars($log['title']); ?></h2>
                    <div class="log-content"><?php echo nl2br(htmlspecialchars($log['content'])); ?></div>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>

    <footer>
        &copy; <?php echo date('Y'); ?> Galaxy Manager Project. Tous droits réservés.
    </footer>
</body>
</html>
