import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useRoute } from "vue-router";
import { useStorage } from '@vueuse/core'
export const tabRouter = defineStore('tabRouter', () => {
  const route = useRoute();
    const tabs=useStorage('tabs',[],localStorage)
    const currentTab=useStorage('currentTab',route.path,localStorage)
  const pushTabs=(tab)=>{
    function deduplicateArrayById(arr) {
      const map = new Map();
      arr.forEach(item => {
        if (!map.has(item.ID)) {
          map.set(item.ID, item);
        }
      });
      return Array.from(map.values());
    }
    tabs.value=deduplicateArrayById([...tabs.value,tab])
  }
  return{
    pushTabs,
      tabs,
    currentTab
  }
})