import router from '@/router/router'
import page from '@/utils/page'
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useTabbarStore = defineStore('tabbar', () => {
    const list = [
        {
            pagePath: '/pages/home/home',
            text: '首页',
            iconPath: '/static/footerBar/home-icon-link.png',
            selectedIconPath: '/static/footerBar/home-icon-active.png',
        },
        {
            pagePath: '/pages/bill/bill',
            text: '学费账单',
            iconPath: '/static/footerBar/tuitionBill-icon-link.png',
            selectedIconPath: '/static/footerBar/tuitionBill-icon-active.png',
        },
        {
            pagePath: '/pages/mine/mine',
            text: '我的',
            iconPath: '/static/footerBar/main-icon-link.png',
            selectedIconPath: '/static/footerBar/main-icon-active.png',
        },
    ]
    const currentUrl = page.getPagePath()
    const current = ref(list.findIndex(item => item.pagePath === currentUrl))

    function switchTab(e: any) {
        if (current.value === e.index) return
        current.value = e.index
        router.switchTab(list[e.index].pagePath)
    }

    return {
        list,
        current,
        switchTab,
    }
})
