'use strict';

var vue = require('vue');
var lodashEs = require('lodash-es');
var elementPlus = require('element-plus');
var zhCn = require('../locale/lang/zh-cn.js');

const buildTranslator = (locale) => (path, option) => translate(path, option, vue.unref(locale));
const translate = (path, option, locale) => lodashEs.get(locale, path, path).replace(
  /\{(\w+)\}/g,
  (_, key) => {
    var _a;
    return `${(_a = option == null ? void 0 : option[key]) != null ? _a : `{${key}}`}`;
  }
);
const buildLocaleContext = (locale) => {
  const lang = vue.computed(() => vue.unref(locale).name);
  const localeRef = vue.isRef(locale) ? locale : vue.ref(locale);
  return {
    lang,
    locale: localeRef,
    t: buildTranslator(locale)
  };
};
const useLocale = (localeOverrides) => {
  const locale = localeOverrides || vue.inject(elementPlus.localeContextKey, vue.ref());
  return buildLocaleContext(vue.computed(() => {
    var _a;
    return ((_a = locale == null ? void 0 : locale.value) == null ? void 0 : _a.plus) ? locale.value : zhCn.default;
  }));
};

exports.buildLocaleContext = buildLocaleContext;
exports.buildTranslator = buildTranslator;
exports.translate = translate;
exports.useLocale = useLocale;
