<?php

/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace AppBundle\Form\Admin;

use AppBundle\Entity\Company;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class TerritoryAdminType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $company = $options['data'];
        $company->init();

        $terType = "";
        $extra = $company->getExtra();
        if ($extra != null) {
            if (is_array($extra)) {
                $terType = (isset($extra['terType'])) ? $extra['terType'] : '';
            }
        }

        // Common fields
        $builder
            ->add('brandName', TextType::class, array('label' => 'Nom'))
            ->add('description', TextType::class, array('label' => 'profile.company.description', 'required' => false))
            ->add('descriptionAdmin', TextareaType::class, array('label' => 'Description additionel réservé aux administrateur (Attention contenu affiché en front)', 'required' => false))
            ->add('website', UrlType::class, array(
                'label' => 'profile.company.website',
                'required' => false,
                'attr' => array(
                    'placeholder' => 'http://...',
                )));
        // Addresses fields
        $builder
            ->add('address', TextType::class, array(
                'label' => 'Adresse',
                'required' => false,
            ))
            ->add('addressComp', TextType::class, array(
                'label' => 'Complément Adresse',
                'required' => false,
            ))
            ->add('zipcode', TextType::class, array(
                'label' => 'Code postal',
                'required' => false,
            ))
            ->add('city', TextType::class, array(
                'label' => 'Ville',
                'required' => false,
            ))
            ->add('country', CountryType::class, array(
                'label' => 'Pays',
                'required' => false,
            ));
        //Tags field
        $builder
            ->add('tagsComma', TextType::class, array(
                'label' => 'profile.company.tags',
                'required' => false,
            ));
        // File fields
        $builder
            ->add('file', FileType::class, array(
                'label' => 'profile.company.logo',
                'required' => false,
                'attr' => array(
                    'class' => 'file-path validate',
                ),
            ));
        // Emphasis
        $builder
            ->add('emphasis', CheckboxType::class, array(
                'label' => 'A la une',
                'required' => false,
            ))
            ->add('emphasisOrder', IntegerType::class, array(
                'label' => 'Ordre',
                'required' => false,
            ));
        $builder->add('isPrivate', CheckboxType::class, array(
            'label' => 'Page territoire privé ( non listée en front )',
            'required' => false,
        ));
        $builder->add('terType', ChoiceType::class, array(
            'mapped' => false,
            'label' => 'Type ',
            'data' => $terType,
            'choices' => array(
                'Région' => 'Région',
                'Communauté d\'agglomération' => 'Communauté d\'agglomération',
                'Communauté de commune' => 'Communauté de commune',
                'Commune' => 'Commune',
                'Département' => 'Département',
            ),
        ));
    }

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