<div class="mt-3 p-3 border-top" id="rpm-agreement-{{$note->id}}">
    <p class="mb-3">I understand that:</p>

    <form action="/nop" method="post" id="rpm-agreement-form">

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-1" required></div>
            <span>I am the only person who should be using the remote monitoring equipment as instructed. I will not use the equipment for reasons other than health monitoring.</span>
        </label>

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-2" required></div>
            <span>I will not tamper with the equipment. I understand that I am responsible for any fees associated with misuse of the equipment.</span>
        </label>

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-3" required></div>
            <span>I understand the equipment is only designed for the Wellness at Home program and not designed for, intended or permitted for use on the Internet.</span>
        </label>

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-4" required></div>
            <span>The equipment is meant to monitor symptoms and vitals only. It is NOT AN EMERGENCY RESPONSE unit. Call 911 for immediate medical emergencies.</span>
        </label>

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-5" required></div>
            <span>My data and medical information obtained from my participation in the RPM program may/may not be considered part of my patient record, but may be shared with other health care professionals to enhance my care and I authorize such professional disclosure. My data and information will be securely transmitted data and reviewed at the clinician’s discretion.</span>
        </label>

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-6" required></div>
            <span>I will comply with the RPM program clinical expectations and if I don’t, I may be removed from the RPM program and I will return the RPM equipment.</span>
        </label>

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-7" required></div>
            <span>I have the right to withdraw my consent to participate in the RPM program and stop receiving RPM Services at any time by returning the equipment.</span>
        </label>

        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-8" required></div>
            <span>I agree to participate in the Chronic Care Management program.</span>
        </label>
        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-9" required></div>
            <span>I understand that CCM involves a combination of face-to-face and non-face-to-face services to ensure that my healthcare needs are met.</span>
        </label>
        <label class="d-flex align-items-baseline mb-3">
            <div class="mr-2 align-self-stretch" style="padding-top: 2px;"><input type="checkbox" name="rpm-agreement-10" required></div>
            <span>I understand that I can revoke my participation in CCM at anytime.</span>
        </label>
    </form>

    <?php $patient = $note->client; ?>

    <div class="border rounded p-3 mb-3 max-width-500px" id="rpm-agreement-reasons-{{$note->id}}">
        <div class="d-flex align-items-center mb-2">
            <p class="mb-0 mr-2"><b>RM Reasons</b></p>
            <div>@include('app.patient.partials.put-rm-reasons', ['recordType' => 'CLIENT', 'record' => $patient])</div>
        </div>
        <div class="max-width-500px">
            <div>
                @include('app.patient.partials.rm-reasons-display', ['recordType' => 'CLIENT', 'record' => $patient])
            </div>
            {{--<div>
                @if(!$patient->rmReasons || !count($patient->rmReasons))
                    <span class="text-secondary d-block mb-2">None</span>
                @else
                    <div>
                        @foreach($patient->rmReasons as $reason)
                            <div class="border-bottom pb-1 mb-1 d-flex align-items-start">
                                <b class="min-width-70px">{{$reason->code}}</b>
                                <span class="max-width-200px mr-3">{{$reason->description}}</span>
                                <div moe relative class="ml-auto">
                                    <a start show><i class="fa fa-edit"></i></a>
                                    <form url="/api/clientCmRmReason/updateBasic" class="mcp-theme-1" right target="#rpm-agreement-reasons-{{$note->id}}">
                                        <input type="hidden" name="uid" value="{{$reason->uid}}">
                                        <div class="mb-2">
                                            <label class="text-sm mb-1 text-secondary">Code *</label>
                                            <input type="text" class="form-control form-control-sm"
                                                icd-autocomplete-code
                                                name="code" value="{{$reason->code}}" required>
                                        </div>
                                        <div class="mb-2">
                                            <label class="text-sm mb-1 text-secondary">Description</label>
                                            <input type="text" class="form-control form-control-sm"
                                                icd-autocomplete-description
                                                name="description" value="{{$reason->description}}">
                                        </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>
                                <div moe relative class="ml-2">
                                    <a start show><i class="fa fa-trash-alt text-danger on-hover-opaque"></i></a>
                                    <form url="/api/clientCmRmReason/remove" class="mcp-theme-1" right target="#rpm-agreement-reasons-{{$note->id}}">
                                        <input type="hidden" name="uid" value="{{$reason->uid}}">
                                        <p>Remove this RM reason?</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>
                            </div>
                        @endforeach
                    </div>
                @endif
            </div>--}}
            {{--
            <div class="d-flex align-items-baseline">
                <div moe>
                    <a start show>+ Add From Dx</a>
                    <form url="/api/clientCmRmReason/create" class="mcp-theme-1" target="#rpm-agreement-reasons-{{$note->id}}">
                        <input type="hidden" name="clientUid" value="{{$patient->uid}}">
                        <input type="hidden" name="cmOrRm" value="RM">
                        <input type="hidden" name="code" value="">
                        <input type="hidden" name="description" value="">
                        <div class="mb-2">
                            <label class="text-sm mb-1 text-secondary">Reason *</label>
                            <select type="text" class="form-control form-control-sm problem-select" name="problem" required>
                                <?php $problems = \App\Models\Point::getPointsOfCategory($patient, "PROBLEM"); ?>
                                <option value="">-- select --</option>
                                @foreach($problems as $problem)
                                    @if(!!@($problem->data->icd))
                                        <option value="{{$problem->uid}}" data-icd="{{$problem->data->icd}}" data-name="{{$problem->data->name}}">{{$problem->data->icd}} - {{$problem->data->name}}</option>
                                    @endif
                                @endforeach
                            </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>
                <span class="mx-2 text-secondary text-sm">|</span>
                <div moe>
                    <a start show>+ Add New</a>
                    <form url="/api/clientCmRmReason/create" class="mcp-theme-1" target="#rpm-agreement-reasons-{{$note->id}}">
                        <input type="hidden" name="clientUid" value="{{$patient->uid}}">
                        <input type="hidden" name="cmOrRm" value="RM">
                        <div class="mb-2">
                            <label class="text-sm mb-1 text-secondary">Code *</label>
                            <input type="text" class="form-control form-control-sm"
                                   icd-autocomplete-code
                                   name="code" value="" required>
                        </div>
                        <div class="mb-2">
                            <label class="text-sm mb-1 text-secondary">Description</label>
                            <input type="text" class="form-control form-control-sm"
                                   icd-autocomplete-description
                                   name="description" value="">
                        </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>
            </div>
            --}}
        </div>
    </div>

    <hr class="m-neg-3">

    <div class="d-flex align-items-center justify-content-center">
        <button class="btn btn-primary btn-sm font-weight-bold px-3 btn-rpm-agreement-submit">Submit</button>
        <button class="ml-3 btn btn-default border btn-sm px-3" onclick="return closeStagPopup()">Close</button>
    </div>

</div>

<script>
    (function() {

        function init() {

            let parentForm = $('#rpm-agreement-{{$note->id}}');

            parentForm.find('.btn-rpm-agreement-submit')
                .off('click')
                .on('click', function() {
                    let form = parentForm.find('#rpm-agreement-form')[0];
                    if(!form.checkValidity()) {
                        form.reportValidity();
                        return false;
                    }
                    showMask();
                    $.post('/api/client/setIsEnrolledInRmToTrue', {uid: '{{$note->client->uid}}'}, _data => {
                        hideMask();
                        if(!hasResponseError(_data)) {
                            closeStagPopup();
                            fastReload();
                        }
                    }, 'json');
                });

            runMCInitializer('icd-autocomplete');
        }

        addMCInitializer('rpm-agreement-{{$note->id}}', init, '#rpm-agreement-{{$note->id}}')

    }).call(window);
</script>