<?php

namespace App\Form;

use App\Entity\LocationRate;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\Extension\Core\Type\RangeType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Range;

class LocationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('lowerBound', RangeType::class, [
                'label' => 'basics.lowerBound',
                'attr' => [
                    'min' => 0,
                    'max' => 100
                    ]            
                ])
            ->add('upperBound', RangeType::class, [
                'label' => 'basics.upperBound',
                'attr' => [
                    'min' => 0,
                    'max' => 100
                    ]            
                ])
            ->add('rate', PercentType::class, [
                'label' => 'basics.rate',
                'type' => 'integer',
                'constraints' => [
                    new Range([
                        'min' => 0,
                        'max' => 100,
                        'minMessage' => 'You must be at least {{ limit }} tall to enter',
                        'maxMessage' => 'You cannot be taller than {{ limit }} to enter',
                        ]),
                    ],

                ])
            ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => LocationRate::class
        ));
    }
}
