import { Notify } from 'quasar';
import { auth } from '@services/AuthService';
import isString from 'lodash/isString';
import { ActionTree, mapActions } from 'vuex';

export const state = {};

export const getters = {};

export const mutations = {};

export const actions: ActionTree<any, any> = {
  /**
   * show information about error.
   * @param {commit} state commit commit
   * @param {{ message: any}[]} args any arguments
   */
  error({ commit = {} }, ...args) {
    console.error(...args);

    if (auth.isAuthorized()) {
      Notify.create({
        color: 'negative',
        icon: 'error',
        message: isString(args[0])
          ? args[0]
          : args[0].message || `${args.join(' ')}`,
      });
    }
  },
};

export const utilsErrorMethods = mapActions('utils/error', ['error']);
