<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\MainBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Intl\Languages;
use Symfony\Component\OptionsResolver\OptionsResolver;

class UserLocaleType extends AbstractType
{
    public function __construct(private readonly array $availableLanguages) {}

    public function configureOptions(OptionsResolver $resolver): void
    {
        $choices = [];
        foreach ($this->availableLanguages as $languageCode) {
            $choices[Languages::getName($languageCode)] = $languageCode;
        }

        $resolver->setDefaults([
            'choices' => $choices,
            'placeholder' => 'user.locale.placeholder',
            'required' => true,
            'label' => 'user.locale.label',
            'help' => 'user.locale.help',
        ]);
    }

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