import { parrotI18n } from '@cloudtower/parrot';
import _message from '../core/message/message.js';
import { antdKit } from '../legacy-antd.js';
import { omit } from 'lodash';
import React__default, { createContext, useMemo, useEffect, useContext } from 'react';
import { ConfigProvider } from '../core/ConfigProvider/index.js';
import { createBatchMessageMethods } from '../core/message-group/index.js';
import { MessageContext } from '../core/message/useMessage.js';

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 = createContext(antdKit);
const UIKitProvider = (props) => {
  const { children, kit = antdKit, message, lng = "en-US", config } = props;
  const batchMessage = useMemo(() => {
    if ((message == null ? void 0 : message.batch) != null) {
      return createBatchMessageMethods(_message, message.batch);
    }
  }, [message == null ? void 0 : message.batch]);
  const _kit = useMemo(() => {
    return __spreadProps(__spreadValues({}, kit), {
      message: batchMessage != null ? batchMessage : _message
    });
  }, [batchMessage, kit]);
  useEffect(() => {
    _message.config(__spreadProps(__spreadValues({}, omit(message, "batch")), {
      configProviderProps: config
    }));
  }, [message, config]);
  useEffect(() => {
    if (parrotI18n.language !== lng) {
      parrotI18n.changeLanguage(lng);
    }
  }, [lng]);
  return /* @__PURE__ */ React__default.createElement(kitContext.Provider, { value: _kit }, /* @__PURE__ */ React__default.createElement(ConfigProvider, __spreadValues({}, config), /* @__PURE__ */ React__default.createElement(MessageContext.Provider, { value: batchMessage != null ? batchMessage : _message }, children)));
};
var UIKitProvider$1 = UIKitProvider;
const useUIKit = () => {
  return useContext(kitContext);
};

export { UIKitProvider$1 as default, kitContext, useUIKit };
