import useParrotTranslation from '../../hooks/useParrotTranslation.js';
import { ConfigProvider as ConfigProvider$2 } from 'antd';
import enUS from 'antd/lib/locale/en_US';
import zhCN from 'antd/lib/locale/zh_CN';
import { ConfigProvider as ConfigProvider$1 } from 'antd5';
import antd5enUS from 'antd5/lib/locale/en_US';
import antd5zhCN from 'antd5/lib/locale/zh_CN';
import dayjs from 'dayjs';
import moment from 'moment';
import React__default, { createContext, useContext, useEffect } from 'react';
import { useAntdPatchEnLocales } from '../../hooks/useAntdPatchEnLocales.js';

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 = createContext({});
const useConfig = () => {
  return useContext(ConfigProviderContext);
};
const ConfigProvider = ({
  antd5Configs,
  antd4Configs,
  config = {},
  children
}) => {
  const { i18n } = useParrotTranslation();
  useEffect(() => {
    const adjustDateLocale = (lng) => {
      moment.locale(lng === "zh-CN" ? "zh-cn" : "en");
      dayjs.locale(lng === "zh-CN" ? "zh-cn" : "en");
    };
    i18n.on("languageChanged", adjustDateLocale);
    adjustDateLocale(i18n.language);
  }, [i18n]);
  const patchEnLocale = useAntdPatchEnLocales(enUS);
  return /* @__PURE__ */ React__default.createElement(ConfigProviderContext.Provider, { value: config }, /* @__PURE__ */ React__default.createElement(
    ConfigProvider$1,
    __spreadValues({
      autoInsertSpaceInButton: false,
      locale: i18n.language === "zh-CN" ? antd5zhCN : antd5enUS
    }, antd5Configs),
    /* @__PURE__ */ React__default.createElement(
      ConfigProvider$2,
      __spreadValues({
        autoInsertSpaceInButton: false,
        locale: i18n.language === "zh-CN" ? zhCN : patchEnLocale
      }, antd4Configs),
      children
    )
  ));
};

export { ConfigProvider, useConfig };
