@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 Stations Revenue</strong> By Month and Year</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 Admissions</h5>
								</div>
								<div class="card-body">
									<form method="GET" action="{{ url()->current() }}">
										<div class="row g-3">
											<!-- Month Dropdown -->
											<div class="col-md-6">
												<label for="month" class="form-label">Month</label>
												<select class="form-select" id="month" name="month" required>
													<option value="">-- Select Month --</option>
													@foreach ([
														'01' => 'January',
														'02' => 'February',
														'03' => 'March',
														'04' => 'April',
														'05' => 'May',
														'06' => 'June',
														'07' => 'July',
														'08' => 'August',
														'09' => 'September',
														'10' => 'October',
														'11' => 'November',
														'12' => 'December',
													] as $num => $name)
														<option value="{{ $num }}" {{ request('month') == $num ? 'selected' : '' }}>
															{{ $name }}
														</option>
													@endforeach
												</select>
											</div>

											<!-- Year Dropdown -->
											<div class="col-md-6">
												<label for="year" class="form-label">Year</label>
												<select class="form-select" id="year" name="year" required>
													<option value="">-- Select Year --</option>
													@for ($y = 2024; $y <= date('Y') + 1; $y++)
														<option value="{{ $y }}" {{ request('year') == $y ? 'selected' : '' }}>
															{{ $y }}
														</option>
													@endfor
												</select>
											</div>
										</div>

										<div class="mt-3">
											<button type="submit" class="btn btn-primary">Filter</button>
											<a href="{{ url()->current() }}" class="btn btn-secondary">Reset</a>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
					
					<div class="card">
						<div class="card-header">
							<h5 class="card-title">Revenue Collection in {{ $duration }}</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>Station</th>
											<th>Total Income (KES)</th>
									</tr>
								</thead>
								<tbody>
									@forelse($revenues as $index => $revenue)
										<tr>
											<td>{{ $index + 1 }}</td>
											<td>{{ $revenue->station }}</td>
											<td>{{ number_format($revenue->total_income, 2) }}</td>
										</tr>
									@empty
										<tr>
											<td colspan="3" class="text-center text-muted">
												No data found for {{ $month ? \Carbon\Carbon::createFromDate($year, $month, 1)->format('F Y') : $year }}
											</td>
										</tr>
									@endforelse
								</tbody>
								
							</table>
						</div>
					</div>
					

				</div>
				
			</main>
@endsection