import { Producto } from 'src/models';
import { MutationTree } from 'vuex';
import { ProductosState } from './ProductosState';

export const mutations: MutationTree<ProductosState> = {
  setCurrent: (state, data: Producto | null) => {
    state.current = data;
  },
  setData: (state, data?: Producto) => {
    if (data === undefined) return;
    state.data = data;
  },
  setList: (state, value: Producto[]) => (state.list = value),
  setQueryParams: (state, value: any) => (state.queryParams = value),
  setCount: (state, value: number) => (state.count = value),
  setLoading: (state, value: boolean) => (state.loading = value),
  setStats: (state, value: any) => (state.stats = value),
  setLoadingStats: (state, value: boolean) => (state.loadingStats = value),
  reset: (state) => {
    state.data = null;
    state.current = null;
    state.queryParams = null;
    state.list = [];
  },
  setCurrentTab: (state, tab: string) => (state.currentTab = tab),
};
