import { ref, computed, watch, resolveComponent, createElementBlock, openBlock, Fragment, createBlock, createCommentVNode, createElementVNode, normalizeProps, mergeProps, unref, createVNode, guardReactiveProps, isRef, withCtx, resolveDynamicComponent } from "vue";
import "../../../node_modules/grid-layout-plus/es/index.mjs";
import * as all from "./components/all.mjs";
import { pageHistory } from "./utils/pageHistory.mjs";
/* empty css           */
import _export_sfc from "../../../_virtual/_plugin-vue_export-helper.mjs";
import De from "../../../node_modules/grid-layout-plus/es/components/grid-layout.vue.mjs";
const _hoisted_1 = { class: "grid-wrapper no-scrollbar" };
const _hoisted_2 = { class: "component-content" };
const colNum = 24;
const rowHeight = 10;
const _sfc_main = {
  __name: "page",
  props: {
    parentPage: {
      type: Object,
      required: true
    },
    routePage: {
      type: Object
    }
  },
  setup(__props) {
    const props = __props;
    const formData = ref({});
    function getComp(type) {
      return all[type];
    }
    const layoutData = computed(() => {
      var _a;
      if (Array.isArray(props.parentPage.layoutData)) {
        return ((_a = props.parentPage.layoutData) == null ? void 0 : _a.map((item) => {
          item.isResizable = false;
          return item;
        })) || [];
      }
      return props.parentPage.layoutData;
    });
    const tabbarActive = ref(0);
    const childPage = ref(null);
    function onTabbarChange(pageId) {
      if (!pageId) {
        return;
      }
      const page = props.parentPage.children.find((item) => item.id == pageId);
      if (!page) ;
      else {
        childPage.value = page;
        pageHistory.replace(page);
      }
      console.log("🚀 ~ onTabbarChange ~ page:", page);
    }
    const currentPage = computed(() => {
      return childPage.value || props.parentPage || {};
    });
    watch(
      [() => props.parentPage, () => props.routePage],
      () => {
        var _a;
        childPage.value = props.routePage;
        if (props.parentPage.footerType == "tabbar") {
          tabbarActive.value = ((_a = props.routePage) == null ? void 0 : _a.id) || props.parentPage.tabbarConfig.tabbarOptions[0].pageId;
        }
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _component_FecMobileNavBar = resolveComponent("FecMobileNavBar");
      const _component_page = resolveComponent("page", true);
      const _component_FecMobileMenuGrid = resolveComponent("FecMobileMenuGrid");
      const _component_FecMobileNoticeBar = resolveComponent("FecMobileNoticeBar");
      const _component_FecMobileDataStat = resolveComponent("FecMobileDataStat");
      const _component_FecMobileTabbar = resolveComponent("FecMobileTabbar");
      const _component_FecMobileActionBar = resolveComponent("FecMobileActionBar");
      return openBlock(), createElementBlock(Fragment, null, [
        __props.parentPage.isNavBar ? (openBlock(), createBlock(_component_FecMobileNavBar, normalizeProps(mergeProps({ key: 0 }, __props.parentPage.navBarConfig)), null, 16)) : createCommentVNode("", true),
        createElementVNode("div", _hoisted_1, [
          __props.parentPage.footerType == "tabbar" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
            unref(childPage) ? (openBlock(), createBlock(_component_page, {
              key: 0,
              parentPage: unref(childPage)
            }, null, 8, ["parentPage"])) : createCommentVNode("", true)
          ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
            __props.parentPage.type == "home" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
              createVNode(_component_FecMobileMenuGrid, normalizeProps(guardReactiveProps(__props.parentPage.layoutData.menuGridProps)), null, 16),
              createVNode(_component_FecMobileNoticeBar),
              createVNode(_component_FecMobileDataStat)
            ], 64)) : __props.parentPage.type == "approval" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [], 64)) : (openBlock(), createBlock(unref(De), {
              key: 2,
              ref: "gridLayout",
              layout: unref(layoutData),
              "onUpdate:layout": _cache[0] || (_cache[0] = ($event) => isRef(layoutData) ? layoutData.value = $event : null),
              "row-height": rowHeight,
              margin: [0, 0],
              "col-num": colNum,
              "use-css-transforms": false,
              "is-draggable": false,
              "is-resizable": false,
              style: { "height": "100%" }
            }, {
              item: withCtx(({ item: { component } }) => [
                createElementVNode("div", _hoisted_2, [
                  (openBlock(), createBlock(resolveDynamicComponent(getComp(component.fieldType)), mergeProps(component.props, {
                    modelValue: unref(formData)[component.props.fieldName],
                    "onUpdate:modelValue": ($event) => unref(formData)[component.props.fieldName] = $event,
                    dataSources: unref(currentPage).dataSources,
                    compId: component.id,
                    currentPage: unref(currentPage)
                  }), null, 16, ["modelValue", "onUpdate:modelValue", "dataSources", "compId", "currentPage"]))
                ])
              ]),
              _: 1
            }, 8, ["layout"]))
          ], 64))
        ]),
        __props.parentPage.footerType == "tabbar" ? (openBlock(), createBlock(_component_FecMobileTabbar, mergeProps({
          key: 1,
          modelValue: unref(tabbarActive),
          "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(tabbarActive) ? tabbarActive.value = $event : null)
        }, __props.parentPage.tabbarConfig, { onChange: onTabbarChange }), null, 16, ["modelValue"])) : createCommentVNode("", true),
        __props.parentPage.footerType == "actionBar" ? (openBlock(), createBlock(_component_FecMobileActionBar, normalizeProps(mergeProps({ key: 2 }, __props.parentPage.actionBarConfig)), null, 16)) : createCommentVNode("", true)
      ], 64);
    };
  }
};
const MobilePage = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-71059c96"]]);
export {
  MobilePage as default
};
