<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\EventBundle\Form\Type;

use Chill\EventBundle\Entity\EventTheme;
use Chill\EventBundle\Repository\EventThemeRepository;
use Chill\EventBundle\Templating\Entity\EventThemeRender;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PickEventThemeType extends AbstractType
{
    public function __construct(private readonly EventThemeRender $eventThemeRender, private readonly EventThemeRepository $eventThemeRepository) {}

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            ->setDefaults([
                'class' => EventTheme::class,
                'choices' => $this->eventThemeRepository->findByActiveOrdered(),
                'choice_label' => fn (EventTheme $et) => $this->eventThemeRender->renderString($et, []),
                'placeholder' => 'event.form.Select one or more themes',
                'required' => true,
                'attr' => ['class' => 'select2'],
                'label' => 'event.theme.label',
                'multiple' => false,
            ])
            ->setAllowedTypes('multiple', ['bool']);
    }

    public function getParent(): string
    {
        return EntityType::class;
    }
}
