<?php

namespace App\Form\BackendAdmin;

use Symfony\Component\OptionsResolver\OptionsResolver;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

use Symfony\Bridge\Doctrine\Form\Type\EntityType;

use FOS\CKEditorBundle\Form\Type\CKEditorType;

use App\Entity\Service;
use App\Entity\Societe;
use App\Entity\Categorie;

use App\Repository\CategorieRepository;

class ServiceType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('titre')
            ->add('marque')
            ->add('description', CKEditorType::class)
            ->add('adress')
            ->add('prix_marche')
            ->add('prix_promo')
            ->add('limit_type', ChoiceType::class, array(
                'choices' => array(
                    'Limitation par date' => 0,
                    'Limitation par Rendez-vous' => 1,
                ),
                'expanded' => true
            ))
                
            ->add('duree')      

            ->add('limit_date', DateType::class, [
                'widget' => 'single_text',
                'required' => false,
            ])


            
            ->add('societe', EntityType::class, [
                'class' => Societe::class,
                'choice_label' => 'nom',
                'multiple' => false,])
            ->add('categorie', EntityType::class, array(
                'label' => 'Liste des groupes',
                'class' => Categorie::class,
                'required' => true,
                'placeholder' => 'Sélectionnez une catégorie',
                'query_builder' => function (CategorieRepository $er) {
                    return $er->createQueryBuilder('u')
                              ->orderBy('u.nom', 'ASC');
                },
                'choice_label' => function (Categorie $categorie) {
                    return $categorie->getId() . ' - ' . $categorie->getNom();
                }
            ))
            ->add("save", SubmitType::class)

        ;
    }

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