import { pinia } from '../index'
export const useKeepAliveStore = defineStore('eco-keep-alive', {
  state: () => ({
    keepAliveName: [] as string[]
  }),
  getters: {
    getKeepAliveName: state => state.keepAliveName
  },
  actions: {
    addKeepAliveName(name: string) {
      if (!this.keepAliveName.includes(name)) {
        this.keepAliveName.push(name)
      }
    },
    removeKeepAliveName(name: string) {
      this.keepAliveName = this.keepAliveName.filter(item => item !== name)
    },
    setKeepAliveName(keepAliveNames: string[] = []) {
      this.keepAliveName = keepAliveNames
    }
  },
  persist: true
})

export const useKeepAliveStoreWithOut = () => {
  return useKeepAliveStore(pinia)
}
