<?php

namespace App\Controller;

use App\Repository\CategoryRepository;
use App\Repository\ProductRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class IceCreamController extends AbstractController
{
    #[Route('/')]
    public function all(Request $request, ProductRepository $productRepository, CategoryRepository $categoryRepository)
    {
        $category = $request->query->get('category');
   
        if ($category) {
            $products = $productRepository->findByCategory($category);
        } else {
            $products = $productRepository->findAll();
        }
 
        $categories = $categoryRepository->findAll();
        return $this->render('ice_cream/all.html.twig', [
          'products' => $products,
          'categories' => $categories,
          'selected_category' => $category
        ]);
    }

    #[Route('product/{id}')]
    public function get(int $id, ProductRepository $productRepository)
    {
        $product = $productRepository->find($id);
        return $this->render('ice_cream/get.html.twig', [
          'product' => $product
        ]);
    }

    #[Route('contacts')]
    public function contacts()
    {
        return $this->render('ice_cream/contacts.html.twig');
    }


#[Route('feedback')]
    public function feedback()
{
    return $this->render('ice_cream/feedback.html.twig');
}
}
