@extends('layout')
@section('title','Nouveau dépôt ')
@section('content')
		<br/>
          <div class="section-body">
		  <meta name="_token" content="{{ csrf_token() }}" />
            <div class="row">
              <div class="col-lg-10 offset-1 col-md-12 ">
				@if (session('status'))
					<div class="alert alert-warning" style="font-size: 15px; background-color: #328039; color: white">
						<i class="fa fa-check"></i> &nbsp; {{ session('status') }}
					</div>
				@endif
				@if (session('error'))
					<div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white">
						<i class="ti-na"></i> {{ session('error') }}
					</div>
				@endif
				@if ($errors->any())
					<div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white" >
						<ul>
							@foreach ($errors->all() as $error)
								<li> <i class="ti-na"></i> {{ $error }}</li>
							@endforeach
						</ul>
					</div>
				@endif
				<br/>
                <div class="card">
                  <div class="card-header">
                    <h4>Enregistrer un nouveau dépôt (<h7><strong>Les champs en * sont obligatoires</strong></h7>)</h4>
                  </div>
                  <div class="card-body">
				<form action="" method="POST" id="formulaire" enctype="multipart/form-data">
                {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
                    <div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Nom du dépôt <font color="red">*</font></label>
                      <input type="text" class="form-control" name="nom" required>
                    </div>
					</div>
					@php
				        $d = date('Y-m-d');
					@endphp
                      </div>
					 <hr>  	
                   <div class="pull-left">
                    <input type="submit" class="btn btn-icon icon-left btn-success" id="bRegister" value="Enregistrer">
                  </div>
					<br><br>	  
				</form>
					  
					    </div>
						 
                    </div>
                  </div>
                </div>
          </div>
		   <div class="section-body">
            <div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4>Liste des dépôts</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th class="text-center"> N° </th>
                            <th class="text-center">Nom</th>
                            <th class="text-center">Date</th>
                            <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($depot as $depots)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{$depots->nom}}</td>
							<td style="text-align:center;">{{$depots->date}}</td>
							<td style="text-align:center;">
							<a type="button" href="{{route('modifier-depot',['id'=>$depots->id])}}" data-toggle="tooltip" data-placement="bottom" title="Modifier infos" class="btn btn-icon btn-info"><i class="fas fa-edit"></i></a>
							</td>
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
		  
             
            </div>
          </div>
		  
 
	   @push('scripts') 
		<script>
			$(document).ready(function(){
				$("#formulaire").on("submit", function(e) {
				e.preventDefault();
				var nom = $("input[name=nom]").val();
	

			var form_data = new FormData();
			form_data.append('nom', nom);
	        	
				$.ajaxSetup({
				headers: {
					'X-CSRF-Token': $('meta[name=_token]').attr('content')
				}
			});
				$.ajax({
				url: "{{url('depotPost')}}", // point to server-side PHP script
				data: form_data,
				type: 'POST',
				dataType: 'JSON',
				contentType: false, // The content type used when sending data to the server.
				cache: false, // To unable request pages to be cached
				processData: false,
				beforeSend: function(){
					$("#bRegister").attr("value", "Traitement en cours, veuillez patienter...");
				},
				success: function(data) {
					if(data.type == 'error'){
						toastr.error(data.response, data.title, {timeOut: 15000})
					} else {
					
					    toastr.success(data.response, data.title, {timeOut: 15000})
						$("#bRegister").attr("value", "Enregistrer");
						window.location.reload();
						//window.location.href = '/succes-demande';
					}
				}
                })
				});
				});
			
	    </script>
@endpush

@endsection