/* empty css                                               */
/* empty css                                                 */
/* empty css                                                */
/* empty css                                               */
/* empty css                                                */
/* empty css                                                     */
/* empty css                                              */
import { inject, computed, createElementBlock, openBlock, normalizeStyle, unref, createVNode, isRef, withCtx, Fragment, renderList, createBlock, mergeProps, createElementVNode, createCommentVNode } from "vue";
import { findPageById } from "../../../utils/common.mjs";
import MobilePage from "../../../page.vue.mjs";
/* empty css           */
import _export_sfc from "../../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { Tabs } from "../../../../node_modules/vant/es/tabs/index.mjs";
import { Tab } from "../../../../node_modules/vant/es/tab/index.mjs";
const _hoisted_1 = { class: "fec-tab-content" };
const _sfc_main = {
  __name: "Tabs",
  props: {
    params: {
      type: Object,
      default: {}
    },
    modelValue: {
      type: String,
      default: ""
    },
    options: {
      type: Array,
      default: []
    },
    autoHeight: {
      //高度自适应
      type: Boolean,
      default: true
    },
    height: {
      //高度
      type: String,
      default: "300"
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const pageList = inject("pageList");
    const activeName = computed({
      get: () => {
        return props.modelValue;
      },
      set: (val) => {
        emit("update:modelValue", val);
      }
    });
    const compHeight = computed(() => {
      if (props.autoHeight) {
        return "100%";
      } else {
        return props.height + "px";
      }
    });
    const pageCache = computed(() => {
      const cache = {};
      props.options.forEach((item) => {
        if (item.pageId) {
          cache[item.pageId] = findPageById(pageList.value, item.pageId);
        }
      });
      console.log("🚀 ~ cache:", cache);
      return cache;
    });
    const getPage = (pageId) => {
      return pageCache.value[pageId] || null;
    };
    return (_ctx, _cache) => {
      const _component_van_tab = Tab;
      const _component_van_tabs = Tabs;
      return openBlock(), createElementBlock("div", {
        class: "fec-tabs-container",
        style: normalizeStyle("height:" + unref(compHeight))
      }, [
        createVNode(_component_van_tabs, {
          sticky: "",
          class: "fec-tabs",
          active: unref(activeName),
          "onUpdate:active": _cache[0] || (_cache[0] = ($event) => isRef(activeName) ? activeName.value = $event : null),
          "lazy-render": ""
        }, {
          default: withCtx(() => [
            (openBlock(true), createElementBlock(Fragment, null, renderList(__props.options, (item) => {
              return openBlock(), createBlock(_component_van_tab, mergeProps({ ref_for: true }, item, {
                name: item.id,
                replace: "",
                "show-zero-badge": false
              }), {
                default: withCtx(() => [
                  createElementVNode("div", _hoisted_1, [
                    item.pageId && getPage(item.pageId) ? (openBlock(), createBlock(MobilePage, {
                      key: 0,
                      parentPage: getPage(item.pageId),
                      params: __props.params
                    }, null, 8, ["parentPage", "params"])) : createCommentVNode("", true)
                  ])
                ]),
                _: 2
              }, 1040, ["name"]);
            }), 256))
          ]),
          _: 1
        }, 8, ["active"])
      ], 4);
    };
  }
};
const _Tabs = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-3ac885e8"]]);
export {
  _Tabs as default
};
