<div class="mb-2">
    <span class="font-weight-bold">Is this {{$label}} currently active?</span>
    <div class="d-flex align-items-baseline mt-1">
        <label class="my-0 d-inline-flex align-items-center">
            <input type="radio" name="isRemoved" required value="0" {{!$point || !$point->is_removed ? 'checked' : ''}}>
            <span class="ml-1">Yes</span>
        </label>
        <label class="ml-3 my-0 d-inline-flex align-items-center">
            <input type="radio" name="isRemoved" required value="1" {{$point && $point->is_removed ? 'checked' : ''}}>
            <span class="ml-1">No</span>
        </label>
    </div>
</div>

<div if-active class="d-none">

    <hr class="mb-2 mt-0">

    <div class="mb-2">
        <span class="font-weight-bold">Is this pre-existing, or being {{@$addVerbPT ? strtolower($addVerbPT) : 'added'}} during this visit?</span>
        @if($point && $point->added_in_note_id !== $note->id && !$point->is_removed)
            <div class="mt-1">
                @if($point->addition_reason_category === 'ON_INTAKE')
                    Added as pre-existing on {{friendly_date($point->note->effective_dateest)}}
                @else
                    Added during visit on {{friendly_date($point->note->effective_dateest)}}
                @endif
                <input type="radio" name="additionReasonCategory" value="{{$point->addition_reason_category}}" checked class="d-none">
            </div>
        @else
            <div class="d-flex align-items-baseline mt-1">
                <label class="my-0 d-inline-flex align-items-center">
                    <input type="radio" name="additionReasonCategory" value="ON_INTAKE"
				{{ !$point ? 'checked' : '' }}
                            {{$point && $point->addition_reason_category === 'ON_INTAKE' ? 'checked' : ''}}
                            {{0 && $point && $point->added_in_note_id !== $note->id ? 'readonly disabled' : ''}}>
                    <span class="ml-1">Pre-existing</span>
                </label>
                <label class="ml-3 my-0 d-inline-flex align-items-center">
                    <input type="radio" name="additionReasonCategory" value="DURING_VISIT"
                            {{$point && $point->addition_reason_category === 'DURING_VISIT' ? 'checked' : ''}}
                            {{0 && $point && $point->added_in_note_id !== $note->id ? 'readonly disabled' : ''}}>
                    <span class="ml-1">{{@$addVerbPT ? ucwords($addVerbPT) : 'Added'}} during this visit (as part of my {{@$apTerm ? $apTerm : 'plan'}})</span>
                </label>
            </div>
        @endif
    </div>

</div>

<div if-not-active class="d-none">

    <hr class="mb-2 mt-0">

    @if(@$point)
        <div class="mb-2">
            <span class="font-weight-bold">Is this {{$label}} being removed due to an entry error?</span>
            <div class="d-flex align-items-baseline mt-1">
                <label class="my-0 d-inline-flex align-items-center">
                    <input type="radio" name="isRemovedDueToEntryError" value="1" {{$point && $point->is_removed && $point->is_removed_due_to_entry_error ? 'checked' : ''}}>
                    <span class="ml-1">Yes</span>
                </label>
                <label class="ml-3 my-0 d-inline-flex align-items-center">
                    <input type="radio" name="isRemovedDueToEntryError" value="0" {{$point && $point->is_removed && !$point->is_removed_due_to_entry_error ? 'checked' : ''}}>
                    <span class="ml-1">No</span>
                </label>
            </div>
        </div>
    @endif

    <div {{@$point ? 'if-not-entry-error class="d-none"' : ''}}>

        <div class="mb-2">
            <span class="font-weight-bold">Was this {{$label}} removed PRIOR to this visit or DURING this visit?</span>
            @if($point && $point->added_in_note_id !== $note->id && $point->is_removed)
                <div class="mt-1">
                    @if($point->removal_reason_category === 'ON_INTAKE')
                        Removed prior to the visit on {{friendly_date($point->note->effective_dateest)}}
                    @else
                        Removed during visit on {{friendly_date($point->note->effective_dateest)}}
                    @endif
                    <input type="radio" name="removalReasonCategory" value="{{$point->removal_reason_category}}" checked class="d-none">
                </div>
            @else
                <div class="d-flex align-items-baseline mt-1">
                    <label class="my-0 d-inline-flex align-items-center">
                        <input type="radio" name="removalReasonCategory" value="ON_INTAKE" {{$point && $point->removal_reason_category === 'ON_INTAKE' ? 'checked' : ''}}>
                        <span class="ml-1">Prior to visit</span>
                    </label>
                    <label class="ml-3 my-0 d-inline-flex align-items-center">
                        <input type="radio" name="removalReasonCategory" value="DURING_VISIT" {{$point && $point->removal_reason_category === 'DURING_VISIT' ? 'checked' : ''}}>
                        <span class="ml-1">Removed during this visit (as part of my {{@$apTerm ? $apTerm : 'plan'}})</span>
                    </label>
                </div>
            @endif
        </div>

    </div>

</div>

<div {{@$point ? 'if-not-entry-error class="d-none"' : ''}}>
    <div if-addition-or-removal-on-intake-or-during-visit class="d-none">
        <div class="row mb-2">
            <div class="col-3 pr-0">
                <label class="text-sm mb-0 font-weight-bold">Start Date</label>
                <input type="date"
                       data-name="start_date"
                       value="{{@$point->data ? @$point->data->start_date : ''}}"
                       class="form-control form-control-sm min-width-unset">
            </div>
            <div class="col-3 pr-0">
                <label class="text-sm mb-0 font-weight-bold">{{@$addVerbPT ? ucwords($addVerbPT) : 'Added'}} By</label>
                <input type="text"
                       data-name="prescriber"
                       value="{{@$point->data ? @$point->data->prescriber : ''}}"
                       class="form-control form-control-sm min-width-unset">
            </div>
            <div class="col-3 pr-0">
                <div if-not-active class="d-none">
                    <div if-removal-on-intake-or-during-visit class="d-none">
                        <label class="text-sm mb-0 font-weight-bold">End Date</label>
                        <input type="date"
                               name="removalEffectiveDate"
                               value="{{@$point->removal_effective_date}}"
                               class="form-control form-control-sm min-width-unset">
                    </div>
                </div>
            </div>
            <div class="col-3">
                <div if-not-active class="d-none">
                    <div if-removal-on-intake-or-during-visit class="d-none">
                        <label class="text-sm mb-0 font-weight-bold">Removal By/Memo</label>
                        <input type="text"
                               name="removalReasonMemo"
                               value="{{@$point->removal_reason_memo}}"
                               class="form-control form-control-sm min-width-unset">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div {{@$point ? 'if-not-entry-error class="d-none"' : ''}}>
    <div if-active-or-not-active class="d-none">

    @if(1 || $patient->core_note_id !== $note->id) {{-- allow review/plan from core note --}}
	<div class="row">
        @if(!@$noReview)
            <div class="mb-2 col-md-6 pr-0">
                <?php
                $currentValue = '';
                $previousValue = '';
                $previousChildReview = null;
                if (@$point) {
                    if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
                        $parsedReview = json_decode($point->lastChildReview->data);
                        if (@($parsedReview->value)) {
                            $currentValue = $parsedReview->value;
                            $previousChildReview = \App\Models\Point::where('id', '<', $point->lastChildReview->id)
                                ->where('category', 'REVIEW')
                                ->where('parent_point_id', $point->id)
                                ->orderBy('id', 'DESC')
                                ->first();
                            if ($previousChildReview && $previousChildReview->data) {
                                $parsedReview = json_decode($previousChildReview->data);
                                if (@($parsedReview->value)) {
                                    $previousValue = $parsedReview->value;
                                }
                            }
                        }
                    } else {
                        $previousChildReview = \App\Models\Point::where('parent_point_id', $point->id)
                            ->where('category', 'REVIEW')
                            ->orderBy('id', 'DESC')
                            ->first();
                        if ($previousChildReview && $previousChildReview->data) {
                            $parsedReview = json_decode($previousChildReview->data);
                            if (@$parsedReview->value) {
                                $previousValue = $parsedReview->value;
                            }
                        }
                    }
                }
            ?>
                <label class="text-sm mb-0 font-weight-bold">{{@$reviewLabel ? $reviewLabel : 'Subjective'}}</label>
                <div note-rte
                     class="form-group mb-2 rte-holder bg-white border rounded"
                     data-field-name="reviewValue"><?= $currentValue ?></div>
                <?php if($previousValue): ?>
                <div class="mb-2">
                    <div class="d-flex align-items-baseline mb-1">
                        <span class="text-sm text-secondary">Previous {{@$reviewLabel ? $reviewLabel : 'Subjective'}} / <?= friendlier_date($previousChildReview->created_at) ?> (click to copy)</span>
                    </div>
                    <div class="p-1 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
                </div>
                <div class="d-none disallow-if-review-same-as" compare-width="reviewValue"><?= str_compact($previousValue) ?></div>
                <?php endif; ?>
            </div>
        @endif

        @if(!@$noPlan)
            <div class="mb-2 col-md-6">
                <?php
                $currentValue = '';
                $previousValue = '';
                $previousChildPlan = null;
                if (@$point) {
                    if ($point->lastChildPlan && $point->last_child_plan_point_scoped_note_id === $note->id) {
                        $parsedPlan = json_decode($point->lastChildPlan->data);
                        $currentValue = @($parsedPlan->value) ? $parsedPlan->value : '';
                        $previousChildPlan = \App\Models\Point::where('id', '<', $point->lastChildPlan->id)
                            ->where('category', 'PLAN')
                            ->where('parent_point_id', $point->id)
                            ->orderBy('id', 'DESC')
                            ->first();
                        if ($previousChildPlan && $previousChildPlan->data) {
                            $parsedPlan = json_decode($previousChildPlan->data);
                            $previousValue = $parsedPlan->value;
                        }
                    } else {
                        $previousChildPlan = \App\Models\Point::where('parent_point_id', $point->id)
                            ->where('category', 'PLAN')
                            ->orderBy('id', 'DESC')
                            ->first();
                        if ($previousChildPlan && $previousChildPlan->data) {
                            $parsedPlan = json_decode($previousChildPlan->data);
                            $previousValue = $parsedPlan->value;
                        }
                    }
                }
                ?>
                <label class="text-sm mb-0 font-weight-bold">{{@$planLabel ? $planLabel : 'Plan'}}</label>
                <div note-rte
                     class="form-group mb-2 rte-holder bg-white border rounded"
                     data-field-name="planValue"><?= $currentValue ?></div>
                <?php if($previousValue): ?>
                <div class="mb-2">
                    <div class="d-flex align-items-baseline mb-1">
                        <span class="text-sm text-secondary">Previous {{@$planLabel ? $planLabel : 'Plan'}} / <?= friendlier_date($previousChildPlan->created_at) ?> (click to copy)</span>
                    </div>
                    <div class="p-1 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
                </div>
                <div class="d-none disallow-if-plan-same-as" compare-width="planValue"><?= str_compact($previousValue) ?></div>
                <?php endif; ?>
            </div>
        @endif
	</div>
    @endif

    </div>
</div>
