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

'use strict';

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

var vue = require('vue');
var cloneDeep = require('lodash/cloneDeep');
var isFunction = require('lodash/isFunction');
var isString = require('lodash/isString');
var configProvider_context = require('./context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');

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

var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);

var globalConfigCopy = vue.ref();
function useConfig(componentName) {
  var injectGlobalConfig = vue.getCurrentInstance() ? vue.inject(configProvider_context.configProviderInjectKey, null) : globalConfigCopy;
  var mergedGlobalConfig = vue.computed(function () {
    return (injectGlobalConfig === null || injectGlobalConfig === void 0 ? void 0 : injectGlobalConfig.value) || configProvider_context.defaultGlobalConfig;
  });
  var globalConfig = vue.computed(function () {
    return mergedGlobalConfig.value[componentName];
  });
  var classPrefix = vue.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__default["default"](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__default["default"](pattern)) {
      if (!args.length) return pattern(vue.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__default["default"](configProvider_context.defaultGlobalConfig);
  var mergedGlobalConfig = vue.computed(function () {
    return configProvider_context.mergeWith(defaultData, props.globalConfig);
  });
  vue.provide(configProvider_context.configProviderInjectKey, mergedGlobalConfig);
  if (!globalConfigCopy.value) globalConfigCopy.value = mergedGlobalConfig.value;
  return mergedGlobalConfig;
};

exports.provideConfig = provideConfig;
exports.useConfig = useConfig;
//# sourceMappingURL=useConfig.js.map
