import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__locale_index_mjs__ from "../locale/index.mjs";
const useLanguageSettings = ()=>{
    var _data_data;
    const { t, i18n } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const api = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useAPIClient)();
    const { data } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useSystemSettings)();
    const enabledLanguages = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        var _data_data;
        return (null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.enabledLanguages) || [];
    }, [
        null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.enabledLanguages
    ]);
    const result = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            key: 'language',
            eventKey: 'LanguageSettings',
            label: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__index_mjs__.SelectWithTitle, {
                title: t('Language'),
                options: Object.keys(__WEBPACK_EXTERNAL_MODULE__locale_index_mjs__["default"]).filter((lang)=>enabledLanguages.includes(lang)).map((lang)=>({
                        label: __WEBPACK_EXTERNAL_MODULE__locale_index_mjs__["default"][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 };
