import ApiConnect from "../ApiConfig";

export const user_login = async (data) => {
  // console.log(data)
  try {
    const result = await ApiConnect("login", {
      method: "POST",
      data: data,
      // withCredentials: true,
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed login api");

    return error;
  }
};
// export const user_login = async (data) => {
//   try {
//     const result = await axios.post("http://localhost:3000/api//login", data, { withCredentials: true });
//     return result;
//   } catch (error) {
//     console.log(error);
//     console.log(error + " failed login api");

//     return error;
//   }
// };
export const register_user = async (data) => {
  try {
    const result = await ApiConnect("register", {
      method: "POST",
      data: data,
      // withCredentials: true,
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed register api");

    return error;
  }
};
export const get_user_token = async (data) => {
  try {
    const result = await ApiConnect("profile", {
      method: "GET",
      headers: {
        Authorization: `Bearer ${data.token}`,
      },
      // withCredentials: true,
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed user api");

    return error;
  }
};
export const forgot_password = async (data) => {
  // console.log(data)
  try {
    const result = await ApiConnect("forgot-password", {
      method: "POST",
      data: data.body,
      // withCredentials: true,
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed forgot password email api");

    return error;
  }
};
export const change_password = async (data) => {
  // console.log(data)
  // try {
    const result = await ApiConnect("change-password", {
      method: "POST",
      data: data.body,
      // withCredentials: true,
    });
    return result;
  // } catch (error) {
  //   console.log(error);
  //   console.log(error + "failed change password email api");

  //   return error;
  // }
};