<?php

/*
 * This file is part of the VitiCore 2.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin;

use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
use CpCreation\VitiCore\Gite\Model\Room;
use CpCreation\VitiCore\Gite\Model\RoomImage;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class RoomType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add(
                'translations', TranslationsType::class, [
                    'label' => false,
                    'fields' => [
                        'header' => [
                            'field_type' => TextType::class,
                            'label' => 'Header',
                            'required' => false,
                        ],
                        'title' => [
                            'field_type' => TextType::class,
                            'label' => 'Titre',
                            'required' => false,
                        ],
                        'description' => [
                            'field_type' => TrumbowygType::class,
                            'label' => 'Description',
                            'required' => false,
                        ],
                        'otherDescription' => [
                            'field_type' => TrumbowygType::class,
                            'label' => 'Description Supplémentaire',
                            'required' => false,
                        ],
                    ],
                    'excluded_fields' => ['slug'],
                ]
            )
            ->add(
                'images', ImageCollectionType::class, [
                    'label' => false,
                    'entry_type' => RoomImageType::class,
                    'allow_add' => true,
                    'allow_delete' => true,
                    'error_bubbling' => false,
                    'prototype' => true,
                    'by_reference' => false,
                    'delete_empty' => true,
                    'attr' => [
                        'data-name-prefix' => 'ImageRoom',
                        'class' => 'image-collection',
                    ],
                    'entry_options' => [
                        'data_class' => RoomImage::class,
                        'label' => false,
                    ],
                ]
            );
    }

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