<?php
if(!@$intakeOrVisit) {
    $intakeOrVisit = 'INTAKE'; // default
}
$whenLabel = ($intakeOrVisit === 'INTAKE') ? 'on intake' : 'during visit';
$epPart = ($intakeOrVisit === 'INTAKE') ? 'OnIntake' : 'DuringVisit';
$whenNotLabel = ($intakeOrVisit === 'INTAKE') ? 'during visit' : 'on intake';
$epNotPart = ($intakeOrVisit === 'INTAKE') ? 'DuringVisit' : 'OnIntake';
?>
<?php if ($point->is_removed): ?>
    <?php if ($point->is_removed_due_to_entry_error): ?>
        <span class="font-weight-bold text-secondary mr-2 text-nowrap">Entry error</span>
    <?php else: ?>
        <?php if($point->removal_reason_category === 'DURING_VISIT'): ?>
        <span class="ont-weight-bold text-secondary mr-2 text-nowrap">Removed during visit</span>
        <?php elseif($point->removal_reason_category === 'ON_INTAKE'): ?>
        <span class="ont-weight-bold text-secondary mr-2 text-nowrap">Historic</span>
        <?php endif; ?>
    <?php endif; ?>
    <div visit-moe>
        <form show url="/api/visitPoint/undoMarkRemoved" class="mcp-theme-1">
            <input type="hidden" name="uid" value="<?= $point->uid ?>">
            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
            <a submit href="#" title="Undo"><i class="fa fa-undo on-hover-opaque"></i></a>
        </form>
    </div>
<?php else: ?>
    <?php if($point->added_in_note_id === $note->id): ?>
        <?php if ($point->added_in_note_id === $note->id): ?>
            <?php if ($point->addition_reason_category === 'DURING_VISIT'): ?>
                <span class="mx-2 font-weight-bold text-success text-nowrap">* Added during visit</span>
            <?php else: ?>
                <span class="mx-2 font-weight-bold text-info text-nowrap">* Added on intake</span>
            <?php endif;?>
        <?php endif; ?>
    <?php endif; ?>
    <div visit-moe>
        <a start show href="#" title="Remove"><i class="fa fa-trash-alt text-danger on-hover-opaque"></i></a>
        <form url="/api/visitPoint/markRemoved<?= $epPart ?>" class="mcp-theme-1">
            <input type="hidden" name="uid" value="<?= $point->uid ?>">
            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">

            <p class="mb-2"><b>Remove <?= $label ?> <?= $whenLabel ?></b></p>

            <div class="mb-2">
                <label class="text-sm text-secondary mb-1">Removal Reason</label>
                <textarea name="removalReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
            </div>
            <?php if($point->added_in_note_id === $note->id): ?>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Is Entry Error?  *</label>
                    <select name="isRemovedDueToEntryError" class="form-control form-control-sm" required>
                        <option value="">-- select --</option>
                        <option value="1">Yes</option>
                        <option value="0">No</option>
                    </select>
                </div>
            <?php else: ?>
                <input type="hidden" name="isRemovedDueToEntryError" value="0">
            <?php endif; ?>
            <div class="mb-2">
                <label class="text-sm text-secondary mb-1">Removal Effective Date</label>
                <input type="date" name="removalEffectiveDate"
                       value="<?= date('Y-m-d') ?>"
                       max="<?= date('Y-m-d') ?>"
                       class="form-control form-control-sm">
            </div>
            <div>
                <button submit class="btn btn-sm btn-danger mr-2">Remove</button>
                <button cancel class="btn btn-sm btn-default border">Cancel</button>
            </div>
        </form>
    </div>
<?php endif; ?>

<!-- additional actions -->
<div class="ml-2 position-relative on-click-menu">
    <span class="d-block btn btn-sm btn-default px-1 py-0 border font-weight-bold text-secondary align-middle">&hellip;</span>
    <div menu class="bg-white border">

        <!-- if removed -->
            <!-- ACT: update removal reason memo -->
            <!-- if entry error -->
                <!-- ACT: mark as not entry error-->
            <!-- if not entry error-->
                <!-- ACT: mark as entry error-->
        <!-- if not removed -->
            <!-- ACT: update addition reason memo -->
            <!-- ACT: mark added during visit -->

        <?php if ($point->is_removed): ?>
            <div class="border-bottom">
                <div visit-moe>
                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Update removal reason</a>
                    <form url="/api/visitPoint/updateRemovalReasonMemo" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="<?= $point->uid ?>">
                        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
                        <p class="mb-2"><b>Update Removal Reason</b></p>
                        <div class="mb-2">
                            <label class="text-sm text-secondary mb-1">Removal Reason</label>
                            <textarea name="removalReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
                        </div>
                        <div>
                            <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                    </form>
                </div>
            </div>
            <?php if ($point->is_removed_due_to_entry_error): ?>
                <div class="border-bottom">
                    <div visit-moe>
                        <form show url="/api/visitPoint/setIsRemovedDueToEntryErrorToFalse" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="<?= $point->uid ?>">
                            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
                            <a submit href="#" class="text-nowrap px-2 py-1 d-block">Mark as not entry error</a>
                        </form>
                    </div>
                </div>
            <?php else: ?>
                <div class="border-bottom">
                    <div visit-moe>
                        <form show url="/api/visitPoint/setIsRemovedDueToEntryErrorToTrue" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="<?= $point->uid ?>">
                            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
                            <a submit href="#" class="text-nowrap px-2 py-1 d-block">Mark as entry error</a>
                        </form>
                    </div>
                </div>
            <?php endif; ?>
        <?php else: ?>
            <div class="border-bottom">
                <div visit-moe>
                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Update addition reason</a>
                    <form url="/api/visitPoint/updateAdditionReasonMemo" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="<?= $point->uid ?>">
                        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
                        <p class="mb-2"><b>Update Addition Reason</b></p>
                        <div class="mb-2">
                            <label class="text-sm text-secondary mb-1">Addition Reason</label>
                            <textarea name="additionReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
                        </div>
                        <div>
                            <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="border-bottom">
                <div visit-moe>
                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Mark as added <?= $whenNotLabel ?></a>
                    <form url="/api/visitPoint/markAdded<?= $epNotPart ?>" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="<?= $point->uid ?>">
                        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
                        <p class="mb-2"><b>Mark as added <?= $whenNotLabel ?></b></p>
                        <div class="mb-2">
                            <label class="text-sm text-secondary mb-1">Addition Reason</label>
                            <textarea name="additionReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
                        </div>
                        <div>
                            <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                        </div>
                    </form>
                </div>
            </div>
        <?php endif; ?>


    </div>
</div>
