<?php

namespace KupShop\ArticlesBundle\Twig\Components\Articles\Detail;

use KupShop\ArticlesBundle\GTM\PageViews\Article;
use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Entity\EditableContent;
use KupShop\ComponentsBundle\Entity\ObjectInfo;
use KupShop\ComponentsBundle\GTM\PostMount\GTMViewData;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use Symfony\Contracts\Service\Attribute\Required;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent(template: '@Articles/components/Articles/Detail/View/View.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null),
])]
class View extends BaseComponent
{
    use GTMViewData;
    private array $article;
    #[Required]
    public Article $gtmClass;

    public function getBlockId(): ?int
    {
        return $this->article['id_block'] ?? null;
    }

    protected function getObjectInfo(): ObjectInfo
    {
        return new ObjectInfo(
            type: 'article',
            id: $this->article['id'] ?? null,
            name: (translate('objects', 'blocks', true, true)['article'] ?? 'article').': '.$this->article['title'] ?? ''
        );
    }

    public function getContent(): EditableContent
    {
        return new EditableContent(
            blockId: $this->getBlockId(),
            objectInfo: $this->getObjectInfo()
        );
    }

    public function setArticle(array $article): void
    {
        $this->article = $article;
    }

    /**
     * Je to takhle idiotsky pojmenovany abych se k tomu dostal ale zaroven se to moc nenapovidalo v twig šabloně
     *  Pokud existuje lepsi reseni, sem s nim pls.
     *
     * @deprecated
     */
    public function articleForGTM(): array
    {
        return $this->article;
    }
}
