<div class="row" id="rm-setup">
    <div class="col-12">
        <div class="mb-2">
            <div class="d-flex flex-wrap">
                <div class="d-flex align-items-center">
                    <span class="mr-2 text-secondary">Eligible for RM?</span>
                    <span class="mr-1">{{ ucwords($patient->is_eligible_for_rm ? $patient->is_eligible_for_rm : '-') }}</span>
                    <div moe class="">
                        <a start show><i class="fa fa-edit on-hover-opaque"></i></a>
                        <form url="/api/client/updateRmEligibility" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            @if($patient->is_enrolled_in_rm == 'YES')
                              <div class="alert alert-info p-1 mb-1">
                                Patient is currently enrolled in RPM. Un-enroll the patient to make changes.
                              </div>
                            @endif
                            <div class="mb-2">
                                <label class="text-sm mb-1 text-secondary">Is Eligible?</label>
                                <select name="isEligibleForRm"
                                        class="form-control form-control-sm"
                                        {{$patient->is_enrolled_in_rm === 'YES' ? 'disabled' : '' }}
                                        onchange="toggleDisabledAsNeeded(this, 'NO', 'not-eligible-for-rm')">
                                    <option value="">-- Select Status --</option>
                                    <option value="YES" {{ $patient->is_eligible_for_rm === 'YES' ? 'selected' : '' }}>YES</option>
                                    <option value="NO" {{ $patient->is_eligible_for_rm === 'NO' ? 'selected' : '' }}>NO</option>
                                    <option value="UNKNOWN" {{ $patient->is_eligible_for_rm === 'UNKNOWN' ? 'selected' : '' }}>UNKNOWN</option>
                                </select>
                            </div>
                            <div class="mb-2">
                                <label class="text-sm mb-1 text-secondary">Why not eligible category</label>
                                <input type="text" class="not-eligible-for-rm form-control form-control-sm"
                                    {{$patient->is_eligible_for_rm === 'NO' ? '' : 'disabled' }}
                                    name="whyNotEligibleForRmCategory" value="{{$patient->why_not_eligible_for_rm_category}}">
                            </div>
                            <div class="mb-2">
                                <label class="text-sm mb-1 text-secondary">Why not eligible memo</label>
                                <input type="text" class="not-eligible-for-rm form-control form-control-sm"
                                    {{$patient->is_eligible_for_rm === 'NO' ? '' : 'disabled' }}
                                    name="whyNotEligibleForRmMemo" value="{{$patient->why_not_eligible_for_rm_memo}}">
                            </div>
                            <div>
                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                            </div>
                        </form>
                    </div>
                    @if($patient->is_eligible_for_rm === 'NO')
                    <span class="ml-1 on-hover-show d-inline-block on-hover-opaque">
                        <i class="fa fa-info-circle"></i>
                        <div class="on-hover-content py-2 pl-3 text-nowrap text-dark" style="left:0;right:auto;">
                            <div>
                                <small class="text-sm"><b>Category:</b> {{$patient->why_not_eligible_for_rm_category ?: '-'}}</small>
                            </div>
                            <div>
                                <small class="text-sm"><b>Memo:</b> {{$patient->why_not_eligible_for_rm_memo ?: '-'}}</small>
                            </div>
                        </div>
                    </span>
                    @endif
                </div>
                <span class="text-secondary mx-2">|</span>

                <div class="d-flex align-items-center">
                    <span class="mr-1 text-secondary">Enrollment:</span>
                    <span>{{ ucwords($patient->is_enrolled_in_rm ? $patient->is_enrolled_in_rm : '-') }}</span> {{-- correct --}}
                    @if($patient->is_enrolled_in_rm === 'NO' && $patient->why_not_enrolled_in_rm_category) {{-- correct --}}
                        <span class="text-sm ml-2">({{$patient->why_not_enrolled_in_rm_category}})</span>
                    @endif

                    <span class="ml-2 text-secondary">|</span>
                    <div moe class="ml-2">
                        <a start show>{{$patient->is_enrolled_in_rm === 'YES' ? 'Un-enroll' : ($patient->is_enrolled_in_rm === 'NO' ? 'Edit Reason' : 'Not interested/other')}}</a> {{-- correct --}}
                        <form url="/api/client/setIsEnrolledInRmToFalse" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <p class="mb-2 text-nowrap">
                                {{$patient->is_enrolled_in_rm === 'YES' ? 'Mark as not enrolled' : ($patient->is_enrolled_in_rm === 'NO' ? 'Edit Reason' : 'Not interested/other')}} {{-- correct --}}
                            </p>
                            <div class="mb-2">
                                <label class="text-secondary text-sm mb-1">Reason</label>
                                <select name="whyNotEnrolledInRmCategory" class="form-control" required>
                                    <option value="">-- select --</option>
                                    <option {{$patient->why_not_enrolled_in_rm_category === 'Withdrawn' ? 'selected' : ''}} value="Withdrawn">Withdrawn</option>
                                    <option {{$patient->why_not_enrolled_in_rm_category === 'Inactive' ? 'selected' : ''}} value="Inactive">Inactive</option>
                                    <option {{$patient->why_not_enrolled_in_rm_category === 'Entry Error' ? 'selected' : ''}} value="Entry Error">Entry Error</option>
                                    <option {{$patient->why_not_enrolled_in_rm_category === 'Test Chart' ? 'selected' : ''}} value="Test Chart">Test Chart</option>
                                    <option {{$patient->why_not_enrolled_in_rm_category === 'Deceased' ? 'selected' : ''}} value="Deceased">Deceased</option>
                                    <option {{$patient->why_not_enrolled_in_rm_category === 'No Longer Eligible' ? 'selected' : ''}} value="No Longer Eligible">No Longer Eligible</option>
                                </select>
                            </div>
                            <div class="mb-2">
                                <label class="text-secondary text-sm mb-1">Memo</label>
                                <textarea type="text" name="whyNotEnrolledInRmMemo" class="form-control">{{$patient->why_not_enrolled_in_rm_memo}}</textarea>
                            </div>
                            <div>
                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                            </div>
                        </form>
                    </div>

                    @if(!$patient->is_enrolled_in_rm || $patient->is_enrolled_in_rm === 'NO' || $patient->is_enrolled_in_rm === 'UNKNOWN') {{-- correct --}}
                      <?php
                      $rmDisplayData = [
                        'icd_1' => [
                          'title' => 'ICD 1',
                          'reason' => $patient->rm_reason_icd1,
                          'description' => $patient->rm_reason_icd1description
                        ],
                        'icd_2' => [
                          'title' => 'ICD 2',
                          'reason' => $patient->rm_reason_icd2,
                          'description' => $patient->rm_reason_icd2description
                        ],
                        'icd_3' => [
                          'title' => 'ICD 3',
                          'reason' => $patient->rm_reason_icd3,
                          'description' => $patient->rm_reason_icd3description
                        ],
                        'icd_4' => [
                          'title' => 'ICD 4',
                          'reason' => $patient->rm_reason_icd4,
                          'description' => $patient->rm_reason_icd4description
                        ],
                      ];
                      ?>
                      <?php $emptyICDs = true; ?>
                      @foreach($rmDisplayData as $rmKey=>$rmData)
                      <?php
                      $emptyICD = true;
                      if (!empty($rmData['reason']) || !empty($rmData['description'])) {
                        $emptyICDs = false;
                        $emptyICD = false;
                      }
                      ?>
                      @endforeach
                        <span class="ml-2 text-secondary">|</span>
                        <div moe wide class="ml-2">
                            <a start show>Enroll</a>
                            @if($emptyICDs)
                            <form url="" class="mcp-theme-1">
                              <div class="text-danger p-1 mb-0">
                                Please specify relevant RM reason(s) before enrolling the patient.
                              </div>
                            </form>
                            @else
                            <form url="/api/client/setIsEnrolledInRmToTrue" class="mcp-theme-1">
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <h2 class="font-weight-bold">RPM Enrollment:</h2>
                                <h3>Please confirm the following with patient:</h3>
                                <p class="mb-2">I understand that:</p>
                                <ul style="list-style:none;" class="pl-2">
                                    <li class="d-flex mb-1 align-items-start">
                                        <input type="checkbox" required="true" class="mt-1 mr-2" id="x" name="x">
                                        <label class="c-pointer" for="x">I am the only person who should be using the remote monitoring equipment as instructed. I will
                                            not use the device for reasons other than my own personal health monitoring. I understand that
                                            I can only participate in this program with one Medical Provider at a time.</label>
                                    </li>
                                    <li class="d-flex mb-1 align-items-start">
                                        <input type="checkbox" required="true" class="mt-1 mr-2" id="y" name="y">
                                        <label class="c-pointer" for="y">I will not tamper with the equipment. I understand that I am responsible for any fees associated
                                            with misuse of the equipment.</label>
                                    </li>
                                    <li class="d-flex mb-1 align-items-start">
                                        <input type="checkbox" required="true" class="mt-1 mr-2" id="z" name="z">
                                        <label class="c-pointer" for="z">I understand the devices are only designed for the RPM program.</label>
                                    </li>
                                </ul>
                                <div class="mb-2">
                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                </div>
                            </form>
                            @endif
                        </div>
                    @endif
                </div>
            </div>

        </div>

        <div class="d-flex align-items-baseline mb-1">
            <div class="flex-grow-1">
                <div>
                    <div class="d-flex align-items-center mb-1">
                        <span class="mr-2 text-secondary">RM Reasons:</span>
                        @include('app.patient.partials.put-rm-reasons', ['recordType' => 'CLIENT', 'record' => $patient])
                    </div>
                    <div class="pl-3">
                        @include('app.patient.partials.rm-reasons-display', ['recordType' => 'CLIENT', 'record' => $patient])
                    </div>
                </div>
            </div>
        </div>
        @if(@$note)
          <div class="my-2">
            @include('app.patient.note.partials.care-plan-details')
          </div>
        @endif



        @if($pro->pro_type === 'ADMIN')
            <div class="d-flex align-items-start mb-2">
              <div class="d-flex mr-3">
                <div class="text-secondary">
                  RME Pro:
                </div>
                <div class="">
                  <div class="d-inline-flex align-items-start">
                    <b>{{ $patient->rme ? $patient->rme->displayName() : '-' }}</b>
                    @if(!$patient->rme)
                    <div moe class="ml-2">
                      <a start show><i class="fa fa-edit on-hover-opaque"></i></a>
                      <form url="/api/client/putRmePro" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$patient->uid}}">
                        <div class="mb-2">
                          <label class="text-secondary text-sm">RME Pro</label>
                          <select provider-search data-pro-uid="{{ @$patient->rme->uid }}" name="rmeProUid" class="form-control form-control-sm">
                            <option value=""> --select--</option>
                          </select>
                        </div>
                        <div>
                          <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                          <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                      </form>
                    </div>
                    @else
                    <div moe class="ml-2">
                      <a start show><i class="fa fa-trash-alt text-danger on-hover-opaque"></i></a>
                      <form url="/api/client/removeRmePro" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$patient->uid}}">
                        <p>Remove RME Pro?</p>
                        <div>
                          <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                          <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                      </form>
                    </div>
                    @endif
                  </div>
                </div>
              </div>
              <div class="d-flex">
                <div class="text-secondary">
                  RMM Pro:
                </div>
                <div class="">
                  <div class="d-inline-flex align-items-start">
                    <b>{{ $patient->rmm ? $patient->rmm->displayName() : '-' }}</b>
                    @if(!$patient->rme)
                    <div moe class="ml-2">
                        <a start show><i class="fa fa-edit on-hover-opaque"></i></a>
                        <form url="/api/client/putRmmPro" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <div class="mb-2">
                                <label class="text-secondary text-sm">RMM Pro</label>
                                <select provider-search data-pro-uid="{{ @$patient->rmm->uid }}" name="rmmProUid" class="form-control form-control-sm">
                                    <option value=""> --select--</option>
                                </select>
                            </div>
                            <div>
                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                            </div>
                        </form>
                    </div>
                    @else
                    <div moe class="ml-2">
                        <a start show><i class="fa fa-trash-alt text-danger on-hover-opaque"></i></a>
                        <form url="/api/client/removeRmmPro" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <p>Remove RMM Pro?</p>
                            <div>
                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                            </div>
                        </form>
                    </div>
                    @endif
                  </div>
                </div>
              </div>
            </div>
        @endif

    </div>

</div>
<script>
    (function () {
        function init() {
            $(document)
                .off('change', '.problem-select')
                .on('change', '.problem-select', function() {
                    let form = $(this).closest('form'),
                        selected = $(this).find('option:selected').first();
                    form.find('[name="code"]').val(selected.attr('data-icd'));
                    form.find('[name="description"]').val(selected.attr('data-name'));
                    return false;
                });
        }
        addMCInitializer('rm-setup', init, '#rm-setup')
    }).call(window);
</script>
