<?php

declare(strict_types=1);

namespace External\CykloSpecialityBundle\EventSubscriber;

use KupShop\CatalogBundle\Event\CategoryEvent;
use KupShop\CatalogBundle\ProductList\ProductListBanners;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CategorySubscriber implements EventSubscriberInterface
{
    public function __construct(private readonly ProductListBanners $banners)
    {
    }

    public static function getSubscribedEvents(): array
    {
        return [
            CategoryEvent::NAME => ['addCatalogSliders', 200],
        ];
    }

    public function addCatalogSliders(CategoryEvent $event): void
    {
        $slider_id = $event->getCategory()['id_slider'] ?? null;

        if ($slider_id) {
            $this->banners->setStepSize(5)
                ->setCount(1)
                ->setMinPosition(5)
                ->setSliderId((int) $slider_id)
                ->setSeedFromFilterParams($event->getFilterParams())
                ->attach($event->getProductList(), $event->getPager());
        }
    }
}
