
// import getGQL from "../utils/getGQL";
import * as actions from "../constants/actions/index";
import {getGQL }from "../utils/getGQL";


function actionLogOut() {
  // console.log(actions)
  return {
    type: actions.LOGOUT,
  };
}

// export default actionLogOut;
// ............................
  // let p = getGQL('http://player.asmer.fs.a-level.com.ua/graphql')(
  //   let p = getGQL('/graphql')(
  //     `query Login(login: String!, password: String!){
  //     login(login: "${login}", password: "${password}")
  //     }`
  //   ).then((data) =>
  //     console.log(data)
  // )

  // store.dispatch(actionPending())
  // p.then(data => store.dispatch(actionResolved(data)))

export const doLogOut = (store, dispatch) => {
  // debugger
  try {
    store.dispatch(actionLogOut());

  } catch (error) {
    console.log(error)
    if (error.message.includes("Invalid token")) {
      alert("Invalid credentials!");
    } else {
      alert("Something went wrong");
    }
  }
};

// export default doLogOut, actionLogOut;
// export default doLogOut, actionLogOut;

// export const doLogOut = ({dispatch, history}) => {
//     try {
//         // console.log(login, password, localStorage.authToken);
//         localStorage.authToken = "";
//         const token = localStorage.authToken;
//         dispatch(actionLogOut(token));
//         console.log("localStorage.authToken: " + localStorage.authToken);
//         history.push("/login");
//     } catch (error) {
//       if (error.message.includes("Invalid token")) {
//         alert("Invalid credentials!");
//       } else {
//         alert("Something went wrong");
//       }
//     }
// };