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

$config = Config::load();
$about = $config['about'] ?? [
    'title' => 'À propos',
    'content' => '',
    'background' => ''
];

// Fonction pour convertir le contenu Delta en HTML
function deltaToHtml($content) {
    return DeltaConverter::toHtml($content);
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($about['title']) ?> - <?= htmlspecialchars($config['site']['name']) ?></title>
    
    <?php if (file_exists(__DIR__ . '/assets/images/site/favicon.png')): ?>
        <link rel="icon" type="image/png" href="assets/images/site/favicon.png">
    <?php endif; ?>
    
    <link rel="stylesheet" href="assets/css/public.css">
    <link rel="stylesheet" href="assets/css/content.css">
</head>
<body>
    <!-- En-tête avec image de fond -->
    <header class="novel-header">
        <?php if (!empty($about['background'])): ?>
            <div class="novel-header-background" style="background-image: url('<?= htmlspecialchars($about['background']) ?>');"></div>
        <?php endif; ?>
        <h1><?= htmlspecialchars($about['title']) ?></h1>
    </header>

    <!-- Contenu principal -->
    <div class="novel-content single-column">
        <div class="novel-description">
            <?= deltaToHtml($about['content']) ?>
        </div>
    </div>

    <div class="back-to-home">
        <a href="index.php">&larr; Retour à l'accueil</a>
    </div>

    <button class="scroll-top" aria-label="Retour en haut de page">↑</button>

    <script>
    document.addEventListener('DOMContentLoaded', function() {
        const scrollTopBtn = document.querySelector('.scroll-top');
        
        window.addEventListener('scroll', function() {
            if (window.pageYOffset > 300) {
                scrollTopBtn.classList.add('visible');
            } else {
                scrollTopBtn.classList.remove('visible');
            }
        });
        
        scrollTopBtn.addEventListener('click', function() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        });
    });
    </script>
</body>
</html>