<?php

namespace App\Controller;

use App\Dto\Contact\ContactType;
use App\Dto\Contact\DtoContact;
use App\Entity\Account;
use App\Entity\AccountResetPasswordRequest;
use App\Form\RequestPasswordConfirmType;
use App\Form\RequestPasswordRequestType;
use App\Service\Mailer\Mailer;
use App\Service\ResetPassword\Event\ResetPasswordConfirmEvent;
use App\Service\ResetPassword\Event\ResetPasswordEvent;
use Doctrine\ORM\EntityManagerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Twig\Environment;

class ContactController extends AbstractController
{

    #[Route(path: '/contact', name: 'app_contact', options: ['sitemap' => false], methods: ['GET','POST'])]
    public function index(Request $request,Mailer $mailer): Response
    {
        $dto = new DtoContact();
        $form = $this->createForm(ContactType::class,$dto);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $mailer->send('contact@e-cosplay.fr','E-Cosplay',"[E-Cosplay] - Demande de contact","mails/contact.twig", [
                'dto' => $dto
            ]);
            $this->addFlash("success","Votre message à été envoyée");
            return $this->redirectToRoute('app_contact');
        }
        return $this->render('contact.twig',[
            'form' => $form->createView(),
        ]);
    }
}
