import { transporter, mailConfig } from "$config/mail/index.js";

export const sendEmail = (data = {}) => {
  const transporterOptions = {
    subject: data?.subject || "",
    from: mailConfig?.emailUser,
    to: data?.to,
  };

  if (data?.html) {
    transporterOptions.html = data?.html || "<p></p>";
  } else {
    transporterOptions.text = data?.text || "";
  }

  transporter.sendMail(transporterOptions, (err, data) => {
    if (err) {
      console.log("Error on send email", err);
    } else {
      console.log({
        message: "Your message has been sent",
      });
    }
  });
};
