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}

` : ""} ${ registration.ticketType && registration.ticketType !== "guest" && registration.amountPaid > 0 ? `

Ticket Information

Ticket Type
${registration.ticketType === "member" ? "Member Ticket" : "Public Ticket"}
Amount Paid
$${registration.amountPaid.toFixed(2)} CAD
${ registration.paymentId ? `
Transaction ID
${registration.paymentId}
` : "" }
` : registration.ticketType === "member" && registration.amountPaid === 0 ? `

✨ Member Benefit: This event is free for Ghost Guild members!

` : "" }
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 }; } } /** * Send waitlist notification email when a spot opens up */ export async function sendWaitlistNotificationEmail(waitlistEntry, 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: [waitlistEntry.email], subject: `A spot opened up for ${eventData.title}!`, html: `

A Spot Just Opened Up! 🎉

Hi ${waitlistEntry.name},

Great news! A spot has become available for ${eventData.title}, and you're on the waitlist.

⏰ Act fast! Spots are filled on a first-come, first-served basis.

Event
${eventData.title}
Date
${formatDate(eventData.startDate)}
Time
${formatTime(eventData.startDate, eventData.endDate)}
Location
${eventData.location}
Register Now →

If you can no longer attend, no worries! Just ignore this email and the spot will go to the next person on the waitlist.

`, }); if (error) { console.error("Failed to send waitlist notification email:", error); return { success: false, error }; } return { success: true, data }; } catch (error) { console.error("Error sending waitlist notification email:", error); return { success: false, error }; } } /** * Send series pass confirmation email */ export async function sendSeriesPassConfirmation(options) { const { to, name, series, ticket, events, paymentId } = options; 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)}`; }; const formatPrice = (price, currency = "CAD") => { if (price === 0) return "Free"; return new Intl.NumberFormat("en-CA", { style: "currency", currency, }).format(price); }; const seriesTypeLabels = { workshop_series: "Workshop Series", recurring_meetup: "Recurring Meetup", multi_day: "Multi-Day Event", course: "Course", tournament: "Tournament", }; try { const { data, error } = await resend.emails.send({ from: "Ghost Guild ", to: [to], subject: `Your Series Pass for ${series.title}`, html: `

🎫 Your Series Pass is Ready!

You're registered for all events

Hi ${name},

Great news! Your series pass for ${series.title} is confirmed. You're now registered for all ${events.length} events in this ${seriesTypeLabels[series.type] || "series"}.

${ ticket.isFree && ticket.type === "member" ? `

✨ Member Benefit

This series pass is free for Ghost Guild members. Thank you for being part of our community!

` : "" }

Series Pass Details

Series
${series.title}
${ series.description ? `
About
${series.description}
` : "" }
Pass Type
${ticket.type === "member" ? "Member Pass" : "Public Pass"}
Amount Paid
${formatPrice(ticket.price, ticket.currency)}
${ paymentId ? `
Transaction ID
${paymentId}
` : "" }
Total Events
${events.length} events included

Your Event Schedule

You're automatically registered for all of these events:

${events .map( (event, index) => `
Event ${index + 1}: ${event.title}
📅 ${formatDate(event.startDate)}
🕐 ${formatTime(event.startDate, event.endDate)}
📍 ${event.location}
`, ) .join("")}

What's Next?

  • Mark these dates in your calendar
  • You'll receive individual reminders before each event
  • Event links and materials will be shared closer to each date
  • Join the conversation in our Slack community
`, }); if (error) { console.error("Failed to send series pass confirmation email:", error); return { success: false, error }; } return { success: true, data }; } catch (error) { console.error("Error sending series pass confirmation email:", error); return { success: false, error }; } }