import { reactive, watchEffect, defineComponent, computed, watch, createVNode } from 'vue';
import '../../../locale/index.mjs';
import '../../../theme/index.mjs';
import seedToken from '../../../theme/token/themes/seed.mjs';
import { DesignTokenProvider } from '../../../theme/token/internal.mjs';
import '../../../constants/index.mjs';
import { LocaleProvider } from '../../locale-provider/index.mjs';
import LocaleReceiver from '../../locale-provider/src/LocaleReceiver.mjs';
import message from '../../message/index.mjs';
import '../../notification/index.mjs';
import useStyle from '../style/index.mjs';
import { globalConfigForApi, getGlobalPrefixCls, getGlobalIconPrefixCls } from './config.mjs';
import renderEmpty from './renderEmpty.mjs';
import './context/index.mjs';
import useTheme from './hooks/useTheme.mjs';
import { registerTheme } from './cssVariables.mjs';
import { configProviderProps } from './props.mjs';
import { useConfigContextInject, defaultIconPrefixCls, useConfigContextProvider, useProvideGlobalForm } from './context/context.mjs';
import createTheme from '../../../theme/cssinjs/theme/createTheme.mjs';
import localeValues from '../../../locale/lang/en_US.mjs';
import { useProviderSize } from './context/sizeContext.mjs';
import { useProviderDisabled } from './context/disabledContext.mjs';
import { ANT_MARK } from '../../../constants/component.mjs';
import api from '../../notification/src/Notification.mjs';

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

export { configConsumerProps, AConfigProvider as default, setGlobalConfig };
//# sourceMappingURL=ConfigProvider.mjs.map
