<div class="mcp-theme-1 px-3 py-2 border-top mt-3 min-height-500px" id="remote-monitoring-measurements-{{$careMonth->id}}">
    <?php
    $stampAllEndPoint = '';
    if(count($measurements)) {
        if ($measurements[0]->mcp_pro_id === $pro->id) {
            $stampAllEndPoint = '/api/measurement/bulkStampAsMcp';
        } elseif ($measurements[0]->default_na_pro_id === $pro->id || $measurements[0]->rmm_pro_id === $pro->id || $measurements[0]->rme_pro_id === $pro->id) {
            $stampAllEndPoint = '/api/measurement/bulkStampAsNonHcp';
        }
        $measurementUids = [];
        foreach($measurements as $measurement) {
            if(!empty($measurement->label) && !in_array($measurement->label, ["SBP", "DBP"])) {
                $measurementUids[] = $measurement->uid;
            }
        }
        $measurementUids = implode('|', $measurementUids);
    }
    ?>
    @if($stampAllEndPoint && !!$measurementUids)
        <div moe relative class="btn-stamp-all">
            <a href="#" start show class="btn btn-sm btn-primary text-white font-weight-bold">
                Stamp All
            </a>
            <form url="{{$stampAllEndPoint}}">
                <input type="hidden" name="measurementUids" value="{{$measurementUids}}">
                <p class="mb-1">Stamp all measurements?</p>
                @if($measurement->mcp_pro_id !== $pro->id)
                    <div class="mb-2 border border-info p-2 mt-2 bg-light width-300px">
                        <span>I have had interactive communication with {{$measurement->name_first}} {{$measurement->name_last}}.</span>
                        <div class="d-flex border-top mt-2">
                            <label class="mt-2 mb-0 d-inline-flex align-items-center mr-3">
                                <input type="radio" class="mr-2" name="communicatedToPatient" value="true">
                                <span>Yes</span>
                            </label>
                            <label class="mt-2 mb-0 d-inline-flex align-items-center">
                                <input type="radio" class="mr-2" name="communicatedToPatient" value="false" checked>
                                <span>No</span>
                            </label>
                        </div>
                    </div>
                @else
                    <input type="hidden" name="communicatedToPatient" value="false">
                @endif
                <div class="mb-2">
                    <label class="mb-1 text-secondary text-sm">Memo</label>
                    <textarea class="form-control form-control-sm" name="memo"></textarea>
                </div>
                <div class="form-group m-0">
                    <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
                    <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
                </div>
            </form>
        </div>
    @endif
    <div class="mt-0 pb-1">
        <table class="table table-striped table-sm table-bordered mt-2 mb-0">
            <thead>
            <tr>
                <th class="px-2 text-secondary w-25">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">Actions</th>
            </tr>
            </thead>
            <tbody>
            @foreach($measurements as $measurement)
                @if(!empty($measurement->label))
                    @if(!in_array($measurement->label, ["SBP", "DBP"]))
                        <tr>
                            <td class="px-2">
                                @if($measurement->ts)
                                    <?php $timestampInSec = floor($measurement->ts / 1000); ?>
                                    {{ friendly_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN') }}
                                @else
                                    {{ friendly_date_time_short_with_tz($measurement->effective_date, true, 'EASTERN') }}
                                @endif
                                EST
                            </td>
                            <td class="px-2">{{ $measurement->label }}</td>
                            <td class="px-2">
                                @if($measurement->label === 'BP')
                                    {{ round($measurement->sbp_mm_hg, 2) }}/{{ round($measurement->dbp_mm_hg, 2) }} mmHg
                                    <span class="font-weight-normal d-inline-block pl-2">Pulse:</span>
                                    {{ $measurement->value_pulse }} {{ $measurement->value_irregular === 0?'Irregular':'' }} {{ $measurement->value_irregular === 1?'Regular':'' }}
                                @elseif($measurement->label === 'Wt. (lbs.)')
                                    {{ round($measurement->numeric_value, 2) }} lbs
                                @else
                                    {{ $measurement->value }}
                                @endif
                            </td>
                            <td class="px-2">
                                <?php
                                $stampEndPoint = '';
                                if ($measurement->mcp_pro_id === $pro->id) {
                                    $stampEndPoint = '/api/measurement/stampAsMcp';
                                } elseif ($measurement->default_na_pro_id === $pro->id || $measurement->rmm_pro_id === $pro->id || $measurement->rme_pro_id === $pro->id) {
                                    $stampEndPoint = '/api/measurement/stampAsNonHcp';
                                }
                                ?>
                                @if($stampEndPoint)
                                    <div moe relative>
                                        <a href="#" start show>Stamp</a>
                                        <form url="{{$stampEndPoint}}" right class="width-300px">
                                            <input type="hidden" name="uid" value="{{$measurement->uid}}">
                                            <p class="mb-1">Stamp this measurement?</p>
                                            <div class="mt-2 bg-light border p-2">
                                                <div class="mb-1 text-secondary">{{ $measurement->label }}</div>
                                                <div class="font-weight-bold mb-1">
                                                    @if($measurement->label === 'BP')
                                                        {{ round($measurement->sbp_mm_hg, 2) }}/{{ round($measurement->dbp_mm_hg, 2) }} mmHg
                                                        <span class="font-weight-normal d-inline-block pl-2">Pulse:</span>
                                                        {{ $measurement->value_pulse }} {{ $measurement->value_irregular === 0?'Irregular':'' }} {{ $measurement->value_irregular === 1?'Regular':'' }}
                                                    @elseif($measurement->label === 'Wt. (lbs.)')
                                                        {{ round($measurement->numeric_value, 2) }} lbs
                                                    @else
                                                        {{ $measurement->value }}
                                                    @endif
                                                </div>
                                                <div class="text-sm">
                                                    <?php $timestampInSec = floor($measurement->ts / 1000); ?>
                                                    {{ friendly_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN') }} EST
                                                </div>
                                            </div>
                                            @if($measurement->mcp_pro_id !== $pro->id)
                                                <div class="mb-2 border border-info p-2 mt-2 bg-light">
                                                    <span>I have had interactive communication with {{$measurement->name_first}} {{$measurement->name_last}}.</span>
                                                    <div class="d-flex border-top mt-2">
                                                        <label class="mt-2 mb-0 d-inline-flex align-items-center mr-3">
                                                            <input type="radio" class="mr-2" name="communicatedToPatient" value="true">
                                                            <span>Yes</span>
                                                        </label>
                                                        <label class="mt-2 mb-0 d-inline-flex align-items-center">
                                                            <input type="radio" class="mr-2" name="communicatedToPatient" value="false" checked>
                                                            <span>No</span>
                                                        </label>
                                                    </div>
                                                </div>
                                            @else
                                                <input type="hidden" name="communicatedToPatient" value="false">
                                            @endif
                                            <div class="mb-2">
                                                <label class="mb-1 text-secondary text-sm">Memo</label>
                                                <textarea class="form-control form-control-sm" name="memo"></textarea>
                                            </div>
                                            <div class="form-group m-0">
                                                <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
                                                <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
                                            </div>
                                        </form>
                                    </div>
                                @endif
                            </td>
                        </tr>
                    @endif
                @endif
            @endforeach
            @if(!$measurements || count($measurements) === 0)
                <tr>
                    <td class="text-secondary p-2 border-0" colspan="4">
                        No items to show
                    </td>
                </tr>
            @endif
            </tbody>
        </table>
    </div>
</div>
<script>
    (function () {
        function init() {
            $('.stag-popup-content .stag-popup-title .btn-stamp-all').remove();
            $('.btn-stamp-all')
                .addClass('ml-3')
                .insertAfter(
                    $('#remote-monitoring-measurements-{{$careMonth->id}}')
                        .closest('.stag-popup-content')
                        .find('.stag-popup-title>span')
                );
        }
        addMCInitializer('remote-monitoring-measurements-{{$careMonth->id}}', init, '#remote-monitoring-measurements-{{$careMonth->id}}')
    }).call(window);
</script>