@extends('layouts.admin')

@section('content')
<div class="card mb-3">
    <div class="card-header">
        <h5 class="mb-0">Benefit Popularity by Age Group</h5>
    </div>
    <div class="card-body">
        <!-- Date Filter Form -->
        <form method="GET" action="{{ url('/covers-report/benefit-by-age') }}" class="row g-3 mb-4">
            <div class="col-md-4">
                <label for="start_date" class="form-label">Start Date</label>
                <input type="date" name="start_date" class="form-control"
                    value="{{ $startDate ?? now()->startOfYear()->format('Y-m-d') }}">
            </div>
            <div class="col-md-4">
                <label for="end_date" class="form-label">End Date</label>
                <input type="date" name="end_date" class="form-control"
                    value="{{ $endDate ?? now()->format('Y-m-d') }}">
            </div>
            <div class="col-md-4 align-self-end">
                <button type="submit" class="btn btn-primary btn-sm">
                    <i class="fas fa-search"></i> Filter
                </button>
            </div>
        </form>

        <!-- Report Table -->
        <div class="dt-responsive table-sm table-responsive">
            <table id="basic-btn" class="table table-sm table-striped table-bordered nowrap">
                <thead class="bg-200 text-900">
                    <tr>
                        <th>#</th>
                        <th>Age Group</th>
                        <th>Cover Name</th>
                        <th>Sum Assured</th>
                        <th>Members Count</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($benefitStats as $index => $item)
                    <tr>
                        <td>{{ $index + 1 }}</td>
                        <td>{{ $item->age_group }} - {{ $item->age_group + 9 }}</td>
                        <td>{{ $item->cover_name }}</td>
                        <td>E{{ number_format($item->sum_assured, 2) }}</td>
                        <td>{{ $item->member_count }}</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
