<?php

namespace App\EventSubscriber;

use Presta\SitemapBundle\Event\SitemapPopulateEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;

#[AsEventListener(event: ExceptionEvent::class, method: 'onException', priority: 10)]
class ErrorListener
{
    public function __construct(private readonly Environment $environment)
    {
    }

    public function onException(ExceptionEvent $exceptionEvent) {
        $exception = $exceptionEvent->getThrowable();
/*
        if($_ENV['APP_ENV'] == "prod") {
            if ($exception instanceof NotFoundHttpException) {
                $response = new Response($this->environment->render('error/404.twig', [
                    'no_index' => true,
                ]));
                $response->setStatusCode(Response::HTTP_NOT_FOUND);
                $exceptionEvent->setResponse($response);
                $exceptionEvent->stopPropagation();
            } else {
                $response = new Response($this->environment->render('error/error.twig', [
                    'no_index' => true,
                ]));

                $response->setStatusCode(Response::HTTP_NOT_FOUND);
                $exceptionEvent->setResponse($response);
                $exceptionEvent->stopPropagation();
            }
        }*/
    }
}
