import { defineStore } from "pinia";

export const useMenuStore = defineStore("menuStore", {
  state: () => ({
    menusAll: [],
    menus: [],
    model: "",
  }),
  getters: {
    getMenus: (state) => state.menus,
    getModel: (state) => state.model,
  },
  actions: {
    setMenus(menus) {
      this.menusAll = menus;
    },
    setModel(model) {
      this.model = model;
      this.menus = [];
      for (let i = 0; i < this.menusAll.length; i++) {
        if (this.menusAll[i].meta.model === model) {
          this.menus.push(this.menusAll[i]);
        }
      }
    },
  },
  persist: {
    storage: window.sessionStorage,
  },
});
