<?php

namespace App\Form;

use App\Entity\Question;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

use Symfony\Component\Form\Extension\Core\Type\CollectionType;

use Symfony\Component\Form\Extension\Core\Type\FileType;

class QuestionType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('title')
            ->add('name_en', null, [
                'label' => '🇬🇧 Name',
            ])
            ->add('name_fr', null, [
                'label' => '🇫🇷 Nom',
            ])
            ->add('name_ar', null, [
                'label' => '🇸🇦 العربية',
            ])
            ->add('choice', ChoiceType::class, [
                'label' => 'Gender',
                'choices' => [
                    'Choix Multiple' => 'multiple',
                    'Choix Unique' => 'unique',
                ],
                'expanded' => true, // This makes it radio buttons instead of select
                'multiple' => false, // Single selection
                'required' => true,
                'placeholder' => false, // Remove the empty option
            ])
            ->add('type_modality', ChoiceType::class, [
                'label' => 'Type',
                'choices' => [
                    'Text' => '1',
                    'Image' => '3',
                    'Video' => '4',
                    'Son' => '5',
                    'Form Text' => '2',
                ],
                'placeholder' => 'Choose a type modality', // Optional placeholder
                'required' => true,
            ])
            ->add('amount')
            ->add('max_participant')
            ->add('modalitys', CollectionType::class, array(
                'entry_type'   => ModalityType::class,
                'allow_add' => true,
                'allow_delete' => true,
                'prototype' => true,
                'by_reference' => false
            ))
            ->add('attachments', CollectionType::class, [
                'label' => 'Pièces jointes',
                'entry_type' => AttachmentType::class,
                'entry_options' => ['label' => false],
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
                'prototype' => true,
                'prototype_name' => '__attachment_prot__',
                'required' => false,
            ]);
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Question::class,
        ]);
    }
}
