<?php

namespace KupShop\ComponentsBundle\Twig\Components\SectionList;

use Doctrine\Common\Collections\ArrayCollection;
use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Entity\Thumbnail;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use KupShop\ComponentsBundle\Twig\DataProvider\SectionDataTrait;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent(template: '@Components/components/SectionList/Section/Section.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null),
])]
class Section extends BaseComponent
{
    use DefaultActionTrait;

    use SectionDataTrait;

    #[LiveProp]
    public bool $isHidden = true;

    public function getName(): string
    {
        return $this->sectionDataProvider->getName($this->id_section);
    }

    public function getUrl(): string
    {
        return $this->sectionDataProvider->getUrl($this->id_section);
    }

    public function getThumbnail(): ?Thumbnail
    {
        return $this->sectionDataProvider->getThumbnail($this->id_section);
    }

    public function getChildren(): ?ArrayCollection
    {
        return $this->sectionDataProvider->getChildren($this->id_section);
    }

    #[LiveAction]
    public function toggleAction(): void
    {
        if ($this->isHidden) {
            $this->isHidden = false;
        } else {
            $this->isHidden = true;
        }
    }
}
