'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var parrot = require('@cloudtower/parrot');
var message = require('../core/message/message.js');
var legacyAntd = require('../legacy-antd.js');
var _ = require('lodash');
var React = require('react');
var index$1 = require('../core/ConfigProvider/index.js');
var index = require('../core/message-group/index.js');
var useMessage = require('../core/message/useMessage.js');

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

var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
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;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const kitContext = React.createContext(legacyAntd.antdKit);
const UIKitProvider = (props) => {
  const { children, kit = legacyAntd.antdKit, message: message$1, lng = "en-US", config } = props;
  const batchMessage = React.useMemo(() => {
    if ((message$1 == null ? void 0 : message$1.batch) != null) {
      return index.createBatchMessageMethods(message.default, message$1.batch);
    }
  }, [message$1 == null ? void 0 : message$1.batch]);
  const _kit = React.useMemo(() => {
    return __spreadProps(__spreadValues({}, kit), {
      message: batchMessage != null ? batchMessage : message.default
    });
  }, [batchMessage, kit]);
  React.useEffect(() => {
    message.default.config(_.omit(message$1, "batch"));
  }, [message$1]);
  React.useEffect(() => {
    if (parrot.parrotI18n.language !== lng) {
      parrot.parrotI18n.changeLanguage(lng);
    }
  }, [lng]);
  return /* @__PURE__ */ React__default.default.createElement(kitContext.Provider, { value: _kit }, /* @__PURE__ */ React__default.default.createElement(useMessage.MessageContext.Provider, { value: batchMessage != null ? batchMessage : message.default }, /* @__PURE__ */ React__default.default.createElement(
    index$1.ConfigProvider,
    {
      antd4Configs: __spreadValues({}, config == null ? void 0 : config.antd4Configs),
      antd5Configs: __spreadValues({}, config == null ? void 0 : config.antd5Configs)
    },
    children
  )));
};
var UIKitProvider$1 = UIKitProvider;
const useUIKit = () => {
  return React.useContext(kitContext);
};

exports.default = UIKitProvider$1;
exports.kitContext = kitContext;
exports.useUIKit = useUIKit;
