import { defineComponent, useAttrs, computed, resolveComponent, createBlock, openBlock, mergeProps, unref, withCtx, createCommentVNode, renderSlot } from 'vue';
import { ANT_LOCALE_LIST, DEFAULT_LOCALE } from '../../../locale/config.mjs';
import '../../../utils/index.mjs';
import { theme } from 'ant-design-vue';
import dayjs from 'dayjs';
import { DEFAULT_THEME_MODE, THEME_ENUM, configProviderProps } from './config-provider.mjs';
import { useConfigProvider } from './hooks.mjs';
import { isObject } from 'lodash-es';
import { createNamespace } from '../../../utils/create-namespace.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "LlConfigProvider"
  },
  __name: "config-provider",
  props: configProviderProps,
  setup(__props) {
    const attrs = useAttrs();
    const props = __props;
    const { provideGlobalConfig, setTheme } = useConfigProvider();
    const { defaultAlgorithm } = theme;
    const antLocale = computed(() => {
      const locale = props.locale;
      if (locale && locale.name) {
        const newLocale = ANT_LOCALE_LIST.find(
          (item) => item.name === locale.name
        );
        dayjs.locale(locale.name);
        return newLocale.locale;
      }
      dayjs.locale(DEFAULT_LOCALE);
      return null;
    });
    const theme$1 = computed(() => {
      if (props.theme && isObject(props.theme)) {
        const {
          type = DEFAULT_THEME_MODE,
          inherit = true,
          components,
          extraToken = {}
        } = props.theme;
        props.theme.extraToken;
        let { token, algorithm = defaultAlgorithm } = props.theme;
        token = { ...extraToken };
        if (type && THEME_ENUM[type]) {
          const storageTheme = type || DEFAULT_THEME_MODE;
          const themeToken = setTheme(storageTheme);
          algorithm = themeToken.algorithm;
          token = { ...themeToken.token, ...extraToken };
        }
        return {
          token,
          inherit,
          algorithm,
          components
        };
      }
      return {};
    });
    const bem = createNamespace("config-provider");
    provideGlobalConfig(computed(() => props));
    return (_ctx, _cache) => {
      const _component_a_config_provider = resolveComponent("a-config-provider");
      return openBlock(), createBlock(_component_a_config_provider, mergeProps({
        class: unref(bem).b()
      }, unref(attrs), {
        theme: theme$1.value,
        "auto-insert-space-in-button": _ctx.autoInsertSpaceInButton,
        "component-size": _ctx.componentSize,
        locale: antLocale.value
      }), {
        default: withCtx(() => [
          createCommentVNode(" \u9ED8\u8BA4\u63D2\u69FD "),
          renderSlot(_ctx.$slots, "default"),
          createCommentVNode(" \u81EA\u5B9A\u4E49\u7A7A\u6570\u636E "),
          renderSlot(_ctx.$slots, "renderEmpty")
        ]),
        _: 3
        /* FORWARDED */
      }, 16, ["class", "theme", "auto-insert-space-in-button", "component-size", "locale"]);
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=config-provider.vue2.mjs.map
