{{-- Overview & Team tab — editable case fields + team + consent link. --}}
<div class="tab-pane active" id="tab_overview">
  <form class="medsx-form" action="{{ route('medsx.cases.update', $case->id) }}" method="POST" data-reload="true">
    {{ csrf_field() }} {{ method_field('PUT') }}
    <input type="hidden" name="section" value="overview">
    <input type="hidden" name="patient_id" value="{{ $case->patient_id }}">

    <div class="row">
      <div class="col-md-4"><strong>@lang('medsurgery::lang.patient'):</strong> {{ $patientName }}</div>
      <div class="col-md-4"><strong>@lang('medsurgery::lang.case_no'):</strong> {{ $case->case_no }}</div>
      <div class="col-md-4"><strong>@lang('medsurgery::lang.priority'):</strong> @lang('medsurgery::lang.priority_' . $case->priority)</div>
    </div>
    <hr>

    <h5><i class="fa fa-users"></i> @lang('medsurgery::lang.team')</h5>
    <div class="row">
      <div class="col-md-4 form-group">
        <label>@lang('medsurgery::lang.surgeon')</label>
        <select name="primary_surgeon_id" class="form-control input-sm">
          <option value="">@lang('medsurgery::lang.none')</option>
          @foreach($doctors as $did => $dname)
            <option value="{{ $did }}" @selected((int) $case->primary_surgeon_id === (int) $did)>{{ $dname }}</option>
          @endforeach
        </select>
      </div>
      <div class="col-md-4 form-group">
        <label>@lang('medsurgery::lang.anesthetist_name')</label>
        <input type="text" name="anesthetist_name" class="form-control input-sm" value="{{ $case->anesthetist_name }}">
      </div>
      <div class="col-md-4 form-group">
        <label>@lang('medsurgery::lang.anesthesia_type')</label>
        <select name="anesthesia_type" class="form-control input-sm">
          <option value="">@lang('medsurgery::lang.none')</option>
          @foreach(\Modules\MedSurgery\Entities\MedsxCase::ANESTHESIA_TYPES as $a)
            <option value="{{ $a }}" @selected($case->anesthesia_type === $a)>@lang('medsurgery::lang.anesthesia_' . $a)</option>
          @endforeach
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-md-4 form-group">
        <label>@lang('medsurgery::lang.scrub_nurse') (id)</label>
        <input type="number" name="scrub_nurse_id" class="form-control input-sm" value="{{ $case->scrub_nurse_id }}">
      </div>
      <div class="col-md-4 form-group">
        <label>@lang('medsurgery::lang.circulating_nurse') (id)</label>
        <input type="number" name="circulating_nurse_id" class="form-control input-sm" value="{{ $case->circulating_nurse_id }}">
      </div>
      <div class="col-md-4 form-group">
        <label>@lang('medsurgery::lang.asa_class')</label>
        <input type="number" name="asa_class" class="form-control input-sm" min="1" max="6" value="{{ $case->asa_class }}">
      </div>
    </div>

    <hr>
    <h5><i class="fa fa-calendar"></i> @lang('medsurgery::lang.schedule')</h5>
    <div class="row">
      <div class="col-md-3 form-group">
        <label>@lang('medsurgery::lang.or_room')</label>
        <select name="or_room_id" class="form-control input-sm">
          <option value="">@lang('medsurgery::lang.none')</option>
          @foreach($rooms as $rid => $rname)
            <option value="{{ $rid }}" @selected((int) $case->or_room_id === (int) $rid)>{{ $rname }}</option>
          @endforeach
        </select>
        @if(empty($rooms))
          <p class="help-block text-warning"><small>@lang('medsurgery::lang.no_or_rooms_hint')</small></p>
        @endif
      </div>
      <div class="col-md-3 form-group">
        <label>@lang('medsurgery::lang.scheduled_start')</label>
        <input type="datetime-local" name="scheduled_start" class="form-control input-sm"
          value="{{ optional($case->scheduled_start)->format('Y-m-d\TH:i') }}">
      </div>
      <div class="col-md-3 form-group">
        <label>@lang('medsurgery::lang.scheduled_end')</label>
        <input type="datetime-local" name="scheduled_end" class="form-control input-sm"
          value="{{ optional($case->scheduled_end)->format('Y-m-d\TH:i') }}">
      </div>
      <div class="col-md-3 form-group">
        <label>@lang('medsurgery::lang.consent')</label>
        <select name="consent_id" class="form-control input-sm">
          <option value="">@lang('medsurgery::lang.select_consent')</option>
          @foreach($consents as $cid => $ctitle)
            <option value="{{ $cid }}" @selected((int) $case->consent_id === (int) $cid)>{{ $ctitle }}</option>
          @endforeach
        </select>
      </div>
    </div>

    <div class="form-group">
      <label>@lang('medsurgery::lang.diagnosis')</label>
      <textarea name="diagnosis" class="form-control input-sm" rows="2">{{ $case->diagnosis }}</textarea>
    </div>

    <button type="submit" class="btn btn-primary btn-sm">@lang('medsurgery::lang.save_overview')</button>
  </form>

  {{-- Procedures (read-only summary of the JSON column) --}}
  <hr>
  <h5>@lang('medsurgery::lang.procedures')</h5>
  <table class="table table-condensed table-bordered">
    <thead><tr>
      <th>@lang('medsurgery::lang.procedure_name')</th>
      <th>@lang('medsurgery::lang.cpt_code')</th>
      <th>@lang('medsurgery::lang.laterality')</th>
    </tr></thead>
    <tbody>
      @forelse(($case->procedures ?? []) as $p)
        <tr>
          <td>{{ $p['name'] ?? '' }}</td>
          <td>{{ $p['cpt_code'] ?? '—' }}</td>
          <td>{{ !empty($p['laterality']) ? __('medsurgery::lang.laterality_' . $p['laterality']) : '—' }}</td>
        </tr>
      @empty
        <tr><td colspan="3" class="text-muted">—</td></tr>
      @endforelse
    </tbody>
  </table>
</div>
