"use strict";
appCore.controller("ForgotPasswordCtrl", ["$scope", "$http", "$timeout", "vServices", "jwtHelper", "authManager", "$location", "$state", function ($scope, $http, $timeout, vServices, jwtHelper, authManager, $location, $state) {
  $scope.data = {emp_email: "", captcha: null};

  $scope.forgotPasswordSubmit = function () {
    if (!$scope.data.emp_email)  toastr.warning("Please fill the Email.", "Warning!", {timeOut: 5000});
    else {
      grecaptcha.ready(function () {
        grecaptcha.execute($scope.$root.constant.googleCaptchaSiteKey, {action: "login"}).then(function (captcha) {
          $scope.data.captcha = captcha;
          vServices.callApi("/auth/forgot_password", "POST", $scope.data, {}, true).then(function (res, err) {
            if (res) {
              toastr.success(res, "Success!", {timeOut: 5000});
              $(document).find('div.grecaptcha-badge').remove();
              $state.go("login", {}, {});
            }
            else if (err) {
              alert(err);
            }
          });
        });
      });
    }
  };
}]);
