import { shallowRef, provide, watch, unref, triggerRef, inject, computed, defineComponent } from 'vue';
import '../../utils/index.mjs';
import '../../version/index.mjs';
import '../cssinjs/index.mjs';
import derivative from './themes/default/index.mjs';
import seedToken from './themes/seed.mjs';
import formatToken from './util/alias.mjs';
import createTheme from '../cssinjs/theme/createTheme.mjs';
import { objectType } from '../../utils/vue/propType.mjs';
import { version } from '../../version/version.mjs';
import useCacheToken from '../cssinjs/hooks/useCacheToken.mjs';

const defaultTheme = createTheme(derivative);
const defaultConfig = {
  token: seedToken,
  hashed: true
};
const DesignTokenContextKey = Symbol("DesignTokenContext");
const globalDesignTokenApi = shallowRef();
function useDesignTokenProvider(value) {
  provide(DesignTokenContextKey, value);
  watch(
    value,
    () => {
      globalDesignTokenApi.value = unref(value);
      triggerRef(globalDesignTokenApi);
    },
    { immediate: true, deep: true }
  );
}
function useDesignTokenInject() {
  return inject(
    DesignTokenContextKey,
    computed(() => globalDesignTokenApi.value || defaultConfig)
  );
}
const DesignTokenProvider = defineComponent({
  props: {
    value: objectType()
  },
  setup(props, { slots }) {
    useDesignTokenProvider(computed(() => props.value));
    return () => {
      var _a;
      return (_a = slots.default) == null ? void 0 : _a.call(slots);
    };
  }
});
function useToken() {
  const designTokenContext = inject(
    DesignTokenContextKey,
    computed(() => globalDesignTokenApi.value || defaultConfig)
  );
  const salt = computed(() => `${version}-${designTokenContext.value.hashed || ""}`);
  const mergedTheme = computed(() => designTokenContext.value.theme || defaultTheme);
  const cacheToken = useCacheToken(
    mergedTheme,
    computed(() => [seedToken, designTokenContext.value.token]),
    computed(() => ({
      salt: salt.value,
      override: {
        override: designTokenContext.value.token,
        ...designTokenContext.value.components
      },
      formatToken
    }))
  );
  return [
    mergedTheme,
    computed(() => cacheToken.value[0]),
    computed(() => designTokenContext.value.hashed ? cacheToken.value[1] : "")
  ];
}

export { DesignTokenProvider, defaultConfig, globalDesignTokenApi, useDesignTokenInject, useDesignTokenProvider, useToken };
//# sourceMappingURL=internal.mjs.map
