@extends ('layouts.patient')
@section('inner-content')

    <div class="">
        <div class="mt-0 pb-1">
            <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($performer->pro->pro_type == 'ADMIN')
                <span class="mx-2 text-secondary">|</span>
                <div moe>
                    <a start show class="py-0 font-weight-normal">Process Client BDT Measurements Report</a>
                    <form url="/api/clientBdtReport/processClientBdtReport">
                        <input type="hidden" name="uid" value="{{ $patient->uid }}">
                        <div class="mb-2">
                            <label for="" class="control-label">Process client bd measurements report?</label>
                        </div>
                       
                        <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>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 w-25">Effective Date</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>--}}
                    <th class="px-2 text-secondary"></th>
                </tr>
                </thead>
                <tbody>
                @foreach($patient->measurements as $measurement)
                    @if(!empty($measurement->label))
                        @if(!in_array($measurement->label, ["SBP", "DBP"]))
                        <tr>
                            <td class="px-2">
                                @if($measurement->client_bdt_measurement_id)
                                    <?php $timestampInSec = floor($measurement->bdt_measurement_timestamp/1000); ?>
                                    {{ friendly_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN') }}
                                @else
                                    {{ friendly_date_time_short_with_tz($measurement->effective_date, true, 'EASTERN') }}
                                @endif
                            </td>
                            <td class="px-2">{{ $measurement->label }}</td>
                            <td class="px-2">
                                @if(empty($measurement->client_bdt_measurement_id))
                                    {{ $measurement->value }}
                                @elseif($measurement->is_cellular_zero)
                                    <i class="font-size-11 fa fa-rss"></i>
                                @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.)')
                                        {{ round($measurement->clientBDTMeasurement->measurement->weight_in_pounds, 1) }} lbs
                                    @endif
                                @endif
                            </td>
                            {{--<td></td>
                            <td></td>--}}
                            <td class="px-2">
                                <span 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>
                                </span>
                                <span 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 required type="text" class="form-control form-control-sm" name="label" value="{{ $measurement->label }}" placeholder="Type">
                                        </div>
                                        <div class="mb-2">
                                            <input required autofocus type="text" class="form-control form-control-sm" name="value" value="{{ $measurement->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>
                                </span>
                            </td>
                        </tr>
                        @endif
                    @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>

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

{{--    <div class="">--}}
{{--        <div class="d-flex align-items-start pb-2">--}}
{{--            <h4 class="font-weight-bold m-0">Cellular Measurements</h4>--}}
{{--        </div>--}}
{{--        <table class="table table-striped table-sm table-bordered mb-0">--}}
{{--            @if($patient->measurements && count($patient->measurements))--}}
{{--                <thead>--}}
{{--                <tr>--}}
{{--                    <th class="px-2 text-secondary w-25">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>--}}
{{--                </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)*2.20462, 1) }} lb</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>--}}
{{--                    </tr>--}}
{{--                @endforeach--}}
{{--                </tbody>--}}
{{--            @else--}}
{{--                <tbody>--}}
{{--                <tr>--}}
{{--                    <td class="text-secondary p-3">No device measurements for this patient</td>--}}
{{--                </tr>--}}
{{--                </tbody>--}}
{{--            @endif--}}
{{--        </table>--}}
{{--    </div>--}}
@endsection
