"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../node_modules/element-plus/es/index.js");
;/* empty css                                                       */
;/* empty css                                                           */
;/* empty css                                                               */
;/* empty css                                                            */
;/* empty css                                                            */
;/* empty css                                                          */
;/* empty css                                      */
;/* empty css                                       */
const Vue = require("vue");
const page = require("./page.vue.js");
const index$2 = require("./api/index.js");
const eventBus = require("./utils/eventBus.js");
const pageHistory = require("./utils/pageHistory.js");
const common = require("./utils/common.js");
;/* empty css                                                           */
;/* empty css                                                             */
;/* empty css            */
const _pluginVue_exportHelper = require("../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../node_modules/element-plus/es/components/container/index.js");
const index$3 = require("../../../node_modules/element-plus/es/components/message/index.js");
const index$1 = require("../node_modules/vant/es/empty/index.js");
const _sfc_main = {
  __name: "index",
  props: {
    appId: {
      type: String,
      default: ""
    },
    pageKey: {
      type: String,
      default: ""
    }
  },
  setup(__props) {
    const props = __props;
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const pageList = Vue.ref({});
    const configLoading = Vue.ref(true);
    const noTargetPage = Vue.ref(false);
    const loadConfig = async () => {
      var _a, _b;
      if (!props.appId) {
        return;
      }
      configLoading.value = true;
      try {
        let option = await index$2.default.getAppById(ctx.$http, props.appId);
        pageList.value = ((_a = JSON.parse(option.pageConfig)) == null ? void 0 : _a.pageConfig) || [];
        pageHistory.pageHistory.clear();
        let homePage;
        if (props.pageKey) {
          homePage = pageList.value.find((page2) => page2.isHome);
          if (!homePage) {
            noTargetPage.value = true;
          }
        } else {
          homePage = pageList.value.find((page2) => page2.isHome);
          if (!homePage) {
            homePage = (_b = pageList.value) == null ? void 0 : _b[0];
          }
        }
        let pageId = homePage.id;
        if (homePage.footerType == "tabbar") {
          pageId = homePage.tabbarConfig.tabbarOptions[0].pageId;
        }
        loadPage(pageId);
      } catch (error) {
        console.error("加载配置失败:", error);
        index$3.ElMessage.error("加载配置失败");
      } finally {
        configLoading.value = false;
      }
    };
    const currentPage = Vue.ref(null);
    const routePage = Vue.ref(null);
    function loadPage(pageId) {
      var _a;
      if (((_a = currentPage.value) == null ? void 0 : _a.id) == pageId) {
        return;
      }
      const targetPage = common.findPageById(pageList.value, pageId);
      if (targetPage) {
        if (targetPage.parentPage) {
          currentPage.value = targetPage.parentPage;
          routePage.value = targetPage;
        } else {
          currentPage.value = targetPage;
          routePage.value = null;
        }
        pageHistory.pageHistory.push(targetPage);
        noTargetPage.value = false;
      } else {
        noTargetPage.value = true;
        currentPage.value = null;
        routePage.value = null;
      }
    }
    const pageParams = Vue.ref({});
    eventBus.default.on("loadPage", (pageId, params) => {
      loadPage(pageId);
      pageParams.value = params || { applyId: "7a16522c29e047d1be80e884773a87ac" };
    });
    Vue.provide("pageList", pageList);
    Vue.onMounted(() => {
      loadConfig();
    });
    return (_ctx, _cache) => {
      const _component_van_empty = index$1.Empty;
      const _component_el_container = index.ElContainer;
      return !Vue.unref(configLoading) ? (Vue.openBlock(), Vue.createBlock(_component_el_container, {
        key: 0,
        direction: "vertical",
        class: "fec-mobile-app",
        ref: "fecMobileAppRef"
      }, {
        default: Vue.withCtx(() => [
          !Vue.unref(noTargetPage) ? (Vue.openBlock(), Vue.createBlock(Vue.unref(page.default), {
            key: 0,
            parentPage: Vue.unref(currentPage),
            routePage: Vue.unref(routePage),
            params: Vue.unref(pageParams)
          }, null, 8, ["parentPage", "routePage", "params"])) : (Vue.openBlock(), Vue.createBlock(_component_van_empty, {
            key: 1,
            image: "search",
            description: "页面找不到了"
          }))
        ]),
        _: 1
      }, 512)) : Vue.createCommentVNode("", true);
    };
  }
};
const MobileApp = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-4e4cf5f1"]]);
exports.default = MobileApp;
