import { getCurrentInstance, ref, onMounted, watch, createBlock, createElementBlock, openBlock, resolveDynamicComponent, normalizeProps, mergeProps } from "vue";
import { loadComponentByPath } from "../utils/common.mjs";
import _export_sfc from "../../../_virtual/_plugin-vue_export-helper.mjs";
const _hoisted_1 = {
  key: 1,
  class: "loading"
};
const _hoisted_2 = {
  key: 2,
  class: "error"
};
const _sfc_main = {
  __name: "ComponentLoader",
  props: {
    route: {
      type: String,
      required: true
    }
  },
  setup(__props) {
    const props = __props;
    const currentInstance = getCurrentInstance();
    const ctx = currentInstance.proxy;
    const router = ctx.$router;
    const component = ref(null);
    const loading = ref(false);
    async function loadComponent() {
      if (!props.route) return;
      loading.value = true;
      try {
        const comp = await loadComponentByPath(props.route, router);
        component.value = comp;
      } catch (e) {
        console.error(`Failed to load component from route: ${props.route}`, e);
        component.value = null;
      } finally {
        loading.value = false;
      }
    }
    onMounted(loadComponent);
    watch(() => props.route, loadComponent);
    return (_ctx, _cache) => {
      return component.value ? (openBlock(), createBlock(resolveDynamicComponent(component.value), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), null, 16)) : loading.value ? (openBlock(), createElementBlock("span", _hoisted_1, "加载中...")) : (openBlock(), createElementBlock("span", _hoisted_2, "组件加载失败: 组件不存在"));
    };
  }
};
const ComponentLoader = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-eba24dcb"]]);
export {
  ComponentLoader as default
};
