<table class="table-sm table-bordered v-top">
    <tr>
        <td class="text-secondary">Care Plan:</td>
        <td>
            <div class="{{ $patient->has_care_plan_flag && !$patient->is_flag_cleared ? '':'d-flex' }}">
                <div class="d-inline-flex align-items-center">
                    @if($patient->has_cm_setup_been_performed)
                        <div class="text-nowrap text-success">
                            @if($patient->cm_setup_note_id === $note->id)
                                <i class="fa fa-check"></i>
                                <b>Created on this note</b>
                            @elseif($patient->cmSetupNote)
                                <i class="fa fa-check"></i>
                                <b>Created on</b>
                                <div 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>
                                </div>
                            @else
                                <i class="fa fa-exclamation-triangle text-warning-mellow"></i>
                                <b class="text-warning-mellow">Performed, but CM setup note missing!</b> <!-- will never reach this point -->
                            @endif
                        </div>
                        @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
                            <div moe class="ml-2">
                                <a href="" show start>Undo</a>
                                <form url="/api/note/undoMarkCmSetupPerformed" >
                                    <input type="hidden" name="uid" value="{{$note->uid}}">
                                    <p>Mark Comprehensive Care Plan as not created?</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 Created</b>
                                </span>
                        @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
                            <div moe class="ml-2">
                                <a href="#" show start>Mark as created</a>
                                <form url="/api/note/markCmSetupPerformed" >
                                    <input type="hidden" name="uid" value="{{$note->uid}}">
                                    <p>Mark Comprehensive Care Plan as created?</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>
                @if($pro->pro_type === 'ADMIN' && $patient->has_cm_setup_been_performed && $note->was_cm_setup_performed)
                    <div class="d-flex align-items-baseline">
                        <div class="d-inline-flex align-items-center flex-grow-1 ml-3">
                            <span class="pr-1">Manager Signature:</span>
                            @if($note->cm_setup_manager_signature_status !== 'SIGNED')
                                <div moe class="">
                                    <a start show>Sign</a>
                                    <form url="/api/note/updateCmSetupManagerSignatureStatus" class="mcp-theme-1">
                                        <input type="hidden" name="uid" value="{{$note->uid}}">
                                        <input type="hidden" name="managerSignatureStatus" value="SIGNED">
                                        <p>Sign Off Care Plan Creation as Manager?</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 class="pr-1" title="by: {{$note->cmSetupManagerSignatureStatusUpdatedBySession ? $note->cmSetupManagerSignatureStatusUpdatedBySession->pro->displayName() : ''}} @ {{friendly_date_time($note->cm_setup_manager_signature_status_updated_at)}}">SIGNED</b>
                                <div moe class="">
                                    <a start show>Undo</a>
                                    <form url="/api/note/updateCmSetupManagerSignatureStatus" class="mcp-theme-1">
                                        <input type="hidden" name="uid" value="{{$note->uid}}">
                                        <input type="hidden" name="managerSignatureStatus" value="">
                                        <p>Undo sign as manager for Care Plan Creation?</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>
                    @include('app.patient.note.flag-care-plan')
                @endif
            </div>
        </td>
    </tr>
</table>
