/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { inject, ref, h } from '@vue/composition-api';
import { defaultGlobalConfig } from './context.js';
import 'lodash';
import '../../_chunks/dep-def4c2ce.js';

const t = function (pattern) {
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    args[_key - 1] = arguments[_key];
  }
  const [data] = args;
  if (typeof pattern === "string") {
    if (!data) return pattern;
    const regular = /\{\s*([\w-]+)\s*\}/g;
    const translated = pattern.replace(regular, (match, key) => {
      if (data) return String(data[key]);
      return "";
    });
    return translated;
  }
  if (typeof pattern === "function") {
    if (!args.length) return pattern(h);
    return pattern(...args);
  }
  return "";
};
function useConfig(componentName) {
  const injectGlobalConfig = inject("globalConfig", null);
  const mergedGlobalConfig = injectGlobalConfig || defaultGlobalConfig;
  const global = ref(mergedGlobalConfig[componentName]);
  const classPrefix = ref(mergedGlobalConfig.classPrefix);
  return {
    t,
    global,
    classPrefix
  };
}
function usePrefixClass(componentName) {
  const {
    classPrefix
  } = useConfig("classPrefix");
  return ref(componentName ? `${classPrefix.value}-${componentName}` : classPrefix.value);
}

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