import { registerExisting, type RegisterExistingData, resetPassword, type ResetPasswordData, verifyEmail, type VerifyEmailData } from "./auth.js" import { installerApproved, type InstallerApprovedData, installerRejected, type InstallerRejectedData, quoteRequestAdmin, type QuoteRequestAdminData, quoteRequestReceived, type QuoteRequestReceivedData, quoteSent, type QuoteSentData, showroomBookingConfirmed, type ShowroomBookingConfirmedData, staffNotification, type StaffNotificationData, ticketReply, type TicketReplyData, } from "./business.js" import type { RenderedEmail } from "./layout.js" import { orderCanceled, type OrderCanceledData, orderConfirmation, type OrderConfirmationData, orderPlacedAdmin, type OrderPlacedAdminData, orderShipped, type OrderShippedData, } from "./orders.js" export type { RenderedEmail } from "./layout.js" export type { OrderEmailData } from "./orders.js" /** Dati richiesti da ogni template (il nome รจ anche il tag inviato al provider). */ export type EmailTemplates = { "verify-email": VerifyEmailData "reset-password": ResetPasswordData "register-existing": RegisterExistingData "order-confirmation": OrderConfirmationData "order-placed-admin": OrderPlacedAdminData "order-canceled": OrderCanceledData "order-shipped": OrderShippedData "quote-request-admin": QuoteRequestAdminData "quote-request-received": QuoteRequestReceivedData "quote-sent": QuoteSentData "ticket-reply": TicketReplyData "showroom-booking-confirmed": ShowroomBookingConfirmedData "staff-notification": StaffNotificationData "installer-approved": InstallerApprovedData "installer-rejected": InstallerRejectedData } export type EmailTemplate = keyof EmailTemplates const renderers: { [K in EmailTemplate]: (data: EmailTemplates[K]) => RenderedEmail } = { "verify-email": verifyEmail, "reset-password": resetPassword, "register-existing": registerExisting, "order-confirmation": orderConfirmation, "order-placed-admin": orderPlacedAdmin, "order-canceled": orderCanceled, "order-shipped": orderShipped, "quote-request-admin": quoteRequestAdmin, "quote-request-received": quoteRequestReceived, "quote-sent": quoteSent, "ticket-reply": ticketReply, "showroom-booking-confirmed": showroomBookingConfirmed, "staff-notification": staffNotification, "installer-approved": installerApproved, "installer-rejected": installerRejected, } export const EMAIL_TEMPLATES = Object.keys(renderers) as EmailTemplate[] /** Renderizza un template (oggetto, HTML con layout comune, testo). */ export function renderEmail(template: T, data: EmailTemplates[T]): RenderedEmail { return renderers[template](data) }