<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\GTM\PageViews;

use KupShop\ComponentsBundle\Interfaces\GTMComponentViewInterface;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use Query\Operator;

class Section implements GTMComponentViewInterface
{
    /**
     * @param \KupShop\ComponentsBundle\Twig\Components\Section\View $component
     */
    public function getPushData($component): object
    {
        if ($component->getSection()) {
            $catZboziName = sqlQueryBuilder()->select('fs.category_text')
                ->from('sections', 's')
                ->leftJoin('s', 'kupshop_shared.feed_seznam', 'fs', 's.feed_seznam = fs.id')
                ->andWhere(Operator::equals(['s.id' => $component->getSection()->getId()]))
                ->execute()->fetchOne();
        }

        return (object) [
            'category' => (object) [
                'id' => $component->getSection()->getId(),
                'name' => $component->getSection()->getName(),
                'path' => $component->getSection()->getUrl(),
                'cat_zbozi_name' => $catZboziName ?? null,
            ],
        ];
    }

    /**
     * @param \KupShop\ComponentsBundle\Twig\Components\Section\View $component
     */
    public function getPageTypeString(BaseComponent $component): ?string
    {
        if ($component->getSection()) {
            return 'category';
        }
    }
}
