import { connect } from 'herculex';

const getPageInfo = (state) => {
  const { $global, templateUUID } = state;
  const pageConfig = $global.pageConfig || {};
  return pageConfig[templateUUID] || {};
};

const getTplExtInfo = (state) => {
  const { extInfoObj } = getPageInfo(state);
  return extInfoObj || {};
};

Component(connect({
  mapStateToProps: {
    isShowPageLoginModal: state => state.$getters.isShowPageLoginModal,
    isShowEnterAd: state => state.isShowEnterAd,
    enterAdComponent: state => state.enterAdComponent,
    componentList: state => state.componentList,
    isRenderMain: state => state.isRenderMain,
    showLoginModal: state => state.showLoginModal,
    hasTabBar: state => state.hasTabBar,
    bottomTips: state => state.bottomTips,
    extInfoObj: state => getTplExtInfo(state),
    activePageExtIfo: state => state.activePageExtIfo,
    isMessagePluginLoad: state => state.$global.isMessagePluginLoad,
  },
  data: {
    tabbarHeight: 0,
  },
})({
  didUpdate(prevData) {
    if (!prevData.hasTabBar && this.data.hasTabBar) {
      my.createSelectorQuery()
        .select('.tabbar-box').boundingClientRect().exec((ret) => {
          this.setData({
            tabbarHeight: ret[0].height,
          });
        });
    }
  },
  methods: {
    // todo onReloadHandle
    // eslint-disable-next-line no-empty-function
    async onReloadHandle() {},
  },
}));
