
const nodemailer = require("nodemailer");
const mailFrom = "noreply@talentstube.io"
const clePubliqueMailJet = "355697fac93fca865660734b4fdffaeb"
const clePriveMailJet = "ddecf75321ca89c09e561857b13534c8"

function setup() {
  return nodemailer.createTransport({
    host: process.env.EMAIL_SERVER,
    port: process.env.EMAIL_PORT,
    auth: {
      user: process.env.EMAIL_USERNAME,
      pass: process.env.EMAIL_PASSWORD
    }
  });
}
exports.sendTransactionnelEmail = function () {
  // US technique 444
      var mailjet2 = require('node-mailjet')
        .connect('805b8adce80bc6aa9422ddff20bb4171', 'f3bce955f21bc9456d65245c50e8c512')
      
      console.log("envoi du mail avec mailjet laniau2")
      let request = mailjet2.post("send", {'version': 'v3.1'})
      .request({
        "Messages":[
          {
            "From": {
              "Email": "dev@talentstube.com",
              "Name": "Laurent"
            },
            "To": [
              {
                "Email": "dev@talentstube.com",
                "Name": "Laurent"
              }
            ],
            "TemplateID": 2087555,
            "TemplateLanguage": true,
            "Variables": {
              "prénom": "\"]]</title><!--[if !mso]><!-- --><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><!--<![endif]--><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style type=\"text/css",
              "lien": '<p style="display:inline-block;background:#36eda4;color:#ffffff;font-family:Arial,sans-serif;font-size:13px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;border-radius:3px"><span style="font-size:11px;text-align:center;background-color:#36eda4;color:#ffffff;font-family:Arial"><b>&nbsp; &nbsp; &nbsp; &nbsp;<a href="www.talentstube.com">Activer mon compte</a> &nbsp; &nbsp; &nbsp;</b></span></p>'
              },
            "Subject": "Test [[data:prénom:'ggg']]",
            "TextPart": "",
            "HTMLPart": "",
            "CustomID": "AppGettingStartedTest"
          }
        ]
      })
      request
      .then((result) => {
        console.log(result.body)
      })
      .catch((err) => {
        console.log(err.statusCode)
      })
}
exports.sendConfirmationEmail = function (nom, prenom, tokenUrl, mail) {
  // const tranport = setup();
  // const email = {
  //   from: process.env.EMAIL_FROM,
  //   to: process.env.NODE_ENV === 'production'? mail : 'l.laniau@talentstube.com',
  //   subject: `Bienvenue ${mail} `,
  //   text: `
  //   Bonjour ${prenom} ${nom},

  //   Veuillez cliquer sur le lien ci-dessous pour activer votre compte Talents Tube.

  //   ${tokenUrl}

  //   *Ce lien ne peut être utilisé qu’une seule fois pour valider votre compte.

  //   Si vous n’êtes pas à l’origine de l’inscription sur Talents Tube, veuillez contacter le support Talents Tube.

  //   Merci de votre compréhension.

  //   Talents Tube

  //  };
  // var mailjet2 = require('node-mailjet')
  //       .connect('805b8adce80bc6aa9422ddff20bb4171', 'f3bce955f21bc9456d65245c50e8c512')
      
  //     console.log("envoi du mail avec mailjet laniau2")
  //     let request = mailjet2.post("send", {'version': 'v3.1'})
  //     .request({
  //       "Messages":[
  //         {
  //           "From": {
  //             "Email": "l.laniau@talentstube.com",
  //             "Name": "Laurent"
  //           },
  //           "To": [
  //             {
  //               "Email": "l.laniau@talentstube.com",
  //               "Name": "Laurent"
  //             }
  //           ],
  //           "TemplateID": 2087555,
  //           "TemplateLanguage": true,
  //           "Variables": {
  //             "prénom": "\"]]</title><!--[if !mso]><!-- --><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><!--<![endif]--><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style type=\"text/css",
  //             "lien": '<p style="display:inline-block;background:#36eda4;color:#ffffff;font-family:Arial,sans-serif;font-size:13px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;border-radius:3px"><span style="font-size:11px;text-align:center;background-color:#36eda4;color:#ffffff;font-family:Arial"><b>&nbsp; &nbsp; &nbsp; &nbsp;<a href="www.talentstube.com">Activer mon compte</a> &nbsp; &nbsp; &nbsp;</b></span></p>'
  //             },
  //           "Subject": "Test [[data:prénom:'ggg']]",
  //           "TextPart": "My first Mailjet email",
  //           "HTMLPart": "<h3>Dear passenger 1, welcome to <a href='https://www.mailjet.com/'>Mailjet</a>!</h3><br />May the delivery force be with you!",
  //           "CustomID": "AppGettingStartedTest"
  //         }
  //       ]
  //     })
  //     request
  //     .then((result) => {
  //       console.log(result.body)
  //     })
  //     .catch((err) => {
  //       console.log(err.statusCode)
  //     })
  var mailjet2 = require('node-mailjet')
        .connect(clePubliqueMailJet, clePriveMailJet)
      
      console.log("envoi du mail avec mailjet "+mailFrom)
      let request = mailjet2.post("send", {'version': 'v3.1'})
      .request({
        "Messages":[
          {
            "From": {
              "Email": mailFrom,
              "Name": "Talents Tube"
            },
            "To": [
              {
                "Email": mail,
                "Name": prenom
              }
            ],
            "TemplateID": 2115317,
            "TemplateLanguage": true,
            "Variables": {
              "nom": nom,
              "prenom": prenom,
              // "tokenUrl": "<a href='"+tokenUrl+"'>Activer le compte</a>"
              "tokenUrl": tokenUrl
              },
            "Subject": "Bienvenue sur Talents Tube",
            "TextPart": "",
            "HTMLPart": "",
            "CustomID": "AppGettingStartedTest"
          }
        ]
      })
      request
      .then((result) => {
        console.log(result.body)
      })
      .catch((err) => {
        console.log(err.statusCode)
      }) 
    // ,
    // html: `
    // `
  

  // tranport.sendMail(email);
}
