(function (paw, utils, _super) {
  paw.lang.extend(Fa2Approve, _super);
  function Fa2Approve(settings, localization) {
    _super.call(this, settings, localization);

    this.successMessageAfterCompleted = true;
    this.faValidityInitial = null;
  }

  Fa2Approve.prototype.init = function () {
    _super.prototype.init.call(this);

    this.faValidityInitial = utils.value.strToNum(
      this.settings.$tokenValidityInput.attr("data-initial-value")
    );

    this.checkFa2();
  };

  Fa2Approve.prototype.destroy = function () {
    _super.prototype.destroy.call(this);

    if (!this.fa2Completed) {
      this.settings.$tokenValidityInput.val(this.faValidityInitial);
    }
  };

  Fa2Approve.prototype.onFa2Requested = function (resp) {
    this.fa2Data.phoneNumber = resp.PhoneNumber;
    this.fa2Data.email = resp.Email;
    this.fa2Data.viberPhone = resp.ViberPhone;
    this.fa2Data.resendLockDuration = 2;
    return true;
  };

  Fa2Approve.prototype.onFa2CheckedError = function () {
    return !self.fa2Completed;
  };

  Fa2Approve.prototype.requestFa2 = function () {
    return utils.async.get(this.settings.userData2FaApiUrl);
  };

  Fa2Approve.prototype.onCheckedError = function () {
    this.settings.$tokenValidityInput.val(this.faValidityInitial);

    this.settings.onReset();
  };

  paw.com.fa2.Fa2Approve = Fa2Approve;
})(paw, paw.utils, paw.com.fa2.Fa2Base);
