import { createContext, useEffect } from "react";
import zhCN from "../locale/zh-CN.js";
import { isObject } from "../_util/is.js";
import { lighten } from "./util.js";
import Message from "../Message/index.js";
import Notification from "../Notification/index.js";
import Empty from "../Empty/index.js";
import { setConfigProviderProps } from "../Modal/config.js";
import { IconContext } from "../../icon/react-icon/context.js";
import omit from "../_util/omit.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var colorList = {
  primaryColor: {
    default: "--arcoblue-6",
    hover: "--arcoblue-5",
    active: "--arcoblue-7"
  },
  successColor: {
    default: "--green-6",
    hover: "--green-5",
    active: "--green-7"
  },
  infoColor: {
    default: "--arcoblue-6",
    hover: "--arcoblue-5",
    active: "--arcoblue-7"
  },
  warningColor: {
    default: "--orangered-6",
    hover: "--orangered-5",
    active: "--orangered-7"
  },
  dangerColor: {
    default: "--red-6",
    hover: "--red-5",
    active: "--red-7"
  }
};
function setTheme(theme) {
  if (theme && isObject(theme)) {
    var root_1 = document.body;
    Object.keys(colorList).forEach(function(color) {
      if (theme[color]) {
        root_1.style.setProperty(colorList[color].default, lighten(theme[color], 0));
        if (!theme[color + "Hover"]) {
          root_1.style.setProperty(colorList[color].hover, lighten(theme[color], 10));
        }
        if (!theme[color + "Active"]) {
          root_1.style.setProperty(colorList[color].active, lighten(theme[color], -10));
        }
      }
    });
  }
}
function renderEmpty(componentName) {
  switch (componentName) {
    default:
      return /* @__PURE__ */ jsx(Empty, {});
  }
}
var defaultProps = {
  locale: zhCN,
  prefixCls: "arco",
  getPopupContainer: function() {
    return document.body;
  },
  size: "default",
  renderEmpty,
  focusLock: {
    modal: {
      autoFocus: true
    },
    drawer: {
      autoFocus: true
    }
  }
};
var componentConfig = {};
var ConfigContext = createContext(__assign({
  getPrefixCls: function(componentName, customPrefix) {
    return (customPrefix || "arco") + "-" + componentName;
  }
}, defaultProps));
function ConfigProvider(baseProps) {
  var props = useMergeProps(baseProps, defaultProps, componentConfig);
  var theme = props.theme, prefixCls = props.prefixCls, children = props.children, locale = props.locale, rtl = props.rtl, _a = props.effectGlobalNotice, effectGlobalNotice = _a === void 0 ? true : _a;
  useEffect(function() {
    setTheme(theme);
  }, [theme]);
  useEffect(function() {
    if (effectGlobalNotice) {
      Message.config({
        prefixCls,
        rtl
      });
      Notification.config({
        prefixCls,
        rtl
      });
    }
  }, [prefixCls, rtl, effectGlobalNotice]);
  function getPrefixCls(componentName, customPrefix) {
    return (customPrefix || prefixCls) + "-" + componentName;
  }
  var config = __assign(__assign({}, omit(props, ["children"])), {
    getPrefixCls
  });
  useEffect(function() {
    setConfigProviderProps({
      locale,
      prefixCls,
      rtl
    });
  }, [locale, prefixCls]);
  var child = children;
  if (prefixCls && prefixCls !== "arco") {
    child = /* @__PURE__ */ jsx(IconContext.Provider, {
      value: {
        prefixCls
      },
      children
    });
  }
  return /* @__PURE__ */ jsx(ConfigContext.Provider, {
    value: config,
    children: child
  });
}
ConfigProvider.ConfigContext = ConfigContext;
ConfigProvider.displayName = "ConfigProvider";
ConfigContext.Consumer;
export {
  ConfigContext,
  ConfigProvider as default
};
//# sourceMappingURL=index.js.map
