@extends('layouts/unauthorized')

@section('title')
	@parent
	Восстановление пароля
@stop

@section('js')
	<script type="text/javascript">
		runAllForms();

		// Validation
		$(function() {
			// Validation
			$("#login-form").validate({
				// Rules for form validation
				rules : {
					email : {
						required	: true,
						email			: true
					},
					password : {
						required	: true,
						minlength	: 3
					},
					password_confirmation : {
						required	: true,
						equalTo		: '#password'
					}
				},
				// Messages for form validation
				messages : {
					email : {
						required : 'Необходимо указать электронную почту',
						email : 'Необходимо указать корректную электронную почту'
					},
					password : {
						required : 'Необходимо указать пароль',
						minlength : 'Пароль не должен быть короче 3 символов'
					},
					password_confirmation : {
						required : 'Введите подтверждение пароля',
						equalTo : 'Пароль не совпадает с подтверждением'
					}
				},
				// Ajax form submition
				submitHandler : function(form) {
					var l = Ladda.create($('#login-form button[type="submit"]').get()[0]);
					l.start();
					$(form).ajaxSubmit({
						error : function(data) {
							l.stop();
						},
						success : function(data) {
							if (data.status == 'success') {
								$.SmartMessageBox({
									title : "<i class='fa fa-check txt-color-greenDark'></i> Пароль <span class='txt-color-greenDark'><strong>успешно изменен</strong></span>",
									content : "Теперь вы можете попробовать зайти на сайт под новым паролем",
									buttons : '[Закрыть]'
								}, function() {
									$.root_.addClass('animated fadeOutUp');
									setTimeout(function(){ window.location = '/login' }, 1000);
								});
							}
							else {
								l.stop();
								$('#login-form label').removeClass('state-error').removeClass('state-success');
								$('em.invalid').remove();
								$.each(data.errorMessages, function(index, value){
									$('#login-form input[name="'+index+'"]').parent().addClass('state-error').after('<em for="'+index+'" class="invalid">'+value+'</em>');
								});
							}
						}
					});
				},
				// Do not change code below
				errorPlacement : function(error, element) {
					error.insertAfter(element.parent());
				}
			});
		});
	</script>
@stop

@section('content')
	{{ Form::open(array('action' => 'RemindersController@postReset', 'id' => 'login-form', 'class' => 'smart-form client-form')) }}
		<header>
			Восстановление пароля
		</header>

		<fieldset>
			<section>
				<label class="label">E-mail</label>
				<label class="input {{ ($errors->has('email')) ? 'state-error' : '' }}"> <i class="icon-append fa fa-envelope"></i>
					{{ Form::email('email', isset($input['email']) ? $input['email'] : null) }}
					<b class="tooltip tooltip-bottom-right">Укажите вашу электронную почту</b> </label>
					{{ ($errors->has('email') ?  '<em for="email" class="invalid">'.$errors->first('email').'</em>' : '') }}
			</section>

			<section>
				<label class="label">Пароль</label>
				<label class="input {{ ($errors->has('password')) ? 'state-error' : '' }}"> <i class="icon-append fa fa-lock"></i>
					{{ Form::password('password', array('id' => 'password')) }}
					<b class="tooltip tooltip-bottom-right">Не забудьте пароль</b> </label>
					{{ ($errors->has('password') ?  '<em for="password" class="invalid">'.$errors->first('password').'</em>' : '') }}
			</section>

			<section>
				<label class="label">Подтверждение пароля</label>
				<label class="input {{ ($errors->has('password_confirmation')) ? 'state-error' : '' }}"> <i class="icon-append fa fa-lock"></i>
					{{ Form::password('password_confirmation', null) }}
					<b class="tooltip tooltip-bottom-right">Не забудьте пароль</b> </label>
					{{ ($errors->has('password_confirmation') ?  '<em for="password_confirmation" class="invalid">'.$errors->first('password_confirmation').'</em>' : '') }}
			</section>
		</fieldset>

		<footer>
			{{ Form::hidden('token', $token) }}
			<button type="submit" class="btn btn-primary ladda-button" data-style="zoom-out">
				Изменить пароль
			</button>
		</footer>
	{{ Form::close() }}
@stop
