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__api_client_index_mjs__ from "../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__common_index_mjs__ from "../common/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__CurrentUserProvider_mjs__ from "./CurrentUserProvider.mjs";
const useSwitchRole = ()=>{
    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
    const roles = (0, __WEBPACK_EXTERNAL_MODULE__CurrentUserProvider_mjs__.useCurrentRoles)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const result = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            key: 'role',
            eventKey: 'SwitchRole',
            label: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__common_index_mjs__.SelectWithTitle, {
                title: t('Switch role'),
                fieldNames: {
                    label: 'title',
                    value: 'name'
                },
                options: roles,
                defaultValue: api.auth.role,
                onChange: async (roleName)=>{
                    api.auth.setRole(roleName);
                    await api.resource('users').setDefaultRole({
                        values: {
                            roleName
                        }
                    });
                    location.reload();
                    window.location.reload();
                }
            })
        }), [
        api,
        roles,
        t
    ]);
    if (roles.length <= 1) return null;
    return result;
};
export { useSwitchRole };
