<div class="mt-3 p-3 border-top min-height-500px" id="note-sign-confirmation-{{$note->id}}">
    <p class="mb-2 font-weight-bold font-size-13 text-secondary">Visit Information</p>
    <div class="pl-3 border-left">
        <div class="mb-2 d-flex align-items-baseline">
            <span class="width-150px">New or Follow-up visit:</span>
            @if($note->new_or_fu_or_na === "NEW")
                <b class="mr-3 width-70px">New</b>
                <div moe relative>
                    <a href="#" start show>Change to <b>Follow-up</b></a>
                    <form url="/api/note/updateNewOrFuOrNa">
                        <p class="text-nowrap">Change to <b>Follow-up</b> visit?</p>
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <input type="hidden" name="newOrFuOrNa" value="FU">
                        <div class="mb-0">
                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                        </div>
                    </form>
                </div>
            @elseif($note->new_or_fu_or_na === "FU")
                <b class="mr-3 width-70px">Follow-up</b>
                <div moe relative>
                    <a href="#" start show>Change to <b>New</b></a>
                    <form url="/api/note/updateNewOrFuOrNa">
                        <p class="text-nowrap">Change to <b>New</b> visit?</p>
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <input type="hidden" name="newOrFuOrNa" value="NEW">
                        <div class="mb-0">
                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                        </div>
                    </form>
                </div>
            @endif
        </div>
        <div class="mb-2 d-flex align-items-baseline">
        <span class="width-150px">Visit Method:</span>
        @if(!!$note->method)
            <b class="mr-3 text-capitalize width-70px">{{noteMethodDisplay($note->method)}}</b>
        @else
            <span class="mr-3 text-danger width-70px">(not set)</span>
        @endif
        <div moe relative>
            <a href="" show start>Change</a>
            <form url="/api/note/updateMethod">
                <input type="hidden" name="uid" value="{{$note->uid}}">
                <div class="mb-2">
                    <select name="method" class="form-control form-control-sm note-method-select" required>
                        <option value="AUDIO" {{ $note->method === "AUDIO" ? "selected" : "" }}>Audio</option>
                        <option value="VIDEO" {{ $note->method === "VIDEO" ? "selected" : "" }}>Video</option>
                        <option value="IN_CLINIC" {{ $note->method === "IN_CLINIC" ? "selected" : "" }}>In-Clinic</option>
                        <option value="HOUSE_CALL" {{ $note->method === "HOUSE_CALL" ? "selected" : "" }}>House Call</option>
                    </select>
                </div>
                <div class="form-group if-in-clinic">
                    <label for="" class="text-secondary text-sm mb-1">Location</label>
                    <select name="hcpCompanyLocationUid" class="form-control">
                        <option value=""></option>
                        @foreach($note->hcpPro->companyLocations() as $location)
                            <option value="{{$location->uid}}" {{$location->id === $note->hcp_company_location_id ? 'selected' : ''}}>{{$location->line1}} {{$location->city}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="mb-0">
                    <button class="btn btn-primary btn-sm" submit>Submit</button>
                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                </div>
            </form>
        </div>
    </div>
        <div class="mb-2 d-flex align-items-baseline">
            <span class="width-150px">Visit Date:</span>
            @if(!!$note->effective_dateest)
                <b class="mr-3 text-capitalize width-70px">{{friendly_date_time($note->effective_dateest, false, '')}}</b>
            @else
                <span class="mr-3 text-danger width-70px">(not set)</span>
            @endif
            <div moe relative>
                <a href="" show start>Change</a>
                <form url="/api/note/putEffectiveDateEST">
                    <input type="hidden" name="uid" value="{{$note->uid}}">
                    <div class="mb-2">
                        <label for="" class="text-secondary text-sm">Effective date EST</label>
                        <input type="date" name="effectiveDateEST" value="{{$note->effective_dateest}}" class="form-control form-control-sm">
                    </div>
                    <div class="mb-0">
                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                    </div>
                </form>
            </div>
        </div>
    </div>


    {{-- rpm time entry --}}
    <?php
    // resolve care month from the effective date of this note
    $cmStartDate = date('Y-m-01', strtotime($note->effective_dateest));
    $careMonth = \App\Models\CareMonth::where('client_id', $note->client->id)->where('start_date', $cmStartDate)->first();
    ?>
    @if($careMonth && $careMonth->is_client_enrolled_in_rm)
        <div class="p-3 mt-3 border bg-aliceblue">
            <p class="mb-2">Did you review the patient's remote measurements and/or had communication regarding RPM during this visit? If yes, please add a time entry to cover the same (if you have not already done it).</p>
            <div class="d-flex align-items-center">
                <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px"><span class="text-secondary">RPM time billed:</span> {{time_in_hrminsec($careMonth->rm_total_time_in_seconds_by_mcp)}}</h6>
                <?php
                $rmBills = $careMonth->getBillsOfType('RM');
                $activeRMBill = false;
                foreach ($rmBills as $rmBill) {
                    if(!$rmBill->is_cancelled && $careMonth->rm_bill_id === $rmBill->id) {
                        $activeRMBill = $rmBill;
                        break;
                    }
                }
                ?>
                <span class="mx-2 text-secondary">|</span>
                @include('app.practice-management.care_month_add_entry_form', [
                    'right' => false,
                    'defaultDate' => $note->effective_dateest,
                    'defaultSeconds' => 120,
                    'defaultInteracted' => true,
                    'defaultComment' => 'I have discussed remote monitoring data to date and encouraged patient to regularly measure and follow the care plan.'
                    ])
            </div>
        </div>
    @endif

    {{-- claim icds --}}

    <?php
    $claimICDData = [
    	'icd_1' => [
    		'title' => 'ICD 1',
    		'reason' => $note->note_reason_icd1,
    		'description' => $note->note_reason_icd1description,
    	],
    	'icd_2' => [
    		'title' => 'ICD 2',
    		'reason' => $note->note_reason_icd2,
    		'description' => $note->note_reason_icd2description,
    	],
    	'icd_3' => [
    		'title' => 'ICD 3',
    		'reason' => $note->note_reason_icd3,
    		'description' => $note->note_reason_icd3description,
    	],
    	'icd_4' => [
    		'title' => 'ICD 4',
    		'reason' => $note->note_reason_icd4,
    		'description' => $note->note_reason_icd4description,
    	],
    ];
    ?>
    <?php $emptyClaimICDs = true; ?>
    @foreach($claimICDData as $rmKey=>$rmData)
      <?php
      $emptyICD = true;
      if (!empty($rmData['reason']) || !empty($rmData['description'])) {
        $emptyClaimICDs = false;
        $emptyICD = false;
      }
      ?>
    @endforeach
    @if($emptyClaimICDs)
      <div class="alert alert-danger px-3 mt-3">
        Please ensure you have specified ICD codes relevant to this note before signing.
      </div>
    @else
      {{-- fu appt --}}
      <div class="px-3 pt-3 mt-3 border bg-aliceblue">
        @include('app/patient/note/follow-up-appointment', ['noMinHeight' => true])
      </div>
    @endif




    {{-- get problems(plan) and medications(plan) segments --}}
    <?php
    $problemsPlan = null;
    $medicationsPlan = null;
    foreach($note->segments as $segment) {
        if($segment->segmentTemplate->internal_name === 'plan_problems') {
            $problemsPlan = $segment;
        }
        if($segment->segmentTemplate->internal_name === 'plan_medications') {
            $medicationsPlan = $segment;
        }
        if($problemsPlan && $medicationsPlan) break;
    }
    ?>
    @if($problemsPlan)
        <hr class="m-neg-3">
        <p class="mb-2 font-weight-bold font-size-13 text-secondary">Problems (Plan)</p>
        <div class="pl-3 border-left">
            <div>{!! $problemsPlan->summary_html !!}</div>
        </div>
    @endif
    @if($problemsPlan)
        <hr class="m-neg-3">
        <p class="mb-2 font-weight-bold font-size-13 text-secondary">Medications (Plan)</p>
        <div class="pl-3 border-left">
            <div>{!! $medicationsPlan->summary_html !!}</div>
        </div>
    @endif

    @if(!is_null($note->is_follow_up_needed))
        <hr class="m-neg-3">
        <p class="my-3">After signing - you will not be able to modify content. You may only add addendums.</p>

        <div class="d-flex align-items-center justify-content-center">
            <button class="btn btn-success btn-sm font-weight-bold px-3 btn-sign">Sign</button>
            <button class="ml-3 btn btn-default border btn-sm px-3" onclick="return closeStagPopup()">Close</button>
        </div>
    @endif

</div>

<script>
    (function() {

        function init() {

            /*let blockSigningMarker = $('.relevant-without-review-critical[data-target-segment]').first();
            if(blockSigningMarker.length) {
                toastr.error('A relevant problem does not contain an updated HPI/Subjective.');
                closeStagPopup(true);
                $('.note-tree-node [data-segment-internal-name="' + blockSigningMarker.attr('data-target-segment') + '"]').trigger('click');
                return false;
            }*/

            $('#note-sign-confirmation-{{$note->id}} .btn-sign')
                .off('click')
                .on('click', function() {
                    $.post('/api/note/signAsHcp', {uid: '{{$note->uid}}'}, _data => {
                        if(!hasResponseError(_data)) {
                            toastr.success('Note signed');
                            closeStagPopup();
                            fastReload();
                        }
                    }, 'json');
                    return false;
                });

            runMCInitializer('icd-autocomplete');

            @if($careMonth && $careMonth->is_client_enrolled_in_rm)
            initMoes();
            initProSuggest();
            $('#note-sign-confirmation-{{$note->id}}').find('[cm-rte]').each(function() {

                $(this).wrap(
                    $('<div class="border-left border-right rte-holder"/>')
                        .attr('data-shortcuts', '')
                );

                // give a unique id to this editor instance
                var editorID = Math.ceil(Math.random() * 99999), fieldName = $(this).attr('data-name');

                var el = this;
                var existingContent = $(el).attr('data-content') ? $(el).attr('data-content') : $(el).html();
                var quill = new Quill(el, {
                    theme: 'snow',
                    modules: stagQuillConfig
                });

                var toolbar = $(quill.container).prev('.ql-toolbar');

                // add button for new shortcut
                var newSCButton = $('<button class="btn bg-white btn-sm btn-default text-primary w-auto px-2 border py-0 ' +
                    'text-sm add-shortcut" data-editor-id="' + editorID + '">+ Shortcut</button>');
                toolbar.append(newSCButton);

                quill.root.innerHTML = existingContent;

                $('<input type="hidden" name="' + fieldName + '">').val(existingContent).insertAfter(el);

                quill.on('text-change', function(delta, oldDelta, source) {
                    $(el).next('[name="' + fieldName + '"]').val(quill.root.innerHTML);
                });

                $(quill.container)
                    .find('.ql-editor[contenteditable]')
                    .attr('data-field', fieldName)
                    .attr('data-editor-id', editorID)
                    .attr('with-shortcuts', 1);

            });
            @endif
        }

        addMCInitializer('note-sign-confirmation-{{$note->id}}', init, '#note-sign-confirmation-{{$note->id}}')

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