import getXSRFToken from "../getXSRF";

export default async function deleteProfilePhoto(): Promise<{ status: number; ok: boolean; data?: any; error?: string }> {
  try {
    const csrfToken = await getXSRFToken();
    const response = await fetch(`${import.meta.env.VITE_API_URL}/api/profile-photo`, {
      method: "DELETE",
      headers: { "X-XSRF-TOKEN": decodeURIComponent(csrfToken) },
      credentials: "include",
    });

    const status = response.status;
    let data = null;
    try {
      data = await response.json();
    } catch (e) {
      // Pas de JSON dans la réponse
    }

    return { status, ok: response.ok, data };
  } catch (err: any) {
    return { status: 0, ok: false, error: err?.message || "Erreur réseau" };
  }
}
