import nodemailer from 'nodemailer';
import { O as ORIGIN, S as SMTP_PASS, h as SMTP_USER, i as SMTP_URL, E as EMAIL_DEFAULT_FROM, j as SMTP_PORT, N as NODE_ENV } from './index3-Cipag7JS.js';

const isProd = NODE_ENV === "production";
class Transporter {
  async _createInstance() {
    const options = {
      host: SMTP_URL,
      port: Number(SMTP_PORT),
      secure: false,
      // true for 465, false for other ports
      auth: { user: SMTP_USER, pass: SMTP_PASS }
    };
    if (!isProd) {
      const testAccount = await nodemailer.createTestAccount();
      options.host = "smtp.ethereal.email";
      options.port = 587;
      options.auth = { user: testAccount.user, pass: testAccount.pass };
    }
    return nodemailer.createTransport(options);
  }
  /**
   * @param {{
   * to: string
   * subject: string
   * from?: string
   * }
   * & ( { text: string, html?: never } | { text?: never, html: string } )
   * } options
   */
  async send({ to, from = EMAIL_DEFAULT_FROM, subject, text, html }) {
    const self = await this._createInstance();
    const info = await self.sendMail({
      to,
      from,
      subject,
      text,
      html
    });
    const previewUrl = nodemailer.getTestMessageUrl(info);
    if (previewUrl) {
      console.log("Email Preview URL: %s", previewUrl);
    }
  }
}
function mail({ to, from, subject, text, html }) {
  if (!isProd) {
    subject = `[${NODE_ENV || "DEV"}] ` + subject;
  }
  const mailer = new Transporter();
  return mailer.send({ to, from, subject, text, html });
}
function sendCongratulationsEmail({ user, card }) {
  console.log("sendCongratulationsEmail", user);
  const appUrl = new URL(ORIGIN);
  const domainName = appUrl.hostname;
  return mail({
    to: user.email,
    subject: "Did someone just earn a bonus?",
    html: `<p>According to our systems, you may have just qualified for the credit card bonus on your card, ${card.nickname}. Bonuses may not reach your account until the spending deadline has arrived.</p>
<p>Next steps:</p>
<ul>
  <li>Double-check with your bank to confirm</li>
  <li><a href="${appUrl}/sign-in">Sign in</a> to your dashboard for more details</li>
  <li>Visit <a href="${appUrl}">${domainName}</a> to add a new card and start you next bonus quest</li>       
</ul>`
  });
}

export { mail as m, sendCongratulationsEmail as s };
//# sourceMappingURL=index5-BOKyATXQ.js.map
