/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');
var cloneDeep = require('lodash/cloneDeep');
var mergeWith = require('lodash/mergeWith');
var configProvider_context = require('./context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
var mergeWith__default = /*#__PURE__*/_interopDefaultLegacy(mergeWith);

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

  var t = function t(pattern, data) {
    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") {
      return pattern(data !== null && data !== void 0 ? data : VueCompositionAPI.h);
    }

    return "";
  };

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

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

exports.merge = merge;
exports.useConfig = useConfig;
exports.usePrefixClass = usePrefixClass;
//# sourceMappingURL=useConfig.js.map
