<?php

declare(strict_types=1);

namespace KupShop\ArticlesBundle\Twig\Components\Search;

use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use Query\Operator;
use Query\QueryBuilder;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\PreMount;

#[AsTwigComponent(template: '@Articles/components/ArticlesList/ArticlesList.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null),
])]
class ArticlesList extends \KupShop\ArticlesBundle\Twig\Components\ArticlesList
{
    public array $articleIds;

    #[PreMount]
    public function filterByIds(): void
    {
        $this->addSpec(function (QueryBuilder $qb) {
            $qb->andWhere(Operator::inIntArray($this->articleIds, 'a.id'));
        });
    }
}
