<?php

namespace AutoAdmin\Bundle\Seo\Form;

use AutoAdmin\Bundle\Admin\Form\Type\AdminFormType;
use AutoAdmin\Bundle\Seo\Entity\SeoMetadata;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class SeoMetadataType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add(
            'title',
            TextType::class,
            [
                'label' => 'seo.form.title',
                'empty_data' => '',
                'required' => false,
                'attr' => ['class' => 'count-chars'],
            ]
        );

        $builder->add(
            'description',
            TextType::class,
            [
                'label' => 'seo.form.description',
                'empty_data' => '',
                'required' => false,
                'attr' => ['class' => 'count-chars'],
            ]
        );

        $builder->add(
            'noIndex',
            CheckboxType::class,
            [
                'label' => 'seo.form.no_index',
                'required' => false,
            ]
        );
        $builder->add(
            'noFollow',
            CheckboxType::class,
            [
                'label' => 'seo.form.no_follow',
                'required' => false,
            ]
        );
        $builder->add(
            'hideFromSitemap',
            CheckboxType::class,
            [
                'label' => 'seo.form.hide_from_sitemap',
                'required' => false,
            ]
        );
        $builder->add(
            'canonicalOverride',
            TextType::class,
            [
                'label' => 'seo.form.canonical_override',
                'required' => false,
            ]
        );
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        parent::configureOptions($resolver);

        $resolver->setDefault('data_class', SeoMetadata::class);
        $resolver->setDefault('label', false);
    }

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