{{$category}}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 = $('#{{$category}}-pharmacy-search').val();
        var city = $('#{{$category}}-pharmacy-search-city').val(),
            state = $('#{{$category}}-pharmacy-search-state').val(),
            zip = $('#{{$category}}-pharmacy-search-zip').val();
        if (!!term && lastTerm !== term) {
            $.get('/pharmacy-suggest?term=' + encodeURIComponent($.trim(term)) +
                (!!city ? '&city=' + encodeURIComponent(city) : '') +
                (!!state ? '&state=' + encodeURIComponent(state) : '') +
                (!!zip ? '&zip=' + encodeURIComponent(zip) : ''),
            function (_data) {
                $('.suggestions-outer.{{$category}}-pharmacy-suggestions').html(_data).removeClass('d-none');
            });
            lastTerm = term;
        } else {
            $('.suggestions-outer.{{$category}}-pharmacy-suggestions').addClass('d-none');
        }
    }, 250);
    $('#{{$category}}-pharmacy-search')
        .on('keydown', function (e) {
            var term = $.trim($('#{{$category}}-pharmacy-search').val());
            var activeItem = $('.suggestions-outer.{{$category}}-pharmacy-suggestions .suggest-item.active');
            switch (e.which) {
                case 27:
                    $('.suggestions-outer.{{$category}}-pharmacy-suggestions').addClass('d-none');
                    return false;
                case 38:
                    if (activeItem.prev().length) {
                        activeItem.prev()
                            .addClass('active')
                            .siblings().removeClass('active');
                        activeItem = $('.suggestions-outer.{{$category}}-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.{{$category}}-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.{{$category}}-pharmacy-suggestions')
                            .html('<span class="d-block no-suggest-items">Searching...</span>')
                            .removeClass('d-none');
                        returnedFunction();
                    } else {
                        $('.suggestions-outer.{{$category}}-pharmacy-suggestions').addClass('d-none');
                    }
                    break;
            }
        })
        .on('keypress', function (e) {
            var term = $.trim($('#{{$category}}-pharmacy-search').val());
            if (!!term) {
                $('.suggestions-outer.{{$category}}-pharmacy-suggestions')
                    .html('<span class="d-block no-suggest-items">Searching...</span>')
                    .removeClass('d-none');
                returnedFunction();
            } else {
                $('.suggestions-outer.{{$category}}-pharmacy-suggestions').addClass('d-none');
            }
        });
    $(document).on('click', '.suggestions-outer.{{$category}}-pharmacy-suggestions .suggest-item.pharmacy-suggest[data-target-uid]', function () {
        $('#{{$category}}-pharmacy-search').val('');
        $('.suggestions-outer.{{$category}}-pharmacy-suggestions').addClass('d-none');
        self.{{$category}}ApplySuggestion(this);
        return false;
    });
},
{{$category}}ApplySuggestion: function(_elem) {
    this.{{$category}}PopupItem.data.pharmacyName = $(_elem).attr('data-pharmacyName');
    this.{{$category}}PopupItem.data.pharmacyCity = $(_elem).attr('data-pharmacyCity');
    this.{{$category}}PopupItem.data.pharmacyState = $(_elem).attr('data-pharmacyState');
    this.{{$category}}PopupItem.data.pharmacyAddressMemo = $(_elem).attr('data-pharmacyAddressMemo');
    this.{{$category}}PopupItem.data.pharmacyPhone = $(_elem).attr('data-pharmacyPhone');
    this.{{$category}}PopupItem.data.pharmacyFax = $(_elem).attr('data-pharmacyFax');
    this.{{$category}}PopupItem.data.pharmacyZip = $(_elem).attr('data-pharmacyZip');
},
