import { apiFetch } from "../helpers/fetcher";

const BASE_URL = 'auth';

const API_URL = `http://localhost:5000/${BASE_URL}`;

export interface LoginData {
  nom: string;
  prenom: string;
  mot_de_passe: string;
}

export async function login(data: LoginData) {
  const dataResult = await apiFetch(`${API_URL}/login`, {
    method: "POST",
    body: JSON.stringify(data)
  });
  localStorage.setItem("token", dataResult.access_token);
  localStorage.setItem("user", JSON.stringify(dataResult.user));
  return dataResult;
}

export async function getCurrentUser() {
  return apiFetch(`${API_URL}/me`);
}