<template>
	<u-tabbar v-if="showTabbar" height="120rpx" icon-size="50rpx" v-model="current" v-bind="tabbarStyle" :list="tabbarList"
		@change="handleChange" :hide-tab-bar="false" :border-top="false"></u-tabbar>
</template>

<script lang="ts" setup>
	import { onShow } from '@dcloudio/uni-app'
	import { navigateTo } from '@/utils/util'
	import { computed, ref } from 'vue'
	import { t } from '@/utils/util'

	const current = ref()
	const tabbarList = ref([
		{
			iconPath: "../../static/images/tabs/home_off.png",
			selectedIconPath: "../../static/images/tabs/home_on.png",
			text: t('tabbar.index'),
			pagePath: "/pages/index/index",
			link: {
				path: "/pages/index/index",
				type: "shop"
			}
		},
		{
			iconPath: "../../static/images/tabs/item_off.png",
			selectedIconPath: "../../static/images/tabs/item_on.png",
			text: t('tabbar.mine'),
			pagePath: "/pages/item/index",
			link: {
				path: "/pages/item/index",
				type: "shop"
			}
		},
		{
			iconPath: "../../static/images/tabs/mine_on.gif",
			selectedIconPath: "../../static/images/tabs/mine_on.gif",
			text: '',
			pagePath: "/pages/mine/index",
			link: {
				path: "/pages/mine/index",
				type: "shop"
			}
		},
		
		{
			iconPath: "../../static/images/tabs/team_off.png",
			selectedIconPath: "../../static/images/tabs/team_on.png",
			text: t('tabbar.team'),
			pagePath: "/pages/team/index",
			link: {
				path: "/pages/team/index",
				type: "shop"
			}
		},
		{
			iconPath: "../../static/images/tabs/my_off.png",
			selectedIconPath: "../../static/images/tabs/my_on.png",
			text: t('tabbar.my'),
			pagePath: "/pages/user/user",
			link: {
				path: "/pages/user/user",
				type: "shop"
			}
		},
	])

	const showTabbar = computed(() => {
		const currentPages = getCurrentPages()
		const currentPage = currentPages[currentPages.length - 1]
		const current = tabbarList.value.findIndex((item : any) => {
			return item.pagePath === '/' + currentPage.route
		})
		return current >= 0
	})

	const tabbarStyle = computed(() => ({
		activeColor: "#A1DBF5",
		inactiveColor: "#FFFFFF"
	}))
	const handleChange = (index : number) => {
		const selectTab = tabbarList.value[index]
		navigateTo(selectTab.link, 'switchTab')
	}
	onShow(() => {
		uni.hideTabBar();
	})
</script>