@extends('layouts.admin')

@section('content')
<div class="card mb-3">
    <div class="card-header">
        <h5 class="mb-0">Lapse Analysis by Cover Structure</h5>
    </div>
    <div class="card-body">
        <!-- Filter Form -->
        <form method="GET" action="{{ url('/covers-report/lapse-analysis') }}" 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()->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>

        <!-- Lapse Stats 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>Cover Name</th>
                        <th>Sum Assured</th>
                        <th>Total Members</th>
                        <th>Lapsed Members</th>
                        <th>Lapse Rate (%)</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($lapseStats as $index => $row)
                    <tr>
                        <td>{{ $index + 1 }}</td>
                        <td>{{ $row->cover_name }}</td>
                        <td>E{{ number_format($row->sum_assured, 2) }}</td>
                        <td>{{ $row->total_members }}</td>
                        <td>{{ $row->lapsed_members }}</td>
                        <td>{{ number_format($row->lapse_rate, 2) }}%</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
