'use strict';

var pinia = require('pinia');

const useKeepALiveNames = pinia.defineStore("keepALiveNames", {
  state: () => ({
    keepAliveNames: [],
    cachedViews: []
  }),
  actions: {
    async setCacheKeepAlive(data) {
      this.keepAliveNames = data;
    },
    async addCachedView(view) {
      if (view.meta.isKeepAlive) this.cachedViews?.push(view.name);
    },
    async delCachedView(view) {
      const index = this.cachedViews.indexOf(view.name);
      if (index > -1) this.cachedViews.splice(index, 1);
    },
    async delOthersCachedViews(view) {
      if (view.meta.isKeepAlive) this.cachedViews = [view.name];
      else this.cachedViews = [];
    },
    async delAllCachedViews() {
      this.cachedViews = [];
    }
  }
});

exports.useKeepALiveNames = useKeepALiveNames;
