<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\Twig\Components\EditableContent;

use KupShop\ComponentsBundle\Attributes\Blocek;
use KupShop\ComponentsBundle\Attributes\BlocekAttribute;
use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Twig\Components\Utils\EditableContent\BlocekDataResult;
use KupShop\ComponentsBundle\Twig\Components\Utils\EditableContent\BlocekDataTrait;
use KupShop\ContentBundle\Util\BlocekTypes;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\PostMount;

#[AsTwigComponent(template: '@Components/components/EditableContent/ProductParameters/ProductParameters.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null, newCss: null),
])]
#[Blocek(title: 'Parametry produktu')]
class ProductParameters extends ContentTemplate
{
    use BlocekDataTrait;

    public ?int $id_product = null;

    #[BlocekAttribute(title: 'Zobrazit výrobce')]
    public bool $showProducer = false;

    #[BlocekAttribute(title: 'Zobrazit nadpis')]
    public bool $showHeader = false;

    #[BlocekAttribute(
        title: 'Vzhled parametrů',
        type: BlocekTypes::SELECT,
        options: [
            'Výchozí' => 'default',
            'Pruhy' => 'stripped',
            'Rámeček' => 'bordered',
        ]
    )]
    public string $style = 'default';

    #[BlocekAttribute(
        title: 'Produkt',
        type: BlocekTypes::AUTOCOMPLETE,
        autocompleteType: 'productId',
        autocompleteMulti: false,
        autocompletePreload: 'products'
    )]
    private ?BlocekDataResult $productsConfig = null;

    #[PostMount]
    public function prepareSpecs(): void
    {
        if ($this->productsConfig) {
            $this->id_product = $this->productsConfig->getValues()[0];
        }
    }

    public function setProductsConfig(?array $productsConfig): void
    {
        $this->productsConfig = new BlocekDataResult($productsConfig);
    }
}
