import type { Invoice } from "../types"; interface EmailTemplateData { invoice: Invoice; businessProfile?: { name?: string; logo?: { src?: string }; address?: string; email_from_name?: string; }; company?: { name?: string; }; contact?: { first_name?: string; last_name?: string; email?: string; }; items?: Array<{ description: string; quantity: number; unit_price: number; line_total_with_tax: number; }>; message?: string; } export function generateInvoiceEmailHTML(data: EmailTemplateData): string { const { invoice, businessProfile, company, contact, items, message } = data; const contactName = contact?.first_name ? `${contact.first_name} ${contact.last_name || ""}`.trim() : "Valued Customer"; const companyName = company?.name || ""; const senderName = businessProfile?.email_from_name || businessProfile?.name || "Your Company"; return ` Invoice ${invoice.invoice_number}
${ message ? ` ` : "" } ${ items && items.length > 0 ? ` ` : "" } ${ invoice.payment_terms ? ` ` : "" }
${ businessProfile?.logo?.src ? ` ${senderName} ` : `

${senderName}

` } ${ businessProfile?.address ? `

${businessProfile.address.replace(/\n/g, "
")}

` : "" }

Invoice #${invoice.invoice_number}

Hello ${contactName}${companyName ? ` from ${companyName}` : ""},

${message}

Issue Date: ${new Date(invoice.issue_date).toLocaleDateString()}
Due Date: ${new Date(invoice.due_date).toLocaleDateString()}
Amount Due: ${invoice.currency} ${invoice.total.toFixed(2)}

Invoice Details

${items .map( (item) => ` `, ) .join("")}
Description Qty Amount
${item.description} ${item.quantity} ${invoice.currency} ${item.line_total_with_tax.toFixed(2)}

Payment Terms: ${invoice.payment_terms}

Thank you for your business!

If you have any questions about this invoice, please contact us.

`.trim(); }