'use strict';

var vue = require('vue');
require('../../utils/index.cjs');
require('../../version/index.cjs');
require('../cssinjs/index.cjs');
var index = require('./themes/default/index.cjs');
var seed = require('./themes/seed.cjs');
var alias = require('./util/alias.cjs');
var createTheme = require('../cssinjs/theme/createTheme.cjs');
var propType = require('../../utils/vue/propType.cjs');
var version = require('../../version/version.cjs');
var useCacheToken = require('../cssinjs/hooks/useCacheToken.cjs');

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

exports.DesignTokenProvider = DesignTokenProvider;
exports.defaultConfig = defaultConfig;
exports.globalDesignTokenApi = globalDesignTokenApi;
exports.useDesignTokenInject = useDesignTokenInject;
exports.useDesignTokenProvider = useDesignTokenProvider;
exports.useToken = useToken;
//# sourceMappingURL=internal.cjs.map
