import { defineStore } from 'pinia'

export const useTabbarStore = defineStore('tabbar', {
  persist: true,
  state: () => ({
    tabbarIndex: uni.getStorageSync('app-tabbar-index') || 0,
  }),
  actions: {
    setCurIdx(idx: number) {
      this.tabbarIndex = idx
      uni.setStorageSync('app-tabbar-index', idx)
    },
  },
  getters: {
    curIdx: ({ tabbarIndex }) => tabbarIndex,
  },
})
