(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  namespace('ncsa.coachrms.login');
  ncsa.coachrms.login.CoachRegistrationCreator = (function() {
    function _Class(options) {
      this.verifyAjaxOptions = __bind(this.verifyAjaxOptions, this);
      this.registrationVerifySuccess = __bind(this.registrationVerifySuccess, this);
      this.registrationVerifyError = __bind(this.registrationVerifyError, this);
      this.verifyRegistration = __bind(this.verifyRegistration, this);
      this.errorCreateText = __bind(this.errorCreateText, this);
      this.createAjaxOptions = __bind(this.createAjaxOptions, this);
      this.registrationCreateSuccess = __bind(this.registrationCreateSuccess, this);
      this.registrationCreateError = __bind(this.registrationCreateError, this);
      this.createRegistration = __bind(this.createRegistration, this);      this.baseUrl = options['baseUrl'];
      this.$el = options['el'];
      this.$verifyEl = options['verifyEl'];
      this.tf = options._tf ? options._tf.split("#")[1] : "";
    }
    _Class.prototype.createRegistration = function() {
      if (!checkPassword($("#password").val())) {
        $('._flash').text("Your password is not strong enough.").addClass('alert').show();
        return false;
      }
      return $.ajax(this.createAjaxOptions());
    };
    _Class.prototype.registrationCreateError = function(jqXHR, textStatus, errorThrown) {
      return $('._flash').text(this.errorCreateText(jqXHR)).addClass('alert').show();
    };
    _Class.prototype.registrationCreateSuccess = function(data) {
      $('._flash').hide();
      $('._existing_user_email').text(data != null ? data.emailAddress : void 0);
      if ((data != null ? data.error : void 0)) {
        $("#registration_form").hide();
        if ((data != null ? data.errorStatus : void 0) === "duplicateForDifferentCollege") {
          return $('.duplicate_coach_registration').show();
        } else if ((data != null ? data.errorStatus : void 0) === "userExists") {
          return $('.user_exists').show();
        }
      } else {
        $('.js-signup-banner').hide();
        $('#registrationEmailAddress2').val(data != null ? data.emailAddress : void 0);
        $("#registration_form").hide();
        return $('.verify_email_registration').show();
      }
    };
    _Class.prototype.createAjaxOptions = function() {
      return {
        url: ("" + this.baseUrl + "/registrations/create") + this.tf,
        type: 'post',
        error: this.registrationCreateError,
        success: this.registrationCreateSuccess,
        data: this.$el.serialize()
      };
    };
    _Class.prototype.errorCreateText = function(xhr) {
      if (xhr.status === 404) {
        return 'No information in our database matched your Email, College, and Sport.  Please re-check your data';
      }
      if (xhr.status === 400) {
        return 'Email Address and College are required.';
      }
      if (xhr.status === 406) {
        return 'Passwords do not match.';
      }
      return 'An error occurred during registration';
    };
    _Class.prototype.verifyRegistration = function() {
      return $.ajax(this.verifyAjaxOptions());
    };
    _Class.prototype.registrationVerifyError = function(jqXHR, textStatus, errorThrown) {
      return $('._flash').text(this.verifyErrorText(jqXHR)).addClass('alert').show();
    };
    _Class.prototype.registrationVerifySuccess = function(data) {
      if ((data != null ? data.verifiedEmail : void 0) === false) {
        $('._flash').text();
        $('#registrationVerificationCode').val("");
        return $('._flash').text("Verification Code was incorrect.").addClass('alert').show();
      } else {
        $('._flash').hide();
        $('#j_username').val(data != null ? data.emailAddress : void 0);
        $('#j_password').val($('#password').val());
        $('#login_form').submit();
        return $('.verify_email_registration').hide();
      }
    };
    _Class.prototype.verifyAjaxOptions = function() {
      return {
        url: ("" + this.baseUrl + "/registrations/verify") + this.tf,
        type: 'post',
        error: this.registrationVerifyError,
        success: this.registrationVerifySuccess,
        data: this.$verifyEl.serialize()
      };
    };
    _Class.prototype.verifyErrorText = function(xhr) {
      if (xhr.status === 400) {
        return 'Email Address and Verification Code are required.';
      }
      return 'An error occurred during verification';
    };
    return _Class;
  })();
}).call(this);
