<?php

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

use CpCreation\VitiCore\SocialNetwork\Model\SocialNetwork;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class SocialNetworkStep1Type extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $choices = [];
        foreach ($options['social_network_methods'] as $method) {
            $choices[(string) $method] = $method;
        }

        $builder->add('network', ChoiceType::class, [
            'choices' => $choices,
            'label' => 'Choisir un réseau social',
            'placeholder' => 'Aucun',
            'required' => false,
        ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => SocialNetwork::class,
            'social_network_methods' => [], // option custom
        ]);

        $resolver->setAllowedTypes('social_network_methods', 'array');
    }

    public function getBlockPrefix(): string
    {
        return 'social_network_step1';
    }
}
