@php
    use App\Models\IncidentStatus;
    $caseStatus = IncidentStatus::where('victimid', $id)->first() ?? new IncidentStatus();
    $pendingCaseStatusIdsForJs = isset($pendingCaseStatusIds) ? array_values($pendingCaseStatusIds) : \App\Models\CaseStatus::where('name', 'like', '%Pending%')->pluck('id')->map(function ($id) { return (string) $id; })->toArray();
    $pendingPointOptionsForJs = isset($pendingPoints) ? $pendingPoints->map(function ($point) { return ['id' => (string) $point->id, 'name' => $point->name]; })->values() : collect();
@endphp

<div class="row">
    <legend>Case Status</legend>

    <div class="col-sm-6" id="home1">
        <div class="form-group row">
            <label class="col-md-4 col-form-label text-md-left">Date: <span class="text-danger">*</span></label>
            <div class="col-md-8">
                <input type="text" readonly class="form-control datepicker" name="date_reported"
                       value="{{ old('date_reported', $caseStatus->date_logged) }}" required>
            </div>
        </div>

        <div class="form-group row">
            <label class="col-md-4 col-form-label text-md-left">Case Status: <span class="text-danger">*</span></label>
            <div class="col-md-8">
                <select id="reportedto" class="form-control search-select" name="reportedto" required data-case-status-select data-pending-target="#statuses">
                    <option value="">Choose One</option>
                    @foreach($statuses as $status)
                        <option value="{{ $status->id }}"
                            {{ old('reportedto', $caseStatus->incident_status) == $status->id ? 'selected' : '' }}>
                            {{ $status->name }}
                        </option>
                    @endforeach
                </select>
            </div>
        </div>

        <div class="form-group row" id="statuses" data-pending-points-container
             data-current-pendingpoint="{{ old('pendingpoint', $caseStatus->pendingpoint) }}"></div>
        <div class="form-group row" id="satisfied"></div>
    </div>

    <div class="col-sm-6" id="home1">
        <div class="form-group row">
            <label class="col-sm-2 col-form-label">Details</label>
            <div class="col-sm-10">
                <textarea rows="5" cols="5" class="form-control" name="notes" placeholder="Details">{{ old('notes', $caseStatus->details) }}</textarea>
            </div>
        </div>
    </div>
</div>

@include('dataentry.partials.case_status_pending_points_script', [
    'pendingCaseStatusIdsForJs' => $pendingCaseStatusIdsForJs,
    'pendingPointOptionsForJs' => $pendingPointOptionsForJs,
])
