<?php

declare(strict_types=1);

namespace ACP\Metric\Config\User;

use AC\Helper;
use AC\MetaType;
use ACP\Metric\Config\Meta\Choice;

class Language extends Choice
{
    public static function create(): ?self
    {
        $translations = Helper\AvailableTranslations::create()->get_available_translations();

        $languages = [];

        foreach (get_available_languages() as $language) {
            $languages[$language] = $translations[$language]['native_name'] ?? $language;
        }

        natcasesort($languages);

        /** @var self|null $config */
        $config = self::from_choices(
            MetaType::create_user_meta(),
            'locale',
            $languages
        );

        return $config;
    }

}
