import { t } from './i18n.js';

export function generatePDFReport(pkChart, patient, mode) {
  const { jsPDF } = window.jspdf;
  const doc = new jsPDF('landscape', 'mm', 'a4');

  // Header
  doc.setFillColor(30, 41, 59);
  doc.rect(0, 0, 297, 25, 'F');

  doc.setTextColor(255, 255, 255);
  doc.setFontSize(16);
  doc.setFont("helvetica", "bold");
  doc.text(t('pdf.title'), 14, 16);

  // Patient information
  doc.setTextColor(50, 50, 50);
  doc.setFontSize(10);
  doc.setFont("helvetica", "normal");

  const dateStr = new Date().toLocaleString();

  doc.text(`${t('pdf.date')}${dateStr}`, 14, 35);
  doc.setFont("helvetica", "bold");
  doc.text(`${t('pdf.mode')}${mode}`, 14, 42);
  doc.text(t('pdf.patient_info', patient), 14, 49);

  // Chart image
  const chartImage = pkChart.toBase64Image('image/jpeg', 1.0);
  doc.addImage(chartImage, 'JPEG', 14, 55, 268, 120);

  // Footer
  doc.setFont("helvetica", "italic");
  doc.setFontSize(8);
  doc.setTextColor(150, 150, 150);
  doc.text(t('pdf.disclaimer'), 14, 192);

  doc.save(`KetaPK_Simulation_${patient.weight}kg_${mode}.pdf`);
}