<?php

namespace KupShop\ComponentsBundle\Twig\Components\Product\Collections;

use KupShop\CatalogBundle\ProductList\ProductList;
use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Entity\Thumbnail;
use KupShop\ComponentsBundle\Twig\Components\Product\Collections;
use KupShop\ContentBundle\Util\ImageLocator;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent(template: '@Components/components/Product/Collections/SquaresCatalog/SquaresCatalog.1.html.twig')]
#[Component(2, [
    new Version(1, newJs: null),
    new Version(2, newTemplate: true, newJs: true, newCss: true),
])]
class SquaresCatalog extends Collections
{
    public int $limit = 3;
    public string $image_type = 'product_catalog';

    public function __construct(
        private ProductList $productList,
        private ImageLocator $imageLocator,
    ) {
        parent::__construct($this->productList);
    }

    public function getThumbnailSrc(Thumbnail $thumbnail): string
    {
        $settings = $this->imageLocator->getTypeConfig($this->image_type);
        $imageTypeSizeKey = array_key_first($settings['sizes']);

        return $this->imageLocator->getThumbnailUrl($thumbnail, $this->image_type, $imageTypeSizeKey);
    }
}
