{{-- Post-op tab — findings/complications/specimens/implants (editable in post_op). --}}
<div class="tab-pane" id="tab_postop">
  @unless($isPostOp)
    <div class="callout callout-info">@lang('medsurgery::lang.postop_locked')</div>
  @endunless

  <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="postop">
    @php $ro = $isPostOp ? '' : 'disabled'; @endphp

    <div class="row">
      <div class="col-md-6 form-group">
        <label>@lang('medsurgery::lang.findings')</label>
        <textarea name="findings" class="form-control" rows="3" {{ $ro }}>{{ $case->findings }}</textarea>
      </div>
      <div class="col-md-6 form-group">
        <label>@lang('medsurgery::lang.complications')</label>
        <textarea name="complications" class="form-control" rows="3" {{ $ro }}>{{ $case->complications }}</textarea>
      </div>
    </div>

    <div class="row">
      <div class="col-md-4 form-group">
        <label>@lang('medsurgery::lang.blood_loss')</label>
        <select name="blood_loss" class="form-control" {{ $ro }}>
          <option value="">@lang('medsurgery::lang.none')</option>
          @foreach(\Modules\MedSurgery\Entities\MedsxCase::BLOOD_LOSS as $b)
            <option value="{{ $b }}" @selected($case->blood_loss === $b)>@lang('medsurgery::lang.blood_loss_' . $b)</option>
          @endforeach
        </select>
      </div>
    </div>

    {{-- Specimens --}}
    <label>@lang('medsurgery::lang.specimens')</label>
    <table class="table table-condensed table-bordered">
      <thead><tr>
        <th>@lang('medsurgery::lang.specimen_desc')</th>
        <th>@lang('medsurgery::lang.specimen_sent_to')</th>
        <th>@lang('medsurgery::lang.specimen_lab_no')</th>
        <th style="width:40px;"></th>
      </tr></thead>
      <tbody id="medsx_spec_rows">
        @foreach(($case->specimens ?? []) as $i => $s)
          <tr class="medsx-row">
            <td><input type="text" name="specimens[{{ $i }}][description]" class="form-control input-sm" value="{{ $s['description'] ?? '' }}" {{ $ro }}></td>
            <td><input type="text" name="specimens[{{ $i }}][sent_to]" class="form-control input-sm" value="{{ $s['sent_to'] ?? '' }}" {{ $ro }}></td>
            <td><input type="text" name="specimens[{{ $i }}][lab_number]" class="form-control input-sm" value="{{ $s['lab_number'] ?? '' }}" {{ $ro }}></td>
            <td>@if($isPostOp)<button type="button" class="btn btn-xs btn-danger medsx-row-del"><i class="fa fa-times"></i></button>@endif</td>
          </tr>
        @endforeach
      </tbody>
    </table>
    @if($isPostOp)
      <button type="button" class="btn btn-xs btn-default medsx-row-add" data-template="tpl_specimen" data-target="#medsx_spec_rows">
        <i class="fa fa-plus"></i> @lang('medsurgery::lang.add')
      </button>
    @endif

    {{-- Implants --}}
    <label style="margin-top:12px;">@lang('medsurgery::lang.implants')</label>
    <table class="table table-condensed table-bordered">
      <thead><tr>
        <th>@lang('medsurgery::lang.implant_name')</th>
        <th>@lang('medsurgery::lang.implant_serial')</th>
        <th>@lang('medsurgery::lang.implant_lot')</th>
        <th style="width:40px;"></th>
      </tr></thead>
      <tbody id="medsx_impl_rows">
        @foreach(($case->implants ?? []) as $i => $im)
          <tr class="medsx-row">
            <td><input type="text" name="implants[{{ $i }}][name]" class="form-control input-sm" value="{{ $im['name'] ?? '' }}" {{ $ro }}></td>
            <td><input type="text" name="implants[{{ $i }}][serial]" class="form-control input-sm" value="{{ $im['serial'] ?? '' }}" {{ $ro }}></td>
            <td><input type="text" name="implants[{{ $i }}][lot]" class="form-control input-sm" value="{{ $im['lot'] ?? '' }}" {{ $ro }}></td>
            <td>@if($isPostOp)<button type="button" class="btn btn-xs btn-danger medsx-row-del"><i class="fa fa-times"></i></button>@endif</td>
          </tr>
        @endforeach
      </tbody>
    </table>
    @if($isPostOp)
      <button type="button" class="btn btn-xs btn-default medsx-row-add" data-template="tpl_implant" data-target="#medsx_impl_rows">
        <i class="fa fa-plus"></i> @lang('medsurgery::lang.add')
      </button>
    @endif

    @if($isPostOp)
      <div style="margin-top:16px;">
        <button type="submit" class="btn btn-primary btn-sm">@lang('medsurgery::lang.save_postop')</button>
      </div>
    @endif
  </form>

  {{-- Op-note attach (fail-soft MedDocuments) --}}
  <hr>
  <h5><i class="fa fa-paperclip"></i> @lang('medsurgery::lang.op_note')</h5>
  <form action="{{ route('medsx.cases.opnote', $case->id) }}" method="POST" enctype="multipart/form-data" id="medsx_opnote_form">
    {{ csrf_field() }}
    <div class="row">
      <div class="col-md-6 form-group">
        <input type="file" name="op_note" class="form-control input-sm" required>
      </div>
      <div class="col-md-3">
        <button type="submit" class="btn btn-default btn-sm">@lang('medsurgery::lang.attach_op_note')</button>
      </div>
    </div>
  </form>

  <script type="text/template" id="tpl_specimen">
    <tr class="medsx-row">
      <td><input type="text" name="specimens[__IDX__][description]" class="form-control input-sm"></td>
      <td><input type="text" name="specimens[__IDX__][sent_to]" class="form-control input-sm"></td>
      <td><input type="text" name="specimens[__IDX__][lab_number]" class="form-control input-sm"></td>
      <td><button type="button" class="btn btn-xs btn-danger medsx-row-del"><i class="fa fa-times"></i></button></td>
    </tr>
  </script>
  <script type="text/template" id="tpl_implant">
    <tr class="medsx-row">
      <td><input type="text" name="implants[__IDX__][name]" class="form-control input-sm"></td>
      <td><input type="text" name="implants[__IDX__][serial]" class="form-control input-sm"></td>
      <td><input type="text" name="implants[__IDX__][lot]" class="form-control input-sm"></td>
      <td><button type="button" class="btn btn-xs btn-danger medsx-row-del"><i class="fa fa-times"></i></button></td>
    </tr>
  </script>
</div>
