<div class="mb-3 d-flex align-items-baseline">
    <span class="flex-grow-1">Enrollment:</span>
    <div class="width-300px d-inline-flex align-items-center">
        @if($patient->is_enrolled_in_cm === 'YES')
            <span class="text-nowrap text-success">
                <i class="fa fa-check"></i>
                <b>Enrolled</b>
            </span>
            <div moe class="ml-3">
                <a href="" show start>Undo</a>
                <form url="/api/client/setIsEnrolledInCmToFalse" >
                    <input type="hidden" name="uid" value="{{$patient->uid}}">
                    <p>Un-enroll from CCM?</p>
                    <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>
        @else
            <span class="text-nowrap text-warning-mellow">
                                            <i class="fa fa-times"></i>
                                            <b>Not Enrolled</b>
                                        </span>
            @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
                <a native target="_blank"
                   class="screen-only ml-3"
                   update-parent
                   open-in-stag-popup
                   popup-style="medium overflow-visible"
                   mc-initer="ccm-agreement-{{$note->id}}"
                   title="Consent To Chronic Care Management Services"
                   href="/note/ccm-agreement/{{$note->uid}}?popupmode=1">
                    Mark as enrolled
                </a>
            @endif
        @endif
    </div>
</div>

<div class="d-flex align-items-baseline mb-3">
    <span class="flex-grow-1">Reasons:</span>
    <div class="width-300px d-inline-flex align-items-center">
        @if(!$patient->cmReasons || !count($patient->cmReasons))
            <span class="text-secondary">None</span>
        @else
            <div class="w-100">
                @foreach($patient->cmReasons 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 >
                                <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 >
                                <input type="hidden" name="uid" value="{{$reason->uid}}">
                                <p>Remove this CM 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
                @if(!$patient->cmReasons || count($patient->cmReasons) < 2)
                    <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" >
                                <input type="hidden" name="clientUid" value="{{$patient->uid}}">
                                <input type="hidden" name="cmOrRm" value="CM">
                                <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</a>
                            <form url="/api/clientCmRmReason/create" class="mcp-theme-1" >
                                <input type="hidden" name="clientUid" value="{{$patient->uid}}">
                                <input type="hidden" name="cmOrRm" value="CM">
                                <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>
                @endif
            </div>
        @endif
    </div>
</div>

<div class="mb-3 d-flex align-items-baseline">
    <span class="flex-grow-1">Setup:</span>
    <div class="width-300px d-inline-flex align-items-center">
        @if($patient->has_cm_setup_been_performed)
            <span class="text-nowrap text-success">
                @if($patient->cm_setup_note_id === $note->id)
                    <i class="fa fa-check"></i>
                    <b>Performed on this note</b>
                @elseif($patient->cmSetupNote)
                    <i class="fa fa-check"></i>
                    <b>Performed on</b>
                    <span class="d-inline position-relative on-click-menu">
                        <span class="text-primary c-pointer">{{friendly_date($patient->cmSetupNote->effective_dateest)}}</span>
                        <div menu right class="bg-white border">
                            <a native target="_blank"
                               href="<?= route('patients.view.notes.view.dashboard', ['patient' => $patient, 'note' => $patient->cmSetupNote]) ?>"
                               class="px-2 py-1 d-block text-nowrap text-sm">Go to note</a>
                        </div>
                    </span>
                @else
                    <i class="fa fa-exclamation-triangle text-warning-mellow"></i>
                    <b class="text-warning-mellow">Performed, but CM setup note missing!</b>
                @endif
                                        </span>
            @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
                <div moe class="ml-3">
                    <a href="" show start>Undo</a>
                    <form url="/api/note/undoMarkCmSetupPerformed" >
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <p>Mark CCM Setup as not performed?</p>
                        <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
        @else
            <span class="text-nowrap text-warning-mellow">
                <i class="fa fa-times"></i>
                <b>Not Performed</b>
            </span>
            @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
                <div moe class="ml-3">
                    <a href="#" show start>Mark Performed</a>
                    <form url="/api/note/markCmSetupPerformed" >
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <p>Mark CCM Setup as performed?</p>
                        <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
        @endif
    </div>
</div>

@if($pro->id === $patient->mcp_pro_id && $note->was_cm_setup_performed)
    <div class="d-flex align-items-baseline">
        <span class="flex-grow-1"></span>
        <div class="width-300px d-inline-flex align-items-center">
            <span class="pr-2">MCP Signature:</span>
            @if($note->cm_setup_mcp_signature_status !== 'SIGNED')
                <div moe class="">
                    <a start show>Sign</a>
                    <form url="/api/note/updateCmSetupMcpSignatureStatus" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <input type="hidden" name="mcpSignatureStatus" value="SIGNED">
                        <p>Sign CM Setup Performed as MCP?</p>
                        <div>
                            <button submit class="btn btn-sm btn-success mr-1">Sign</button>
                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                    </form>
                </div>
            @else
                <b>SIGNED</b>
                <div moe class="ml-3">
                    <a start show>Undo</a>
                    <form url="/api/note/updateCmSetupMcpSignatureStatus" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <input type="hidden" name="mcpSignatureStatus" value="">
                        <p>Undo sign as MCP for CM Setup Performed?</p>
                        <div>
                            <button submit class="btn btn-sm btn-primary mr-1">Undo</button>
                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                    </form>
                </div>
            @endif
        </div>
    </div>
@endif

@if($pro->id === $patient->default_na_pro_id && $note->was_cm_setup_performed)
    <div class="d-flex align-items-baseline">
        <span class="min-width-140px">Care Coord. Sign.:</span>
        <div class="d-inline-flex align-items-center flex-grow-1">
            @if($note->cm_setup_na_signature_status !== 'SIGNED')
                <div moe class="">
                    <a start show>Sign</a>
                    <form url="/api/note/updateCmSetupNaSignatureStatus" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <input type="hidden" name="naSignatureStatus" value="SIGNED">
                        <p>Sign CM Setup Performed as Care Coordinator?</p>
                        <div>
                            <button submit class="btn btn-sm btn-success mr-1">Sign</button>
                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                    </form>
                </div>
            @else
                <b>SIGNED</b>
                <div moe class="ml-3">
                    <a start show>Undo</a>
                    <form url="/api/note/updateCmSetupNaSignatureStatus" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$note->uid}}">
                        <input type="hidden" name="naSignatureStatus" value="">
                        <p>Undo sign as Care Coordinator for CM Setup Performed?</p>
                        <div>
                            <button submit class="btn btn-sm btn-primary mr-1">Sign</button>
                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                    </form>
                </div>
            @endif
        </div>
    </div>
@endif