<?php if( count($errors) > 0 ): ?>
<div class="alert alert-danger">
	<ul>
		<?php foreach($errors->all() as $error): ?>
		<li><?php echo e($error); ?></li>
		<?php endforeach; ?>
	</ul>
</div>
<?php endif; ?>

<form id="form-usuario" method="POST" enctype="multipart/form-data" role="form">

	<?php if($action == 'create'): ?>
	<h3>Registrar Usuario</h3>
	<?php elseif($action == 'edit'): ?>
	<h3>Editar Usuario</h3>
	<?php endif; ?>

	<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>" />

	<input type="hidden" name="id" value="<?php echo e($mock->id); ?>" />

	<div class="form-group">
		<div class="">
			<p>
				<img src="<?php echo e($mock->avatar); ?>" class="avatar margin-10-tp" style="width:30%;" />
			</p>
			<p>
				<label for="photo">Avatar</label>
				<input type="file" id="photo" name="photo" />
			</p>
		</div>
	</div>

	<?php if($mock->id == $sessionUser->id): ?>
	<div class="form-group">
		<label for="rol">Rol</label>
		<input type="hidden" name="rol" value="<?php echo e($mock->rol); ?>">
		<select id="rol" class="form-control" required data-error="Por favor, seleccione un rol." disabled="disabled">
				<option selected ><?php echo e($mock->rolName); ?></option>
		</select>
		<div class="help-block with-errors"></div>
	</div>
	<?php else: ?>
	<div class="form-group">
		<label for="rol">Rol</label>
		<select id="rol" name="rol" class="form-control" required data-error="Por favor, seleccione un rol.">
			<?php foreach($roles as $rol => $value): ?>
				<option value="<?php echo e($rol); ?>" <?php echo e($mock->rol == $rol ? 'selected' : ''); ?>><?php echo e($value); ?></option>
				<?php echo e($rol); ?> <?php echo e($value); ?>

			<?php endforeach; ?>
		</select>
		<div class="help-block with-errors"></div>
	</div>
	<?php endif; ?>

	<?php if($action == 'create'): ?>
	<div class="form-group">
		<label for="email">Email</label>
		<input type="email" id="email" name="email" class="form-control" value="<?php echo e($mock->email); ?>" required/>
		<div class="help-block with-errors"></div>
	</div>
	<?php else: ?>
	<div class="form-group">
		<label for="email">Email</label>
		<input type="email" id="email" name="email" class="form-control" value="<?php echo e($mock->email); ?>" required/>
		<div class="help-block with-errors"></div>
	</div>
	<?php endif; ?>

	<div class="form-group">
		<label for="nombre">Nombre</label>
		<input type="text" id="nombre" name="nombre" class="form-control" value="<?php echo e($mock->nombre); ?>" required/>
		<div class="help-block with-errors"></div>
	</div>

	<div class="form-group">
		<label for="apellido">Apellido</label>
		<input type="text" id="apellido" name="apellido" class="form-control" value="<?php echo e($mock->apellido); ?>" required/>
		<div class="help-block with-errors"></div>
	</div>

	<?php if(in_array($sessionUser->rol, [App\Models\Usuario::ROL_ADMIN, App\Models\Usuario::ROL_ADMIN_CONCESIONARIO]) && $action == 'edit'): ?>
	<div class="form-group">
		<label for="password">Contraseña</label>
		<input type="password" id="password" name="password" class="form-control"/>
		<div class="help-block with-errors"></div>
	</div>

	<div class="form-group">
		<label for="password">Confirmar contraseña</label>
		<input type="password" id="password_confirmation" name="password_confirmation" class="form-control"/>
		<div class="help-block with-errors"></div>
	</div>
	<?php endif; ?>

	<div class="form-group">
		<input type="submit" class="btn btn-primary" value="Guardar" />
		<a href="<?php echo e(url('admin/usuarios')); ?>" class="btn btn-default">Cancelar</a>
	</div>

</form>

<?php $__env->startSection('scripts'); ?>
	<script type="text/javascript">

		$('#form-usuario').bootstrapValidator({
			fields: {
				photo: {
					validators: {
						file: {
							extension: 'jpeg,jpg,png,JPG,PNG',
							type: 'image/jpeg,image/png',
							message: 'La imagen debe tener formato .jpg o .png.'
						}
					}
				},
				nombre: {
            validators: {
                notEmpty: {
                    message: 'Por favor, introduzca un nombre.'
                }
            }
        },
        apellido: {
            validators: {
                notEmpty: {
                    message: 'Por favor, introduzca un apellido'
                }
            }
        },
				email: {
            validators: {
                notEmpty: {
                    message: 'Por favor, introduzca un correo electrónico.'
                },
                email: {
                	message: 'Por favor, introduzca una dirección de correo válida.'
                },
                remote: {
                	url: '/admin/usuarios/validate-unique-email/',
                	data: function(validator) {
                        return {
                            id: validator.getFieldElements('id').val()
                        };
                    },
                }
            }
        },
				password: {
	          validators: {
	              identical: {
									field: 'password_confirmation',
									message: 'La clave introducida y su confirmación no son idénticas.'

								}
	          }
	      },
	      password_confirmation: {
	          validators: {
	              identical: {
	              	field: 'password',
	              	message: 'La clave introducida y su confirmación no son idénticas.'
	              }

	          }
				},

			},

		});

    </script>

<?php $__env->stopSection(); ?>
