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__tachybase_utils_client__ from "@tachybase/utils/client";
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__user_index_mjs__ from "../../user/index.mjs";
const useTabSettings = ()=>({
        key: 'tab',
        eventKey: 'tab',
        label: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Label, {})
    });
function Label() {
    var _currentUser_data_data_systemSettings;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { updateUserPageStyle } = useUpdatePageStyleSettings();
    const currentUser = (0, __WEBPACK_EXTERNAL_MODULE__user_index_mjs__.useCurrentUserContext)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__common_index_mjs__.SelectWithTitle, {
        title: t('Page style'),
        defaultValue: (null === (_currentUser_data_data_systemSettings = currentUser.data.data.systemSettings) || void 0 === _currentUser_data_data_systemSettings ? void 0 : _currentUser_data_data_systemSettings.pageStyle) || 'classical',
        options: [
            {
                label: t('classical'),
                value: 'classical'
            },
            {
                label: t('tabs'),
                value: 'tab'
            }
        ],
        onChange: updateUserPageStyle
    });
}
function useUpdatePageStyleSettings() {
    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
    const currentUser = (0, __WEBPACK_EXTERNAL_MODULE__user_index_mjs__.useCurrentUserContext)();
    const updateUserPageStyle = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(async (pageStyle)=>{
        var _currentUser_data_data_systemSettings;
        if (pageStyle === (null === (_currentUser_data_data_systemSettings = currentUser.data.data.systemSettings) || void 0 === _currentUser_data_data_systemSettings ? void 0 : _currentUser_data_data_systemSettings.pageStyle)) return;
        try {
            await api.resource('users').updateProfile({
                values: {
                    systemSettings: {
                        ...currentUser.data.data.systemSettings || {},
                        pageStyle
                    }
                }
            });
            currentUser.mutate({
                data: {
                    ...currentUser.data.data,
                    systemSettings: {
                        ...currentUser.data.data.systemSettings || {},
                        pageStyle
                    }
                }
            });
        } catch (err) {
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.error)(err);
        }
    }, [
        api,
        currentUser
    ]);
    return {
        updateUserPageStyle
    };
}
export { Label, useTabSettings, useUpdatePageStyleSettings };
