<?php
namespace App\Controller\Www;

use App\Entity\EventMedia;
use App\Repository\EventMediaRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

#[Route(name: "www_")]
class GaleryController extends AbstractController
{
    #[Route("/galerie", name: "galery")]

    public function galery(EntityManagerInterface $manager) {
        return $this->_galery(1, $manager);
    }

    #[Route("/galerie/{page}", 
        name: "galery_page",
        requirements:[ 
            "page" => "\d+"
        ]
    )]     
    public function galery_page(string $page, EntityManagerInterface $manager) {
        $ipage = intval($page);
        return $this->_galery($ipage, $manager);
    }

    public function _galery(int $page_number, EntityManagerInterface $manager) {
        $galery = $manager->getRepository(EventMedia::class)->findForGalery((3*6), $page_number);

        return $this->render("www/galery.html.twig",
            [
                "medias"    => $galery->results,
                "prev_page" => ($galery->prev_page_number > 0) ? $this->generateUrl('www_galery_page', ["page" => $galery->prev_page_number]) : "",
                "next_page" => ($galery->next_page_number > 0) ? $this->generateUrl('www_galery_page', ["page" => $galery->next_page_number]) : "",
            ]
        );
    }




}