import { getCurrentInstance, provide, computed } from 'vue';
import '../../../hooks/index.mjs';
import { theme } from 'ant-design-vue';
import { THEME_ENUM } from './config-provider.mjs';
import { localeContextKey } from '../../../hooks/use-locale/index.mjs';

"use strict";
const { darkAlgorithm, defaultAlgorithm } = theme;
const useConfigProvider = () => {
  const provideGlobalConfig = (config, app) => {
    const inSetup = !!getCurrentInstance();
    const provideFn = app?.provide ?? (inSetup ? provide : void 0);
    if (!provideFn) {
      console.warn(
        "provideGlobalConfig",
        "provideGlobalConfig() can only be used inside setup()."
      );
      return;
    }
    provideFn(
      localeContextKey,
      computed(() => config.value.locale)
    );
  };
  const getRootVarible = (root, name) => {
    return root.getPropertyValue(name).trim();
  };
  const getTheme = (root, name) => {
    const root_computed = getComputedStyle(root);
    const colorPrimaryBg = getRootVarible(root_computed, "--color-primary-bg");
    const colorPrimaryBgHover = getRootVarible(
      root_computed,
      "--color-primary-bg-hover"
    );
    const colorPrimaryBorder = getRootVarible(
      root_computed,
      "--color-primary-border"
    );
    const colorPrimaryBorderHover = getRootVarible(
      root_computed,
      "--color-primary-border-hover"
    );
    const colorPrimaryHover = getRootVarible(
      root_computed,
      "--color-primary-hover"
    );
    const colorPrimary = getRootVarible(root_computed, "--color-primary");
    const darkColorPrimary = getRootVarible(
      root_computed,
      "--dark-color-primary"
    );
    const colorPrimaryActive = getRootVarible(
      root_computed,
      "--color-primary-active"
    );
    const colorPrimaryTextHover = getRootVarible(
      root_computed,
      "--color-primary-text-hover"
    );
    const colorPrimaryText = getRootVarible(
      root_computed,
      "--color-primary-text"
    );
    const colorPrimaryTextActive = getRootVarible(
      root_computed,
      "--color-primary-text-active"
    );
    const colorSuccess = getRootVarible(root_computed, "--color-success");
    const colorWarning = getRootVarible(root_computed, "--color-warning");
    const colorError = getRootVarible(root_computed, "--color-error");
    const colorInfo = getRootVarible(root_computed, "--color-info");
    const colorTextBase = getRootVarible(root_computed, "--color-text-base");
    const colorText = getRootVarible(root_computed, "--color-text");
    const colorTextSecondary = getRootVarible(
      root_computed,
      "--color-text-secondary"
    );
    const colorTextTertiary = getRootVarible(
      root_computed,
      "--color-text-tertiary"
    );
    const colorTextQuaternary = getRootVarible(
      root_computed,
      "--color-text-quaternary"
    );
    const colorBorder = getRootVarible(root_computed, "--color-border");
    const colorBorderSecondary = getRootVarible(
      root_computed,
      "--color-border-secondary"
    );
    const colorSplit = getRootVarible(root_computed, "--color-split");
    const colorFill = getRootVarible(root_computed, "--color-fill");
    const colorFillSecondary = getRootVarible(
      root_computed,
      "--color-fill-secondary"
    );
    const colorFillTertiary = getRootVarible(
      root_computed,
      "--color-fill-tertiary"
    );
    const colorFillQuaternary = getRootVarible(
      root_computed,
      "--color-fill-quaternary"
    );
    const colorBgBase = getRootVarible(root_computed, "--color-bg-base");
    const colorBgContainer = getRootVarible(
      root_computed,
      "--color-bg-container"
    );
    const colorBgElevated = getRootVarible(root_computed, "--color-bg-elevated");
    const colorBgLayout = getRootVarible(root_computed, "--color-bg-layout");
    const colorBgSpotlight = getRootVarible(
      root_computed,
      "--color-bg-spotlight"
    );
    const colorBgMask = getRootVarible(root_computed, "--color-bg-mask");
    const controlItemBgHover = getRootVarible(
      root_computed,
      "--control-item-bg-hover"
    );
    const fontFamily = getRootVarible(root_computed, "--font-family");
    return {
      fontFamily,
      colorPrimaryBg,
      colorPrimaryBgHover,
      colorPrimaryBorder,
      colorPrimaryBorderHover,
      colorPrimaryHover,
      colorPrimary: name === THEME_ENUM["dark"] ? darkColorPrimary : colorPrimary,
      colorPrimaryActive,
      colorPrimaryTextHover,
      colorPrimaryText,
      colorPrimaryTextActive,
      colorSuccess,
      colorWarning,
      colorError,
      colorInfo,
      colorTextBase,
      colorText,
      colorTextSecondary,
      colorTextTertiary,
      colorTextQuaternary,
      colorBorder,
      colorBorderSecondary,
      colorSplit,
      colorFill,
      colorFillSecondary,
      colorFillTertiary,
      colorFillQuaternary,
      colorBgBase,
      colorBgContainer,
      colorBgElevated,
      colorBgLayout,
      colorBgSpotlight,
      colorBgMask,
      controlItemBgHover,
      // 尺寸高度配置
      controlHeightSM: 28,
      controlHeight: 36,
      controlHeightLG: 40,
      // 圆角配置
      borderRadiusSM: 6,
      borderRadius: 6,
      borderRadiusLG: 8
    };
  };
  const setTheme = (name) => {
    const root = document.documentElement;
    root.style.colorScheme = "light";
    if (name) {
      root.className = name;
    }
    const theme2 = getTheme(root, name);
    return {
      token: theme2,
      algorithm: name === THEME_ENUM["dark"] ? [darkAlgorithm] : [defaultAlgorithm]
    };
  };
  return {
    provideGlobalConfig,
    getTheme,
    setTheme
  };
};

export { useConfigProvider };
//# sourceMappingURL=hooks.mjs.map
