"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const common = require("../utils/common.js");
const _pluginVue_exportHelper = require("../../../_virtual/_plugin-vue_export-helper.js");
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 = vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const router = ctx.$router;
    const component = vue.ref(null);
    const loading = vue.ref(false);
    async function loadComponent() {
      if (!props.route) return;
      loading.value = true;
      try {
        const comp = await common.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;
      }
    }
    vue.onMounted(loadComponent);
    vue.watch(() => props.route, loadComponent);
    return (_ctx, _cache) => {
      return component.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(component.value), vue.normalizeProps(vue.mergeProps({ key: 0 }, _ctx.$attrs)), null, 16)) : loading.value ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_1, "加载中...")) : (vue.openBlock(), vue.createElementBlock("span", _hoisted_2, "组件加载失败: 组件不存在"));
    };
  }
};
const ComponentLoader = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-eba24dcb"]]);
exports.default = ComponentLoader;
