export default function(){

    type TDownloadAppKeys = "PROPERTY" | "SECURITY" | "HYGIENE" | "MECHANICAL_ELECTRICAL" | "PEST_CONTROL" | "LANDSCAPING" | "POOL_MAINTENANCE"

    async function downloadPDF({ url, title, orientation, appKey} : { url: string; title: string; orientation: "P" | "L", appKey: TDownloadAppKeys }) {
    const res = await useNuxtApp().$api<Blob | MediaSource>("/api/site-soa/generate-pdf", {
      method: "GET",
      query: { url, title, orientation, appKey },
    });
    if (!res) throw new Error("Error downloading PDF");
    const downloadUrl = window.URL.createObjectURL(res);
    const a = document.createElement("a");
    a.href = downloadUrl;
    a.download = title; // Specify the file name
    document.body.appendChild(a);
    a.click(); // Trigger the download
    window.URL.revokeObjectURL(downloadUrl); // Clean up
  }

  return {
    downloadPDF
  }


}