<?php

namespace App\Form\Type;

use App\Entity\Siege;
use App\Entity\Groupe;
use App\Entity\GlobalParameter;
use Doctrine\ORM\EntityManagerInterface;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email as EmailConstraint;
use Symfony\Component\Validator\Constraints\Type as TypeConstraint;
use Symfony\Component\Validator\Constraints\Regex as RegexConstraint;

class GlobalConfigurationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('mlcname', GlobalParameterType::class, array(
                'label' => 'Nom de la Monnaie (long) :',
                'name_param' => GlobalParameter::MLC_NAME,
                '_placeholder' => 'Monnaie Locale Complémentaire',
                'required' => true,
            ))
            ->add('mlcsmallname', GlobalParameterType::class, array(
                'label' => 'Nom court de la Monnaie ou abbréviation :',
                'name_param' => GlobalParameter::MLC_NAME_SMALL,
                '_placeholder' => 'MLC',
                'required' => true,
            ))
            ->add('mlcnotifemail', GlobalParameterType::class, array(
                'label' => "Email utilisé pour l'envoi des notifications :",
                'name_param' => GlobalParameter::MLC_NOTIF_EMAIL,
                'required' => true,
                '_placeholder' => 'notification@mlc.com',
                'constraints_param' => [
                    new EmailConstraint(['message' => 'Email invalide !'])
                ],
            ))
            ->add('mlccotisation', GlobalParameterType::class, array(
                'label' => 'Montant par défaut des cotisations:',
                'name_param' => GlobalParameter::COTISATION_MONTANT,
                'help' => 'Ne pas utiliser de virgule ",", utiliser le point "."',
                'required' => true,
                '_placeholder' => '10',
                'constraints_param' => [
                    new TypeConstraint(['type' => 'numeric', 'message' => "Le montant n'est pas valide !"])
                ],
            ))
            ->add('mapcenter', GlobalParameterType::class, array(
                'label' => 'Coordonnées du centre de la carte (Format [lat,long], exemple : [45.7,3.2]):',
                'name_param' => GlobalParameter::MAP_CENTER,
                'required' => true,
                '_placeholder' => '[45.7,3.2]',
                'constraints_param' => [
                    new RegexConstraint(['pattern' => '/^\[[0-9]+\.[0-9]+,[0-9]+\.[0-9]+\]/', 'message' => 'Coordonnées invalide, format attendu : [45.7,3.2]'])
                ],
            ))
            ->add('mapzoom', GlobalParameterType::class, array(
                'label' => 'Zoom de la carte (nombre entre 1 et 15) :',
                'name_param' => GlobalParameter::MAP_ZOOM,
                'required' => true,
                '_placeholder' => '9',
                'constraints_param' => [
                    new RegexConstraint(['pattern' => '/^[0-9]{1,2}$/', 'message' => 'Le zoom doit être un nombre entre 0 et 15 !'])
                ],
            ))
            ->add('mlcfavicon', GlobalParameterType::class, array(
                'label' => 'Chemin du favicon :',
                '_data' => '/images/favicon.png',
                'name_param' => GlobalParameter::FAVICON_URL,
                'required' => true,
            ))
            ->add('mlctitle', GlobalParameterType::class, array(
                'label' => '[SEO] Titre par défaut des pages du site web :',
                'name_param' => GlobalParameter::MLC_TITLE,
                'required' => true,
            ))
            ->add('mlcdescription', GlobalParameterType::class, array(
                'label' => '[SEO] Description par défaut des pages du site web :',
                'name_param' => GlobalParameter::MLC_DESCRIPTION,
                'required' => true,
            ))
            ->add('mlckeywords', GlobalParameterType::class, array(
                'label' => '[SEO] Mot clés par défaut des pages du site web :',
                'name_param' => GlobalParameter::MLC_KEYWORDS,
                'required' => true,
            ))
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            // 'cascade_validation' => true
        ]);
    }

    public function getBlockPrefix()
    {
        return 'formSiege';
    }
}
