<?php

// documentation : https://github.com/dustin10/VichUploaderBundle/blob/master/docs/form/vich_image_type.md

namespace App\Form;

use App\Entity\Sponsor;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Vich\UploaderBundle\Form\Type\VichImageType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;

class SponsorType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $sponsorTypes = \App\Entity\SponsorType::cases();

        $builder
            ->add('name', TextType::class, [ 'required' => true, 'attr' => ['maxlength' => 150],
            'translation_domain' => 'admin' ])
            ->add('sort_name', TextType::class, [ 'required' => true, 'attr' => ['maxlength' => 150],
            'translation_domain' => 'admin' ])

            ->add('active', CheckboxType::class, [ 'required' => false,
            'translation_domain' => 'admin' ])

            ->add('logoFile', VichImageType::class, [
                'data_class' => null, 
                // 'help' => 'Fichier *.png uniquement, max 1 Mo',
                'allow_delete' => false,
                'download_uri' => false,
                'required' => false,
                'translation_domain' => 'admin'
            ])

            ->add('description', TextareaType::class, [ 
                'required' => false,
                'translation_domain' => 'admin' 
            ])

            ->add('url', TextType::class, [ 'required' => false, 'attr' => ['maxlength' => 255],
            'translation_domain' => 'admin' ])
            ->add('phone', TextType::class, [ 'required' => false, 'attr' => ['maxlength' => 10],
            'translation_domain' => 'admin' ])
            ->add('email', TextType::class, [ 'required' => false, 'attr' => ['maxlength' => 100],
            'translation_domain' => 'admin' ])
            ->add('address', TextareaType::class, [ 'required' => false, 'attr' => ['maxlength' => 255],
            'translation_domain' => 'admin' ])

            ->add('type', ChoiceType::class, [
                'choices'  => $sponsorTypes,
                'choice_value' => 'value',
                'choice_label' => function(?\App\Entity\SponsorType $e): string { return 'sponsor-type.'.$e->value; },
                'choice_translation_domain' => "fields",
                'required' => true,
                'translation_domain' => 'admin'
            ]);
            ;
    }

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