import { ref, provide, watchEffect, inject, defineComponent, computed } from 'vue';
import { toReactive } from '@vueuse/core';
import '../cssinjs/index.mjs';
import '../version/index.mjs';
import { objectType } from '../_util/type.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 { 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 = ref();
const useDesignTokenProvider = (value) => {
  provide(DesignTokenContextKey, value);
  watchEffect(() => {
    globalDesignTokenApi.value = value;
  });
};
const useDesignTokenInject = () => {
  return inject(DesignTokenContextKey, globalDesignTokenApi.value || defaultConfig);
};
const DesignTokenProvider = defineComponent({
  props: {
    value: objectType()
  },
  setup(props, { slots }) {
    useDesignTokenProvider(toReactive(computed(() => props.value)));
    return () => {
      var _a;
      return (_a = slots.default) == null ? void 0 : _a.call(slots);
    };
  }
});
function useToken() {
  const designTokenContext = inject(
    DesignTokenContextKey,
    globalDesignTokenApi.value || defaultConfig
  );
  const salt = computed(() => `${version}-${designTokenContext.hashed || ""}`);
  const mergedTheme = computed(() => designTokenContext.theme || defaultTheme);
  const cacheToken = useCacheToken(
    mergedTheme,
    computed(() => [seedToken, designTokenContext.token]),
    computed(() => ({
      salt: salt.value,
      override: { override: designTokenContext.token, ...designTokenContext.components },
      formatToken
    }))
  );
  return [
    mergedTheme,
    computed(() => cacheToken.value[0]),
    computed(() => designTokenContext.hashed ? cacheToken.value[1] : "")
  ];
}

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