<?php
require_once APP_ROOT . '/src/Database.php';
require_once APP_ROOT . '/src/Parsedown.php';

class LicenceController {
    public static function create(): self {
        return new self();
    }

    public function handle(): array {
        try {
            $db = Database::getInstance();
            $dbPage = $db->getPage('licenses');
            $content = $dbPage ? $dbPage['content'] : '';
            $pageTitle = $dbPage ? $dbPage['title'] : 'Licences';
        } catch (Exception $e) {
            error_log("Error loading licence page: " . $e->getMessage());
            $content = '';
            $pageTitle = 'Licences';
        }

        $pd = new Parsedown();
        $pd->setSafeMode(true);
        $html = $pd->text($content);

        return [
            'content'          => $content,
            'html'             => $html,
            'pageTitle'        => $pageTitle . ' – Posterg',
            'metaDescription'  => "Informations sur les licences d'utilisation des mémoires publiés sur Posterg, le répertoire des TFE de l'erg.",
            'currentNav'       => 'licence',
            'extraCss'         => ['/assets/css/apropos.css'],
            'bodyClass'        => 'apropos-body',
        ];
    }
}
