import { getCurrentInstance, computed, provide, unref, ref, inject } from 'vue';
import get from 'lodash/get';
import defaultLang from '../../locale/lang/zh-cn.mjs';
import { buildProps, definePropType } from '../../utils/props.mjs';

const useLocaleProps = buildProps({
  locale: {
    type: definePropType(Object)
  }
});
const localeContextKey = Symbol("localeContextKey");
let localeContextCache;
const provideLocale = () => {
  const vm = getCurrentInstance();
  const props = vm.props;
  const locale = computed(() => props.locale || defaultLang);
  const lang = computed(() => locale.value.name);
  const t = buildTranslator(locale);
  const provides = {
    locale,
    lang,
    t
  };
  localeContextCache = provides;
  provide(localeContextKey, provides);
};
const buildTranslator = (locale) => (path) => translate(path, unref(locale));
const translate = (path, locale) => get(locale, path, "");
const localeProviderMaker = (locale = defaultLang) => {
  const lang = ref(locale.name);
  const localeRef = ref(locale);
  return {
    lang,
    locale: localeRef,
    t: buildTranslator(localeRef)
  };
};
const useLocale = () => {
  return inject(localeContextKey, localeContextCache || localeProviderMaker(defaultLang));
};

export { buildTranslator, localeContextKey, localeProviderMaker, provideLocale, translate, useLocale, useLocaleProps };
//# sourceMappingURL=index.mjs.map
