<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

use Symfony\Component\Routing\Attribute\Route;

use App\Repository\BroadcastRepository;

#[Route('/rapport')]
final class RapportController extends AbstractController
{
    /**
     * @param BroadcastRepository $broadcastRepository
     * @return $this
     */
    public function __construct(
        private BroadcastRepository $broadcastRepository,
    ) {
        $this->broadcastRepository = $broadcastRepository;
    }

    #[Route('/index', name: 'app_rapport_index')]
    public function index(Request $request): Response
    {
        $language = $request->getSession()->get('_locale');

        $broadcasts = $this->broadcastRepository->findBroadcastByUser($this->getUser());
        
        $listeInvestigations = [];

        foreach($broadcasts as $broadcast)
        {
            $investigation = $broadcast->getInvestigation();
            if($language == 'fr'){
                $listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameFr()];
            }elseif($language == 'en'){
                $listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameEn()];
            }elseif($language == 'ar'){
                $listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameAr()];
            }else{
                $listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameFr()];
            }
        }
        return $this->render('rapport/index.html.twig', ["listeInvestigations"=>$listeInvestigations]);
    }

    
}
