{{-- Pre-authorisation create/edit modal form. --}}
@php $isEdit = $preAuth->exists; @endphp
<div class="modal-dialog" role="document">
  <div class="modal-content">
    <form class="medbill-form"
        action="{{ $isEdit ? route('medbill.preauth.update', $preAuth->id) : route('medbill.preauth.store') }}"
        method="POST">
      {{ csrf_field() }}
      @if($isEdit) {{ method_field('PUT') }} @endif
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">{{ $isEdit ? __('medbilling::lang.edit_preauth') : __('medbilling::lang.add_preauth') }}</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-6 form-group">
            <label>@lang('medbilling::lang.patient') *</label>
            <select name="patient_id" class="form-control" required>
              <option value="">—</option>
              @foreach($patients as $id => $name)
                <option value="{{ $id }}" @selected((int) $preAuth->patient_id === (int) $id)>{{ $name }}</option>
              @endforeach
            </select>
          </div>
          <div class="col-md-6 form-group">
            <label>@lang('medbilling::lang.payer') *</label>
            <select name="payer_id" class="form-control" required>
              <option value="">—</option>
              @foreach($payers as $id => $name)
                <option value="{{ $id }}" @selected((int) $preAuth->payer_id === (int) $id)>{{ $name }}</option>
              @endforeach
            </select>
          </div>
        </div>
        <div class="form-group">
          <label>@lang('medbilling::lang.policy') *</label>
          <select name="policy_id" class="form-control" required>
            <option value="">—</option>
            @foreach($policies as $id => $label)
              <option value="{{ $id }}" @selected((int) $preAuth->policy_id === (int) $id)>{{ $label }}</option>
            @endforeach
          </select>
        </div>
        <div class="form-group">
          <label>@lang('medbilling::lang.service_description') *</label>
          <input type="text" name="service_description" class="form-control" required value="{{ $preAuth->service_description }}">
        </div>
        <div class="row">
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.requested_amount')</label>
            <input type="number" step="0.0001" min="0" name="requested_amount" class="form-control" value="{{ $preAuth->requested_amount }}">
          </div>
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.status') *</label>
            <select name="status" class="form-control" required>
              @foreach(['requested','approved','denied','expired'] as $st)
                <option value="{{ $st }}" @selected(($preAuth->status ?? 'requested') === $st)>@lang('medbilling::lang.preauth_status_' . $st)</option>
              @endforeach
            </select>
          </div>
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.valid_until')</label>
            <input type="date" name="valid_until" class="form-control" value="{{ optional($preAuth->valid_until)->format('Y-m-d') }}">
          </div>
        </div>
        <div class="form-group">
          <label>@lang('medbilling::lang.auth_no')</label>
          <input type="text" name="auth_no" class="form-control" value="{{ $preAuth->auth_no }}">
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">@lang('medbilling::lang.cancel')</button>
        <button type="submit" class="btn btn-primary">@lang('medbilling::lang.save')</button>
      </div>
    </form>
  </div>
</div>
