@extends('layouts.app')

@section('title',"Editar Entidad")

@section('content')
<div class="alert alert-secundary p-2 mb-0"><a href="{{ url('entidad') }}"><i class="icon-arrow-left13"></i> Volver al listado de entidad</a></div>
<div class="card ">
	<div class="card-body">
		<div class="response-data">
		</div>
		@foreach ($data['entidad'] as $en)
			<form action="{{ url('entidad/'.$en->id) }}" class="form-login" onsubmit="updatingform(this); return false">
				<input type="hidden" name="action" value="agregar">
				<div class="row">
					<div class="col-12 text-center text-uppercase ">
						<h3 class="font-weight-light">Actualizar entidad</h3>
					</div>
				</div>
				<br/>
				<div class="row">
					<div class="col-2 ">
						<select name="persona_nacionalidad" class="form-control"   id="persona" onchange="tipe_person(this); return false">
							@if($en->persona_nacionalidad == 'e')
								<option value="e" selected="selected"   >Extranjero</option>
								<option value="n" >Nacional</option>

							@elseif($en->persona_nacionalidad == 'n')
								<option value="n" selected="selected"   >Nacional</option>
								<option value="e" >Extranjero</option>

							@else
								<option value="n" >Nacional</option>
								<option value="e" >Extranjero</option>
							@endif
						</select>
					</div>
					<div class="col-2">
						<select name="persona_tipe" class="form-control"  id="input-cont" required="" >
							@if($en->persona_tipe == 'n')
								<option value="n" selected="selected" >Natural</option>
								<option value="j" >Juridica</option>

							@elseif($en->persona_tipe == 'j')
								<option value="j" selected="selected" >Juridica</option>
								<option value="n" >Nacional</option>
							@else
								<option value="j" >Juridica</option>
								<option value="n" >Nacional</option>
							@endif
						</select>
					</div>
					<div class="col-2">
						<select name="identidad_document_id" class="form-control"  id="input-cont" onchange="change_document(); return false" >
							<option value="">Tipo</option>
								@foreach ($data['identidad'] as $i)
									@if(!empty($en->identidad_document) AND $i->codigo == $en->identidad_document->codigo)
										<option value="{{ $en->identidad_document->id }}" data-codigo="{{ $en->identidad_document->codigo }}"selected="selected">{{$i->abrv}} || {{ $en->identidad_document->descripcion }}</option>
									@else
										<option value="{{ $i->id }}" data-codigo="{{ $i->codigo }}">{{ $i->abrv}} || {{ $i->descripcion}} </option>
									@endif
								@endforeach
						</select>
					</div>
					<div class="col-2">
						<input type="text" class="form-control"  id="tipe_c" name="numero"  placeholder="Numero de  documento"  required="" value="{{ $en->numero }}" onkeyup="tipe_ciudadano(this); return false">
					</div>
					<div class="col-2 text-left">
						@if($en->is_aduanas == '1')
							<input type="checkbox"   id="input-cont" name="is_aduanas"  value="1" checked> <span id="input-label">Agente Aduanas </span>
						@else
							<input type="checkbox"   id="input-cont" name="is_aduanas"  value="1"> <span id="input-label">Agente Aduanas </span>
						@endif
					</div>
					<div class="col-2">
						<a  href="#" onclick="search_document(this); return false " data-url="{{ url('utilitarios') }}" class="btn btn-warning btn-sm btn-search hide">Buscar</a>
					</div>
				</div>
				<hr>
				<div class="row">
					<div class="col-4">
						<input type="text" class="form-control" id="input-cont"  name="nsocial" placeholder="Razon social" value="{{ $en->nsocial }}">
					</div>
					<div class="col-4">
						<input type="text" class="form-control" id="input-cont"  name="nomenclatura" placeholder="Nomenclatura" value="{{ $en->nomenclatura }}">
					</div>
					<div class="col-4">
						<input type="email" class="form-control" id="input-cont"  name="email" placeholder="example@gmail.com" value="{{ $en->email }}">
					</div>
				</div>
				<hr>
				<div class="row">
					<div class="col-4">
						<input type="text" class="form-control" id="input-cont"  name="direccion" placeholder="Direccion " value="{{ $en->direccion }}">
					</div>
					<div class="col-2">
						<input type="text" class="form-control ubigeo_input" id="input-cont"  name="ubigeo" placeholder="Ubigeo" value="{{ $en->ubigeo }}">
					</div>
					<div class="col-2">
						<a href="" data-url="{{ url('utilitarios') }}"  data-tipe="edit" class="btn btn-primary btn-sm" onclick="search_ubigeo(this); return false">Bucar ubigeo</a>
					</div>
					<div class="col-4">
						<input type="text" class="form-control" id="input-cont"  name="departamento" placeholder="Departamento" value="{{ $en->departamento }}">
					</div>
				</div>

				<hr>
				<div class="content-natural hide">
					<div class="row">
						<div class="col-3">
							<input type="text" class="form-control names_natural" id="input-cont"  name="nombre1" placeholder="Ingrese su primer nombre" value="{{ $en->nombre1 }}">
						</div>
						<div class="col-3">
							<input type="text" class="form-control names_natural" id="input-cont"  name="nombre2" placeholder="Ingrese su segundo nombre" value="{{ $en->nombre2 }}">
						</div>
						<div class="col-3">
							<input type="text" class="form-control names_natural" id="input-cont"  name="apaterno" placeholder="Ingrese su apellido paterno" value="{{ $en->apaterno }}">
						</div>
						<div class="col-3">
							<input type="text" class="form-control names_natural" id="input-cont"  name="amaterno" placeholder="Ingrese su apellido materno" value="{{ $en->amaterno }}">
						</div>

					</div>
					<hr>
				</div>
				<div class="row edit_has">
					<div class="col-4 hide content-href-reload">
						<a href="#" class="reload_ubications" id="reload_selects" data-tipe="add"  >Cargar Ubicaciones manualmente</a>
					</div>
					<div class="col-8 text-center">
						<a href="#" class="edit_ubication_href" id="reload_selects" data-tipe="edit" >+ Editar Ubicación</a>
					</div>
				</div>
				<div class="row edit_has_ubication">
					@if(!empty($en->departamentos))
						<div class="col-4">
							<input type="text" class="form-control input_hidden_ubication" disabled="" value="{{ $en->departamentos->nombre }}">
						</div>
					@endif
					@if(!empty($en->provincias))
						<div class="col-4">
							<input type="text" class="form-control input_hidden_ubication" disabled="" value="{{ $en->provincias->nombre }}" >
						</div>
					@endif
					@if(!empty($en->distritos))
						<div class="col-4">
							<input type="text" class="form-control input_hidden_ubication" disabled=""  value="{{ $en->distritos->nombre }}">
						</div>
					@endif
				</div>

				<div class="edit_select hide">
					<div class="row">
						<div class="col-4">
							<select  data-name="departamentos_id"  data-tipe="provincias"  id="dynamic_selects"   class="form-control dynamic_selects selectpicker" data-live-search="true" >
								<option value="">Seleccionar..</option>
							</select>
						</div>
						<div class="col-4">
							<select data-name="provincias_id" data-tipe="distritos"  id="provincias"   class="form-control dynamic_selects selectpicker" disabled="" data-live-search="true">

							</select>
						</div>
						<div class="col-4">
							<select data-name="distritos_id"  data-tipe="ubigeo"  id="distritos" class="form-control dynamic_selects selectpicker"  data-live-search="true" disabled="">
							</select>
						</div>
					</div>
				</div>
				<hr>
				<div class="services_entidad {{ ($en->persona_nacionalidad == 'e') ? '' : 'hide' }}" >
					@if(!empty($services['services']))
			            @forelse ($services['services'] as $s)
							@include('Catalogo.views.utilities.select', ['select' => $s->table_tipe])
						@empty

						@endforelse

						@forelse ($services['tables'] as $t)
							@include('Catalogo.views.utilities.select', ['select' => $t])
						@empty

						@endforelse
					@else
						<?php $countservices = count($services['staticservices']); ?>
						@for ($i = 0; $i < $countservices; $i++)
							@include('Catalogo.views.utilities.select', ['select' => $services['staticservices'][$i]])
						@endfor
					@endif
				</div>
				@endforeach

				<div class="row">
					<div class="col-12 text-center">
						<br>
						<button class="btn btn-primary"><i class="icon-rotate-cw2 "></i> Actualizar</button>
					</div>
				</div>
			</form>
	</div>
</div>
	<script>
		var departamentos = @json($data['departamentos']);
		var provincias = @json($data['provincias']);
		var distrito = @json($data['distritos']);
		var ubigeourl = '{{ url("utilitarios") }}';
	</script>
	@section('scripts')
		<script src="{!! asset('assets/views_functions/entidad.js') !!}"></script>
	@endsection
@endsection