<?php

use App\Models\Point;

$category = 'HOW_TO_SMBP';
$endPoint = 'upsertNoteSingleton';

//$point = Point::getGlobalSingletonOfCategory($patient, $category, true);
$point = Point::where('added_in_note_id', $note->id)->where('category', $category)->orderBy('id', 'DESC')->first();


$bp_checkboxes = [
    [
        'section' => 'Prepare',
        'items' => [
            'Avoid caffeine, cigarettes and other stimulants 30 minutes before you measure your blood pressure.',
            'Wait at least 30 minutes after a meal.',
            'If you’re on blood pressure medication, measure your BP before you take your medication.',
            'Empty your bladder beforehand.',
            'Find a quiet space where you can sit comfortably without distraction.'
        ],
    ],
    [
        'section' => 'Position',
        'items' => [
            'Put cuff on bare arm, above elbow at mid-arm.',
            'Position arm so cuff is at heart level.',
            'Keep arm supported, palm up, with muscles relaxed.',
            'Sit with legs uncrossed.',
            'Keep feet flat on the floor.',
            'Keep your back supported.'

        ]
    ],
    [
        'section' => 'Measure',
        'items' => [
            'Rest for five minutes while in position before starting.',
            'Take two or three measurements, one minute apart.',
            'Keep your body relaxed and in position during measurements.',
            'Sit quietly with no distractions during measurements—avoid conversations, TV, phones and other devices.',
            'Record your measurements when finished.'
        ]
    ]
];
	
$contentData = [];

foreach($bp_checkboxes as $x){
    foreach($x['items'] as $item){
        $contentData[$item] = null;
    }
}

if (!!@$point->data) {
    $contentData = json_decode($point->data, true);
}

?>

<div visit-moe close-on-save close-on-cancel class="d-block">
    <form show url="/api/visitPoint/<?= $endPoint ?>" class="mcp-theme-1">
        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
        <input type="hidden" name="category" value="<?= $category ?>">
        <input type="hidden" name="data" value="{{json_encode($contentData)}}">

        @foreach($bp_checkboxes as $cb)
            <h2>{{$cb['section']}}</h2>
            @foreach($cb['items'] as $item)
            <div class="ml-1 mb-1">
                <label class="mb-1 d-flex align-items-center">
                    <input readonly type="checkbox" data-name="{{$item}}" {{@($contentData[$item] ? 'checked' : '')}} class="mr-2">
                    <span class="ml-2">{{$item}}</strong></span>
                </label>
            </div>
            @endforeach
            @if($cb['section'] != 'Measure')
            <hr class="my-3">
            @endif
        @endforeach
    </form>
</div>
