<?php

namespace Lc\SovBundle\Controller\Site;

use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Container\Site\PageContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Site\PageFactory;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Repository\RepositoryQueryInterface;

abstract class PageAdminController extends AbstractAdminController
{

    public function getRepositoryQuery() :RepositoryQueryInterface
    {
        return $this->get(PageContainer::class)->getRepositoryQuery();
    }

    public function configureFields(string $pageName): iterable
    {
        $panel = parent::configureFields($pageName);

        return array_merge(
                [
                        FormField::addPanel('general'),
                        TextField::new('title'),
                        NumberField::new('position')
                                ->hideOnIndex()
                                ->hideOnForm(),
                        CKEditorField::new('description'),
                        StatusField::new('status'),
                ],
                $panel
        );
    }

    public function createEntity(string $entityFqcn)
    {
        return $this->get(PageContainer::class)->getFactory()->create();
    }

}
