import axios from 'axios';
import store from '../store';
import {getStudiesSuccess, getStudySuccess} from '../actions/study-actions';

const mockEndpoints = {
  GET_STUDIES: 'http://localhost:3009/studies',
  GET_STUDY: 'http://localhost:3009/studys/'
};

const prodEndpoints = {
  GET_STUDIES: 'https://shielddash.herokuapp.com/studies',
  GET_STUDY: 'https://shielddash.herokuapp.com/studies/'
}

// TODO: Check node environment to set this.
const endpoints = mockEndpoints;

// We should only hit this once signed in.
var apiArgs = {
  idtoken: localStorage.user_token
};

// Fetch list of studies.
export function getStudies() {
  return axios.get(endpoints.GET_STUDIES, {params: apiArgs}).then(response => {
    store.dispatch(getStudiesSuccess(response.data));
    return response;
  }).catch(err => {
    console.error(err);
  });
}

// Fetch specific study.
export function getStudy(studyId) {
  return axios.get(endpoints.GET_STUDY + studyId, {params: apiArgs}).then(response => {
    store.dispatch(getStudySuccess(response.data));
    return response;
  }).catch(err => {
    console.error(err);
  });
}

@@ -321,32 +321,33 @@
 uapp.com/studies
+/
 ',%0A  GET_STUDY: 
@@ -460,120 +460,169 @@
 s = 
-mockEndpoints;%0A%0A// We should only hit this once signed in.%0Avar apiArgs = %7B%0A  idtoken: localStorage.user_token
+process.env.NODE_ENV === 'dev' ? mockEndpoints : prodEndpoints;%0A%0A// Auth token from LS.%0Alet jwt = localStorage.user_token;%0Alet headers = %7B%0A  Authorization: jwt
 %0A%7D
-;
 %0A%0A//
@@ -719,30 +719,31 @@
 UDIES, %7B
-params: apiArg
+headers: header
 s%7D).then
@@ -1001,22 +1001,23 @@
 d, %7B
-params: apiArg
+headers: header
 s%7D).

tweak the api requests for testing