<?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;

use AppBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
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;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;

class CareerType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('companyCareer', TextType::class, array(
                'label' => 'talent.profile.career.company.label',
            ))
            ->add('jobCareer', TextType::class, array(
                'label' => 'talent.profile.career.job.label',
            ))
            ->add('placeCareer', TextType::class, array(
                'label' => 'talent.profile.career.place.label',
            ))
            ->add('beginMonthCareer', ChoiceType::class, array(
                'label' => 'talent.profile.career.begin.label',
                'choices' => $this->getMonths(),
                'placeholder' => 'Mois'
            ))
            ->add('beginYearCareer', ChoiceType::class, array(
                'label' => 'talent.profile.career.begin.label',
                'choices' => $this->getYears(1960),
                'placeholder' => 'Année',
                'attr' => array(
                    'class' => 'beginYearCareer'
                )
            ))
            ->add('endMonthCareer', ChoiceType::class, array(
                'label' => 'talent.profile.career.end.label',
                'choices' => $this->getMonths(),
                'required' => false,
                'placeholder' => 'Mois'
            ))
            ->add('endYearCareer', ChoiceType::class, array(
                'label' => 'talent.profile.career.end.label',
                'choices' => $this->getYears(1960),
                'required' => false,
                'placeholder' => 'Année',
                'attr' => array(
                    'class' => 'endYearCareer'
                )
            ))
            ->add('actualJobCareer', CheckboxType::class, array(
                'label' => 'talent.profile.career.actualJob.label',
                'required' => false
            ))
            ->add('descriptionCareer', TextareaType::class, array(
                'label' => 'profile.company.description',
                'required' => false,
                'attr' => array(
                    'class' => 'materialize-textarea'
                )
            ))
            ->add('tagsComma', TextType::class, array(
                'label' => 'talent.profile.career.skills.label',
                'required' => false,
                'attr' => array(
                    'data-role'=>"materialtags"
                )
            ));
    }

    private function getYears($min, $max='current')
    {
        $years = range($min, ($max === 'current' ? date('Y') : $max));
        $resultYears = array_combine($years, $years);
        arsort($resultYears);

        return $resultYears;
    }

    private function getMonths()
    {
        $months = array();
        for ($m=1; $m<=12; $m++) {
        $month = strftime('%B', mktime(0,0,0,$m, 1, date('Y')));
        $months[$month] = $m;
        }
        
        return $months;
    }

    public function getName()
    {
        return 'career';
    }
}
