'use strict';

var vue = require('vue');
var core = require('@vueuse/core');
require('../cssinjs/index.js');
require('../version/index.js');
var type = require('../_util/type.js');
var index = require('./themes/default/index.js');
var seed = require('./themes/seed.js');
var alias = require('./util/alias.js');
var createTheme = require('../cssinjs/theme/createTheme.js');
var version = require('../version/version.js');
var useCacheToken = require('../cssinjs/hooks/useCacheToken.js');

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

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