<?php

namespace App\Controller\Admin\Site;

use App\Controller\AbstractAdminController;
use App\Entity\Site\Block;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Repository\RepositoryQueryInterface;

class BlockCrudController extends AbstractAdminController
{
    public static function getEntityFqcn(): string
    {
        return Block::class;
    }

    public function getRepositoryQuery(): RepositoryQueryInterface
    {
        return $this->getBlockContainer()->getRepositoryQuery();
    }

    public function createEntity(string $entityFqcn)
    {
        return $this->getBlockContainer()->getFactory()->create();
    }

    public function configureFields(string $pageName): iterable
    {
        if ($this->isGranted("ROLE_SUPER_ADMIN")) {
            $fields[] = TextField::new('devAlias');
        }

        $fields[] = TextField::new('title');
        $fields[] = CKEditorField::new('description')->hideOnIndex();
        $fields[] = StatusField::new('status');

        return $fields;
    }
}
