import useLocalStorage from "@/hooks/useLocalStorage";
import React, {createContext} from "react";

const config: ConfigProps = {
    fontFamily: `'Public Sans', sans-serif`,
    i18n: 'zh-CN',
    appName: "数字人直播",
};

const initialState: CustomizationProps = {
    ...config,
    onChangeContainer: () => {
    },
    onChangeLocalization: (_: I18n) => {
    },
    onChangeFontFamily: (_: string) => {
    }
};

// ==============================|| CONFIG CONTEXT & PROVIDER ||============================== //

const ConfigContext = createContext(initialState);
export const ConfigProvider = ({children}: { children: React.ReactNode }) => {
    const [config, setConfig] = useLocalStorage('app-video-admin-config', initialState);
    // 改变语言
    const onChangeLocalization = (lang: I18n) => {
        setConfig({
            ...config,
            i18n: lang
        });
    };
    // 更改字体
    const onChangeFontFamily = (fontFamily: string) => {
        setConfig({...config, fontFamily})
    }

    return (
        <ConfigContext.Provider value={{
            ...config, onChangeFontFamily, onChangeLocalization
        }}>{children}</ConfigContext.Provider>
    )
}
export default ConfigContext