@extends('layouts.app')

@section('title',"Agregar usuarios")

@section('content')
@if (session('update'))
    <div class="alert alert-success">
        {{ session('update') }}
    </div>
@endif

<div class="response-data" style="display: none;">
	
</div>

<div class="alert alert-secundary p-2 mb-0"><a href="{{ url('user') }}"><i class="icon-arrow-left13"></i> Volver al listado de usuarios</a></div>
<div class="card">
	<div class="card-header header-elements-inline">
		<h5 class="card-title"><i class="icon-clipboard "></i> Usuarios </h5>
		<div class="header-elements">
			<div class="list-icons">
        		<a class="list-icons-item" data-action="collapse"></a>
        		<a class="list-icons-item" data-action="reload"></a>
        		<a class="list-icons-item" data-action="remove"></a>
        	</div>
    	</div>
	</div>	
	<div class="card-body">
		<form action="{{ url('user/'.$user->id) }}" method="POST" onsubmit="updatingform(this); return false">
			<input type="hidden" name="action" value="add">
			<div class="row">
				<div class="col-3">
					<label for=""><b>Nombre:</b></label>
					<input type="text" class="form-control" name="name" required="" placeholder="Ingresa tu nombre" value="{{$user->name}}">
				</div>
				<div class="col-3">
					<label for=""><b>Ruc:</b></label>
					<input type="text" class="form-control" name="ruc" required="" placeholder="Ingresa tu ruc o dni" value="{{$user->ruc}}">
				</div>
				<div class="col-3">
					<label for=""><b>Email:</b></label>
					<input type="email" class="form-control" name="email" required="" placeholder="exampl@gmail.com" value="{{$user->email}}">
				</div>
				<div class="col-3">
					<label for=""><b>Contraseña:</b></label>
					<input type="password" class="form-control" name="password"  placeholder="example:*******"> 
				</div>
			</div>
			<hr>
			<div class="row">
				<div class="col-4">
					<label for=""><b>Nombre empresa:</b></label>
					<input type="text" class="form-control" name="nempresa"  placeholder="Ingresa tu nombre" value="{{$user->nempresa}}">
				</div>
				<div class="col-4">
					<label for=""><b>Direccion:</b></label>
					<input type="text" class="form-control" name="direccion" placeholder="Ingresa tu ruc o dni" value="{{$user->direccion}}">
				</div>
				<div class="col-4">
					<label for=""><b>Rol:</b></label>
					<select id="roles" class="form-control text-uppercase" >
						<option value="">Seleccionar</option>
						@foreach ($role as $r)
							<option value="{{$r->name}}" data-id="{{$r->id}}">{{$r->name}}</option>
						@endforeach
					</select>
				</div>
			</div>
			<hr>
			<h3 class="text-center">Roles seleccionados</h3>
			<div class="row justify-content-center">
				<div class="col-6">
					<div class="row resp-roles">
						@foreach ($user->roles as $r)
							<span class="tag_custom roles{{$r->id}}" id="codenv{{$r->id}}">
								<i class="icon-pen2"></i>
								{{$r->name}} 
									<a href="#"  data-url="{{ url('user/user-'.$user->id.'-'.$r->name) }}" data-id="{{$r->id}}" onclick="deletreg(this); return false">
									<i class="icon-cross"></i>
								</a>
								<input type="hidden"  name="roles[]" value="{{$r->id}}">
							</span>
						@endforeach
					</div>
				</div>
			</div>
			<hr>
			<div class="row">
				<div class="col-12 text-center">
					<button class="btn btn-primary"><i class="icon-floppy-disk "></i> Guardar</button>
				</div>
				
			</div>
		</form>
	</div>

</div>
<div class="response-ajax"></div>
@endsection
@section('scripts')
	<script src="{!! asset('assets/views_functions/user.js') !!}"></script>
@endsection