import { defineComponent, provide, toRefs, getCurrentInstance, inject, ref } from 'vue';
import { defaultContainer } from '../_util/utils';
import { configProviderProps, CONFIG_PROVIDER_INJECTION_KEY } from './const';

function useConfig() {
  // 当不在vue实例使用时
  const vm = getCurrentInstance();
  if (!vm) {
    return {};
  }
  const providerConfig = inject(CONFIG_PROVIDER_INJECTION_KEY, {
    getContainer: ref(defaultContainer)
  });
  return providerConfig;
}
var configProvider = defineComponent({
  name: 'FConfigProvider',
  props: configProviderProps,
  setup(props, _ref) {
    let {
      slots
    } = _ref;
    // 兼容子组件局部设置
    provide(CONFIG_PROVIDER_INJECTION_KEY, toRefs(props));
    return () => {
      var _slots$default;
      return (_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
    };
  }
});

export { configProvider as default, useConfig };
