<?php

namespace App\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProfileNoteFilterType extends AbstractType
{
    public const ORDER_UPDATED = 1;
    public const ORDER_CATEGORY = 2;

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $categories = array_merge(['' => ''], $options['categories']);

        $builder
            ->add('categories', ChoiceType::class, [
                'label' => 'profile.note.categories',
                'required' => false,
                'placeholder' => 'profile.note.select.category',
                'choices' => $categories,
                'autocomplete' => true,
                'multiple' => true,
                'empty_data' => [],
            ])
            ->add('order', ChoiceType::class, [
                'label' => 'profile.note.order',
                'required' => true,
                'choices' => [
                    'profile.note.updated' => self::ORDER_UPDATED,
                    'profile.note.category' => self::ORDER_CATEGORY,
                ],
            ])
            ->setMethod('GET')
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver
            ->setDefaults([
                'categories' => [],
                'order' => 1,
            ])
        ;
    }
}
