import apiClient from "./apiClient";

export const login = async (email, password) => {
  const { data } = await apiClient.post("/api/login/", { email, password });
  localStorage.setItem("access", data.access);
  localStorage.setItem("refresh", data.refresh);
  localStorage.setItem("user", JSON.stringify(data.user));
  return data;
};

export const logout = () => {
  localStorage.clear();
  window.location.href = "/";
};

export const requestPasswordReset = (email) => apiClient.post("/api/password-reset-request/", { email });
export const checkPasswordReset = (uid, token) =>
  apiClient.get(`/api/check-password-reset-token/${uid}/${token}/`);
export const confirmPasswordReset = (uid, token, new_password) =>
  apiClient.post(`/api/reset-password-confirm/${uid}/${token}/`, { new_password });

export const verifyEmail = (token) => apiClient.get(`/api/verify-email/${token}/`);
