<script setup lang="ts">
import { ref } from 'vue'
import FgTabbar from '@/tabbar/index.vue'
import { useLoadingStore } from './store/loading'
import { isPageTabbar, tabbarStore } from './tabbar/store'
import { currRoute } from './utils'

const isCurrentPageTabbar = ref(true)
const loadingStore = useLoadingStore()

onShow(() => {
    console.log('App.ku.vue onShow', currRoute())
    const { path } = currRoute()
    // “蜡笔小开心”提到本地是 '/pages/index/index'，线上是 '/' 导致线上 tabbar 不见了
    // 所以这里需要判断一下，如果是 '/' 就当做首页，也要显示 tabbar
    isCurrentPageTabbar.value = path === '/' || isPageTabbar(path)
    setTimeout(() => {
        if (isCurrentPageTabbar.value) {
            tabbarStore.setAutoCurIdx(path)
        }
    }, 0)
    loadingStore.hideLoading()
})

const helloKuRoot = ref('Hello AppKuVue')

const exposeRef = ref('this is form app.Ku.vue')

defineExpose({
    exposeRef,
})
</script>

<template>
    <view>
        <!-- 这个先隐藏了，知道这样用就行 -->
        <!-- <view class="hidden text-center">
            {{ helloKuRoot }}，这里可以配置全局的东西
        </view> -->

        <KuRootView />
        <up-loading-page :loading="loadingStore.isLoading" z-index="10000" size="50" />
        <FgTabbar v-if="isCurrentPageTabbar" />
    </view>
</template>
