<?php

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\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CompanyAdminType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $company = $options['data'];
        $company->init();
        // Common fields
        $builder
            ->add('brandName', TextType::class, array('label' => 'profile.company.brandname'))
            ->add('businessName', TextType::class, array('label' => 'profile.company.businessname'))
            ->add('description', TextareaType::class, array('label' => 'profile.company.description'))
            ->add('website', UrlType::class, array(
                'label' => 'profile.company.website',
                'required' => false,
                'attr' => array(
                    'placeholder' => 'http://...'
                )));
        // Extra fields
        $builder
            ->add('siren', TextType::class, array(
                'label' => 'profile.company.siren',
            ))
            ->add('size', TextType::class, array(
                'label' => 'profile.company.size',
            ))
            ->add('isPrivate', CheckboxType::class, array(
                'label' => 'Page entreprise privé ( non listée en front )',
                'required' => false
            ));
        // Addresses fields
        $builder
            ->add('address', TextType::class, array(
                'label' => 'Adresse',
            ))
            ->add('addressComp', TextType::class, array(
                'label' => 'Complément Adresse',
                'required' => false
            ))
            ->add('zipcode', TextType::class, array(
                'label' => 'Code postal',
            ))
            ->add('city', TextType::class, array(
                'label' => 'Ville',
            ))
            ->add('country', CountryType::class, array(
                'label' => 'Pays',
            ));
        //Tags field
        $builder
            ->add('tagsComma', TextType::class, array(
                'label' => 'profile.company.tags',
            ));
        // 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
            ));
    }

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