export const downloadVCard = (text: string, filename: string) => {
  const blob = new Blob([text], { type: "text/vcard;charset=utf-8" });
  const url = window.URL.createObjectURL(blob);
  const link = document.createElement("a");
  link.href = url;
  link.setAttribute("download", filename); // ou tout autre nom de fichier que vous voulez
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
};

export const downloadFileImage = async (
  url: string,
  filename: string
): Promise<void> => {
  try {
    const response = await fetch(url);
    const blob = await response.blob();
    const objectUrl = window.URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = objectUrl;
    a.download = filename;
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(objectUrl);
    document.body.removeChild(a);
  } catch (error) {
    console.error("Erreur lors du téléchargement:", error);
    throw error;
  }
};
