/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import { computed, inject, h } from '@vue/composition-api';
import cloneDeep from 'lodash/cloneDeep';
import mergeWith from 'lodash/mergeWith';
import { defaultGlobalConfig } from './context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import './type.js';

var merge = function merge(defaultGlobalConfig2, injectConfig) {
  return mergeWith(defaultGlobalConfig2, injectConfig, function (objValue, srcValue) {
    if (Array.isArray(objValue)) {
      return srcValue;
    }
  });
};
function useConfig(componentName) {
  var mergedGlobalConfig = computed(function () {
    var globalConfig = inject("globalConfig", /* @__PURE__ */Object.create(null));
    var mergedGlobalConfig2 = merge(cloneDeep(defaultGlobalConfig), globalConfig);
    return mergedGlobalConfig2;
  });
  var global = computed(function () {
    return mergedGlobalConfig.value[componentName];
  });
  var classPrefix = computed(function () {
    return mergedGlobalConfig.value.classPrefix;
  });

  var t = function t(pattern) {
    for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
      args[_key - 1] = arguments[_key];
    }

    var data = args[0];

    if (typeof pattern === "string") {
      if (!data) return pattern;
      var regular = /\{\s*([\w-]+)\s*\}/g;
      var translated = pattern.replace(regular, function (match, key) {
        if (data) {
          return String(data[key]);
        }

        return "";
      });
      return translated;
    }

    if (typeof pattern === "function") {
      if (!args.length) return pattern(h);
      return pattern.apply(void 0, args);
    }

    return "";
  };

  return {
    t: t,
    global: global,
    classPrefix: classPrefix
  };
}
function usePrefixClass(componentName) {
  var _useConfig = useConfig("classPrefix"),
      classPrefix = _useConfig.classPrefix;

  return computed(function () {
    return componentName ? "".concat(classPrefix.value, "-").concat(componentName) : classPrefix.value;
  });
}

export { merge, useConfig, usePrefixClass };
//# sourceMappingURL=useConfig.js.map
