@extends('layouts.app')

@section('title', 'Register Sacrament Participation')
@section('kicker', 'Record Holy Communion or another 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="form-card">
        <form method="POST" action="{{ route('sacrament.store') }}">
            @csrf
            <div class="row g-3">
                <div class="col-md-6">
                    <label class="form-label">Member</label>
                    <select name="member_id" class="form-select" required>
                        <option value="">Select member</option>
                        @foreach ($members as $member)
                            <option value="{{ $member->id }}" @selected((string) old('member_id') === (string) $member->id)>
                                {{ $member->full_name }} · {{ $member->member_code }} {{ $member->is_allowed_sacrament ? '' : '(not eligible)' }}
                            </option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-6">
                    <label class="form-label">Sacrament Type</label>
                    <select name="sacrament_type_id" class="form-select" required>
                        @foreach ($types as $type)
                            <option value="{{ $type->id }}" @selected((string) old('sacrament_type_id') === (string) $type->id)>{{ $type->name }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-6">
                    <label class="form-label">Service/Event</label>
                    <select name="church_service_id" class="form-select">
                        <option value="">No service selected</option>
                        @foreach ($services as $service)
                            <option value="{{ $service->id }}" @selected((string) old('church_service_id') === (string) $service->id)>{{ $service->name }} · {{ $service->service_date?->format('d M Y') }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label">Date</label>
                    <input type="date" name="sacrament_date" value="{{ old('sacrament_date', now()->toDateString()) }}" class="form-control" required>
                </div>
                <div class="col-md-3">
                    <label class="form-label">Status</label>
                    <select name="status" class="form-select" required>
                        <option value="participated" @selected(old('status') === 'participated')>Participated</option>
                        <option value="not_participated" @selected(old('status') === 'not_participated')>Not Participated</option>
                    </select>
                </div>
                <div class="col-12">
                    <label class="form-label">Remarks</label>
                    <textarea name="remarks" rows="3" class="form-control">{{ old('remarks') }}</textarea>
                </div>
            </div>
            <div class="mt-4 d-flex gap-2">
                <button class="btn btn-primary"><i data-lucide="save"></i><span>Save Record</span></button>
                <a href="{{ route('sacrament.index') }}" class="btn btn-outline-secondary"><i data-lucide="x"></i><span>Cancel</span></a>
            </div>
        </form>
    </div>
@endsection
