initPharmacySearch: function () {
    let self = this;
    const debounce = (func, wait) => {
        let timeout;
        return function executedFunction(...args) {
            const later = () => {
                clearTimeout(timeout);
                func(...args);
            };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
        };
    };
    var lastTerm = '';
    var returnedFunction = debounce(function () {
        var term = $('#pharmacy-search').val();
        if (!!term && lastTerm !== term) {
            $.get('/pharmacy-suggest?term=' + $.trim(term), function (_data) {
                $('.suggestions-outer.pharmacy-suggestions').html(_data).removeClass('d-none');
            });
            lastTerm = term;
        } else {
            $('.suggestions-outer.pharmacy-suggestions').addClass('d-none');
        }
    }, 250);
    $('#pharmacy-search')
        .on('keydown', function (e) {
            var term = $.trim($('#pharmacy-search').val());
            var activeItem = $('.suggestions-outer.pharmacy-suggestions .suggest-item.active');
            switch (e.which) {
                case 27:
                    $('.suggestions-outer.pharmacy-suggestions').addClass('d-none');
                    return false;
                case 38:
                    if (activeItem.prev().length) {
                        activeItem.prev()
                            .addClass('active')
                            .siblings().removeClass('active');
                        activeItem = $('.suggestions-outer.pharmacy-suggestions .suggest-item.active');
                        if (activeItem.length) {
                            activeItem[0].scrollIntoView();
                        }
                    }
                    return false;
                case 40:
                    if (activeItem.next().length) {
                        activeItem.next()
                            .addClass('active')
                            .siblings().removeClass('active');
                        activeItem = $('.suggestions-outer.pharmacy-suggestions .suggest-item.active');
                        if (activeItem.length) {
                            activeItem[0].scrollIntoView();
                        }
                    }
                    return false;
                case 13:
                    if (activeItem.length) {
                        activeItem.first().click();
                    }
                    return false;
                default:
                    if (!!term) {
                        $('.suggestions-outer.pharmacy-suggestions')
                            .html('<span class="d-block no-suggest-items">Searching...</span>')
                            .removeClass('d-none');
                        returnedFunction();
                    } else {
                        $('.suggestions-outer.pharmacy-suggestions').addClass('d-none');
                    }
                    break;
            }
        })
        .on('keypress', function (e) {
            var term = $.trim($('#pharmacy-search').val());
            if (!!term) {
                $('.suggestions-outer.pharmacy-suggestions')
                    .html('<span class="d-block no-suggest-items">Searching...</span>')
                    .removeClass('d-none');
                returnedFunction();
            } else {
                $('.suggestions-outer.pharmacy-suggestions').addClass('d-none');
            }
        });
    $(document).on('click', '.suggest-item.pharmacy-suggest[data-target-uid]', function () {
        $('#pharmacy-search').val('');
        $('.suggestions-outer.pharmacy-suggestions').addClass('d-none');
        self.applySuggestion(this);
        return false;
    });
},
applySuggestion: function(_elem) {
    this.popupItem.pharmacyName = $(_elem).attr('data-pharmacyName');
    this.popupItem.pharmacyCity = $(_elem).attr('data-pharmacyCity');
    this.popupItem.pharmacyState = $(_elem).attr('data-pharmacyState');
    this.popupItem.pharmacyAddressMemo = $(_elem).attr('data-pharmacyAddressMemo');
    this.popupItem.pharmacyPhone = $(_elem).attr('data-pharmacyPhone');
    this.popupItem.pharmacyFax = $(_elem).attr('data-pharmacyFax');
},
