<?php

namespace App\Form;

use App\Entity\Photos;

use App\Form\CategoryAutocompleteField;
use App\Form\TagAutocompleteField;
use App\Form\PhotoType;
use App\Form\DataTransformer\UploadDataTransformer;

use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PhotosType extends AbstractType
{
    public function __construct(private UploadDataTransformer $transformer){}
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('title')
            ->add('date', DateType::class)
            ->add('category', CategoryAutocompleteField::class)
            ->add('tags', TagAutocompleteField::class, ['required' => false])
            ->add('description')
            ->add('text')
            ->add('thumbnail', FileType::class, [
                'label' => 'Thumbnail',
            ])
            ->add('uploads', CollectionType::class, [
                'entry_type' => PhotoType::class,
                'entry_options' => ['label' => false],
                'allow_add' => true,
                'by_reference' => false,

            ])
            ->add('url')
            ->add('save', SubmitType::class, ['label' => 'Save'])
        ;

        //$builder->get('uploads')->addModelTransformer($this->transformer);
    }

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