<template>
    <view class="page-content
    bg-gradient-to-b from-primary-lighter to-bg bg-[length:100vw_170px] bg-no-repeat">
        <gradient-navbar/>
        <enroll-dashboard/>
        <mx-index-menus :data="pageConfig.menus" class="mt-[-50px]"/>
        <view class="mx-30 mt-30 mb-60 fx-col gap-40">
            <!-- <component v-for="block in pageConfig.blocks" v-bind="block" :is="blockMap[block.is]"/> -->
        </view>
    </view>
</template>

<script setup>
import mxConst from "@/common/mxConst";
import mxConfig from "@/common/mxConfig";
import {onLoad, onShow} from '@dcloudio/uni-app'
import {onMounted, ref, watchEffect} from 'vue';
import {useEnvStore} from "@/hooks/useEnvStore";
import {useTransfer} from "@/hooks/useTransfer";
import {useUserStore} from "@/hooks/useUserStore";
import {useTheme} from "@/hooks/useTheme";
import {useProvidePageConfig} from "@/hooks/usePageConfigInjection";
import {useProvidePageScroll} from "@/hooks/usePageScrollInjection";
import GradientNavbar from "@/pagesOther/pages/index/components/gradient-navbar.vue";
import EnrollDashboard from "@/pagesOther/pages/index/components/enroll-dashboard.vue";
import CarouselBanner from "@/pagesOther/pages/index/components/carousel-banner.vue";
import ScheduleSteps from "@/pagesOther/pages/index/components/schedule-steps.vue";
import NewsTab from "@/pagesOther/pages/index/components/news-tab.vue";
import NewsTop from "@/pagesOther/pages/index/components/news-top.vue";

// 这里和vue2不太一样，vue2中import就能保证正常使用，但vue3中不能简单把component.is赋值为字符串
const blockMap = {
    [CarouselBanner.name]: CarouselBanner,
    [ScheduleSteps.name]: ScheduleSteps,
    [NewsTab.name]: NewsTab,
    [NewsTop.name]: NewsTop
}

const {isLogin, isMobileBind, isScoreLocking} = useUserStore()
const {isParent, isGuideRead} = useEnvStore()
const {transferTo} = useTransfer()
const {brands} = useTheme()
const pageConfig = ref({})
useProvidePageScroll()

watchEffect(() => {
    const pageName = isParent.value ? 'Parent' : 'Index'
    pageConfig.value = useProvidePageConfig(pageName)
    console.log(pageConfig.value)
})

onLoad(() => {
    // 如果是从公众号进入本应用，隐藏底部的tab-bar，首页菜单将包含所有入口。
    if (isParent.value) uni.hideTabBar()
})

onShow(() => {
    if (!isGuideRead.value) {
        transferTo(mxConst.routes.guide)
        return
    }
    if (isLogin.value && !isMobileBind.value) {
        transferTo(mxConst.routes.bindMobile)
        return
    }
    if (isLogin.value && isScoreLocking.value) {
        uni.showModal({
            content: mxConfig.scoreLockingTips,
            showCancel: false,
            confirmText: '去修改分数',
            confirmColor: brands.primary,
            success: () => transferTo(mxConst.routes.basicInfo)
        })
        return
    }
})

onMounted(() => {
    // 这个挂钩可能是给wap2app用的，继续保留
    window.getPages = getPages
})

function getPages() {
    const pages = getCurrentPages();
    uni.postMessage({
        data: {
            pages: pages.length
        }
    });
}
</script>

<style lang="scss" scoped>
</style>
