extends ../layout
block content
    .text-center
        h2 If you original signed up using one of these methods, you can sign in and add your email address to your account:
        br
        a.btn.btn-lg.btn-block.btn-social.btn-github(href='/auth/github')
            i.fa.fa-github
            | Sign in with GitHub
        a.btn.btn-lg.btn-block.btn-social.btn-facebook(href='/auth/facebook')
            i.fa.fa-facebook
            | Sign in with Facebook
        a.btn.btn-lg.btn-block.btn-social.btn-google(href='/auth/google')
            i.fa.fa-google
            | Sign in with Google
        a.btn.btn-lg.btn-block.btn-social.btn-linkedin(href='/auth/linkedin')
            i.fa.fa-linkedin
            | Sign in with LinkedIn
        a.btn.btn-lg.btn-block.btn-social.btn-twitter(href='/auth/twitter')
            i.fa.fa-twitter
            | Sign in with Twitter
        br
        p
          a(href="/signin") Or click here to go back.

    script.
      $(document).ready(function() {
        var method = localStorage.getItem('lastSigninMethodDeprecated'),
          btnSelector = 'a.btn.btn-lg.btn-block.btn-social';
        if (method) {
          try {
            var obj = JSON.parse(method);
          } catch(e) {
            console.error('Invalid sign in object stored', method);
            return;
          }
          $.each($(btnSelector), function(i, item) {
            if (
              $(item).attr('href') === obj.methodLink &&
              $(item).hasClass(obj.methodClass)
            ) {
              $(item).addClass('active');
              $(item).attr('title', 'This is your last signin method');
              return false;
            }
          });
        }

        $(btnSelector).click(function() {
          var obj = {};
          $(this).removeClass('active');
          obj.methodClass = $(this).attr('class').split(' ').pop();
          obj.methodLink = $(this).attr('href');
          localStorage.setItem('lastSigninMethodDeprecated', JSON.stringify(obj));
        });
      });
