<div class="employee-illness-section">

    {{-- ===================== HEADER ===================== --}}
    <div class="employee-illness-header mb-4 d-flex justify-content-between align-items-center">
        <div class="row align-items-center">
            <div class="col">
              <h5 class="employee-illness-title mb-1">Illness / Medical Information</h5>
            <small class="text-muted">
                Record medical conditions for compliance and safety
            </small>
            </div>
            <div class="col-auto">
             <button type="button"
                class="btn btn-sm btn-outline-primary"
                id="addIllnessRow">
            <i class="bi bi-plus"></i> Add Illness
        </button>
            </div>
        </div>     
    </div>

    {{-- ===================== BODY ===================== --}}
    <div class="employee-illness-body">

        <div class="table-responsive">
            <table class="table table-bordered align-middle illness-table"
                   id="illnessTable">

                <thead class="table-light">
                    <tr>
                        <th style="min-width: 220px;">
                            Illness <span class="text-danger">*</span>
                        </th>
                        <th style="min-width: 150px;">Diagnosed On</th>
                        <th class="text-center" style="width: 110px;">Chronic</th>
                        <th class="text-center" style="width: 110px;">Active</th>
                        <th style="min-width: 260px;">Notes</th>
                        <th class="text-center" style="width: 50px;"></th>
                    </tr>
                </thead>

                <tbody>

                    {{-- ===================== EDIT MODE ===================== --}}
                    @if(isset($employee) && $employee->illnesses->count())
                        @foreach($employee->illnesses as $i => $ei)
                            <tr>

                                <td>
                                    <select name="illness[{{ $i }}][illness_id]"
                                            class="form-control"
                                            required>
                                        <option value="">-- Select --</option>
                                        @foreach($illnesses as $ill)
                                            <option value="{{ $ill->id }}"
                                                @selected($ei->illness_id == $ill->id)>
                                                {{ $ill->name }}
                                            </option>
                                        @endforeach
                                    </select>
                                </td>

                                <td>
                                    <input type="date"
                                           name="illness[{{ $i }}][diagnosed_on]"
                                           class="form-control"
                                           value="{{ $ei->diagnosed_on }}">
                                </td>

                                <td class="text-center">
                                    <input type="checkbox"
                                           name="illness[{{ $i }}][chronic]"
                                           value="1"
                                           {{ $ei->chronic ? 'checked' : '' }}>
                                </td>

                                <td class="text-center">
                                    <input type="checkbox"
                                           name="illness[{{ $i }}][active]"
                                           value="1"
                                           {{ $ei->active ? 'checked' : '' }}>
                                </td>

                                <td>
                                    <textarea name="illness[{{ $i }}][notes]"
                                              class="form-control"
                                              rows="2"
                                              placeholder="Additional notes or precautions">{{ $ei->notes }}</textarea>
                                </td>

                                <td class="text-center">
                                    <button type="button"
                                            class="btn btn-sm btn-outline-danger illness-remove-btn remove-row"
                                            title="Remove">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </td>

                            </tr>
                        @endforeach
                    @endif

                </tbody>

            </table>
        </div>

    </div>

</div>
