// utils/exportReport.ts
import html2canvas from "html2canvas";
import jsPDF from "jspdf";

export async function exportPNG(el: HTMLElement) {
  const canvas = await html2canvas(el, {
    scale: 2,
    useCORS: true,
    backgroundColor: "#fff"
  });

  const link = document.createElement("a");
  link.download = "weather-report.png";
  link.href = canvas.toDataURL("image/png");
  link.click();
}

export async function exportPDF(el: HTMLElement) {
  const canvas = await html2canvas(el, {
    scale: 2,
    useCORS: true,
    backgroundColor: "#fff"
  });

  const img = canvas.toDataURL("image/png");
  const pdf = new jsPDF("p", "mm", "a4");

  const pageWidth = 210;
  const imgHeight = (canvas.height * pageWidth) / canvas.width;

  pdf.addImage(img, "PNG", 0, 0, pageWidth, imgHeight);
  pdf.save("weather-report.pdf");
}
