@extends('layouts.app')

@section('title', 'Eligible Members')
@section('kicker', 'Members allowed to take sacrament')

@section('content')
    @include('partials.module-tabs', ['tabs' => [
        ['label' => 'Participants', 'route' => 'sacrament.index', 'icon' => 'cross'],
        ['label' => 'Register', 'route' => 'sacrament.create', 'icon' => 'plus'],
        ['label' => 'History', 'route' => 'sacrament.history', 'icon' => 'history'],
        ['label' => 'Eligible Members', 'route' => 'sacrament.eligible', 'icon' => 'badge-check'],
    ]])

    <div class="content-card mb-3">
        <form method="GET" class="row g-3 align-items-end">
            <div class="col-md-8">
                <label class="form-label">Jumuiya / Cell</label>
                <select name="jumuiya_id" class="form-select">
                    <option value="">All Jumuiya</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-4">
                <button class="btn btn-outline-primary w-100"><i data-lucide="filter"></i><span>Filter</span></button>
            </div>
        </form>
    </div>

    <div class="table-card">
        <div class="table-responsive">
            <table class="table">
                <thead><tr><th>Member</th><th>Jumuiya</th><th>Baptized</th><th>Confirmed</th><th>Phone</th></tr></thead>
                <tbody>
                    @forelse ($members as $member)
                        <tr>
                            <td class="fw-semibold"><a href="{{ route('members.show', $member) }}">{{ $member->full_name }}</a></td>
                            <td>{{ $member->jumuiya?->name ?? '-' }}</td>
                            <td>{{ $member->is_baptized ? 'Yes' : 'No' }}</td>
                            <td>{{ $member->is_confirmed ? 'Yes' : 'No' }}</td>
                            <td>{{ $member->phone ?? '-' }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="5"><div class="empty-state">Hakuna eligible members kwa filter hii.</div></td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        {{ $members->links() }}
    </div>
@endsection
