<?php

namespace App\Form;

use App\Entity\ContentSource;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ContentSourceType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('baseUrl', UrlType::class, [
                'label' => 'Base URL',
            ])
            ->add('imageSelector', TextType::class, [
                'label' => 'Image Selector',
            ])
            ->add('chapterUrlFormat', TextType::class, [
                'label' => 'Chapter URL Format ({slug}, {chapterNumber})',
            ])
            ->add('nextPageSelector', TextType::class, [
                'label' => 'Next Page Selector (let empty if vertical reader)',
                'required' => false,
            ])
            ->add('ChapterSelector', TextType::class, [
                'label' => 'Chapter Selector (required for Javascript scraping)',
                'required' => false,
            ])
            ->add('scrapingType', ChoiceType::class, [
                'label' => 'Scraping Type',
                'choices' => [
                    'HTML' => 'html',
                    'JavaScript' => 'javascript'
                ],
            ]);
    }

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