<template>
    <u-tabbar
        v-model="current"
        v-bind="tabbarStyle"
        :list="tabbarList"
        @change="handleChange"
        :hide-tab-bar="false"
    ></u-tabbar>
</template>

<script lang="ts" setup>
import { useAppStore } from '@/stores/app'
import { navigateTo } from '@/utils/util'
import { computed, ref } from 'vue'
import { useUserStore } from '@/stores/user'
import { onShow } from '@dcloudio/uni-app'
import { storeToRefs } from 'pinia'
const current = ref()
const appStore = useAppStore()

const userStore = useUserStore()
const { userInfo, isLogin } = storeToRefs(userStore)

userStore.getUser()
const tabbarList = computed(() => {
    let list = new Array(0);
    for (let i = 0; i < appStore.getTabbarConfig.length; i++) {
        let item = appStore.getTabbarConfig[i]
        const link = JSON.parse(item.link)

        // 如果是接单，只有师傅才能看到
        if (userInfo.value.staff != true) {
            if (link.path.search('service_order') != -1) {
                continue // 忽略师傅页面
            }
        }

        const my_item = {
            iconPath: item.unselected,
            selectedIconPath: item.selected,
            text: item.name,
            link,
            pagePath: link.path
        }
        list.push(my_item)
    }
    return list

    // return appStore.getTabbarConfig.map((item: any) => {
    //     const link = JSON.parse(item.link)
    //     return {
    //         iconPath: item.unselected,
    //         selectedIconPath: item.selected,
    //         text: item.name,
    //         link,
    //         pagePath: link.path
    //     }
    // })
})

const tabbarStyle = computed(() => ({
    activeColor: appStore.getStyleConfig.selectedColor,
    inactiveColor: appStore.getStyleConfig.defaultColor
}))
const handleChange = (index: number) => {
    const selectTab = tabbarList.value[index]

    navigateTo(selectTab.link, 'reLaunch')
}
</script>
