import {defineStore} from "pinia";
import {ref} from "vue";
import type IAppTabs from "@/interface/app/IAppTabs.ts";


export const tabsStore = defineStore('tabs', () => {
    let selectTab = ref<string>('appHome');
    let appTabs = ref<IAppTabs[]>([]);
    function setSelectTab(tabName: string) {
        selectTab.value = tabName;
    }
    function addAppTab(tabs: IAppTabs) {
        appTabs.value.push(tabs);
    }
    function removeAppTabWithTableName(tabName: string) {
        const tab = appTabs.value.find(item => item.tabName == tabName);
        if (tab) {
            appTabs.value.splice(appTabs.value.indexOf(tab), 1);
        }
    }
    function getAppTab(tabName: string) {
        return appTabs.value.find(item => item.tabName == tabName);
    }
    function resetAppTabs() {
        appTabs.value = [];
        selectTab.value = 'appHome';
    }
    return {selectTab, appTabs, setSelectTab, addAppTab, removeAppTabWithTableName, getAppTab,resetAppTabs};
}, {
    persist: {
        key: 'tabs',
    }
})