import { useState, useEffect, createContext } from 'react';
import { get } from "utils/HttpUtils"
import {GET_SYS_SETTING} from "utils/ApiPathConst"


const SysContext = createContext();

const SysSettingProvider = ({ children }) => {

    const [sysSetting, setSysSetting] = useState({}); 

    useEffect(() => {
        loadSysSetting();
    }, []);


    const loadSysSetting = () => {
        get({
            url: GET_SYS_SETTING,
            onSuccess: (responseData) => {
                // console.log(responseData)
                setSysSetting(responseData);
                localStorage.setItem('sysEnv', responseData.sysEnv)
                localStorage.setItem('paymentSuspension', responseData.suspensionMode)
            }
        });
    }

    return (
        <SysContext.Provider value={{ sysSetting, setSysSetting }} >
            {children}
        </SysContext.Provider>
    );
}

export {SysContext, SysSettingProvider};