<?php

namespace AutoAdmin\Bundle\Media\Form\Type\Media;

use AutoAdmin\Bundle\Admin\Form\Type\AdminContentType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FileType as BaseFileType;

class FileMediaType extends AdminContentType
{
    public function configureOptions(OptionsResolver $resolver)
    {
        parent::configureOptions($resolver);

//        $resolver->setDefault('data_class', FileMedia::class);
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);

        $data = $builder->getData();

        $builder->add('file', BaseFileType::class, [
            'property_path' => 'file',
        ]);

        if (!empty($data) && !empty($data->getId())) {
            $builder->add('title', TextType::class, [
                'property_path' => 'currentTranslation.title',
            ]);
            $builder->add('fileName', TextType::class, [
                'property_path' => 'currentTranslation.fileName',
            ]);
        }
    }

    public function getParent(): string
    {
        return AdminContentType::class;
    }
}
