@extends('training.inc.master')

@section('title','Dashboard')

@section('content')

<main class="content">
				<div class="container-fluid p-0">

				<h1 class="h3 mb-3"><strong>Admissions for {{ $duration }}</strong> </h1>

				@include('training.alerts.alert')


					<div class="card">
								<div class="card-header">
									<h5 class="card-title">Admissions for {{ $duration }}</h5>
									
								</div>
								<div class="card-body">
									<table id="datatables-buttons" class="table table-striped" style="width:100%">
										<thead>
											<tr>
												<th>#</th>												
												<th>Name</th>
												<th>ID Number</th>
												<th>Phone</th>
												<th>Email</th>
												<th>Station</th>
												<th>Course Name</th>
												<th>Amount</th>
												<th>Payment Status</th>
												<th>Admission Date</th>
												<th>Action</th>
											</tr>
										</thead>
										<tbody>
											@foreach ($admissions as $index => $admission)
												<tr>
													<td>{{ $index + 1 }}</td>													
													<td>{{ $admission->student_name }}</td>
													<td>{{ $admission->idno }}</td>
													<td>{{ $admission->phone }}</td>
													<td>{{ $admission->email }}</td>
													<td>{{ $admission->station }}</td>
													<td>{{ $admission->course_name }} {{ $admission->id }}</td>
													<td>{{ $admission->amount }}</td>
													<td>
														@if($admission->paystatus === 'paid')
															<span class="badge bg-success">Cleared</span>
														@else
															<span class="badge bg-danger">Unsettled</span>
														@endif
													</td>
													<td>{{ \Carbon\Carbon::parse($admission->created_at)->format('d-m-Y') }}</td>													
													<td>
														
														@if(!in_array($admission->id, $certifiedIds))
															<button type="button" class="btn btn-success" 
																	data-toggle="modal" 
																	data-target="#certifyModal{{ $admission->id }}">
																Certify Trained Student
															</button>
														@endif

														<!-- Modal is written inline below -->
														<div class="modal fade" id="certifyModal{{ $admission->id }}" tabindex="-1" role="dialog" aria-labelledby="label{{ $admission->id }}" aria-hidden="true">
															<div class="modal-dialog" role="document">
																<div class="modal-content">

																	<div class="modal-header">
																		<h5 class="modal-title" id="label{{ $admission->id }}">Certify Student - {{ $admission->student_name }}</h5>
																		<button type="button" class="close" data-dismiss="modal" aria-label="Close">
																			<span aria-hidden="true">&times;</span>
																		</button>
																	</div>

																	 <div class="modal-body">
																		<form class="row g-3" action="{{ route('registerCertifiedStudent') }}" method="post" autocomplete="off">
																			@csrf
																			<div class="col-md-6">
																				<label for="validationDefault01" class="form-label">Full names</label>
																				<input type="text" class="form-control" id="validationDefault01" name="full_names" value="{{ $admission->student_name }}" required>
																				<input type="hidden" class="form-control" id="validationDefault01" name="account" value="{{ $admission->account }}">
																				<input type="hidden" class="form-control" id="validationDefault01" name="admissionid" value="{{ $admission->id }}">
																				<input type="hidden" class="form-control" id="validationDefault01" name="course_id" value="{{ $admission->course_id }}">
																				<input type="hidden" class="form-control" id="validationDefault01" name="training_station" value="{{ $admission->station }}">
																			</div>
																			<div class="col-md-6">
																				<label for="validationDefault02" class="form-label">ID Number</label>
																				<input type="text" class="form-control" id="validationDefault02" name="national_id" value="{{ $admission->idno }}" required>
																			</div>

																			<div class="col-md-6">
																				<label for="validationDefault02" class="form-label">Phone Number</label>
																				<input type="number" class="form-control" id="validationDefault02" name="phone" value="{{ $admission->phone }}" required>
																			</div>

																			<div class="col-md-6">
																				<label for="validationDefault02" class="form-label">Email address</label>
																				<input type="email" class="form-control" id="validationDefault02" name="email" value="{{ $admission->email }}" required>
																			</div>																		
																			

																			<div class="col-md-6">
																				<label for="validationDefault04" class="form-label">Course</label>
																				<input type="email" class="form-control" id="validationDefault02"  value="{{ $admission->course_name }}" Readonly>
																				
																			</div>

																			<div class="col-md-6">
																				<label for="validationDefault04" class="form-label">Training Station</label>
																				<input type="email" class="form-control" id="validationDefault02"  value="{{ $admission->station }}" Readonly>																				
																			</div>
																			
																			<div class="col-md-6">
																				<label for="validationDefault02" class="form-label">Approval Date</label>
																				<input type="date" class="form-control" id="validationDefault02" name="approvaldate" placeholder="Enter student's approval date" max="{{ date('Y-m-d') }}" required>
																			</div>

																			<div class="col-md-6">
																				<label for="validationDefault04" class="form-label">Trainer Name</label>
																				<select class="form-select choices-single" id="validationDefault04" name="trainerid" required>
																					<option selected disabled value="">Choose...</option>
																					@foreach($trainers as $trainer)
																						<option value="{{ $trainer->pin }}">{{ $trainer->id }} : {{ $trainer->name }}</option>
																					@endforeach
																				</select>
																			</div>

																			<div class="form-group">
																				<label for="send_email">Email Certificate?</label>
																				<select name="send_email" id="send_email" class="form-control" required>
																					<option value="yes">Yes</option>
																					<option value="no">No</option>
																				</select>
																			</div>
																																																
																																
																				</div>
																			<div class="modal-footer">
																			<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
																			<button type="submit" class="btn btn-primary">Award Certificate</button>
																		</form>
																	</div>

																</div>
															</div>
														</div>
														<!-- End modal -->
													</td>
												</tr>
											@endforeach
										</tbody>
										
									</table>
								</div>
							</div>

				</div>
				
			</main>
@endsection