@extends('layouts.app')

@section('title', 'Members Report')
@section('kicker', 'Create membership report by registration date and profile filters')

@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-2"><label class="form-label">Registered From</label><input type="date" name="from_date" value="{{ request('from_date') }}" class="form-control" required></div>
            <div class="col-md-2"><label class="form-label">Registered To</label><input type="date" name="to_date" value="{{ request('to_date') }}" class="form-control" required></div>
            <div class="col-md-2"><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">Gender</label><select name="gender" class="form-select"><option value="">All</option><option value="Male" @selected(request('gender') === 'Male')>Male</option><option value="Female" @selected(request('gender') === 'Female')>Female</option></select></div>
            <div class="col-md-2"><label class="form-label">Status</label><select name="status" class="form-select"><option value="">All</option>@foreach(['active','inactive','transferred','deceased'] as $status)<option value="{{ $status }}" @selected(request('status') === $status)>{{ ucfirst($status) }}</option>@endforeach</select></div>
            <div class="col-md-1"><label class="form-label">Sacrament</label><select name="sacrament_eligibility" class="form-select"><option value="">All</option><option value="1" @selected(request('sacrament_eligibility') === '1')>Yes</option><option value="0" @selected(request('sacrament_eligibility') === '0')>No</option></select></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">
        <div class="d-flex justify-content-between mb-3"><div class="section-title">Members Results</div><button class="btn btn-sm btn-outline-secondary" @disabled(! $created) onclick="window.print()"><i data-lucide="file-down"></i><span>Export PDF</span></button></div>
        @if (! $created)
            <div class="empty-state">Chagua filters na bonyeza Create Report.</div>
        @else
            <div class="table-responsive">
                <table class="table">
                    <thead><tr><th>Full Name</th><th>Gender</th><th>Phone</th><th>Jumuiya</th><th>Position</th><th>Status</th><th>Date Registered</th></tr></thead>
                    <tbody>
                        @forelse ($members as $member)
                            <tr>
                                <td>{{ $member->full_name }}</td>
                                <td>{{ $member->gender ?? '-' }}</td>
                                <td>{{ $member->phone ?? '-' }}</td>
                                <td>{{ $member->jumuiya?->name ?? '-' }}</td>
                                <td>{{ $member->position?->name ?? '-' }}</td>
                                <td>{{ ucfirst($member->status) }}</td>
                                <td>{{ $member->date_registered?->format('d M Y') }}</td>
                            </tr>
                        @empty
                            <tr><td colspan="7"><div class="empty-state">Hakuna data kwa filters hizi.</div></td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        @endif
    </div>
@endsection
