@extends('layouts.admin')

@section('title', 'Edit Peserta — ' . $pp->participant->name)
@section('header', 'Edit Maklumat Peserta')

@section('breadcrumb')
<li class="breadcrumb-item"><a href="{{ route('admin.programs.index') }}">Program</a></li>
<li class="breadcrumb-item"><a href="{{ route('admin.programs.show', $program) }}">{{ Str::limit($program->title, 25) }}</a></li>
<li class="breadcrumb-item"><a href="{{ route('admin.programs.participants.index', $program) }}">Peserta</a></li>
<li class="breadcrumb-item active">Edit</li>
@endsection

@section('content')
<div class="row justify-content-center">
    <div class="col-lg-6">
        <div class="card border-0 shadow-sm">
            <div class="card-header bg-white border-bottom py-3">
                <span class="fw-semibold">
                    <i class="bi bi-person-gear me-2 text-primary"></i>Kemaskini Maklumat Peserta
                </span>
            </div>
            <div class="card-body">
                <form method="POST" action="{{ route('admin.programs.participants.update', [$program, $pp]) }}">
                    @csrf @method('PUT')

                    <div class="mb-3">
                        <label class="form-label fw-medium">Nama Penuh <span class="text-danger">*</span></label>
                        <input type="text" name="name" class="form-control @error('name') is-invalid @enderror"
                               value="{{ old('name', $pp->participant->name) }}" required>
                        @error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-medium">No. Kad Pengenalan <span class="text-danger">*</span></label>
                        <input type="text" name="no_kp" class="form-control @error('no_kp') is-invalid @enderror"
                               value="{{ old('no_kp', $pp->participant->no_kp) }}"
                               placeholder="12 digit tanpa sempang" required>
                        @error('no_kp')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-medium">Emel</label>
                        <input type="email" name="email" class="form-control @error('email') is-invalid @enderror"
                               value="{{ old('email', $pp->participant->email) }}"
                               placeholder="Kosongkan jika tiada">
                        @error('email')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-medium">No. Telefon</label>
                        <input type="text" name="phone" class="form-control @error('phone') is-invalid @enderror"
                               value="{{ old('phone', $pp->participant->phone) }}"
                               placeholder="Kosongkan jika tiada">
                        @error('phone')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-medium">Jabatan / Agensi</label>
                        <input type="text" name="agency" class="form-control @error('agency') is-invalid @enderror"
                               value="{{ old('agency', $pp->participant->agency) }}"
                               placeholder="Kosongkan jika tiada">
                        @error('agency')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>

                    <div class="mb-4">
                        <label class="form-label fw-medium">Sesi</label>
                        <select name="session" class="form-select @error('session') is-invalid @enderror">
                            <option value="">— Tiada Sesi —</option>
                            <option value="pagi"     {{ old('session', $pp->pre_registered_session) === 'pagi'     ? 'selected' : '' }}>Pagi</option>
                            <option value="petang"   {{ old('session', $pp->pre_registered_session) === 'petang'   ? 'selected' : '' }}>Petang</option>
                            <option value="full_day" {{ old('session', $pp->pre_registered_session) === 'full_day' ? 'selected' : '' }}>Sehari Penuh</option>
                        </select>
                        @error('session')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>

                    @foreach($filters as $key => $value)
                    <input type="hidden" name="{{ $key }}" value="{{ $value }}">
                    @endforeach

                    @php $backUrl = route('admin.programs.participants.index', $program) . ($filters ? '?' . http_build_query($filters) : ''); @endphp

                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-check-lg me-1"></i> Simpan
                        </button>
                        <a href="{{ $backUrl }}" class="btn btn-outline-secondary">Batal</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
