@extends('layouts.app')

@section('title', 'Sacrament Report')
@section('kicker', 'Create sacrament participation report')

@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">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">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">Sacrament</label>
                <select name="sacrament_type_id" class="form-select"><option value="">All</option>@foreach ($sacramentTypes as $type)<option value="{{ $type->id }}" @selected((string) request('sacrament_type_id') === (string) $type->id)>{{ $type->name }}</option>@endforeach</select>
            </div>
            <div class="col-md-3">
                <label class="form-label">Service</label>
                <select name="church_service_id" class="form-select"><option value="">All</option>@foreach ($services as $service)<option value="{{ $service->id }}" @selected((string) request('church_service_id') === (string) $service->id)>{{ $service->name }}</option>@endforeach</select>
            </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-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">Sacrament 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>Member</th><th>Jumuiya</th><th>Sacrament</th><th>Date</th><th>Service</th><th>Status</th><th>Recorded By</th><th>Remarks</th></tr></thead>
                    <tbody>
                        @forelse ($records as $record)
                            <tr>
                                <td>{{ $record->member?->full_name }}</td>
                                <td>{{ $record->member?->jumuiya?->name ?? '-' }}</td>
                                <td>{{ $record->sacramentType?->name }}</td>
                                <td>{{ $record->sacrament_date?->format('d M Y') }}</td>
                                <td>{{ $record->churchService?->name ?? '-' }}</td>
                                <td>{{ ucfirst(str_replace('_', ' ', $record->status)) }}</td>
                                <td>{{ $record->recordedBy?->full_name ?? 'System' }}</td>
                                <td>{{ $record->remarks ?? '-' }}</td>
                            </tr>
                        @empty
                            <tr><td colspan="8"><div class="empty-state">Hakuna data kwa filters hizi.</div></td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        @endif
    </div>
@endsection
