import { jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { SelectWithTitle, useAPIClient, useSystemSettings } from "../index.mjs";
import locale from "../locale/index.mjs";
const useLanguageSettings = ()=>{
    var _data_data;
    const { t, i18n } = useTranslation();
    const api = useAPIClient();
    const { data } = useSystemSettings();
    const enabledLanguages = useMemo(()=>{
        var _data_data;
        return (null == data ? void 0 : null == (_data_data = data.data) ? void 0 : _data_data.enabledLanguages) || [];
    }, [
        null == data ? void 0 : null == (_data_data = data.data) ? void 0 : _data_data.enabledLanguages
    ]);
    const result = useMemo(()=>({
            key: 'language',
            eventKey: 'LanguageSettings',
            label: /*#__PURE__*/ jsx(SelectWithTitle, {
                title: t('Language'),
                options: Object.keys(locale).filter((lang)=>enabledLanguages.includes(lang)).map((lang)=>({
                        label: locale[lang].label,
                        value: lang
                    })),
                defaultValue: i18n.language,
                onChange: async (lang)=>{
                    await api.resource('users').updateProfile({
                        values: {
                            appLang: lang
                        }
                    });
                    api.auth.setLocale(lang);
                    window.location.reload();
                }
            })
        }), [
        api,
        enabledLanguages,
        i18n,
        t
    ]);
    if (enabledLanguages.length < 2) return null;
    return result;
};
export { useLanguageSettings };
