export const generateInvoicePDF = async (options: {
invoiceNumber: string;
date: string;
customerName: string;
customerEmail: string;
items: {
description: string;
quantity: number;
price: number;
}[];
currencySymbol: string;
}): Promise<string> => {
const { jsPDF } = await import("npm:jspdf");
const doc = new jsPDF();
const {
invoiceNumber,
date,
customerName,
customerEmail,
items,
currencySymbol,
} = options;
let y = 20;
doc.setFontSize(18);
doc.text("Invoice", 105, y);
y += 10;
doc.setFontSize(12);
doc.text(`Invoice Number: ${invoiceNumber}`, 20, y);
doc.text(`Date: ${date}`, 150, y);
y += 10;
doc.text(`Customer: ${customerName}`, 20, y);
doc.text(`Email: ${customerEmail}`, 150, y);
y += 10;
doc.setFont(undefined, "bold");
doc.text("Description", 20, y);
doc.text("Quantity", 100, y);
doc.text("Price", 150, y);
y += 5;
doc.line(20, y, 180, y);
y += 5;
doc.setFont(undefined, "normal");
items.forEach((item) => {
doc.text(item.description, 20, y);
doc.text(item.quantity.toString(), 100, y);
doc.text(item.price.toString(), 150, y);
y += 5;
});
doc.line(20, y, 180, y);
y += 10;
const total = items.reduce(
(acc, item) => acc + item.quantity * item.price,
0,
);
doc.setFont(undefined, "bold");
doc.text(`Total: ${total}`, 150, y);
return doc.output();
};