'use strict';

var useParrotTranslation = require('../../hooks/useParrotTranslation.js');
var antd = require('antd');
var enUS = require('antd/lib/locale/en_US');
var zhCN = require('antd/lib/locale/zh_CN');
var antd5 = require('antd5');
var antd5enUS = require('antd5/lib/locale/en_US');
var antd5zhCN = require('antd5/lib/locale/zh_CN');
var dayjs = require('dayjs');
var moment = require('moment');
var React = require('react');
var useAntdPatchEnLocales = require('../../hooks/useAntdPatchEnLocales.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var enUS__default = /*#__PURE__*/_interopDefault(enUS);
var zhCN__default = /*#__PURE__*/_interopDefault(zhCN);
var antd5enUS__default = /*#__PURE__*/_interopDefault(antd5enUS);
var antd5zhCN__default = /*#__PURE__*/_interopDefault(antd5zhCN);
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
var moment__default = /*#__PURE__*/_interopDefault(moment);
var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
const ConfigProviderContext = React.createContext({});
const useConfig = () => {
  return React.useContext(ConfigProviderContext);
};
const ConfigProvider = ({
  antd5Configs,
  antd4Configs,
  config = {},
  children
}) => {
  const { i18n } = useParrotTranslation();
  React.useEffect(() => {
    const adjustDateLocale = (lng) => {
      moment__default.default.locale(lng === "zh-CN" ? "zh-cn" : "en");
      dayjs__default.default.locale(lng === "zh-CN" ? "zh-cn" : "en");
    };
    i18n.on("languageChanged", adjustDateLocale);
    adjustDateLocale(i18n.language);
  }, [i18n]);
  const patchEnLocale = useAntdPatchEnLocales.useAntdPatchEnLocales(enUS__default.default);
  return /* @__PURE__ */ React__default.default.createElement(ConfigProviderContext.Provider, { value: config }, /* @__PURE__ */ React__default.default.createElement(
    antd5.ConfigProvider,
    __spreadValues({
      autoInsertSpaceInButton: false,
      locale: i18n.language === "zh-CN" ? antd5zhCN__default.default : antd5enUS__default.default
    }, antd5Configs),
    /* @__PURE__ */ React__default.default.createElement(
      antd.ConfigProvider,
      __spreadValues({
        autoInsertSpaceInButton: false,
        locale: i18n.language === "zh-CN" ? zhCN__default.default : patchEnLocale
      }, antd4Configs),
      children
    )
  ));
};

exports.ConfigProvider = ConfigProvider;
exports.useConfig = useConfig;
