<?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\Form\Extension\Core\Type\FileType as BaseFileType;

class FileMediaType extends AdminContentType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        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;
    }
}
