<?php

namespace App\Form;

use App\Entity\Project;
use App\Entity\Tag;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProjectType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', null, ['label' => 'Nom'])
            ->add('description', null, ['label' => 'Description'])
            ->add('hashtags', null, [
                'label' => 'Hashtags',
                'help_html' => true,
                'help' => 'Mots séparés par des espaces, sans <samp>#</samp>',
            ])
            ->add('source', null, [
                'label' => 'Source',
                'help_html' => true,
                'help' => 'On peut en préciser plusieurs, en les séparant par des <samp>;</samp>',
            ])
            ->add('imagery', null, [
                'label' => 'Imagerie',
                'help_html' => true,
                'help' => 'Cf <a href="https://josm.openstreetmap.de/wiki/Maps" target="_blank">le wiki</a>',
            ])
            ->add('overpassQuery', null, [
                'label' => 'Requête Overpass',
                'required' => false,
                'help_html' => true,
                'help' => 'Cf <a href="https://overpass-turbo.eu/" target="_blank">le frontal</a>. Se limiter à la requête stricto sensu, sans <samp>[out:json][timeout:25];</samp> avant ou <samp>out geom;</samp> après.',
            ])
            ->add('tags', EntityType::class, [
                'label' => 'Étiquettes',
                'class' => Tag::class,
                'choice_label' => 'name',
                'multiple' => true,
                'expanded' => true,
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Project::class,
        ]);
    }
}
