<?php
/** @var App\Models\CareMonth $careMonth */
/** @var App\Models\Pro $pro */
?>
@extends ('layouts.patient')

@section('inner-content')

    <?php
    $shortCutsObject = [];
    foreach ($pro->shortcuts as $shortcut) {

        // %replaceables%
        $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
        $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
        $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);

        $shortCutsObject[] = [
            "name" => $shortcut->shortcut,
            "value" => $shortcut->text
        ];
    }
    ?>
    <script>window.userShortcuts = <?= json_encode($shortCutsObject); ?>;</script>

    @if($patient->has_mcp_done_onboarding_visit !== 'YES')
        <div class="pt-2 d-flex align-items-start">
            <h6 class="my-0 text-secondary d-flex align-items-start">
                <a href="/patients/view/{{ $patient->uid }}/care-months" class="small text-decoration-none mr-3">
                    <i class="fa fa-chevron-left"></i>
                </a>
                <div>
                    <div>
                        <span class="text-dark font-weight-bold">Care Month</span>&nbsp;for&nbsp;<span class="text-dark font-weight-bold">{{friendly_month($careMonth->start_date)}}</span>
                    </div>
                    <div class="text-dark d-inline-flex align-items-center mt-2">
                                    <span class="mr-2">
                                        <i class="fa fa-exclamation-triangle"></i>
                                        MCP Onboarding Visit Pending
                                    </span>
                        <div moe>
                            <a start show>Update</a>
                            <form url="/api/client/updateMcpOnboardingVisitInfo" class="mcp-theme-1">
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <div class="mb-2">
                                    <select name="hasMcpDoneOnboardingVisit"
                                            class="form-control form-control-sm"
                                            onchange="toggleDisabledAsNeeded(this, 'YES', 'if-visit-done')">
                                        <option value="">-- Select Status --</option>
                                        <option value="YES" {{ $patient->has_mcp_done_onboarding_visit === 'YES' ? 'selected' : '' }}>YES</option>
                                        <option value="NO" {{ $patient->has_mcp_done_onboarding_visit === 'NO' ? 'selected' : '' }}>NO</option>
                                        <option value="UNKNOWN" {{ $patient->has_mcp_done_onboarding_visit === 'UNKNOWN' ? 'selected' : '' }}>UNKNOWN</option>
                                    </select>
                                </div>
                                <div class="mb-2">
                                    <input type="date" class="if-visit-done form-control form-control-sm" disabled name="mcpOnboardingVisitDate" max="{{ date('Y-m-d') }}">
                                </div>
                                <div class="mb-2">
                                    <select name="mcpOnboardingVisitNoteUid" disabled
                                            class="form-control form-control-sm if-visit-done"
                                            onchange="toggleVisibilityAsNeeded(this, '', 'if-note-outside-system')">
                                        <option value="">-- Visit Note --</option>
                                        @foreach ($notes as $note)
                                            @if(!empty($note->title) && $note->client_id === $patient->id && !$note->is_cancelled)
                                                <option value="{{$note->uid}}">{{$note->title}}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                                <div class="mb-2 if-note-outside-system">
                                                <textarea class="form-control form-control-sm"
                                                          name="reasonOnboardingVisitNoteOutsideSystem"
                                                          placeholder="Visit note outside the system reason"></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>
                    </div>
                </div>
            </h6>
        </div>
    @else

    <div id="care-month-container">
        <div class="pt-2 d-flex align-items-start">
            <h6 class="my-0 text-secondary d-flex align-items-start">
                <a href="/patients/view/{{ $patient->uid }}/care-months" class="small text-decoration-none mr-3">
                    <i class="fa fa-chevron-left"></i>
                </a>
                <div>
                    <div>
                        <span class="text-dark font-weight-bold">Care Month</span>&nbsp;for&nbsp;<span class="text-dark font-weight-bold">{{friendly_month($careMonth->start_date)}}</span>
                    </div>
                    {{--@if(!$careMonth->is_tm_this_month)
                        <div moe class="mt-2">
                            <a start show>Mark as Transitional Month</a>
                            <form url="/api/careMonth/setIsTmThisMonthToTrue">
                                <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                <p>Mark this care month as <b>Transitional Month</b>?</p>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                </div>
                            </form>
                        </div>
                    @endif--}}
                </div>
            </h6>
            {{--<div class="d-flex align-items-start ml-auto text-secondary">
                <div class="d-inline-flex align-items-start">
                    <div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">RMM</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->rm_total_time_in_seconds_by_rmm_pro)}}
                            </span>
                        </div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">RME</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->rm_total_time_in_seconds_by_rme_pro)}}
                            </span>
                        </div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">MCP</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->rm_total_time_in_seconds_by_mcp)}}
                            </span>
                        </div>
                    </div>
                    <div class="ml-3 text-sm-incl-children">
                        <div class="">RM Total</div>
                        <div class="font-weight-bold text-dark text-nowrap">{{time_in_hrminsec($careMonth->rm_total_time_in_seconds)}}</div>
                    </div>
                </div>
                <div class="d-inline-flex align-items-start border-left pl-3 ml-3">
                    <div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">CM</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->cm_total_time_in_seconds_by_cm_pro)}}
                            </span>
                        </div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">MCP</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->cm_total_time_in_seconds_by_mcp)}}
                            </span>
                        </div>
                    </div>
                    <div class="ml-3 text-sm-incl-children">
                        <div class="">CM Total</div>
                        <div class="font-weight-bold text-dark text-nowrap">{{time_in_hrminsec($careMonth->cm_total_time_in_seconds)}}</div>
                    </div>
                </div>
            </div>--}}
        </div>

        <hr class="m-negator mb-0">

        <div class="row m-negator bg-light py-1 text-sm-incl-children">
            <div class="col-3 pl-3-5">
                <span class="text-secondary">MCP:</span>
                <span class="text-nowrap">{{ $careMonth->mcp ? $careMonth->mcp->displayName() : '-' }}</span>
            </div>
            <div class="col-3">
                <span class="text-secondary">RMM:</span>
                <span class="text-nowrap">{{ $careMonth->rmmPro ? $careMonth->rmmPro->displayName() : '-' }}</span>
            </div>
            <div class="col-3">
                <span class="text-secondary">RME:</span>
                <span class="text-nowrap">{{ $careMonth->rmePro ? $careMonth->rmePro->displayName() : '-' }}</span>
            </div>
            {{--<div class="col-3">
                <span class="text-secondary">CM:</span>
                <span class="text-nowrap">{{ $careMonth->cmPro ? $careMonth->cmPro->displayName() : '-' }}</span>
            </div>--}}
        </div>

        <hr class="m-negator mt-0">

        <?php
        $entries = $careMonth->entries;

        $cmBills = $careMonth->getBillsOfType('CM');
        $activeCMBill = false;
        $cancelledCMBills = new \Illuminate\Support\Collection();
        foreach ($cmBills as $cmBill) {
            if(!$cmBill->is_cancelled && $careMonth->cm_bill_id === $cmBill->id) {
                $activeCMBill = $cmBill;
            }
            else if($cmBill->is_cancelled) {
                $cancelledCMBills->add($cmBill);
            }
        }

        $rmBills = $careMonth->getBillsOfType('RM');
        $activeRMBill = false;
        $cancelledRMBills = new \Illuminate\Support\Collection();
        foreach ($rmBills as $rmBill) {
            if(!$rmBill->is_cancelled && $careMonth->rm_bill_id === $rmBill->id) {
                $activeRMBill = $rmBill;
            }
            else if($rmBill->is_cancelled) {
                $cancelledRMBills->add($rmBill);
            }
        }
        ?>

        <?php $vitalLabels = ['Ht. (in.)','Wt. (lbs.)','Temp. (F)','Pulse','Resp.','Pulse Ox.','SBP','DBP','Smoking Status', 'BMI']; ?>

        <div class="row mb-3">
            <div class="col-12">
                <div class="mt-0">
                    <div class="d-flex align-items-center mb-2">
                        <h6 class="my-0 font-weight-bold text-dark">Measurements</h6>
                        <span class="mx-2 text-secondary">|</span>
                        <div moe>
                            <a start show class="py-0 font-weight-normal">Add</a>
                            <form url="/api/measurement/create">
                                <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                                <div class="mb-2">
                                    <input required autofocus type="text" class="form-control form-control-sm" name="label" value="" placeholder="Type">
                                </div>
                                <div class="mb-2">
                                    <input required type="text" class="form-control form-control-sm" name="value" value="" placeholder="Value">
                                </div>
                                <div class="mb-2">
                                    <input required type="date" class="form-control form-control-sm" name="effectiveDate" max="{{ date('Y-m-d') }}" value="{{ date('Y-m-d') }}">
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </div>
                        @if(0 && $pro->pro_type === 'ADMIN')
                            <span class="mx-2 text-secondary">|</span>
                            <div moe>
                                <a start show class="py-0 font-weight-normal text-secondary">+ BP BDT Measurement</a>
                                <form url="/api/bdtMeasurement/create">
                                    <div class="mb-2">
                                        <input autofocus type="text" class="form-control form-control-sm" name="imei" value="987987987983" placeholder="imei">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="ts" value="1600727786754" placeholder="ts">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="batteryVoltage" value="6308" placeholder="batteryVoltage">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="signalStrength" value="85" placeholder="signalStrength">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueTare" value="" placeholder="valueTare">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueWeight" value="" placeholder="valueWeight">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueSystolic" value="20700" placeholder="valueSystolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueDiastolic" value="9700" placeholder="valueDiastolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valuePulse" value="64" placeholder="valuePulse">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueUnit" value="" placeholder="valueUnit">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueIrregular" value="0" placeholder="valueIrregular">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="rssi" value="71" placeholder="rssi">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="deviceId" value="86011204403081" placeholder="deviceId">
                                    </div>
                                    <input type="hidden" name="secret" value="LTZS20QAFE">
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </div>
                            <span class="mx-2 text-secondary">|</span>
                            <div moe>
                                <a start show class="py-0 font-weight-normal text-secondary">+ Weight BDT Measurement</a>
                                <form url="/api/bdtMeasurement/create">
                                    <div class="mb-2">
                                        <input autofocus type="text" class="form-control form-control-sm" name="imei" value="987987987984" placeholder="imei">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="ts" value="1600727786754" placeholder="ts">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="batteryVoltage" value="6308" placeholder="batteryVoltage">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="signalStrength" value="85" placeholder="signalStrength">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueTare" value="0" placeholder="valueTare">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueWeight" value="61400" placeholder="valueWeight">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueSystolic" value="" placeholder="valueSystolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueDiastolic" value="" placeholder="valueDiastolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valuePulse" value="" placeholder="valuePulse">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueUnit" value="1" placeholder="valueUnit">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueIrregular" value="" placeholder="valueIrregular">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="rssi" value="78" placeholder="rssi">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="deviceId" value="86528404866623" placeholder="deviceId">
                                    </div>
                                    <input type="hidden" name="secret" value="LTZS20QAFE">
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </div>
                        @endif
                    </div>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary">Created</th>
                            <th class="px-2 text-secondary w-25">Category</th>
                            <th class="px-2 text-secondary w-25">Value</th>
                            <th class="px-2 text-secondary">Status</th>
                            <th class="px-2 text-secondary">Memo</th>
                        </tr>
                        </thead>
                        <tbody>
                        @php $measurementsInCareMonth = $patient->measurementsInCareMonth($careMonth); @endphp
                        @foreach($measurementsInCareMonth as $measurement)
                            @if(1 || !empty($measurement->label) && !in_array($measurement->label, $vitalLabels))
                                <tr>
                                    <td class="px-2">{{ friendly_date_time($measurement->created_at) }}</td>
                                    <td class="px-2">{{ $measurement->label }}</td>
                                    <td class="px-2">
                                        @if(empty($measurement->client_bdt_measurement_id))
                                            {{ $measurement->value }}
                                        @else
                                            @if($measurement->label === 'BP')
                                                {{ $measurement->clientBDTMeasurement->measurement->systolic_bp_in_mm_hg }}/{{ $measurement->clientBDTMeasurement->measurement->diastolic_bp_in_mm_hg }} mmHg
                                            @elseif($measurement->label === 'SBP')
                                                {{ $measurement->clientBDTMeasurement->measurement->systolic_bp_in_mm_hg }} mmHg
                                            @elseif($measurement->label === 'DBP')
                                                {{ $measurement->clientBDTMeasurement->measurement->diastolic_bp_in_mm_hg }} mmHg
                                            @elseif($measurement->label === 'Wt. (lbs.)')
                                                {{ $measurement->clientBDTMeasurement->measurement->weight_in_pounds }} lbs
                                            @endif
                                        @endif
                                    </td>
                                    <td></td>
                                    <td></td>

                                    {{--<td class="text-black p-0 border-0">
                                        <div class="d-flex align-items-center">
                                            <div moe relative class="mr-2">
                                                <a class="on-hover-opaque" start show title="Delete">
                                                    <i class="font-size-11 fa fa-trash-alt text-danger"></i>
                                                </a>
                                                <form url="/api/measurement/remove">
                                                    <input type="hidden" name="uid" value="{{ $measurement->uid }}">
                                                    <p class="small min-width-200px">Are you sure you want to delete this entry?</p>
                                                    <div class="d-flex align-items-center">
                                                        <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
                                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                    </div>
                                                </form>
                                            </div>
                                            <div moe class="mr-2">
                                                <a class="on-hover-opaque" start show title="Update">
                                                    <i class="font-size-11 fa fa-edit text-primary"></i>
                                                </a>
                                                <form url="/api/measurement/create">
                                                    <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                                                    <div class="mb-2">
                                                        <input type="text" class="form-control form-control-sm" name="label" value="{{ $measurement->label }}" placeholder="Type">
                                                    </div>
                                                    <div class="mb-2">
                                                        <input autofocus type="text" class="form-control form-control-sm" name="value" value="{{ $measurement->value }}" placeholder="Value">
                                                    </div>
                                                    <div class="mb-2">
                                                        <input type="date" class="form-control form-control-sm" name="effectiveDate" max="{{ date('Y-m-d') }}" value="{{ date('Y-m-d') }}">
                                                    </div>
                                                    <div class="d-flex align-items-center">
                                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                    </div>
                                                </form>
                                            </div>
                                            <span>{{ $measurement->label }}:</span>
                                            <span class="font-weight-bold ml-1">{{ $measurement->value }}</span>
                                            <span class="font-weight-normal text-secondary ml-2 text-sm">(as on {{ friendly_date_time($measurement->effective_date, false) }})</span>
                                        </div>
                                    </td>--}}
                                </tr>
                            @endif
                        @endforeach
                        @if(!$patient->measurements || !count($patient->measurements) === 0)
                            <tr>
                                <td class="text-secondary p-0 border-0">
                                    No items to show
                                </td>
                            </tr>
                        @endif
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        {{-- BDT Measurements --}}
        {{-- <hr class="m-negator mt-4 mb-3">

        <div class="row mb-3">
            <div class="col-12">
                <div class="d-flex align-items-center">
                    <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">Cellular Measurements</h6>
                </div>
                <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                    @if($patient->measurements && count($patient->measurements))
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary">Created</th>
                            <th class="px-2 text-secondary w-25">Category</th>
                            <th class="px-2 text-secondary w-25">Value</th>
                            <th class="px-2 text-secondary">Status</th>
                            <th class="px-2 text-secondary">Memo</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($patient->deviceMeasurements as $measurement)
                            <tr>
                                <td class="px-2">{{ friendly_date_time($measurement->created_at) }}</td>
                                <td class="px-2">{{ $measurement->measurement->device_category }}</td>
                                <td class="px-2">
                                    @if($measurement->measurement->device_category === 'WEIGHT')
                                        <b>{{ round($measurement->measurement->value_weight / 1000, 1) }} Kg</b>
                                    @elseif($measurement->measurement->device_category === 'BP')
                                        <b>{{ $measurement->measurement->systolic_bp_in_mm_hg }}/{{ $measurement->measurement->diastolic_bp_in_mm_hg }} mmHg</b>
                                    @endif
                                </td>
                                <td class="px-2">
                                    <span>
                                        <span>{{ $measurement->status }}</span>
                                        <span moe class="ml-2" relative>
                                            <a href="#" start show><i class="fa fa-edit text-primary"></i></a>
                                            <form url="/api/clientBdtMeasurement/updateStatus" right>
                                                <input type="hidden" name="uid" value="{{ $measurement->uid }}">
                                                <div class="mb-2">
                                                    <select name="status" class="form-control form-control-sm" required>
                                                        <option value="">-- select --</option>
                                                        <option {{$measurement->status === 'NEW' ? 'selected' : ''  }} value="NEW">NEW</option>
                                                        <option {{$measurement->status === 'ACCEPTED' ? 'selected' : ''  }} value="ACCEPTED">ACCEPTED</option>
                                                        <option {{$measurement->status === 'REJECTED' ? 'selected' : ''  }} value="REJECTED">REJECTED</option>
                                                    </select>
                                                </div>
                                                <div class="mb-2">
                                                    <input type="text" name="statusMemo" placeholder="Status memo" class="form-control form-control-sm">
                                                </div>
                                                <div class="d-flex align-items-center">
                                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                </div>
                                            </form>
                                        </span>
                                    </span>
                                </td>
                                <td class="px-2">
                                    {{ $measurement->status_memo }}
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    @else
                        <tbody>
                        <tr>
                            <td class="text-secondary p-3">No device measurements for this patient</td>
                        </tr>
                        </tbody>
                    @endif
                </table>
            </div>
        </div> --}}

        <hr class="m-negator mt-4 mb-3">

        {{-- RM --}}
        <div class="row">
            <div class="col-12">
                @if($careMonth->is_client_enrolled_in_rm)
                    <div class="d-flex align-items-center">
                        <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">Time Entries</h6>
                        @if(!$activeRMBill)
                            <span class="mx-2 text-secondary">|</span>
                            <span moe large>
                                <a start show class="py-0 mb-3">Add</a>
                                <form url="/api/careMonthEntry/createForRm">
                                    <input type="hidden" name="careMonthUid" value="{{ $careMonth->uid }}">
                                    <div class="mb-2">
                                        <div class="row">
                                            <div class="col-4 pr-0">
                                                <select class="form-control form-control-sm w-100" name="proUid" provider-search data-pro-uid="{{ @$pro->uid }}"
                                                        required>
                                                    <option value="">-- Select Pro --</option>
                                                    @foreach($pros as $iPro)
                                                        <option {{ $iPro->uid === $pro->uid ? 'selected' : '' }}
                                                                value="{{ $iPro->uid }}">{{ $iPro->displayName() }}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                            <div class="col-4 pr-0">
                                                <?php
                                                $sD = strtotime($careMonth->start_date);
                                                $y = date('Y', $sD);
                                                $m = date('m', $sD);
                                                $d = date('t', $sD);
                                                $yCurrent = date('Y');
                                                $mCurrent = date('m');
                                                $isToday = false;
                                                if($y === $yCurrent && $m === $mCurrent) {
                                                    $d = date('d');
                                                    $isToday = true;
                                                }
                                                ?>
                                                <input autofocus type="date" min="{{ date($y . '-' . $m . '-01') }}" max="{{ date($y . '-' . $m . '-' . $d) }}"
                                                       value="{{date('Y-m-d')}}"
                                                       class="form-control form-control-sm w-100" name="effectiveDate"
                                                       placeholder="Effective Date" required>
                                            </div>
                                            <div class="col-4">
                                                <input type="number" min="0" max="5400" class="form-control form-control-sm w-100 cm-time-value" name="timeInMinutes"
                                                       value="" placeholder="Time (mins.)" required>
                                            </div>
                                        </div>
                                    </div>
                                    {{--<div class="mb-2">
                                        <div class="row">
                                            <div class="col-4 pr-0 d-flex align-items-center">
                                                <div class="d-flex align-items-center">
                                                    <span>Time Specific:</span>
                                                    <input type="checkbox" name="isTimeSpecific" class="ml-1"
                                                           onchange="enableTimeSpecificFields(this.checked, 'rm-time-value', 'rm-time-range')">
                                                </div>
                                            </div>
                                            <div class="col-4 pr-0">
                                                <input type="time" class="form-control form-control-sm rm-time-range" name="startingTime"
                                                       value="" placeholder="Starting Time" disabled>
                                            </div>
                                            <div class="col-4">
                                                <input type="time" class="form-control form-control-sm rm-time-range" name="endingTime"
                                                       value="" placeholder="Ending Time" disabled>
                                            </div>
                                        </div>
                                    </div>--}}
                                    {{--@include('app/entry-templates/rm/default')--}}
                                    <div class="mb-2">
                                        <div class="row">
                                            <div class="col-12">
                                                <div cm-rte data-content="Reviewed/managed patient measurements" data-name="contentText"></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                            {{--<span class="mx-2 text-secondary">|</span>
                            <span moe>
                                <a start show class="py-0 mb-3 text-danger">Un-Enroll</a>
                                <form url="/api/careMonth/setIsClientEnrolledInRmToFalse">
                                    <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                    <p class="small">Are you sure you want to un-enroll this client from RM?</p>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                    </div>
                                </form>
                            </span>--}}
                        @else
                            <span class="mx-2 text-secondary">|</span>
                            <span class="text-secondary">Can't modify since a bill exists</span>
                        @endif
                    </div>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary border-bottom-0">Effective Date</th>
                            <th class="px-2 text-secondary border-bottom-0">Time</th>
                            <th class="px-2 text-secondary border-bottom-0">Created</th>
                            <th class="px-2 text-secondary border-bottom-0 w-50">Details</th>
                            <th class="px-2 text-secondary border-bottom-0 delete-column">&nbsp;</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($entries as $entry)
                            @if(!$entry->is_removed && $entry->cm_or_rm === "RM")
                                <tr>
                                    <td class="px-2">
                                        <div class="font-weight-bold">{{friendly_date_time($entry->effective_date, false)}}</div>
                                    </td>
                                    <td class="px-2">
                                        {{time_in_hrminsec($entry->time_in_seconds)}}
                                    </td>
                                    <td class="px-2">
                                        {{friendly_date_time($entry->created_at)}}
                                    </td>
                                    <td class="px-2">
                                        <div class="text-secondary in-table-markup">{!! $entry->content_text !!}</div>
<!--                                        <div class="text-secondary text-sm">{{$entry->content_detail}}</div>-->
                                    </td>
                                    <td class="px-2 text-center delete-column">
                                        @if(!$activeRMBill)
                                            <div moe relative>
                                                <a start show><i class="on-hover-opaque fa fa-trash-alt text-danger"></i></a>
                                                <form url="/api/careMonthEntry/remove" right>
                                                    <input type="hidden" name="uid" value="{{ $entry->uid }}">
                                                    <p class="small">Are you sure you want to delete this RM entry?</p>
                                                    <div class="d-flex align-items-center">
                                                        <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
                                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                    </div>
                                                </form>
                                            </div>
                                        @else
                                            <a href="#" class="text-secondary" title="Can't modify since a bill exists"><i class="on-hover-opaque fa fa-trash-alt"></i></a>
                                        @endif
                                    </td>
                                </tr>
                            @endif
                        @endforeach
                        </tbody>
                    </table>
                @else
                    <h6 class="mb-2 text-secondary font-weight-bold text-dark lh-24px">Time Entries</h6>
                    <div class="alert alert-secondary mt-2 mb-0">
                        <b>{{ $patient->displayName() }}</b> is currently not enrolled in <b>RM</b>.
                        <span moe class="">
                            <a start show class="font-weight-bold">Enroll Now</a>
                            <form url="/api/careMonth/setIsClientEnrolledInRmToTrue">
                                <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                <p class="small">Enroll this client in RM?</p>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                </div>
                            </form>
                        </span>
                    </div>
                @endif
            </div>

            {{-- CM --}}
            <?php /*
            @if($careMonth->is_tm_this_month)
                <div class="col-6">
                    <div class="d-flex align-items-center">
                        <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">CM Time Entries</h6>
                    </div>
                    <div class="alert alert-secondary mb-0 mt-2">
                        This care month has been marked as <b>Transitional Month</b>.
                        <span moe class="">
                        <a start show class="font-weight-bold">Undo</a>
                        <form url="/api/careMonth/setIsTmThisMonthToFalse">
                            <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                            <p>Undo mark as <b>Transitional Month</b>?</p>
                            <div class="d-flex align-items-center">
                                <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                            </div>
                        </form>
                    </span>
                    </div>
                </div>
            @else
                @if($careMonth->is_client_enrolled_in_cm)
                    <div class="col-6">
                        <div class="d-flex align-items-center">
                            <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">CM Time Entries</h6>
                            @if(!$activeCMBill)
                                <span class="mx-2 text-secondary">|</span>
                                <span moe large relative>
                                    <a start show class="py-0 mb-3">Add</a>
                                    <form url="/api/careMonthEntry/createForCm" right>
                                        <input type="hidden" name="careMonthUid" value="{{ $careMonth->uid }}">
                                        <div class="mb-2">
                                            <div class="row">
                                                <div class="col-4 pr-0">
                                                    <select class="form-control form-control-sm w-100" name="proUid">
                                                        <option value="">-- Select Pro --</option>
                                                        @foreach($pros as $iPro)
                                                            <option {{ $iPro->uid === $pro->uid ? 'selected' : '' }}
                                                                    value="{{ $iPro->uid }}">{{ $iPro->displayName() }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                                <div class="col-4 pr-0">
                                                    <?php
                                                    $sD = strtotime($careMonth->start_date);
                                                    $y = date('Y', $sD);
                                                    $m = date('m', $sD);
                                                    $d = date('t', $sD);
                                                    $yCurrent = date('Y');
                                                    $mCurrent = date('m');
                                                    if($y === $yCurrent && $m === $mCurrent) {
                                                        $d = date('d');
                                                    }
                                                    ?>
                                                    <input autofocus type="date" min="{{ date($y . '-' . $m . '-01') }}" max="{{ date($y . '-' . $m . '-' . $d) }}"
                                                           class="form-control form-control-sm w-100" name="effectiveDate"
                                                           placeholder="Effective Date">
                                                </div>
                                                <div class="col-4">
                                                    <input type="number" min="0" max="5400" class="form-control form-control-sm w-100 cm-time-value" name="timeInSeconds"
                                                           value="" placeholder="Time in Seconds">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="mb-2">
                                            <div class="row">
                                                <div class="col-4 pr-0 d-flex align-items-center">
                                                    <div class="d-flex align-items-center">
                                                        <span>Time Specific:</span>
                                                        <input type="checkbox" name="isTimeSpecific" class="ml-1"
                                                               onchange="enableTimeSpecificFields(this.checked, 'cm-time-value', 'cm-time-range')">
                                                    </div>
                                                </div>
                                                <div class="col-4 pr-0">
                                                    <input type="time" class="form-control form-control-sm cm-time-range" name="startingTime"
                                                           value="" placeholder="Starting Time" disabled>
                                                </div>
                                                <div class="col-4">
                                                    <input type="time" class="form-control form-control-sm cm-time-range" name="endingTime"
                                                           value="" placeholder="Ending Time" disabled>
                                                </div>
                                            </div>
                                        </div>
                                        @include('app/entry-templates/cm/default')
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </span>
                                <span class="mx-2 text-secondary">|</span>
                                <span moe>
                                    <a start show class="py-0 mb-3 text-danger">Un-Enroll</a>
                                    <form url="/api/careMonth/setIsClientEnrolledInCmToFalse">
                                        <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                        <p class="small">Are you sure you want to un-enroll this client from CM?</p>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                        </div>
                                    </form>
                                </span>
                            @else
                                <span class="mx-2 text-secondary">|</span>
                                <span class="text-secondary">Can't modify since a bill exists</span>
                            @endif
                        </div>
                        <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                            <thead>
                            <tr>
                                <th class="px-2 text-secondary border-bottom-0">Effective Date</th>
                                <th class="px-2 text-secondary border-bottom-0">Time</th>
                                <th class="px-2 text-secondary border-bottom-0 w-50">Details</th>
                                <th class="px-2 text-secondary border-bottom-0 delete-column">&nbsp;</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($entries as $entry)
                                @if(!$entry->is_removed && $entry->cm_or_rm === "CM")
                                    <tr>
                                        <td class="px-2">
                                            <div class="font-weight-bold">{{friendly_date_time($entry->effective_date, false)}}</div>
                                            <div class="small text-secondary">Created: {{friendly_date_time($entry->created_at)}}</div>
                                        </td>
                                        <td class="px-2">
                                            {{time_in_hrminsec($entry->time_in_seconds)}}
                                        </td>
                                        <td class="px-2">
                                            <div class="text-secondary text-s">{!! $entry->content_text !!}</div>
                                            {{--<div class="text-secondary text-sm">{{$entry->content_detail}}</div>--}}
                                        </td>
                                        <td class="px-2 text-center delete-column">
                                            @if(!$activeCMBill)
                                                <div moe relative>
                                                    <a start show><i class="on-hover-opaque fa fa-trash-alt text-danger"></i></a>
                                                    <form url="/api/careMonthEntry/remove" right>
                                                        <input type="hidden" name="uid" value="{{ $entry->uid }}">
                                                        <p class="small">Are you sure you want to delete this CM entry?</p>
                                                        <div class="d-flex align-items-center">
                                                            <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
                                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @else
                                                <a href="#" class="text-secondary" title="Can't modify since a bill exists"><i class="on-hover-opaque fa fa-trash-alt"></i></a>
                                            @endif
                                        </td>
                                    </tr>
                                @endif
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="col-6">
                        <h6 class="mb-3 text-secondary font-weight-bold text-dark">CM Time Entries</h6>
                        <div class="alert alert-secondary mb-0">
                            <b>{{ $patient->displayName() }}</b> is currently not enrolled in <b>CM</b>.
                            <span moe class="">
                            <a start show class="font-weight-bold">Enroll Now</a>
                            <form url="/api/careMonth/setIsClientEnrolledInCmToTrue">
                                <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                <p class="small">Enroll this client in CM?</p>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                </div>
                            </form>
                        </span>
                        </div>
                    </div>
                @endif
            @endif
            */ ?>
        </div>

        <hr class="m-negator mt-4 mb-3">

        <div class="row">

            {{-- rm bills --}}
            <div class="col-12">
                @if($careMonth->is_client_enrolled_in_rm)
                    <div class="d-flex align-items-center">
                        <h6 class="my-0 text-secondary font-weight-bold text-dark">RM Bill
                            @if($activeRMBill && !$activeRMBill->is_signed_by_hcp)
                                <span class="small ml-1 text-secondary">(HCP Sign Pending)</span>
                            @else
                                @if($activeRMBill)
                                    <span class="small ml-1 text-secondary">(Signed by HCP)</span>
                                @endif
                            @endif
                        </h6>
                        @if($activeRMBill === false)
                            <span class="mx-2 text-secondary">|</span>
                            <div moe>
                                <a start show class="py-0 mb-3">Generate</a>
                                <form url="/api/careMonth/generateBillForRm">
                                    <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                    <div class="mb-2">
                                        <select class="form-control" name="rmCode">
                                            <option value="">-- Select RM Code --</option>
                                            @if($rmCodes && count($rmCodes))
                                                @foreach($rmCodes as $rmRate)
                                                    <option value="{{ $rmRate }}">{{ $rmRate }}</option>
                                                @endforeach
                                            @endif
                                        </select>
                                    </div>
                                    <div class="mb-2">
                                        <textarea name="memo" id="" cols="30" rows="5" placeholder="Memo" class="form-control form-control-sm"></textarea>
                                    </div>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" submit>Generate</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </div>
                        @else
                            @if(!$activeRMBill->is_signed_by_hcp && $activeRMBill->hcp_pro_id === $pro->id)
                            <span class="mx-2 text-secondary">|</span>
                            <div moe>
                                <a start show class="py-0 mb-3 text-success">Sign as HCP</a>
                                <form url="/api/bill/signAsHcp">
                                    <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                    <p class="small">Sign this RM bill as HCP?</p>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </div>
                            @endif
                            <span class="mx-2 text-secondary">|</span>
                            <div moe relative>
                                <a start show class="py-0 mb-3 text-danger">Cancel</a>
                                <form url="/api/bill/markCancelled" right>
                                    <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                    <p class="small mb-2">Are you sure you want to cancel this RM bill?</p>
                                    <div class="mb-2">
                                        <textarea name="memo" id="" cols="30" rows="5" placeholder="Memo" class="memo-textarea form-control form-control-sm"></textarea>
                                    </div>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                    </div>
                                </form>
                            </div>
                        @endif
                    </div>
                    @if($activeRMBill !== false)
                        <div class="border bg-white p-2 mt-2">
                            <div class="">
                                Code: <span class="font-weight-bold text-dark">{{ $activeRMBill->code }}</span>
                                <div class="small text-secondary">Memo: {{$activeRMBill->memo}}</div>
                                <div class="small text-secondary">Created: {{friendly_date_time($activeRMBill->created_at)}}</div>
                            </div>
                            <div class="font-weight-bold text-dark mt-2 mb-1"></div>
                            @if($activeRMBill->hcp_pro_id === $pro->id)
                                <div class="d-flex align-items-center">
                                    @if($activeRMBill->has_hcp_been_paid)
                                        <span class="text-dark">Received HCP Amount: </span>
                                        <span class="font-weight-bold text-success ml-2">${{ $activeRMBill->hcp_payment_amount }}</span>
                                    @else
                                        <span class="text-dark">Expected HCP Amount: </span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $activeRMBill->hcp_expected_payment_amount ? '$' . $activeRMBill->hcp_expected_payment_amount : '-' }}</span>
                                        <span class="ml-auto">
                                            @if($activeRMBill->is_signed_by_hcp)
                                                <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                            @else
                                                <div class="text-primary ml-3">
                                                    <div moe class="text-dark">
                                                        <a start show class="py-0 mb-3 text-primary text-sm">
                                                            <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                        </a>
                                                        <form url="/api/bill/signAsHcp">
                                                            <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                                            <p class="small">Sign this RM bill as HCP?</p>
                                                            <div class="d-flex align-items-center">
                                                                <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            @endif
                                        </span>
                                    @endif
                                </div>
                            @endif
                            @if($activeRMBill->rmm_pro_id === $pro->id)
                                <div class="d-flex align-items-center">
                                    @if($activeRMBill->has_rmm_been_paid)
                                        <span class="text-dark">Received RMM Pro Amount: </span>
                                        <span class="font-weight-bold text-success ml-2">${{ $activeRMBill->rmm_payment_amount }}</span>
                                    @else
                                        <span class="text-dark">Expected RMM Pro Amount: </span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $activeRMBill->rmm_expected_payment_amount ? '$' . $activeRMBill->rmm_expected_payment_amount : '-' }}</span>
                                        <span class="ml-auto">
                                            @if($activeRMBill->is_signed_by_rmm)
                                                <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                            @else
                                                <div class="text-primary ml-3">
                                                    <div moe class="text-dark">
                                                        <a start show class="py-0 mb-3 text-primary text-sm">
                                                            <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                        </a>
                                                        <form url="/api/bill/signAsRmm">
                                                            <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                                            <p class="small">Sign this RM bill as RMM Pro?</p>
                                                            <div class="d-flex align-items-center">
                                                                <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            @endif
                                        </span>
                                    @endif
                                </div>
                            @endif
                            @if($activeRMBill->rme_pro_id === $pro->id)
                                <div class="d-flex align-items-center">
                                    @if($activeRMBill->has_rme_been_paid)
                                        <span class="text-success">Received RME Pro Amount: </span>
                                        <span class="font-weight-bold text-dark ml-2">${{ $activeRMBill->rme_payment_amount }}</span>
                                    @else
                                        <span class="text-dark">Expected RME Pro Amount: </span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $activeRMBill->rme_expected_payment_amount ? '$' . $activeRMBill->rme_expected_payment_amount : '-' }}</span>
                                        <span class="ml-auto">
                                            @if($activeRMBill->is_signed_by_rme)
                                                <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                            @else
                                                <div class="text-primary ml-3">
                                                    <div moe class="text-dark">
                                                        <a start show class="py-0 mb-3 text-primary text-sm">
                                                            <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                        </a>
                                                        <form url="/api/bill/signAsRme">
                                                            <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                                            <p class="small">Sign this RM bill as RME Pro?</p>
                                                            <div class="d-flex align-items-center">
                                                                <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            @endif
                                        </span>
                                    @endif
                                </div>
                            @endif
                        </div>
                    @endif
                    {{-- cancelled rm bills --}}
                    @if(count($cancelledRMBills))
                        @foreach($cancelledRMBills as $cancelledBill)
                            <div class="border bg-light p-2 mt-2 on-hover-opaque mb-3">
                                <div class="d-flex">
                                    <div class="">
                                        Code: <span class="font-weight-bold text-dark">{{ $cancelledBill->code }}</span>
                                        <div class="small text-secondary">Memo: {{$cancelledBill->memo}}</div>
                                        <div class="small text-secondary">Created: {{friendly_date_time($cancelledBill->created_at)}}</div>
                                    </div>
                                    <div class="ml-auto text-secondary font-weight-bold">CANCELLED BILL</div>
                                </div>
                                <div class="font-weight-bold text-dark mt-2 mb-1"></div>
                                @if($cancelledBill->hcp_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($cancelledBill->has_hcp_been_paid)
                                            <span class="text-dark">Received HCP Amount: </span>
                                            <span class="font-weight-bold text-success ml-2">${{ $cancelledBill->hcp_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected HCP Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->hcp_expected_payment_amount ? '$' . $cancelledBill->hcp_expected_payment_amount : '-' }}</span>
                                        @endif
                                    </div>
                                @endif
                                @if($cancelledBill->rmm_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($cancelledBill->has_rmm_been_paid)
                                            <span class="text-dark">Received RMM Pro Amount: </span>
                                            <span class="font-weight-bold text-success ml-2">${{ $cancelledBill->rmm_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected RMM Pro Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->rmm_expected_payment_amount ? '$' . $cancelledBill->rmm_expected_payment_amount : '-' }}</span>
                                        @endif
                                    </div>
                                @endif
                                @if($cancelledBill->rme_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($cancelledBill->has_rme_been_paid)
                                            <span class="text-success">Received RME Pro Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">${{ $cancelledBill->rme_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected RME Pro Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->rme_expected_payment_amount ? '$' . $cancelledBill->rme_expected_payment_amount : '-' }}</span>
                                        @endif
                                    </div>
                                @endif
                            </div>
                        @endforeach
                    @endif
                @endif
            </div>

            {{-- cm bills --}}
            <?php /*
            @if($careMonth->is_tm_this_month)
                <div class="col-6">
                    {{-- no cm bills in tm month --}}
                </div>
            @else
                <div class="col-6">
                    @if($careMonth->is_client_enrolled_in_cm)
                        <div class="d-flex align-items-center">
                            <h6 class="my-0 text-secondary font-weight-bold text-dark">CM Bill
                                @if($activeCMBill && !$activeCMBill->is_signed_by_hcp)
                                    <span class="small ml-1 text-secondary">(HCP Sign Pending)</span>
                                @else
                                    @if($activeCMBill)
                                        <span class="small ml-1 text-secondary">(Signed by HCP)</span>
                                    @endif
                                @endif
                            </h6>
                            @if($activeCMBill === false)
                                <span class="mx-2 text-secondary">|</span>
                                <div moe>
                                    <a start show class="py-0 mb-3">Generate</a>
                                    <form url="/api/careMonth/generateBillForCm">
                                        <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                        <div class="mb-2">
                                            <select class="form-control" name="cmCode">
                                                <option value="">-- Select CM Code --</option>
                                                <?php $cmRates = $pro->cmRates(); ?>
                                                @if($cmRates && count($cmRates))
                                                    @foreach($cmRates as $cmRate)
                                                        <option value="{{ $cmRate->code }}">{{ $cmRate->code }}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                        <div class="mb-2">
                                            <textarea name="memo" id="" cols="30" rows="5" placeholder="Memo" class="form-control form-control-sm"></textarea>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-primary mr-2" submit>Generate</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @else
                                @if(!$activeCMBill->is_signed_by_hcp && $activeCMBill->hcp_pro_id === $pro->id)
                                    <span class="mx-2 text-secondary">|</span>
                                    <div moe>
                                        <a start show class="py-0 mb-3 text-success">Sign as HCP</a>
                                        <form url="/api/bill/signAsHcp">
                                            <input type="hidden" name="uid" value="{{ $activeCMBill->uid }}">
                                            <p class="small">Sign this CM bill as HCP?</p>
                                            <div class="d-flex align-items-center">
                                                <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                            </div>
                                        </form>
                                    </div>
                                @endif
                                <span class="mx-2 text-secondary">|</span>
                                <div moe>
                                    <a start show class="py-0 mb-3 text-danger">Cancel</a>
                                    <form url="/api/bill/markCancelled">
                                        <input type="hidden" name="uid" value="{{ $activeCMBill->uid }}">
                                        <p class="small mb-2">Are you sure you want to cancel this CM bill?</p>
                                        <div class="mb-2">
                                            <textarea name="memo" id="" cols="30" rows="5" placeholder="Memo" class="memo-textarea form-control form-control-sm"></textarea>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                        </div>
                                    </form>
                                </div>
                            @endif
                        </div>
                        @if($activeCMBill !== false)
                            <div class="border bg-white p-2 mt-2">
                                <div class="">
                                    Code: <span class="font-weight-bold text-dark">{{ $activeCMBill->code }}</span>
                                    <div class="small text-secondary">Memo: {{$activeCMBill->memo}}</div>
                                    <div class="small text-secondary">Created: {{friendly_date_time($activeCMBill->created_at)}}</div>
                                </div>
                                <div class="font-weight-bold text-dark mt-2 mb-1"></div>
                                @if($activeCMBill->hcp_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($activeCMBill->has_hcp_been_paid)
                                            <span class="text-dark">Received HCP Amount: </span>
                                            <span class="font-weight-bold text-success ml-2">${{ $activeCMBill->hcp_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected HCP Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $activeCMBill->hcp_expected_payment_amount ? '$' . $activeCMBill->hcp_expected_payment_amount : '-' }}</span>
                                            <span class="ml-auto">
                                            @if($activeCMBill->is_signed_by_hcp)
                                                    <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                                @else
                                                    <div class="text-primary ml-3">
                                                    <div moe class="text-dark">
                                                        <a start show class="py-0 mb-3 text-primary text-sm">
                                                            <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                        </a>
                                                        <form url="/api/bill/signAsHcp">
                                                            <input type="hidden" name="uid" value="{{ $activeCMBill->uid }}">
                                                            <p class="small">Sign this RM bill as HCP?</p>
                                                            <div class="d-flex align-items-center">
                                                                <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                                @endif
                                        </span>
                                        @endif
                                    </div>
                                @endif
                                @if($activeCMBill->cm_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($activeCMBill->has_cm_been_paid)
                                            <span class="text-dark">Received CM Pro Amount: </span>
                                            <span class="font-weight-bold text-success ml-2">${{ $activeCMBill->cm_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected CM Pro Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $activeCMBill->cm_expected_payment_amount ? '$' . $activeCMBill->cm_expected_payment_amount : '-' }}</span>
                                            <span class="ml-auto">
                                            @if($activeCMBill->is_signed_by_cm)
                                                    <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                                @else
                                                    <div class="text-primary ml-3">
                                                    <div moe class="text-dark">
                                                        <a start show class="py-0 mb-3 text-primary text-sm">
                                                            <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                        </a>
                                                        <form url="/api/bill/signAsCm">
                                                            <input type="hidden" name="uid" value="{{ $activeCMBill->uid }}">
                                                            <p class="small">Sign this RM bill as CM Pro?</p>
                                                            <div class="d-flex align-items-center">
                                                                <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                                @endif
                                        </span>
                                        @endif
                                    </div>
                                @endif
                            </div>
                        @endif
                        {{-- cancelled cm bills --}}
                        @if(count($cancelledCMBills))
                            @foreach($cancelledCMBills as $cancelledBill)
                                <div class="border bg-light p-2 mt-2 on-hover-opaque mb-3">
                                    <div class="d-flex">
                                        <div class="">
                                            Code: <span class="font-weight-bold text-dark">{{ $cancelledBill->code }}</span>
                                            <div class="small text-secondary">Memo: {{$cancelledBill->memo}}</div>
                                            <div class="small text-secondary">Created: {{friendly_date_time($cancelledBill->created_at)}}</div>
                                        </div>
                                        <div class="ml-auto text-secondary font-weight-bold">CANCELLED BILL</div>
                                    </div>
                                    <div class="font-weight-bold text-dark mt-2 mb-1"></div>
                                    @if($cancelledBill->hcp_pro_id === $pro->id)
                                        <div class="d-flex align-items-center">
                                            @if($cancelledBill->has_hcp_been_paid)
                                                <span class="text-dark">Received HCP Amount: </span>
                                                <span class="font-weight-bold text-success ml-2">${{ $cancelledBill->hcp_payment_amount }}</span>
                                            @else
                                                <span class="text-dark">Expected HCP Amount: </span>
                                                <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->hcp_expected_payment_amount ? '$' . $cancelledBill->hcp_expected_payment_amount : '-' }}</span>
                                            @endif
                                        </div>
                                    @endif
                                    @if($cancelledBill->cm_pro_id === $pro->id)
                                        <div class="d-flex align-items-center">
                                            @if($cancelledBill->has_cm_been_paid)
                                                <span class="text-dark">Received CM Pro Amount: </span>
                                                <span class="font-weight-bold text-success ml-2">${{ $cancelledBill->cm_payment_amount }}</span>
                                            @else
                                                <span class="text-dark">Expected CM Pro Amount: </span>
                                                <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->cm_expected_payment_amount ? '$' . $cancelledBill->cm_expected_payment_amount : '-' }}</span>
                                            @endif
                                        </div>
                                    @endif
                                </div>
                            @endforeach
                        @endif
                    @endif
                </div>
            @endif
            */ ?>

        </div>

    </div>

    <script>
        (function() {
            function init() {
                $('#care-month-container [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');
                    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);

                })
            }

            addMCInitializer('care-month-dashboard', init, '#care-month-container');

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

    @endif
@endsection
