/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { ref, getCurrentInstance, inject, computed, h, provide } from 'vue';
import { c as cloneDeep_1 } from '../_chunks/dep-095107f7.mjs';
import { i as isFunction_1 } from '../_chunks/dep-5717e263.mjs';
import { i as isString_1 } from '../_chunks/dep-876fb3ec.mjs';
import { c as configProviderInjectKey, d as defaultGlobalConfig, a as mergeWith } from '../_chunks/dep-40d69a9c.mjs';
import './type.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';

var globalConfigCopy = ref();
function useConfig(componentName) {
  var injectGlobalConfig = getCurrentInstance() ? inject(configProviderInjectKey, null) : globalConfigCopy;
  var mergedGlobalConfig = computed(function () {
    return (injectGlobalConfig === null || injectGlobalConfig === void 0 ? void 0 : injectGlobalConfig.value) || defaultGlobalConfig;
  });
  var globalConfig = 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 (isString_1(pattern)) {
      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 (isFunction_1(pattern)) {
      if (!args.length) return pattern(h);
      return pattern.apply(void 0, args);
    }
    return "";
  };
  return {
    t: t,
    global: globalConfig,
    globalConfig: globalConfig,
    classPrefix: classPrefix
  };
}
var provideConfig = function provideConfig(props) {
  var defaultData = cloneDeep_1(defaultGlobalConfig);
  var mergedGlobalConfig = computed(function () {
    return mergeWith(defaultData, props.globalConfig);
  });
  provide(configProviderInjectKey, mergedGlobalConfig);
  if (!globalConfigCopy.value) globalConfigCopy.value = mergedGlobalConfig.value;
  return mergedGlobalConfig;
};

export { provideConfig, useConfig };
//# sourceMappingURL=useConfig.mjs.map
