'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var vueRouter = require('vue-router');
var pinia = require('pinia');
require('../../../../stores/index.js');
require('../../../../utils/index.js');
var mitt = require('../../../../utils/mitt.js');
var keepAliveNames = require('../../../../stores/keepAliveNames.js');
var themeConfig = require('../../../../stores/themeConfig.js');
var storage = require('../../../../utils/storage.js');

const _hoisted_1 = { class: "layout-parent" };
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "parent",
  setup(__props) {
    const Iframes = vue.defineAsyncComponent(() => Promise.resolve().then(function () { return require('./iframes.vue.js'); }));
    const route = vueRouter.useRoute();
    const router = vueRouter.useRouter();
    const storesKeepAliveNames = keepAliveNames.useKeepALiveNames();
    const storesThemeConfig = themeConfig.useThemeConfig();
    const { keepAliveNames: keepAliveNames$1, cachedViews } = pinia.storeToRefs(storesKeepAliveNames);
    const { themeConfig: themeConfig$1 } = pinia.storeToRefs(storesThemeConfig);
    const state = vue.reactive({
      refreshRouterViewKey: "",
      // 非 iframe tagsview 右键菜单刷新时
      iframeRefreshKey: "",
      // iframe tagsview 右键菜单刷新时
      keepAliveNameList: [],
      iframeList: []
    });
    const setTransitionName = vue.computed(() => {
      return themeConfig$1.value.animation;
    });
    const getKeepAliveNames = vue.computed(() => {
      return themeConfig$1.value.isTagsview ? cachedViews.value : state.keepAliveNameList;
    });
    const isIframePage = vue.computed(() => {
      return route.meta.isIframe;
    });
    const getIframeListRoutes = async () => {
      router.getRoutes().forEach((v) => {
        if (v.meta.isIframe) {
          v.meta.isIframeOpen = false;
          v.meta.loading = true;
          state.iframeList.push({ ...v });
        }
      });
    };
    vue.onBeforeMount(() => {
      state.keepAliveNameList = keepAliveNames$1.value;
      mitt.default.on("onTagsViewRefreshRouterView", (fullPath) => {
        var _a;
        const cacheList = cachedViews.value;
        if (route.meta.isKeepAlive) cachedViews.value = (_a = cachedViews.value) == null ? void 0 : _a.filter((name) => route.name !== name);
        state.keepAliveNameList = keepAliveNames$1.value.filter((name) => route.name !== name);
        state.refreshRouterViewKey = "";
        state.iframeRefreshKey = "";
        vue.nextTick(() => {
          if (route.meta.isKeepAlive) cachedViews.value = cacheList;
          state.keepAliveNameList = keepAliveNames$1.value;
          state.refreshRouterViewKey = fullPath;
          state.iframeRefreshKey = fullPath;
        });
      });
    });
    vue.onMounted(() => {
      getIframeListRoutes();
      vue.nextTick(() => {
        setTimeout(() => {
          if (themeConfig$1.value.isCacheTagsView) {
            let tagsViewArr = storage.Session.get("tagsViewList") || [];
            cachedViews.value = tagsViewArr.filter((item) => {
              var _a;
              return (_a = item.meta) == null ? void 0 : _a.isKeepAlive;
            }).map((item) => item.name);
          }
        }, 0);
      });
    });
    vue.onUnmounted(() => {
      mitt.default.off("onTagsViewRefreshRouterView", () => {
      });
    });
    vue.watch(
      () => route.fullPath,
      () => {
        state.refreshRouterViewKey = decodeURI(route.fullPath);
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _component_router_view = vue.resolveComponent("router-view");
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.createVNode(_component_router_view, null, {
          default: vue.withCtx(({ Component }) => [
            vue.createVNode(vue.Transition, {
              name: setTransitionName.value,
              mode: "out-in"
            }, {
              default: vue.withCtx(() => [
                (vue.openBlock(), vue.createBlock(vue.KeepAlive, { include: getKeepAliveNames.value }, [
                  vue.withDirectives((vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(Component), {
                    key: state.refreshRouterViewKey,
                    class: "w100"
                  })), [
                    [vue.vShow, !isIframePage.value]
                  ])
                ], 1032, ["include"]))
              ]),
              _: 2
              /* DYNAMIC */
            }, 1032, ["name"])
          ]),
          _: 1
          /* STABLE */
        }),
        vue.createVNode(vue.Transition, {
          name: setTransitionName.value,
          mode: "out-in",
          persisted: ""
        }, {
          default: vue.withCtx(() => [
            vue.withDirectives(vue.createVNode(vue.unref(Iframes), {
              class: "w100",
              refreshKey: state.iframeRefreshKey,
              name: setTransitionName.value,
              list: state.iframeList
            }, null, 8, ["refreshKey", "name", "list"]), [
              [vue.vShow, isIframePage.value]
            ])
          ]),
          _: 1
          /* STABLE */
        }, 8, ["name"])
      ]);
    };
  }
});

exports.default = _sfc_main;
