<?php
declare(strict_types=1);

use Slim\App;
use Slim\Psr7\Request;
use Slim\Psr7\Response;
use App\Models\Post;
use Slim\Views\Twig;

return function (App $app) {

    // -------------------------------------------------
    // Page publique – liste des articles
    // -------------------------------------------------
    $app->get('/', function (Request $request, Response $response) use ($app) {
        $posts = Post::orderByDesc('id')->get();

        /** @var Twig $view */
        $view = $request->getAttribute('view');   // <-- récupération correcte
        return $view->render($response, 'pages/home.twig', ['posts' => $posts]);
    });
};
