import { Resend } from "resend"; const resend = new Resend(process.env.RESEND_API_KEY); /** * Send event registration confirmation email */ export async function sendEventRegistrationEmail(registration, eventData) { const formatDate = (dateString) => { const date = new Date(dateString); return new Intl.DateTimeFormat("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric", }).format(date); }; const formatTime = (startDate, endDate) => { const start = new Date(startDate); const end = new Date(endDate); const timeFormat = new Intl.DateTimeFormat("en-US", { hour: "numeric", minute: "2-digit", timeZoneName: "short", }); return `${timeFormat.format(start)} - ${timeFormat.format(end)}`; }; try { const { data, error } = await resend.emails.send({ from: "Ghost Guild ", to: [registration.email], subject: `You're registered for ${eventData.title}`, html: `

You're Registered! 🎉

Hi ${registration.name},

Thank you for registering for ${eventData.title}!

Date
${formatDate(eventData.startDate)}
Time
${formatTime(eventData.startDate, eventData.endDate)}
Location
${eventData.location}
${eventData.description ? `

${eventData.description}

` : ""}
View Event Details

Need to cancel?
Visit the event page and click "Cancel Registration" to remove yourself from the attendee list.

`, }); if (error) { console.error("Failed to send registration email:", error); return { success: false, error }; } return { success: true, data }; } catch (error) { console.error("Error sending registration email:", error); return { success: false, error }; } } /** * Send event cancellation confirmation email */ export async function sendEventCancellationEmail(registration, eventData) { try { const { data, error } = await resend.emails.send({ from: "Ghost Guild ", to: [registration.email], subject: `Registration cancelled: ${eventData.title}`, html: `

Registration Cancelled

Hi ${registration.name},

Your registration for ${eventData.title} has been cancelled.

We're sorry you can't make it. You can always register again if your plans change.

Browse Other Events
`, }); if (error) { console.error("Failed to send cancellation email:", error); return { success: false, error }; } return { success: true, data }; } catch (error) { console.error("Error sending cancellation email:", error); return { success: false, error }; } }