import axios from 'axios';
import { useState } from './useState';
import useNotify from './useNotify';

export function useUserConfig() {
    const state = useState();
    const { notify } = useNotify();

    async function fetch() {
        try {
            const { data } = await axios.get('UserConfigs/getUserConfig');
            const user = state.getUser().value;
            user.darkMode = data.darkMode;
            user.companyFk = data.companyFk;
            user.warehouseFk = data.warehouseFk;
            state.setUser(user);

            return data;
        } catch (error) {
            notify('errors.userConfig', 'negative');
            console.error('Error fetching user config:', error);
        }
    }

    return {
        fetch,
    };
}
