<?php

declare(strict_types=1);

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

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\NotBlank;

final class ClientImportUploadType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('file', FileType::class, [
            'label' => 'admin_client_import.upload.file_label',
            'required' => true,
            'constraints' => [
                new NotBlank(message: 'admin_client_import.error.file_required'),
                new File(
                    maxSize: '10M',
                    extensions: ['csv', 'xls', 'xlsx'],
                    extensionsMessage: 'admin_client_import.error.unsupported_extension',
                    maxSizeMessage: 'admin_client_import.error.file_too_large',
                ),
            ],
            'attr' => [
                'accept' => '.csv,.xls,.xlsx',
            ],
        ]);
    }

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