<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Controller\Site;

use CpCreation\VitiCore\Shop\ShopCatalogResolver;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class ShopIndexController extends AbstractController
{
    public function __construct(
        private readonly ShopCatalogResolver $shopCatalogResolver,
    ) {}

    public function __invoke(?string $slug = null): Response
    {
        $catalog = $this->shopCatalogResolver->resolveCatalog(categorySlug: $slug);

        return $this->render('shop/index.html.twig', [
            'category' => $catalog['category'],
        ]);
    }
}
