@extends ('layouts.patient')

@section('inner-content')
    <style>
        #patient-canvas-migrate .rhs .min-height-500px {
          min-height: unset !important;
        }
        #patient-canvas-migrate .rhs .point-content #frm-add-allergy>.row>.col-4.border-left,
        #patient-canvas-migrate .rhs .point-content #frm-add-problem>.row>.col-4.border-left,
        #patient-canvas-migrate .rhs .point-content #frm-add-medication>.row>.col-4.border-left,
        #patient-canvas-migrate .rhs .point-content #frm-add-care-team-member>.row>.col-4.border-left {
          display: none;
        }
        #patient-canvas-migrate .rhs .point-content #allergies-center-{{@$patient->coreNote->id}},
        #patient-canvas-migrate .rhs .point-content #problems-center-{{@$patient->coreNote->id}},
        #patient-canvas-migrate .rhs .point-content #medications-center-{{@$patient->coreNote->id}},
        #patient-canvas-migrate .rhs .point-content #careteam-center-{{@$patient->coreNote->id}} {
          border: 0 !important;
          padding: 0 !important;
          margin: 0 !important;
        }
    </style>
    <?php
    $shortCutsObject = [];
    foreach ($pro->allShortcuts() as $shortcut) {

        // %replaceables%
        $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
        $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
        $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);

        $shortCutsObject[] = [
            "name" => $shortcut->shortcut,
            "value" => $shortcut->text
        ];
    }
    ?>
    <script>window.userShortcuts = <?= json_encode($shortCutsObject); ?>;</script>
    <link href="/select2/select2.min.css" rel="stylesheet" />
    <script src="/select2/select2.min.js"></script>
    <div id="patient-canvas-migrate">

        {{-- CARE PLAN START --}}
        <?php $infoLines = json_decode($patient->info_lines);?>
        <?php $infoLines = !$infoLines ? [] : $infoLines; ?>
        <?php $vitalLabels = ['Ht. (in.)','Wt. (lbs.)','Temp. (F)','Pulse','Resp.','Pulse Ox.','SBP','DBP','Smoking Status', 'BMI']; ?>
        <?php $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_create($patient->created_at))->invert === 1); ?>

        <div class="client-single-dashboard">

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- canvas based allergies --}}
                    @if($isOldClient)
                        <div class="pt-2 mt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Allergies</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.allergies.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- allergies - point -->
                    @include('app.patient.point-based-partials.allergies')
                </div>
            </div>

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- canvas based dx --}}
                    @if($isOldClient)
                        <div class="mt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Current Problems / Focus Areas</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.dx.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- probs - point -->
                    @include('app.patient.point-based-partials.dx')
                </div>
            </div>

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- canvas based rx --}}
                    @if($isOldClient)
                        <div class="pt-2 mt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Current Medications</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.rx.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- meds - point -->
                    @include('app.patient.point-based-partials.rx')
                </div>
            </div>

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- canvas based careteam --}}
                    @if($isOldClient)
                        <div class="pt-2 mt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Care Team</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.care-team.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- careteam - point -->
                    @include('app.patient.point-based-partials.care-team')
                </div>
            </div>

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- history_medical --}}
                    @if($isOldClient)
                        <div class="pt-2 mt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Medical History</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.pmhx.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- pmhx - point -->
                    @include('app.patient.point-based-partials.pmhx')
                </div>
            </div>

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- history_surgical --}}
                    @if($isOldClient)
                        <div class="mt-2 pt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Surgical History</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.pshx.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- pshx - point -->
                    @include('app.patient.point-based-partials.shx')
                </div>
            </div>

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- history_family --}}
                    @if($isOldClient)
                        <div class="mt-2 pt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Family History</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.fhx.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- fhx - point -->
                    @include('app.patient.point-based-partials.fhx')
                </div>
            </div>

            <div class="row border-bottom mb-4 pb-4">
                <div class="col-6">
                    {{-- history_social --}}
                    @if($isOldClient)
                        <div class="mt-2 pt-2">
                            <div class="d-flex align-items-center pb-2">
                                <h6 class="my-0 font-weight-bold text-secondary">Social History</h6>
                                <div class="px-2 font-weight-bold alert alert-warning text-sm my-0 ml-2 py-1">Deprecated</div>
                            </div>
                            <div class="bg-light border p-2 mb-3">
                                @include('app.patient.canvas-sections.sochx.summary')
                            </div>
                        </div>
                    @endif
                </div>
                <div class="col-6 rhs">
                    <!-- sochx - point -->
                    @include('app.patient.point-based-partials.sochx')
                </div>
            </div>

        </div>


    </div>
    <script>
        (function() {
            function init() {
                $('#patient-canvas-migrate .rhs').each(function() {
                    let trigger = $(this).find('[open-in-stag-popup]').first();
                    $.get(trigger.attr('href'), _data => {
                        trigger.closest('.rhs').find('.point-content').first().html(_data);
                        runMCInitializer(trigger.attr('mc-initer'));

                        $('#patient-canvas-migrate .rhs .point-content #frm-add-allergy>.row>.col-8').removeClass('col-8').addClass('col-12');
                        $('#patient-canvas-migrate .rhs .point-content #frm-add-problem>.row>.col-8').removeClass('col-8').addClass('col-12');
                        $('#patient-canvas-migrate .rhs .point-content #frm-add-medication>.row>.col-8').removeClass('col-8').addClass('col-12');
                        $('#patient-canvas-migrate .rhs .point-content #frm-add-care-team-member>.row>.col-8').removeClass('col-8').addClass('col-12');

                        $('#patient-canvas-migrate .rhs .point-content>.p-3.border-top.mt-3.mcp-theme-1')
                            .removeClass()
                            .parent().addClass('overflow-hidden');

                    });
                    trigger.addClass('opacity-0');
                })
            }
            addMCInitializer('patient-canvas-migrate', init, '#patient-canvas-migrate');

        }).call(window);
    </script>
@endsection
