import { jsx } from "react/jsx-runtime";
import { useCallback } from "react";
import { error } from "@tego/client";
import { useTranslation } from "react-i18next";
import { useAPIClient } from "../../api-client/index.mjs";
import { SelectWithTitle } from "../../common/index.mjs";
import { useCurrentUserContext } from "../../user/index.mjs";
const useTabSettings = ()=>({
        key: 'tab',
        eventKey: 'tab',
        label: /*#__PURE__*/ jsx(Label, {})
    });
function Label() {
    var _currentUser_data_data_systemSettings;
    const { t } = useTranslation();
    const { updateUserPageStyle } = useUpdatePageStyleSettings();
    const currentUser = useCurrentUserContext();
    return /*#__PURE__*/ jsx(SelectWithTitle, {
        title: t('Page style'),
        defaultValue: (null == (_currentUser_data_data_systemSettings = 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 = useAPIClient();
    const currentUser = useCurrentUserContext();
    const updateUserPageStyle = 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.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) {
            error(err);
        }
    }, [
        api,
        currentUser
    ]);
    return {
        updateUserPageStyle
    };
}
export { Label, useTabSettings, useUpdatePageStyleSettings };
