import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';
import {
  sha256
} from 'js-sha256'

Vue.use(Vuex);

export default {
  namespaced: true,
  state: {
    auth: {}
  },
  mutations: {
    setAuthentication(state, newAuth) {
      state.auth = newAuth;
    }
  },
  getters: {},
  actions: {
    getAuthentication({
      commit
    }) {
      axios
        .get('/api/Authentication')
        .then(result => commit('setAuthentication', result.data));
    },
    checkAuthentication({
      commit
    }, authObject) {
      var sendObj = authObject;
      sendObj.password = sha256(authObject.password + '≡∆≤≥√∞ProVision');

      axios
        .post('/api/Authentication/Authenticate', sendObj)
        .then(result => commit('setAuthentication', result.data));
      // axios({
      //   url: '/api/Authentication/Authenticate',
      //   data: {
      //     emailAddress: authObject.emailAddress,
      //     password: sha256(authObject.password + '≡∆≤≥√∞ProVision'),
      //   },
      //   method: 'POST',
      // }).then((resp) => {
      //   commit('setAuthentication', resp.data);
      // });
    }
  }
}
