@extends('layouts.app')

@section('title', 'Absent Members')
@section('kicker', 'Find members not marked present for a service')

@section('content')
    @include('partials.module-tabs', ['tabs' => [
        ['label' => 'QR Attendance', 'route' => 'attendance.qr', 'icon' => 'scan-qr-code'],
        ['label' => 'Manual Entry', 'route' => 'attendance.manual', 'icon' => 'list-checks'],
        ['label' => 'Records', 'route' => 'attendance.records', 'icon' => 'clipboard-list'],
        ['label' => 'Today', 'route' => 'attendance.today', 'icon' => 'calendar-check'],
        ['label' => 'Absent', 'route' => 'attendance.absent', 'icon' => 'user-x'],
    ]])

    <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">Service/Event</label>
                <select name="church_service_id" class="form-select">
                    <option value="">Select service/event</option>
                    @foreach ($services as $service)
                        <option value="{{ $service->id }}" @selected($selectedService?->id === $service->id)>{{ $service->name }} · {{ $service->service_date?->format('d M Y') }}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-md-4">
                <button class="btn btn-primary w-100"><i data-lucide="user-x"></i><span>Show Absent</span></button>
            </div>
        </form>
    </div>

    <div class="table-card">
        @if (! $selectedService)
            <div class="empty-state">Chagua service/event kuona absent members.</div>
        @else
            <div class="d-flex justify-content-between mb-3">
                <div class="section-title">{{ $selectedService->name }}</div>
                <span class="badge badge-soft-gold">{{ $members->count() }} absent</span>
            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead><tr><th>Member</th><th>Jumuiya</th><th>Phone</th><th>Position</th></tr></thead>
                    <tbody>
                        @forelse ($members as $member)
                            <tr>
                                <td class="fw-semibold">{{ $member->full_name }}</td>
                                <td>{{ $member->jumuiya?->name ?? '-' }}</td>
                                <td>{{ $member->phone ?? '-' }}</td>
                                <td>{{ $member->position?->name ?? '-' }}</td>
                            </tr>
                        @empty
                            <tr><td colspan="4"><div class="empty-state">Members wote wamewekwa present kwa service hii.</div></td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        @endif
    </div>
@endsection
