<div class="d-flex align-items-end mb-3">
    <b class="large">Measurements in {{friendly_month(date('Y-m-d'))}}</b>
</div>
<table class="table table-striped table-sm table-bordered mb-0">
    <thead>
        <tr>
            <th class="border-0 px-2 text-secondary">Patient</th>
            <th class="border-0 px-2 text-secondary">Category</th>
            <th class="border-0 px-2 text-secondary">Value</th>
            <th class="border-0 px-2 text-secondary">Timestamp</th>
            <th class="border-0 px-2 text-secondary">Mins this month</th>
            <th class="border-0 px-2 text-secondary text-center">Stamp</th>
            <th class="border-0 px-2 text-secondary text-center">Entry</th>
        </tr>
    </thead>
    <tbody>
        @if(count($measurements))
            <?php foreach($measurements as $measurement): ?>
                <?php if(in_array($measurement->label, ['SBP', 'DBP']) ) continue; ?>
                <tr>
                    <td class="px-2">
                        <a native target="_top" href="/mc/patients/view/{{$measurement->client->uid}}" class="font-weight-bold">
                            {{ $measurement->client->name_first }} {{ $measurement->client->name_last }}
                        </a>
                    </td>
                    <td class="px-2">{{ $measurement->label }}</td>
                    <td class="px-2">
                        @if(!$measurement->clientBDTMeasurement)
                         <div><b>{{ $measurement->value }}</b></div>
                        @else
                        <div>
                            @if($measurement->label == 'BP')
                            <div>
                                <b>{{ $measurement->sbp_mm_hg }}</b>/<b>{{ $measurement->dbp_mm_hg }}</b> mmHg
                            </div>
                            @endif
                            @if($measurement->label == 'Wt. (lbs.)')
                            <div>
                                <b>{{ round($measurement->numeric_value, 1)}}</b> lbs
                            </div>
                            @endif
                        </div>
                        @endif
                    </td>
                    <td>
                        {{$measurement->ts}}
                    </td>
                    <td class="px-2">
                        @if($measurement->careMonth)
                        {{ floor($measurement->careMonth->rm_total_time_in_seconds/60) }}
                        @endif
                    </td>
                    <td colspan="px-2">
                        @if($measurement->clientBdtMeasurement)
                        <span moe large relative>
                            <a start show class="py-0 mb-3 font-weight-bold">Update status</a>
                            <form url="/api/measurement/updateStatus" right>
                                <input type="hidden" name="uid" value="{{$measurement->uid}}">
                                <select name="status" id="" class="form-control input-sm">
                                    <option value="">--select--</option>
                                    <option value="ACK">Ok</option>
                                    <option value="INVALID_ACK">Invalid</option>
                                </select>
                                <div class="d-flex align-items-center mt-2">
                                    <button class="btn btn-sm btn-success mr-2" submit>Submit</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        <div v-else class="text-center">-</div>
                        @endif
                    </td>
                    <td colspan="px-2">
                        @if($measurement->clientBdtMeasurement)
                        <div class="text-center">
                            <span moe large relative>
                                <a start show class="py-0 mb-3 font-weight-bold">Add</a>
                                <form url="/api/careMonthEntry/createForRm" right>
                                    <p class="mb-2 d-block text-left"><b>Add RM Entry</b></p>
                                    <input type="hidden" name="careMonthUid" value="{{$measurement->careMonth->uid}}">
                                    <input type="hidden" name="proUid" value="{{$pro->uid}}">
                                    <input type="hidden" name="effectiveDate" value="{{date('Y-m-d')}}">
                                    <div class="bg-light border rounded p-2 mb-2">
                                        <div class="mb-1 d-flex align-items-center">
                                            <span class="width-50px text-left text-secondary">Type</span>
                                            <div><b>{{ $measurement->label }} </b></div>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <span class="width-50px text-left text-secondary">Value</span>
                                            @if(!$measurement->clientBDTMeasurement)
                                                <div><b>{{ $measurement->value }}</b></div>
                                            @else
                                                <div>
                                                    @if($measurement->label == 'BP')
                                                    <div>
                                                        <b>{{ $measurement->clientBdtMeasurement->measurement->systolic_bp_in_mm_hg }}</b>/<b>{{ $measurement->clientBdtMeasurement->measurement->diastolic_bp_in_mm_hg }}</b> mmHg
                                                    </div>
                                                    @endif
                                                    @if($measurement->label == 'Wt. (lbs.)')
                                                    <div>
                                                        <b>{{ floor($measurement->clientBdtMeasurement->measurement->weight_in_pounds)}}</b> lbs
                                                    </div>
                                                    @endif
                                                </div>
                                            @endif
                                        </div>
                                    </div>
                                    <div class="mb-2">
                                        <div class="row">
                                            <div class="col-6 d-flex align-items-center">
                                                <label class="text-secondary text-sm my-0 mr-3 text-nowrap">Time (mins)</label>
                                                <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-12 text-left">
                                                <label class="text-secondary text-sm mb-1">Details</label>
                                                <textarea class="form-control form-control-sm" rows="4" name="contentText">{{ 'Reviewed ' . $measurement->label . ' measurement' }}</textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-success mr-2" submit>Submit</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                        </div>
                        @endif
                    </td>
                </tr>
            <?php endforeach ?>
        @else
            <tr>
                <td class="text-secondary p-0 border-0 p-3" colspan="6">
                    No items to show
                </td>
            </tr>
        @endif
    </tbody>
</table>
