@extends('layouts.app')
@section('title', __('medsurgery::lang.new_case'))
@section('content')
<section class="content-header"><h1>@lang('medsurgery::lang.new_case')</h1></section>
<section class="content">
  <form action="{{ route('medsx.cases.store') }}" method="POST">
    {{ csrf_field() }}
    @component('components.widget', ['class' => 'box-primary', 'title' => __('medsurgery::lang.overview')])
      @if(empty($patients))
        <div class="callout callout-warning">@lang('medsurgery::lang.no_patients')</div>
      @endif
      <div class="row">
        <div class="col-md-6 form-group">
          <label>@lang('medsurgery::lang.patient') *</label>
          <select name="patient_id" class="form-control" required>
            <option value="">@lang('medsurgery::lang.select_patient')</option>
            @foreach($patients as $pid => $pname)
              <option value="{{ $pid }}" @selected(old('patient_id') == $pid)>{{ $pname }}</option>
            @endforeach
          </select>
        </div>
        <div class="col-md-3 form-group">
          <label>@lang('medsurgery::lang.priority') *</label>
          <select name="priority" class="form-control" required>
            @foreach($priorities as $p)
              <option value="{{ $p }}" @selected(old('priority', 'elective') === $p)>@lang('medsurgery::lang.priority_' . $p)</option>
            @endforeach
          </select>
        </div>
        <div class="col-md-3 form-group">
          <label>@lang('medsurgery::lang.appointment_id')</label>
          <input type="number" name="appointment_id" class="form-control" value="{{ old('appointment_id') }}">
        </div>
      </div>

      <div class="row">
        <div class="col-md-6 form-group">
          <label>@lang('medsurgery::lang.surgeon')</label>
          <select name="primary_surgeon_id" class="form-control">
            <option value="">@lang('medsurgery::lang.none')</option>
            @foreach($doctors as $did => $dname)
              <option value="{{ $did }}" @selected(old('primary_surgeon_id') == $did)>{{ $dname }}</option>
            @endforeach
          </select>
        </div>
        <div class="col-md-3 form-group">
          <label>@lang('medsurgery::lang.asa_class')</label>
          <input type="number" name="asa_class" class="form-control" min="1" max="6" value="{{ old('asa_class') }}">
        </div>
        <div class="col-md-3 form-group">
          <label>@lang('medsurgery::lang.anesthesia_type')</label>
          <select name="anesthesia_type" class="form-control">
            <option value="">@lang('medsurgery::lang.none')</option>
            @foreach($anesthesiaTypes as $a)
              <option value="{{ $a }}" @selected(old('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.or_room')</label>
          <select name="or_room_id" class="form-control">
            <option value="">@lang('medsurgery::lang.none')</option>
            @foreach($rooms as $rid => $rname)
              <option value="{{ $rid }}" @selected(old('or_room_id') == $rid)>{{ $rname }}</option>
            @endforeach
          </select>
          @if(empty($rooms))
            <p class="help-block text-warning">@lang('medsurgery::lang.no_or_rooms_hint')</p>
          @endif
        </div>
        <div class="col-md-2 form-group">
          <label>@lang('medsurgery::lang.scheduled_date')</label>
          <input type="date" name="scheduled_date" class="form-control" value="{{ old('scheduled_date') }}">
        </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" value="{{ old('scheduled_start') }}">
        </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" value="{{ old('scheduled_end') }}">
        </div>
      </div>

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

      <label>@lang('medsurgery::lang.procedures')</label>
      <table class="table table-condensed table-bordered">
        <thead><tr>
          <th>@lang('medsurgery::lang.procedure_name')</th>
          <th style="width:160px;">@lang('medsurgery::lang.cpt_code')</th>
          <th style="width:160px;">@lang('medsurgery::lang.laterality')</th>
          <th style="width:40px;"></th>
        </tr></thead>
        <tbody id="medsx_proc_rows">
          <tr class="medsx-row">
            <td><input type="text" name="procedures[0][name]" class="form-control input-sm"></td>
            <td><input type="text" name="procedures[0][cpt_code]" class="form-control input-sm"></td>
            <td>
              <select name="procedures[0][laterality]" class="form-control input-sm">
                @foreach($lateralities as $l)
                  <option value="{{ $l }}">@lang('medsurgery::lang.laterality_' . $l)</option>
                @endforeach
              </select>
            </td>
            <td><button type="button" class="btn btn-xs btn-danger medsx-row-del"><i class="fa fa-times"></i></button></td>
          </tr>
        </tbody>
      </table>
      <button type="button" class="btn btn-xs btn-default medsx-row-add"
        data-template="tpl_procedure" data-target="#medsx_proc_rows">
        <i class="fa fa-plus"></i> @lang('medsurgery::lang.add')
      </button>

      <div style="margin-top:16px;">
        <button type="submit" class="btn btn-primary">@lang('medsurgery::lang.save')</button>
        <a href="{{ route('medsx.cases.index') }}" class="btn btn-default">@lang('medsurgery::lang.cancel')</a>
      </div>
    @endcomponent
  </form>

  <script type="text/template" id="tpl_procedure">
    <tr class="medsx-row">
      <td><input type="text" name="procedures[__IDX__][name]" class="form-control input-sm"></td>
      <td><input type="text" name="procedures[__IDX__][cpt_code]" class="form-control input-sm"></td>
      <td>
        <select name="procedures[__IDX__][laterality]" class="form-control input-sm">
          @foreach($lateralities as $l)
            <option value="{{ $l }}">@lang('medsurgery::lang.laterality_' . $l)</option>
          @endforeach
        </select>
      </td>
      <td><button type="button" class="btn btn-xs btn-danger medsx-row-del"><i class="fa fa-times"></i></button></td>
    </tr>
  </script>
</section>
@endsection
@section('javascript')
@include('medsurgery::partials.scripts')
@endsection
