@extends('layouts.app')

@section('title', 'Absent Members Report')
@section('kicker', 'Members with repeated absence within a selected period')

@section('content')
    @include('partials.module-tabs', ['tabs' => [
        ['label' => 'Attendance', 'route' => 'reports.attendance', 'icon' => 'clipboard-check'],
        ['label' => 'Sacrament', 'route' => 'reports.sacrament', 'icon' => 'cross'],
        ['label' => 'Members', 'route' => 'reports.members', 'icon' => 'users'],
        ['label' => 'Jumuiya', 'route' => 'reports.jumuiya', 'icon' => 'network'],
        ['label' => 'Absent', 'route' => 'reports.absent', 'icon' => 'user-x'],
        ['label' => 'Activity', 'route' => 'reports.user-activity', 'icon' => 'activity'],
    ]])

    <div class="content-card mb-3">
        <form method="GET" class="row g-3 align-items-end">
            <input type="hidden" name="create_report" value="1">
            <div class="col-md-3"><label class="form-label">From</label><input type="date" name="from_date" value="{{ request('from_date') }}" class="form-control" required></div>
            <div class="col-md-3"><label class="form-label">To</label><input type="date" name="to_date" value="{{ request('to_date') }}" class="form-control" required></div>
            <div class="col-md-3"><label class="form-label">Jumuiya</label><select name="jumuiya_id" class="form-select"><option value="">All</option>@foreach ($jumuiyas as $jumuiya)<option value="{{ $jumuiya->id }}" @selected((string) request('jumuiya_id') === (string) $jumuiya->id)>{{ $jumuiya->name }}</option>@endforeach</select></div>
            <div class="col-md-2"><label class="form-label">Min Absence</label><input type="number" min="1" name="minimum_absence_count" value="{{ request('minimum_absence_count', 1) }}" class="form-control"></div>
            <div class="col-md-1"><button class="btn btn-primary w-100"><i data-lucide="file-plus-2"></i></button></div>
        </form>
    </div>
    <div class="table-card">
        @if (! $created)
            <div class="empty-state">Chagua filters na bonyeza Create Report.</div>
        @else
            <div class="table-responsive">
                <table class="table">
                    <thead><tr><th>Member</th><th>Jumuiya</th><th>Phone</th><th>Absence Count</th></tr></thead>
                    <tbody>
                        @forelse ($members as $member)
                            <tr><td>{{ $member->full_name }}</td><td>{{ $member->jumuiya?->name ?? '-' }}</td><td>{{ $member->phone ?? '-' }}</td><td><span class="badge badge-soft-rose">{{ $member->absence_count }}</span></td></tr>
                        @empty
                            <tr><td colspan="4"><div class="empty-state">Hakuna absent members kwa filters hizi.</div></td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        @endif
    </div>
@endsection
