<?php
/** @var \App\Models\Pro $pro */
/** @var \App\Models\Client $patient */

$myName = implode(' ', array_filter([$pro->name_first, $pro->name_last]));
$theirName = [];
if(!empty($patient->name_prefix)) $theirName[] = $patient->name_prefix;
if(!empty($patient->sex)) {
    $theirName[] = ($patient->sex === 'M' ? 'Mr.' : 'Ms.');
}
$theirName[] = $patient->name_last . ', ' . $patient->name_first;
$theirName = implode(" ", $theirName);
?>

<section class="intake primary-form">
    <p>Hello, {{$theirName}}. My name is {{$myName}}.</p>
    <p><b>This is the cardio template!</b><br><br>
        We will have about 15-20 minutes together, and I’m going to ask you some questions to help customize your personalized wellness plan that we will send along with the weight scale, blood pressure cuff, and infrared thermometer - that you can use to stay healthy during quarantine. Is this OK with you?</p>

    <div>
        <div>
            <p>1. First {{$theirName}}, let me ask you, if there were three things that you could magically just change about your health, what would they be?</p>
            <ul >
                <li><input autofocus></li>
                <li><input></li>
                <li><input></li>
            </ul>
        </div>
        <div>
            <p>2. What is your current height and weight?</p>
            <ul >
                <li>
                    <label>Height</label>
                    <input type=number> <span>inches</span>
                </li>
                <li>
                    <label>Weight</label>
                    <input type=number> <span>lbs.</span>
                </li>
            </ul>
        </div>
        <div>
            <p>3. Do you remember what your weight was when you were 20 years old?</p>
            <ul >
                <li>
                    <label>Weight at 20</label>
                    <input type=number> <span>lbs.</span>
                </li>
            </ul>
        </div>
        <div>
            <p>4. Do you know what your waistline circumference is, in inches?</p>
            <ul >
                <li>
                    <label>Waistline</label>
                    <input type=number> <span>inches</span>
                </li>
            </ul>
        </div>
        <div>
            <p>5. How about your waistline circumference in inches when you were 20 years old?</p>
            <ul >
                <li>
                    <label>Waistline at 20</label>
                    <input type=number> <span>inches</span>
                </li>
            </ul>
        </div>
        <div>
            <p>6. How has the current COVID-19 coronavirus pandemic or quarantine affected your weight, stress level, your lifestyle, or simply just your health in general?</p>
            <ul ><li><input></li></ul>
        </div>
        <div>
            <p>7. Would you say that your weight is currently stable, or are you losing weight, or gaining weight?</p>
            <ul ><li><input></li></ul>
        </div>
        <div>
            <p>8. What other medical conditions or feelings are you experiencing that you feel might improve with weight loss? For example, joint pain, energy level, etc.</p>
            <ul >
                <li><input></li>
                <li><input></li>
                <li><input></li>
                <li><button class=add>Add</button></li>
            </ul>
        </div>
        <div>
            <p>9. Encouragement / Education:</p>
            <ul >
                <li><input type=checkbox> <span>Great! I think you will really love this personalized care plan we will send you.</span></li>
                <li><input type=checkbox> <span>Our care plans are structured on the basis of "calorie planning".</span></li>
                <li><input type=checkbox> <span>Did you know that there are 3500 calories in a pound of body fat?</span></li>
                <li><input type=checkbox> <span>So, for example, a 12 ounce can of coke has about 150 calories.</span></li>
                <li><input type=checkbox> <span>It takes you about 35 minutes walking at 3.5 miles per hour to burn those 150 calories. So, it's actually very hard to change weight with exercise! It's much easier to avoid drinking that one can of coke vs. trying to burn it by working out.</span></li>
                <li><input type=checkbox> <span>So, imagine there is a patient with a habit of drinking one can of coke per day.</span></li>
                <li><input type=checkbox> <span>Every 30 days, this patient is consuming about 4500 calories from that one daily can of coke.</span></li>
                <li><input type=checkbox> <span>So, that one coke per day habit is worth about 1.3 pounds of body fat per month!</span></li>
                <li><input type=checkbox> <span>So, with no other changes in exercise or diet, if the ONLY thing this patient did was give up the daily coke habit, he would lose 1.3 pounds per month - or approximately 4 pounds of body fat every 3 months. Just from giving up one can of coke!</span></li>
                <li><input type=checkbox> <span>Exercise is definitely important in keeping your body healthy - but for weight loss - as you can see - is much more important to control calories that come in. And it's not hard to make small changes that really add up!</span></li>
            </ul>
        </div>
        <div>
            <p>10. GOAL: If you set a personal goal, what would you like your weight and waistline to be in...</p>
            <ul class=gappers >
                <li>
                    <span>3 months?</span>
                    <label>Weight</label> <input type=number> <span>lbs.</span>
                    <label>Waistline</label> <input type=number> <span>inches</span>
                </li>
                <li>
                    <span>6 months?</span>
                    <label>Weight</label> <input type=number> <span>lbs.</span>
                    <label>Waistline</label> <input type=number> <span>inches</span>
                </li>
                <li>
                    <span>1 year?</span>
                    <label>Weight</label> <input type=number> <span>lbs.</span>
                    <label>Waistline</label> <input type=number> <span>inches</span>
                </li>
            </ul>
        </div>
        <div>
            <p>11. HEALTHY LIFESTYLE STEPS: So for this sample patient you just saw, giving up coke was a very meaningful lifestyle step that has a big calorie effect over time. What are some things in your life that are simple changes that can really add up? Let’s be SPECIFIC. For example, giving up croutons in your salad, or taking a walk, etc.</p>
            <ul >
                <li><input></li>
                <li><input></li>
                <li><button class=add>Add</button></li>
            </ul>
        </div>
        <div>
            <p>12. What is the highest your weight or waistline has ever been?</p>
            <ul class=gappers >
                <li>
                    <label>Weight</label> <input type=number> <span>lbs.</span>
                    <label>When was that?</label> <input>
                </li>
                <li>
                    <label>Waistline</label> <input type=number> <span>inches</span>
                    <label>When was that?</label> <input>
                </li>
            </ul>
        </div>
        <div>
            <p>13. What is your most recent?</p>
            <ul class=gappers >
                <li>
                    <label>A1c</label> <input type=number>
                    <label>When was that?</label> <input>
                </li>
                <li>
                    <label>BP (S/D)</label> <input type=number>/<input type=number> <span>mmHg</span>
                    <label>When was that?</label> <input>
                </li>
                <li>
                    <label>LDL</label> <input type=number> <span>mg/dL</span>
                    <label>When was that?</label> <input>
                </li>
            </ul>
        </div>
        <div>
            <p>14. Do you recall your highest ever recorded?</p>
            <ul class=gappers >
                <li>
                    <label>A1c</label> <input type=number>
                    <label>When was that?</label> <input>
                </li>
                <li>
                    <label>BP (S/D)</label> <input type=number>/<input type=number> <span>mmHg</span>
                    <label>When was that?</label> <input>
                </li>
                <li>
                    <label>LDL</label> <input type=number> <span>mg/dL</span>
                    <label>When was that?</label> <input>
                </li>
            </ul>
        </div>
        <div>
            <p>15. Are you on any special type of diet?</p>
            <ul ><li><input></li></ul>
        </div>
        <div>
            <p>16. What is a typical day like for you?</p>
            <ul >
                <li><label>What time do you usually wake up</label> <input></li>
                <li><label>How consistent is the time you wake up</label> <input></li>
                <li><label>What do you usually have for breakfast</label> <input></li>
                <li><label>Then what do you do between breakfast and lunch</label> <input></li>
                <li><label>What do you have for lunch</label> <input></li>
                <li><label>Then what do you do between lunch and dinner</label> <input></li>
                <li><label>What do you have for dinner</label> <input></li>
                <li><label>Then what do you do between dinner and going to bed</label> <input></li>
                <li><label>When do you go to bed</label> <input></li>
                <li><label>How consistent is the time you go to bed</label> <input></li>
                <li><label>How well would you say you sleep</label> <input></li>
                <li><label>How much do you smoke</label> <input></li>
                <li><label>How much do you drink</label> <input></li>
            </ul>
        </div>
        <div>
            <p>17. ACTIVITY ASSESSMENT:</p>
            <ul >
                <li><label>How many minutes of walking or movement do you typically get in a day</label> <input type=number></li>
                <li><label>How many days per week do you exercise to the point where your heart rate goes up</label> <input></li>
                <li><label>How many days per week do you exercise to the point where your muscles feel like they've had a work out</label> <input></li>
            </ul>
        </div>
    </div>

    <button>Save</button>
    <button id="sign-and-submit">Sign & Submit</button>
</section>

<style>
    .intake * {
        box-sizing: border-box;
    }

    .intake button {
        margin-top: 10px;
    } .intake input:not([type=checkbox]) {
          border-width: 0 0 1px 0;
          color: blue;
          font-family: monospace;
          font-weight: bold;
          outline: none;
          padding: 0 7px;
      } .intake input:not([type=checkbox]):only-child {
            width: 50%;
        } .intake input[type=checkbox] {
              margin-right: 10px;
          } .intake input[type=number] {
                text-align: center;
                width: 60px;
            } .intake input::-webkit-inner-spin-button {
                  -webkit-appearance: none;
              } .intake label:after {
                    content: ':';
                    margin-right: 5px;
                }

    .intake ol > li {
        margin-bottom: 25px;
    } .intake ul {
          list-style-type: none;
          padding: 0 0 0 20px;
      } .intake ul li {
            align-items: baseline;
            display: flex;
            margin-bottom: 5px;
        }

    .intake .gappers label:not(:first-child) {
        margin-left: 25px;
    }
</style>

<script>
    function initIntakeEvents() {
        document.querySelectorAll('button.add').forEach(button =>
            button.addEventListener('click', function(){
                const parent = this.closest('li'),
                    newEl = parent.previousElementSibling.cloneNode(true),
                    newInput = newEl.querySelector('input')

                newInput.value = ''
                parent.before(newEl)
                newInput.focus()
            })
        )

        $('#sign-and-submit').off('click.sign').on('click.sign', function() {

            // showMask();

            // prepare note content
            var content = $('<div/>');
            content.append($('.intake.primary-form').clone(true));
            content.find('button').remove();

            // change checkboxes to tick/empty
            content.find('input[type="checkbox"]').each(function() {
                var checked = $(this).prop('checked');
                $(this).replaceWith(
                    $('<b/>')
                        .css({
                            display: 'inline-block',
                            minWidth: '18px',
                            marginRight: '13px',
                        })
                        .text(checked ? '✔' : '-')
                );
            });

            // change other inputs to text
            content.find('input').each(function() {
                $(this).replaceWith(
                    $('<b/>')
                        .css({
                            display: 'inline-block',
                            paddingLeft: '6px',
                            paddingRight: '6px',
                        })
                        .text(this.value)
                );
            });

            content.addClass('intake');

            // create note
            $.post('/api/note/createUsingFreeTextHtml', {
                clientUid: '{{ $patient->uid  }}',
                hcpProUid: '{{ $pro->uid  }}',
                effectiveDateEST: '{{ date('Y-m-d') }}',
                title: 'Visit Note',
                freeTextHtml: content[0].outerHTML
            }, function(_data) {
                if (!_data.success) {
                    toastr.error(_data.message);
                }
                else {
                    var noteUid = _data.data;

                    // update visit info
                    $.post('/api/client/updateMcpOnboardingVisitInfo', {
                        uid: '{{$patient->uid}}',
                        hasMcpDoneOnboardingVisit: 'YES',
                        mcpOnboardingVisitDate: '{{date('Y-m-d')}}',
                        mcpOnboardingVisitNoteUid: noteUid,
                    }, function(_data) {
                        if (!_data.success) {
                            toastr.error(_data.message);
                        }
                        else {
                            toastr.success('Patient onboarding complete');
                            hideMask();
                            fastLoad('/patients/view/{{$patient->uid}}/notes/view/' + noteUid, true, false);
                        }
                    }, 'json');
                    return false;

                }
            }, 'json');

        });
    }
</script>
