'use strict';

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

var vue = require('vue');
require('../../../locale/index.cjs');
require('../../../theme/index.cjs');
var seed = require('../../../theme/token/themes/seed.cjs');
var internal = require('../../../theme/token/internal.cjs');
require('../../../constants/index.cjs');
var index$1 = require('../../locale-provider/index.cjs');
var LocaleReceiver = require('../../locale-provider/src/LocaleReceiver.cjs');
var index$2 = require('../../message/index.cjs');
require('../../notification/index.cjs');
var index = require('../style/index.cjs');
var config = require('./config.cjs');
var renderEmpty = require('./renderEmpty.cjs');
require('./context/index.cjs');
var useTheme = require('./hooks/useTheme.cjs');
var cssVariables = require('./cssVariables.cjs');
var props = require('./props.cjs');
var context = require('./context/context.cjs');
var createTheme = require('../../../theme/cssinjs/theme/createTheme.cjs');
var en_US = require('../../../locale/lang/en_US.cjs');
var sizeContext = require('./context/sizeContext.cjs');
var disabledContext = require('./context/disabledContext.cjs');
var component = require('../../../constants/component.cjs');
var Notification = require('../../notification/src/Notification.cjs');

const globalConfigBySet = vue.reactive({});
const configConsumerProps = ["getTargetContainer", "getPopupContainer", "rootPrefixCls", "getPrefixCls", "renderEmpty", "csp", "autoInsertSpaceInButton", "locale", "pageHeader"];
vue.watchEffect(() => {
  Object.assign(config.globalConfigForApi, globalConfigBySet);
  config.globalConfigForApi.prefixCls = config.getGlobalPrefixCls();
  config.globalConfigForApi.iconPrefixCls = config.getGlobalIconPrefixCls();
  config.globalConfigForApi.getPrefixCls = (suffixCls, customizePrefixCls) => {
    if (customizePrefixCls)
      return customizePrefixCls;
    return suffixCls ? `${config.globalConfigForApi.prefixCls}-${suffixCls}` : config.globalConfigForApi.prefixCls;
  };
  config.globalConfigForApi.getRootPrefixCls = () => {
    if (config.globalConfigForApi.prefixCls)
      return config.globalConfigForApi.prefixCls;
    return config.getGlobalPrefixCls();
  };
});
let stopWatchEffect;
function setGlobalConfig(params) {
  if (stopWatchEffect)
    stopWatchEffect();
  stopWatchEffect = vue.watchEffect(() => {
    Object.assign(globalConfigBySet, vue.reactive(params));
    Object.assign(config.globalConfigForApi, vue.reactive(params));
  });
  if (params.theme)
    cssVariables.registerTheme(config.getGlobalPrefixCls(), params.theme);
}
var AConfigProvider = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AConfigProvider",
  inheritAttrs: false,
  props: props.configProviderProps(),
  config: setGlobalConfig,
  setup(props, {
    slots
  }) {
    const parentContext = context.useConfigContextInject();
    const getPrefixCls = (suffixCls, customizePrefixCls) => {
      const {
        prefixCls = "ant"
      } = props;
      if (customizePrefixCls)
        return customizePrefixCls;
      const mergedPrefixCls = prefixCls || parentContext.getPrefixCls("");
      return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls;
    };
    const iconPrefixCls = vue.computed(() => props.iconPrefixCls || parentContext.iconPrefixCls.value || context.defaultIconPrefixCls);
    const shouldWrapSSR = vue.computed(() => iconPrefixCls.value !== parentContext.iconPrefixCls.value);
    const csp = vue.computed(() => {
      var _a;
      return props.csp || ((_a = parentContext.csp) == null ? void 0 : _a.value);
    });
    const wrapSSR = index.default(iconPrefixCls);
    const mergedTheme = useTheme.default(vue.computed(() => props.theme), vue.computed(() => {
      var _a;
      return (_a = parentContext.theme) == null ? void 0 : _a.value;
    }));
    const renderEmptyComponent = (name) => {
      const renderEmpty$1 = props.renderEmpty || slots.renderEmpty || parentContext.renderEmpty || renderEmpty.default;
      return renderEmpty$1(name);
    };
    const autoInsertSpaceInButton = vue.computed(() => {
      var _a, _b;
      return (_b = props.autoInsertSpaceInButton) != null ? _b : (_a = parentContext.autoInsertSpaceInButton) == null ? void 0 : _a.value;
    });
    const locale = vue.computed(() => {
      var _a;
      return props.locale || ((_a = parentContext.locale) == null ? void 0 : _a.value);
    });
    vue.watch(locale, () => {
      globalConfigBySet.locale = locale.value;
    }, {
      immediate: true
    });
    const direction = vue.computed(() => {
      var _a;
      return props.direction || ((_a = parentContext.direction) == null ? void 0 : _a.value);
    });
    const space = vue.computed(() => {
      var _a, _b;
      return (_b = props.space) != null ? _b : (_a = parentContext.space) == null ? void 0 : _a.value;
    });
    const virtual = vue.computed(() => {
      var _a, _b;
      return (_b = props.virtual) != null ? _b : (_a = parentContext.virtual) == null ? void 0 : _a.value;
    });
    const dropdownMatchSelectWidth = vue.computed(() => {
      var _a, _b;
      return (_b = props.dropdownMatchSelectWidth) != null ? _b : (_a = parentContext.dropdownMatchSelectWidth) == null ? void 0 : _a.value;
    });
    const getTargetContainer = vue.computed(() => {
      var _a;
      return props.getTargetContainer !== void 0 ? props.getTargetContainer : (_a = parentContext.getTargetContainer) == null ? void 0 : _a.value;
    });
    const getPopupContainer = vue.computed(() => {
      var _a;
      return props.getPopupContainer !== void 0 ? props.getPopupContainer : (_a = parentContext.getPopupContainer) == null ? void 0 : _a.value;
    });
    const pageHeader = vue.computed(() => {
      var _a;
      return props.pageHeader !== void 0 ? props.pageHeader : (_a = parentContext.pageHeader) == null ? void 0 : _a.value;
    });
    const input = vue.computed(() => {
      var _a;
      return props.input !== void 0 ? props.input : (_a = parentContext.input) == null ? void 0 : _a.value;
    });
    const pagination = vue.computed(() => {
      var _a;
      return props.pagination !== void 0 ? props.pagination : (_a = parentContext.pagination) == null ? void 0 : _a.value;
    });
    const form = vue.computed(() => {
      var _a;
      return props.form !== void 0 ? props.form : (_a = parentContext.form) == null ? void 0 : _a.value;
    });
    const select = vue.computed(() => {
      var _a;
      return props.select !== void 0 ? props.select : (_a = parentContext.select) == null ? void 0 : _a.value;
    });
    const componentSize = vue.computed(() => props.componentSize);
    const componentDisabled = vue.computed(() => props.componentDisabled);
    const wave = vue.computed(() => {
      var _a, _b;
      return (_b = props.wave) != null ? _b : (_a = parentContext.wave) == null ? void 0 : _a.value;
    });
    const configProvider = {
      csp,
      autoInsertSpaceInButton,
      locale,
      direction,
      space,
      virtual,
      dropdownMatchSelectWidth,
      getPrefixCls,
      iconPrefixCls,
      theme: vue.computed(() => {
        var _a, _b;
        return (_b = mergedTheme.value) != null ? _b : (_a = parentContext.theme) == null ? void 0 : _a.value;
      }),
      renderEmpty: renderEmptyComponent,
      getTargetContainer,
      getPopupContainer,
      pageHeader,
      input,
      pagination,
      form,
      select,
      componentSize,
      componentDisabled,
      transformCellText: vue.computed(() => props.transformCellText),
      wave
    };
    const memoTheme = vue.computed(() => {
      const {
        algorithm,
        token,
        ...rest
      } = mergedTheme.value || {};
      const themeObj = algorithm && (!Array.isArray(algorithm) || algorithm.length > 0) ? createTheme.default(algorithm) : void 0;
      return {
        ...rest,
        theme: themeObj,
        token: {
          ...seed.default,
          ...token
        }
      };
    });
    const validateMessagesRef = vue.computed(() => {
      var _a, _b;
      let validateMessages = {};
      if (locale.value) {
        validateMessages = ((_a = locale.value.Form) == null ? void 0 : _a.defaultValidateMessages) || ((_b = en_US.default.Form) == null ? void 0 : _b.defaultValidateMessages) || {};
      }
      if (props.form && props.form.validateMessages)
        validateMessages = {
          ...validateMessages,
          ...props.form.validateMessages
        };
      return validateMessages;
    });
    context.useConfigContextProvider(configProvider);
    context.useProvideGlobalForm({
      validateMessages: validateMessagesRef
    });
    sizeContext.useProviderSize(componentSize);
    disabledContext.useProviderDisabled(componentDisabled);
    const renderProvider = (legacyLocale) => {
      var _a, _b;
      let childNode = shouldWrapSSR.value ? wrapSSR((_a = slots.default) == null ? void 0 : _a.call(slots)) : (_b = slots.default) == null ? void 0 : _b.call(slots);
      if (props.theme) {
        const _childNode = function() {
          return childNode;
        }();
        childNode = vue.createVNode(internal.DesignTokenProvider, {
          "value": memoTheme.value
        }, {
          default: () => [_childNode]
        });
      }
      return vue.createVNode(index$1.LocaleProvider, {
        "locale": locale.value || legacyLocale,
        "ANT_MARK__": component.ANT_MARK
      }, {
        default: () => [childNode]
      });
    };
    vue.watchEffect(() => {
      if (direction.value) {
        index$2.default.config({
          rtl: direction.value === "rtl"
        });
        Notification.default.config({
          rtl: direction.value === "rtl"
        });
      }
    });
    return () => vue.createVNode(LocaleReceiver.default, {
      "children": (_, __, legacyLocale) => renderProvider(legacyLocale)
    }, null);
  }
});

exports.configConsumerProps = configConsumerProps;
exports.default = AConfigProvider;
exports.setGlobalConfig = setGlobalConfig;
//# sourceMappingURL=ConfigProvider.cjs.map
