/**
 * Program: Mixed in for parameters and menus
 * Author: SDL
 * Description: Mixed in for parameters and menus
 */
import { mapGetters, mapActions } from 'vuex';
import _ from 'lodash';

export default {
  computed: {
    ...mapGetters({
      vueStoreParameter: 'getParams',
      menus: 'getMenus',
    }),
    pageId() {
      return this.$route.meta.pageId;
    },
  },
  methods: {
    ...mapActions({
      saveVueStoreParameter: 'setParams',
    }),
    getStoreParameter() {
      return this.vueStoreParameter[this.pageId];
    },
    setStoreParameter(params) {
      // console.info('setStoreParameter', this.pageId, params);
      const saveParams = {
        ...this.getStoreParameter(),
      };
      saveParams[this.pageId] = params;
      this.saveVueStoreParameter(saveParams);
    },
    goBackToList() {
      const parentMenu = this.menus.find(menu => menu.menuId === this.$route.meta.menuId);
      const defaultPage = _.find(parentMenu.pages, ['defaulted', true]);
      if (defaultPage) {
        this.$router.push({ name: defaultPage.pageId, state: { restoreList: true } });
      }
    },
  },
};
