<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\GTM\Events;

use KupShop\ComponentsBundle\Interfaces\GTMComponentInterface;
use Symfony\Contracts\Service\Attribute\Required;

class Variations implements GTMComponentInterface
{
    #[Required]
    public \KupShop\ComponentsBundle\GTM\Utils\DataLoaders\Products $productLoader;

    /**
     * @param \KupShop\ComponentsBundle\Twig\Components\Product\Variations $component
     */
    public function getPushData($component): ?object
    {
        $product = $component->getProductUnified();

        $this->productLoader->getProducts(array_map(function ($variation) use ($product) {
            $variationProduct = clone $product;
            $variationProduct->selectVariation($variation->getId());

            return $variationProduct;
        }, $product->getVariations()));

        return null;
    }
}
