import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

const { siteName, accountsEmail } = Meteor.settings.public;

// Setup Email Verification
Accounts.emailTemplates.siteName = siteName;
Accounts.emailTemplates.from = accountsEmail;

Accounts.emailTemplates.verifyEmail = {
    subject(user) {
        return `${siteName} Email Verification for: ${user.getEmail()}`;
    },
    html(user, url) {
        return `
<p>Hi ${user.firstname}!</p>
<p>Your username is <strong>${user.username}</strong>
<p>Please verify this email address by clicking <a href='${url}'>here</a>.</p>
<br>
<p>
Cheers,<br>
The ${siteName} Team
</p>`;
    }
};

// Setup Enrollement/ Migration email
Accounts.emailTemplates.enrollAccount = {
    subject(user) {
        return `Welcome to the ${siteName}!`;
    },
    html(user, url) {
        return `
<h3>Welcome ${user.firstname}, to the ${siteName}!</h3>
<p>You are ready to finish setting up your account!</p>
<p>Get started by <a href="${url}">clicking here</a> to set your username and password.
Then you will be able to setup your team and invite your friends!
</p>
<p>If you have any questions about the account setup process plese email <a href="mailto:kyle@kylerader.ninja">kyle@greatpuzzlehunt.com</a></p>
<br>
<p>Welcome to the hunt!<br>
<p>Cheers,</p>
<p>The ${siteName} Team</p>`;
    }
};

Accounts.validateLoginAttempt((attempt) => {
  if (!attempt.allowed) {
    return false;
  }
  else if (attempt.user && !attempt.user.emails[0].verified) {
    throw new Meteor.Error(400, 'You must verify your email before logging in!  Questions? See our Contact page.');
  }
  else {
    return true;
  }
});

// Extending Account Creation
Accounts.onCreateUser((options, user) => {

  // Assign all other properties from the options
  user = _.extend(user, _.omit(options, ['password']));

  return user;
});

@@ -919,23 +919,9 @@
 %0A%3Cp%3E
-You are ready t
+T
 o fi
@@ -952,31 +952,8 @@
 ount
-!%3C/p%3E%0A%3Cp%3EGet started by
  %3Ca 
@@ -971,19 +971,16 @@
 %7D%22%3Eclick
-ing
  here%3C/a
@@ -980,16 +980,42 @@
 here%3C/a%3E
+.%3C/p%3E%0A%3Cp%3EYou will be asked
  to set 
@@ -1018,16 +1018,23 @@
 set your
+ email,
  usernam
@@ -1034,16 +1034,17 @@
 username
+,
  and pas
@@ -1075,21 +1075,22 @@
 able to 
-setup
+create
  your te
@@ -1186,16 +1186,17 @@
 cess ple
+a
 se email
@@ -1216,34 +1216,44 @@
 lto:
-kyle@kylerader.ninja%22%3Ekyle
+support@greatpuzzlehunt.com%22%3Esupport
 @gre

Update copy in welcome emails