<? global $lang;?>
<div id="user-login">
  <div class="mini-box">
    <div class="title">Ustaw nowe hasło</div>
    <div class="subtitle">Wpisz nowe hasło do Swojego konta (min. 6 znaków)</div>
    <div class="container-fluid">
      <div class="row">
        <div class="col-12">
          <div class="content user">
            <form method="POST" action="/globelusUser/save_new_password/">
              <input type="hidden" name="hash" value="<?= $this -> hash;?>">
              <div class="form-group row">
                <label form="password" class="col-12 col-sm-4">Hasło:</label>
                <div class="col-12 col-sm-8">
                  <input type="password" name="password" required id="password" class="form-control">
                </div>
              </div>
              <div class="form-group row">
                <label form="password_retype" class="col-12 col-sm-4">Powtórz hasło:</label>
                <div class="col-12 col-sm-8">
                  <input type="password" name="password_retype" required id="password_retype" class="form-control">
                </div>
              </div>
              <div class="form-group row">
                <div class="col-12 col-sm-8 offset-sm-4">
                  <input type="submit" value="Zatwierdź" class="btn btn-success">
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  $( function() {
    $( 'body' ).on( 'click', '#user-login input[type="submit"]', function( e ) {
      e.preventDefault();
      var form = $( this ).closest( 'form' );
      var password = form.find( '#password' ).val();
      var password_retype = form.find( '#password_retype' ).val();
      var alert_text = '';
      if ( password != password_retype ) {
        var alert_text = 'Hasła nie są takie same!';
      }
      if ( password.length < 6 ) {
        var alert_text = 'Hasło musi mieć min. 6 znaków!';
      }
      if ( !form.find( '#password' ).val() ) {
        var alert_text = 'Hasło nie może być puste!';
      }
      if ( alert_text ) {
        $.alert({
          title: '<?= ucfirst( $lang['informacja'] );?>',
          icon: 'fa fa-exclamation',
          content: alert_text,
          type: 'blue',
          closeIcon: true,
          closeIconClass: 'fa fa-close',
          typeAnimated: true,
          animation: 'opacity',
          autoClose: 'confirm|10000',
          columnClass: 'large',
          theme: 'modern',
          buttons: {
            confirm: {
              text: 'Zamknij',
              btnClass: 'btn-blue',
              keys: ['enter'],
              action: function() {

              }
            }
          },
          onClose: function () {
          }
        });
        return false;
      }
      form.submit();
    } );
  });
</script>