<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\Twig\Components\EditableContent;

use KupShop\ComponentsBundle\Entity\EditableContent;
use KupShop\ComponentsBundle\Entity\ObjectInfo;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use Symfony\UX\TwigComponent\Attribute\PreMount;

abstract class ContentTemplate extends BaseComponent
{
    public $blockData;

    public function content(): ?EditableContent
    {
        if (!$this->blockData) {
            return null;
        }

        return new EditableContent($this->blockData['id_block'], new ObjectInfo(
            type: 'fragments',
            id: $this->blockData['id'],
            name: $this->blockData['name'],
        ));
    }

    #[PreMount]
    public function initData($data)
    {
        $data['blockData'] = $this->getTemplateData($data);

        return $data;
    }

    protected function getTemplateData($data): false|array
    {
        return false;
    }
}
