<?php

namespace KupShop\ComponentsBundle\Twig\Components\Section\SubCategories;

use KupShop\CatalogBundle\Entity\Section;
use KupShop\ComponentsBundle\Twig\BaseComponent;

class ItemBase extends BaseComponent
{
    public ?Section $section = null;
    public ?int $id_producer = null;

    public function getUrl(): string
    {
        if ($this->section === null) {
            return '';
        }

        // (LegacyUrlGenerator) automaticky přidá locale prefix
        return path('page', ['path' => $this->id_producer ? $this->section->getAutogeneratedUrl() : $this->section->getUrl()]);
    }

    public function getName(): string
    {
        if ($this->section === null) {
            return '';
        }

        return $this->section->getNameShort() ?: $this->section->getName();
    }
}
