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_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE__defaultTheme_mjs__ from "./defaultTheme.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__AntdAppProvider_mjs__ from "./AntdAppProvider.mjs";
export * from "./type.mjs";
const GlobalThemeContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(null);
GlobalThemeContext.displayName = 'GlobalThemeContext';
const useGlobalTheme = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(GlobalThemeContext) || {
        theme: {},
        isDarkTheme: false
    };
const GlobalThemeProvider = (param)=>{
    let { children, theme: themeFromProps } = param;
    const [theme, setTheme] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(themeFromProps || __WEBPACK_EXTERNAL_MODULE__defaultTheme_mjs__["default"]);
    const currentSettingThemeRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
    const currentEditingThemeRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
    const isDarkTheme = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        const algorithm = null == theme ? void 0 : theme.algorithm;
        if (Array.isArray(algorithm)) return algorithm.includes(__WEBPACK_EXTERNAL_MODULE_antd__.theme.darkAlgorithm);
        return algorithm === __WEBPACK_EXTERNAL_MODULE_antd__.theme.darkAlgorithm;
    }, [
        null == theme ? void 0 : theme.algorithm
    ]);
    const setCurrentEditingTheme = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((themeItem)=>{
        currentEditingThemeRef.current = themeItem ? __WEBPACK_EXTERNAL_MODULE_lodash__["default"].cloneDeep(themeItem) : themeItem;
    }, []);
    const getCurrentEditingTheme = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>currentEditingThemeRef.current, []);
    const setCurrentSettingTheme = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((theme)=>{
        currentSettingThemeRef.current = theme ? __WEBPACK_EXTERNAL_MODULE_lodash__["default"].cloneDeep(theme) : theme;
    }, []);
    const getCurrentSettingTheme = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>currentSettingThemeRef.current, []);
    const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            theme,
            setTheme,
            setCurrentSettingTheme,
            getCurrentSettingTheme,
            setCurrentEditingTheme,
            getCurrentEditingTheme,
            isDarkTheme
        }), [
        getCurrentEditingTheme,
        getCurrentSettingTheme,
        isDarkTheme,
        setCurrentEditingTheme,
        setCurrentSettingTheme,
        theme
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(GlobalThemeContext.Provider, {
        value: value,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.ConfigProvider, {
            theme: __WEBPACK_EXTERNAL_MODULE__defaultTheme_mjs__["default"],
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.ConfigProvider, {
                theme: theme,
                children: children
            })
        })
    });
};
var __webpack_exports__AntdAppProvider = __WEBPACK_EXTERNAL_MODULE__AntdAppProvider_mjs__["default"];
var __webpack_exports__defaultTheme = __WEBPACK_EXTERNAL_MODULE__defaultTheme_mjs__["default"];
export { GlobalThemeProvider, useGlobalTheme, __webpack_exports__AntdAppProvider as AntdAppProvider, __webpack_exports__defaultTheme as defaultTheme };
