@extends('training.inc.master')

@section('title','Dashboard')

@section('content')

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

				<h1 class="h3 mb-3"><strong>Filter Enrolments</strong> By date</h1>
				@include('training.alerts.alert')
					
					<div class="row">
						<div class="col-12">
							<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Filter Enrollments </h5>
								</div>
								<div class="card-body">
									<form method="GET" action="{{ url()->current() }}">										

										<div class="row g-3 align-items-center">
											<div class="col-auto">
												<label for="date" class="col-form-label fw-bold">Select Date:</label>
											</div>
											<div class="col-auto">
												<input type="date" id="date" name="date" 
													value="{{ request('date', now()->toDateString()) }}"
													class="form-control">
											</div>
											<div class="col-auto">
												<button type="submit" class="btn btn-primary">
													<i class="bi bi-search"></i> Filter
												</button>
												<a href="{{ url()->current() }}" class="btn btn-secondary">Reset</a>
											</div>
										</div>						
									</form>
								</div>
							</div>
						</div>
					</div>
					
					<div class="card">
						<div class="card-header">
							<h5 class="card-title">Enrollments done on <b>{{ \Carbon\Carbon::parse($date)->format('d D M Y') }} </b></h5>
							<!-- <h6 class="card-subtitle text-muted">This is data from the filtered month</h6> -->
						</div>
						<div class="card-body">
							<table id="datatables-reponsive" class="table table-striped" style="width:100%">
								<thead>
									<tr>
											<th>#</th>
											<th>Student Name</th>
											<th>Course</th>
											<th>Amount</th>
											<th>TransID</th>
											<th>Station</th>
											<th>Payment Mode</th>
											<th>Paystatus</th>
											<th>Company</th>
									</tr>
								</thead>
								<tbody>

									@forelse($enrollments as $index => $enrollment)
										<tr>
											<td>{{ $index + 1 }}</td>
											<td>{{ $enrollment->name ?? '-' }}</td>
											<td>{{ $enrollment->course_name }}</td>
											<td>{{ number_format($enrollment->amount, 2) }}</td>
											<td>{{ $enrollment->TransID }}</td>
											<td>{{ $enrollment->station }}</td>
											<td>{{ ucfirst($enrollment->paymentmode) }}</td>
											<td>
												@if($enrollment->paystatus === 'paid')
													<span class="badge bg-success">Paid</span>
												@else
													<span class="badge bg-danger">Unpaid</span>
												@endif
											</td>
											<td>{{ $enrollment->companyname }}</td>
										</tr>
									@empty
										<tr>
											<td colspan="9" class="text-center text-muted">No enrollments found for this date.</td>
										</tr>
									@endforelse
									
								</tbody>
								
							</table>
						</div>
					</div>
					

				</div>
				
			</main>
@endsection