import { Resend } from "resend";
import { parseBooleanWithDefault } from "../boolean.js";
import { resolveDefaultEmailFromAddress } from "./config.js";
async function sendEmail({ to, subject, react, from, replyTo, attachments }) {
  const emailDisabled = parseBooleanWithDefault(process.env.OM_DISABLE_EMAIL_DELIVERY, false) || parseBooleanWithDefault(process.env.OM_TEST_MODE, false);
  if (emailDisabled) return;
  const apiKey = process.env.RESEND_API_KEY;
  if (!apiKey) throw new Error("RESEND_API_KEY is not set");
  const resend = new Resend(apiKey);
  const fromAddr = from || resolveDefaultEmailFromAddress();
  if (!fromAddr) {
    throw new Error("EMAIL_FROM_NOT_CONFIGURED: set NOTIFICATIONS_EMAIL_FROM, EMAIL_FROM, or ADMIN_EMAIL");
  }
  const payload = {
    to,
    subject,
    from: fromAddr,
    react,
    ...replyTo ? { reply_to: replyTo } : {},
    ...attachments?.length ? { attachments } : {}
  };
  const result = await resend.emails.send(payload);
  const errorMessage = typeof result?.error === "string" ? result.error : typeof result?.error?.message === "string" ? result.error.message : null;
  if (errorMessage) {
    throw new Error(`RESEND_SEND_FAILED: ${errorMessage}`);
  }
}
export {
  sendEmail
};
//# sourceMappingURL=send.js.map
