// @ts-expect-error TS6133 - React required at runtime for JSX in workers
// biome-ignore lint/correctness/noUnusedImports: React required at runtime for JSX in workers (tsx/esbuild classic transform)
import React from "react"
import { renderEmail } from "../../utils/render.ts"
import type { RenderedEmail } from "../types.ts"
import { MagicLinkEmail } from "./EmailTemplate.tsx"

export interface MagicLinkEmailData {
  readonly userName: string
  readonly magicLinkUrl: string
}

export async function magicLinkTemplate(data: MagicLinkEmailData): Promise<RenderedEmail> {
  return {
    html: await renderEmail(<MagicLinkEmail userName={data.userName} magicLinkUrl={data.magicLinkUrl} />),
    subject: `${data.userName}, here's your sign-in link for Latitude`,
    text: `Hi ${data.userName}, use this link to sign in to Latitude: ${data.magicLinkUrl}`,
  }
}

export default MagicLinkEmail
