(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/cdk/bidi'), require('@angular/cdk/coercion'), require('@angular/cdk/keycodes'), require('@angular/cdk/overlay'), require('@angular/cdk/portal'), require('@angular/cdk/scrolling'), require('@angular/common'), require('@angular/forms'), require('@ng-tangram/components/core'), require('@ng-tangram/components/overlay'), require('@angular/cdk/a11y')) :
    typeof define === 'function' && define.amd ? define('@ng-tangram/components/autocomplete', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/cdk/bidi', '@angular/cdk/coercion', '@angular/cdk/keycodes', '@angular/cdk/overlay', '@angular/cdk/portal', '@angular/cdk/scrolling', '@angular/common', '@angular/forms', '@ng-tangram/components/core', '@ng-tangram/components/overlay', '@angular/cdk/a11y'], factory) :
    (global = global || self, factory((global.nt = global.nt || {}, global.nt.components = global.nt.components || {}, global.nt.components.autocomplete = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.cdk.bidi, global.ng.cdk.coercion, global.ng.cdk.keycodes, global.ng.cdk.overlay, global.ng.cdk.portal, global.ng.cdk.scrolling, global.ng.common, global.ng.forms, global.nt.components.core, global.nt.components.overlay, global.ng.cdk.a11y));
}(this, (function (exports, core, rxjs, operators, bidi, coercion, keycodes, overlay, portal, scrolling, common, forms, core$1, overlay$1, a11y) { 'use strict';

    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var NtAutocompleteOriginDirective = (function () {
        function NtAutocompleteOriginDirective(elementRef) {
            this.elementRef = elementRef;
        }
        NtAutocompleteOriginDirective.ctorParameters = function () { return [
            { type: core.ElementRef }
        ]; };
        NtAutocompleteOriginDirective = __decorate([
            core.Directive({
                selector: '[ntAutocompleteOrigin]',
                exportAs: 'ntAutocompleteOrigin',
            })
        ], NtAutocompleteOriginDirective);
        return NtAutocompleteOriginDirective;
    }());

    var __decorate$1 = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __param = (this && this.__param) || function (paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    };
    var __read = (this && this.__read) || function (o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m) return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
        }
        catch (error) { e = { error: error }; }
        finally {
            try {
                if (r && !r.done && (m = i["return"])) m.call(i);
            }
            finally { if (e) throw e.error; }
        }
        return ar;
    };
    var __spread = (this && this.__spread) || function () {
        for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
        return ar;
    };
    var NT_AUTOCOMPLETE_SCROLL_STRATEGY = new core.InjectionToken('nt-autocomplete-scroll-strategy');
    function NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY(overlay) {
        return function () { return overlay.scrollStrategies.reposition(); };
    }
    var NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER = {
        provide: NT_AUTOCOMPLETE_SCROLL_STRATEGY,
        deps: [overlay.Overlay],
        useFactory: NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY,
    };
    var MAT_AUTOCOMPLETE_VALUE_ACCESSOR = {
        provide: forms.NG_VALUE_ACCESSOR,
        useExisting: core.forwardRef(function () { return NtAutocompleteTriggerDirective; }),
        multi: true
    };
    function getMatAutocompleteMissingPanelError() {
        return Error('Attempting to open an undefined instance of `mat-autocomplete`. ' +
            'Make sure that the id passed to the `matAutocomplete` is correct and that ' +
            'you\'re attempting to open it after the ngAfterContentInit hook.');
    }
    var NtAutocompleteTriggerDirective = (function () {
        function NtAutocompleteTriggerDirective(_element, _overlay, _viewContainerRef, _zone, _changeDetectorRef, scrollStrategy, _dir, _document, _viewportRuler) {
            var _this = this;
            this._element = _element;
            this._overlay = _overlay;
            this._viewContainerRef = _viewContainerRef;
            this._zone = _zone;
            this._changeDetectorRef = _changeDetectorRef;
            this._dir = _dir;
            this._document = _document;
            this._viewportRuler = _viewportRuler;
            this._componentDestroyed = false;
            this._autocompleteDisabled = false;
            this._manuallyFloatingLabel = false;
            this._viewportSubscription = rxjs.Subscription.EMPTY;
            this._canOpenOnNextFocus = true;
            this._closeKeyEventStream = new rxjs.Subject();
            this._windowBlurHandler = function () {
                _this._canOpenOnNextFocus =
                    _this._document.activeElement !== _this._element.nativeElement || _this.panelOpen;
            };
            this._onChange = function () { };
            this._onTouched = function () { };
            this.position = 'auto';
            this.autocompleteAttribute = 'off';
            this._overlayAttached = false;
            this.optionSelections = rxjs.defer(function () {
                if (_this.autocomplete && _this.autocomplete.options) {
                    return rxjs.merge.apply(void 0, __spread(_this.autocomplete.options.map(function (option) { return option.selectionChange; })));
                }
                return _this._zone.onStable
                    .asObservable()
                    .pipe(operators.take(1), operators.switchMap(function () { return _this.optionSelections; }));
            });
            this._scrollStrategy = scrollStrategy;
        }
        Object.defineProperty(NtAutocompleteTriggerDirective.prototype, "autocompleteDisabled", {
            get: function () { return this._autocompleteDisabled; },
            set: function (value) {
                this._autocompleteDisabled = coercion.coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        NtAutocompleteTriggerDirective.prototype.ngAfterViewInit = function () {
            var _this = this;
            var window = this._getWindow();
            if (typeof window !== 'undefined') {
                this._zone.runOutsideAngular(function () {
                    window.addEventListener('blur', _this._windowBlurHandler);
                });
            }
        };
        NtAutocompleteTriggerDirective.prototype.ngOnChanges = function (changes) {
            if (changes['position'] && this._positionStrategy) {
                this._setStrategyPositions(this._positionStrategy);
                if (this.panelOpen) {
                    this._overlayRef.updatePosition();
                }
            }
        };
        NtAutocompleteTriggerDirective.prototype.ngOnDestroy = function () {
            var window = this._getWindow();
            if (typeof window !== 'undefined') {
                window.removeEventListener('blur', this._windowBlurHandler);
            }
            this._viewportSubscription.unsubscribe();
            this._componentDestroyed = true;
            this._destroyPanel();
            this._closeKeyEventStream.complete();
        };
        Object.defineProperty(NtAutocompleteTriggerDirective.prototype, "panelOpen", {
            get: function () {
                return this._overlayAttached && this.autocomplete.showPanel;
            },
            enumerable: true,
            configurable: true
        });
        NtAutocompleteTriggerDirective.prototype.openPanel = function () {
            this._attachOverlay();
        };
        NtAutocompleteTriggerDirective.prototype.closePanel = function () {
            this._resetLabel();
            if (!this._overlayAttached) {
                return;
            }
            if (this.panelOpen) {
                this.autocomplete.closed.emit();
            }
            this.autocomplete._isOpen = this._overlayAttached = false;
            if (this._overlayRef && this._overlayRef.hasAttached()) {
                this._overlayRef.detach();
                this._closingActionsSubscription.unsubscribe();
            }
            if (!this._componentDestroyed) {
                this._changeDetectorRef.detectChanges();
            }
        };
        NtAutocompleteTriggerDirective.prototype.updatePosition = function () {
            if (this._overlayAttached) {
                this._overlayRef.updatePosition();
            }
        };
        Object.defineProperty(NtAutocompleteTriggerDirective.prototype, "panelClosingActions", {
            get: function () {
                var _this = this;
                return rxjs.merge(this.optionSelections, this.autocomplete._keyManager.tabOut.pipe(operators.filter(function () { return _this._overlayAttached; })), this._closeKeyEventStream, this._getOutsideClickStream(), this._overlayRef ?
                    this._overlayRef.detachments().pipe(operators.filter(function () { return _this._overlayAttached; })) :
                    rxjs.of()).pipe(operators.map(function (event) { return event instanceof core$1.NtOptionSelectionChange ? event : null; }));
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtAutocompleteTriggerDirective.prototype, "activeOption", {
            get: function () {
                if (this.autocomplete && this.autocomplete._keyManager) {
                    return this.autocomplete._keyManager.activeItem;
                }
                return null;
            },
            enumerable: true,
            configurable: true
        });
        NtAutocompleteTriggerDirective.prototype.writeValue = function (value) {
            var _this = this;
            Promise.resolve(null).then(function () { return _this._setTriggerValue(value); });
        };
        NtAutocompleteTriggerDirective.prototype.registerOnChange = function (fn) {
            this._onChange = fn;
        };
        NtAutocompleteTriggerDirective.prototype.registerOnTouched = function (fn) {
            this._onTouched = fn;
        };
        NtAutocompleteTriggerDirective.prototype.setDisabledState = function (isDisabled) {
            this._element.nativeElement.disabled = isDisabled;
        };
        NtAutocompleteTriggerDirective.prototype._handleKeydown = function (event) {
            var keyCode = event.keyCode;
            if (keyCode === keycodes.ESCAPE) {
                event.preventDefault();
            }
            if (this.activeOption && keyCode === keycodes.ENTER && this.panelOpen) {
                this.activeOption.selectViaInteraction();
                this._resetActiveItem();
                event.preventDefault();
            }
            else if (this.autocomplete) {
                var prevActiveItem = this.autocomplete._keyManager.activeItem;
                var isArrowKey = keyCode === keycodes.UP_ARROW || keyCode === keycodes.DOWN_ARROW;
                if (this.panelOpen || keyCode === keycodes.TAB) {
                    this.autocomplete._keyManager.onKeydown(event);
                }
                else if (isArrowKey && this._canOpen()) {
                    this.openPanel();
                }
                if (isArrowKey || this.autocomplete._keyManager.activeItem !== prevActiveItem) {
                    this._scrollToOption();
                }
            }
        };
        NtAutocompleteTriggerDirective.prototype._handleInput = function (event) {
            var target = event.target;
            var value = target.value;
            if (target.type === 'number') {
                value = value === '' ? null : parseFloat(value);
            }
            if (this._previousValue !== value) {
                this._previousValue = value;
                this._onChange(value);
                if (this._canOpen() && this._document.activeElement === event.target) {
                    this.openPanel();
                }
            }
        };
        NtAutocompleteTriggerDirective.prototype._handleFocus = function () {
            if (!this._canOpenOnNextFocus) {
                this._canOpenOnNextFocus = true;
            }
            else if (this._canOpen()) {
                this._previousValue = this._element.nativeElement.value;
                this._attachOverlay();
            }
        };
        NtAutocompleteTriggerDirective.prototype._getOutsideClickStream = function () {
            return core$1.fromOutsideElementClick([
                this._element.nativeElement,
                this.autocomplete.panel.nativeElement
            ], this._document);
        };
        NtAutocompleteTriggerDirective.prototype._resetLabel = function () {
            if (this._manuallyFloatingLabel) {
                this._manuallyFloatingLabel = false;
            }
        };
        NtAutocompleteTriggerDirective.prototype._scrollToOption = function () {
            var activeOption = this.autocomplete._keyManager.activeItem || this.autocomplete.options.first;
            if (!activeOption) {
                return;
            }
            var panelElement = this.autocomplete.panel.nativeElement;
            var panelScrollTop = panelElement.scrollTop;
            var panelScrollBottom = panelScrollTop + panelElement.offsetHeight;
            if (panelScrollBottom === 0) {
                panelElement.scrollTop = activeOption.getOffsetTop();
            }
            else if (activeOption.getOffsetTop() < panelScrollTop) {
                panelElement.scrollTop = activeOption.getOffsetTop();
            }
            else if (activeOption.getOffsetTop() + activeOption.getOffsetHeight() >= panelScrollBottom) {
                var scrollOffset = panelElement.offsetHeight - activeOption.getOffsetHeight();
                panelElement.scrollTop = activeOption.getOffsetTop() - scrollOffset;
            }
        };
        NtAutocompleteTriggerDirective.prototype._subscribeToClosingActions = function () {
            var _this = this;
            var firstStable = this._zone.onStable.asObservable().pipe(operators.take(1));
            var optionChanges = this.autocomplete.options.changes.pipe(operators.tap(function () { return _this._positionStrategy.reapplyLastPosition(); }), operators.delay(0));
            return rxjs.merge(firstStable, optionChanges)
                .pipe(operators.switchMap(function () {
                var wasOpen = _this.panelOpen;
                _this._resetActiveItem();
                _this.autocomplete._setVisibility();
                if (_this.panelOpen) {
                    _this._overlayRef.updatePosition();
                    if (wasOpen !== _this.panelOpen) {
                        _this.autocomplete.opened.emit();
                    }
                }
                return _this.panelClosingActions;
            }), operators.take(1))
                .subscribe(function (event) { return _this._setValueAndClose(event); });
        };
        NtAutocompleteTriggerDirective.prototype._destroyPanel = function () {
            if (this._overlayRef) {
                this.closePanel();
                this._overlayRef.dispose();
                this._overlayRef = null;
            }
        };
        NtAutocompleteTriggerDirective.prototype._setTriggerValue = function (value) {
            var toDisplay = this.autocomplete && this.autocomplete.displayWith ?
                this.autocomplete.displayWith(value) :
                value;
            var inputValue = toDisplay != null ? toDisplay : '';
            this._element.nativeElement.value = inputValue;
            this._previousValue = inputValue;
        };
        NtAutocompleteTriggerDirective.prototype._setValueAndClose = function (event) {
            if (event && event.source) {
                this._clearPreviousSelectedOption();
                this._setTriggerValue(event.source.value);
                this._onChange(event.source.value);
                this._element.nativeElement.focus();
                this.autocomplete._emitSelectEvent(event.source);
            }
            this.closePanel();
        };
        NtAutocompleteTriggerDirective.prototype._clearPreviousSelectedOption = function () {
            this.autocomplete.options.forEach(function (option) {
                if (option.selected) {
                    option.deselect();
                }
            });
        };
        NtAutocompleteTriggerDirective.prototype._attachOverlay = function () {
            var _this = this;
            if (!this.autocomplete) {
                throw getMatAutocompleteMissingPanelError();
            }
            var overlayRef = this._overlayRef;
            if (!overlayRef) {
                this._portal = new portal.TemplatePortal(this.autocomplete.template, this._viewContainerRef);
                overlayRef = this._overlay.create(this._getOverlayConfig());
                this._overlayRef = overlayRef;
                overlayRef.keydownEvents().subscribe(function (event) {
                    if (event.keyCode === keycodes.ESCAPE || (event.keyCode === keycodes.UP_ARROW && event.altKey)) {
                        _this._resetActiveItem();
                        _this._closeKeyEventStream.next();
                        event.stopPropagation();
                        event.preventDefault();
                    }
                });
                if (this._viewportRuler) {
                    this._viewportSubscription = this._viewportRuler.change().subscribe(function () {
                        if (_this.panelOpen && overlayRef) {
                            overlayRef.updateSize({ width: _this._getPanelWidth() });
                        }
                    });
                }
            }
            else {
                this._positionStrategy.setOrigin(this._getConnectedElement());
                overlayRef.updateSize({ width: this._getPanelWidth() });
            }
            if (overlayRef && !overlayRef.hasAttached()) {
                overlayRef.attach(this._portal);
                this._closingActionsSubscription = this._subscribeToClosingActions();
            }
            var wasOpen = this.panelOpen;
            this.autocomplete._setVisibility();
            this.autocomplete._isOpen = this._overlayAttached = true;
            if (this.panelOpen && wasOpen !== this.panelOpen) {
                this.autocomplete.opened.emit();
            }
        };
        NtAutocompleteTriggerDirective.prototype._getOverlayConfig = function () {
            return new overlay.OverlayConfig({
                positionStrategy: this._getOverlayPosition(),
                scrollStrategy: this._scrollStrategy(),
                width: this._getPanelWidth(),
                direction: this._dir
            });
        };
        NtAutocompleteTriggerDirective.prototype._getOverlayPosition = function () {
            var strategy = this._overlay.position()
                .flexibleConnectedTo(this._getConnectedElement())
                .withFlexibleDimensions(false)
                .withPush(false);
            this._setStrategyPositions(strategy);
            this._positionStrategy = strategy;
            return strategy;
        };
        NtAutocompleteTriggerDirective.prototype._setStrategyPositions = function (positionStrategy) {
            var belowPositions = [overlay$1.BOTTOM_LEFT, overlay$1.TOP_LEFT];
            var abovePositions = [overlay$1.TOP_LEFT, overlay$1.BOTTOM_LEFT];
            var positions;
            if (this.position === 'above') {
                positions = abovePositions;
            }
            else if (this.position === 'below') {
                positions = belowPositions;
            }
            else {
                positions = __spread(belowPositions, abovePositions);
            }
            positionStrategy.withPositions(positions);
        };
        NtAutocompleteTriggerDirective.prototype._getConnectedElement = function () {
            if (this.connectedTo) {
                return this.connectedTo.elementRef;
            }
            return this._element;
        };
        NtAutocompleteTriggerDirective.prototype._getPanelWidth = function () {
            return this.autocomplete.panelWidth || this._getHostWidth();
        };
        NtAutocompleteTriggerDirective.prototype._getHostWidth = function () {
            return this._getConnectedElement().nativeElement.getBoundingClientRect().width;
        };
        NtAutocompleteTriggerDirective.prototype._resetActiveItem = function () {
            this.autocomplete._keyManager.setActiveItem(this.autocomplete.autoActiveFirstOption ? 0 : -1);
        };
        NtAutocompleteTriggerDirective.prototype._canOpen = function () {
            var element = this._element.nativeElement;
            return !element.readOnly && !element.disabled && !this._autocompleteDisabled;
        };
        NtAutocompleteTriggerDirective.prototype._getWindow = function () {
            var _a;
            return ((_a = this._document) === null || _a === void 0 ? void 0 : _a.defaultView) || window;
        };
        NtAutocompleteTriggerDirective.ctorParameters = function () { return [
            { type: core.ElementRef },
            { type: overlay.Overlay },
            { type: core.ViewContainerRef },
            { type: core.NgZone },
            { type: core.ChangeDetectorRef },
            { type: undefined, decorators: [{ type: core.Inject, args: [NT_AUTOCOMPLETE_SCROLL_STRATEGY,] }] },
            { type: bidi.Directionality, decorators: [{ type: core.Optional }] },
            { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [common.DOCUMENT,] }] },
            { type: scrolling.ViewportRuler }
        ]; };
        __decorate$1([
            core.Input('ntAutocomplete')
        ], NtAutocompleteTriggerDirective.prototype, "autocomplete", void 0);
        __decorate$1([
            core.Input('ntAutocompleteConnectedTo')
        ], NtAutocompleteTriggerDirective.prototype, "connectedTo", void 0);
        __decorate$1([
            core.Input('ntAutocompletePosition')
        ], NtAutocompleteTriggerDirective.prototype, "position", void 0);
        __decorate$1([
            core.Input('autocomplete')
        ], NtAutocompleteTriggerDirective.prototype, "autocompleteAttribute", void 0);
        __decorate$1([
            core.Input('ntAutocompleteDisabled')
        ], NtAutocompleteTriggerDirective.prototype, "autocompleteDisabled", null);
        NtAutocompleteTriggerDirective = __decorate$1([
            core.Directive({
                selector: 'input[ntAutocomplete], textarea[ntAutocomplete]',
                host: {
                    'class': 'nt-autocomplete-trigger',
                    '(focusin)': '_handleFocus()',
                    '(blur)': '_onTouched()',
                    '(input)': '_handleInput($event)',
                    '(keydown)': '_handleKeydown($event)',
                },
                exportAs: 'ntAutocompleteTrigger',
                providers: [MAT_AUTOCOMPLETE_VALUE_ACCESSOR]
            }),
            __param(5, core.Inject(NT_AUTOCOMPLETE_SCROLL_STRATEGY)),
            __param(6, core.Optional()),
            __param(7, core.Optional()), __param(7, core.Inject(common.DOCUMENT))
        ], NtAutocompleteTriggerDirective);
        return NtAutocompleteTriggerDirective;
    }());

    var __decorate$2 = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __param$1 = (this && this.__param) || function (paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    };
    var _uniqueIdCounter = 0;
    var NtAutocompleteSelectedEvent = (function () {
        function NtAutocompleteSelectedEvent(source, option) {
            this.source = source;
            this.option = option;
        }
        return NtAutocompleteSelectedEvent;
    }());
    var NT_AUTOCOMPLETE_DEFAULT_OPTIONS = new core.InjectionToken('nt-autocomplete-default-options', {
        providedIn: 'root',
        factory: NT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY,
    });
    function NT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY() {
        return { autoActiveFirstOption: false };
    }
    var NtAutocompleteComponent = (function () {
        function NtAutocompleteComponent(_changeDetectorRef, _elementRef, defaults) {
            this._changeDetectorRef = _changeDetectorRef;
            this._elementRef = _elementRef;
            this._activeOptionChanges = rxjs.Subscription.EMPTY;
            this.showPanel = false;
            this._isOpen = false;
            this.displayWith = null;
            this.optionSelected = new core.EventEmitter();
            this.opened = new core.EventEmitter();
            this.closed = new core.EventEmitter();
            this.optionActivated = new core.EventEmitter();
            this._classList = {};
            this.id = "nt-autocomplete-" + _uniqueIdCounter++;
            this._autoActiveFirstOption = !!defaults.autoActiveFirstOption;
        }
        NtAutocompleteComponent_1 = NtAutocompleteComponent;
        Object.defineProperty(NtAutocompleteComponent.prototype, "isOpen", {
            get: function () { return this._isOpen && this.showPanel; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtAutocompleteComponent.prototype, "autoActiveFirstOption", {
            get: function () { return this._autoActiveFirstOption; },
            set: function (value) {
                this._autoActiveFirstOption = coercion.coerceBooleanProperty(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(NtAutocompleteComponent.prototype, "classList", {
            set: function (value) {
                if (value && value.length) {
                    this._classList = value.split(' ').reduce(function (classList, className) {
                        classList[className.trim()] = true;
                        return classList;
                    }, {});
                }
                else {
                    this._classList = {};
                }
                this._setVisibilityClasses(this._classList);
                this._elementRef.nativeElement.className = '';
            },
            enumerable: true,
            configurable: true
        });
        NtAutocompleteComponent.prototype.ngAfterContentInit = function () {
            var _this = this;
            this._keyManager = new a11y.ActiveDescendantKeyManager(this.options).withWrap();
            this._activeOptionChanges = this._keyManager.change.subscribe(function (index) {
                _this.optionActivated.emit({ source: _this, option: _this.options.toArray()[index] || null });
            });
            this._setVisibility();
        };
        NtAutocompleteComponent.prototype.ngOnDestroy = function () {
            this._activeOptionChanges.unsubscribe();
        };
        NtAutocompleteComponent.prototype._setScrollTop = function (scrollTop) {
            if (this.panel) {
                this.panel.nativeElement.scrollTop = scrollTop;
            }
        };
        NtAutocompleteComponent.prototype._getScrollTop = function () {
            return this.panel ? this.panel.nativeElement.scrollTop : 0;
        };
        NtAutocompleteComponent.prototype._setVisibility = function () {
            this.showPanel = !!this.options.length;
            this._setVisibilityClasses(this._classList);
            this._changeDetectorRef.markForCheck();
        };
        NtAutocompleteComponent.prototype._emitSelectEvent = function (option) {
            var event = new NtAutocompleteSelectedEvent(this, option);
            this.optionSelected.emit(event);
        };
        NtAutocompleteComponent.prototype._setVisibilityClasses = function (classList) {
            classList['mat-autocomplete-visible'] = this.showPanel;
            classList['mat-autocomplete-hidden'] = !this.showPanel;
        };
        var NtAutocompleteComponent_1;
        NtAutocompleteComponent.ctorParameters = function () { return [
            { type: core.ChangeDetectorRef },
            { type: core.ElementRef },
            { type: undefined, decorators: [{ type: core.Inject, args: [NT_AUTOCOMPLETE_DEFAULT_OPTIONS,] }] }
        ]; };
        __decorate$2([
            core.ViewChild(core.TemplateRef, { static: true })
        ], NtAutocompleteComponent.prototype, "template", void 0);
        __decorate$2([
            core.ViewChild('panel')
        ], NtAutocompleteComponent.prototype, "panel", void 0);
        __decorate$2([
            core.ContentChildren(core$1.NtOptionComponent, { descendants: true })
        ], NtAutocompleteComponent.prototype, "options", void 0);
        __decorate$2([
            core.Input()
        ], NtAutocompleteComponent.prototype, "displayWith", void 0);
        __decorate$2([
            core.Input()
        ], NtAutocompleteComponent.prototype, "autoActiveFirstOption", null);
        __decorate$2([
            core.Input()
        ], NtAutocompleteComponent.prototype, "panelWidth", void 0);
        __decorate$2([
            core.Output()
        ], NtAutocompleteComponent.prototype, "optionSelected", void 0);
        __decorate$2([
            core.Output()
        ], NtAutocompleteComponent.prototype, "opened", void 0);
        __decorate$2([
            core.Output()
        ], NtAutocompleteComponent.prototype, "closed", void 0);
        __decorate$2([
            core.Output()
        ], NtAutocompleteComponent.prototype, "optionActivated", void 0);
        __decorate$2([
            core.Input('class')
        ], NtAutocompleteComponent.prototype, "classList", null);
        NtAutocompleteComponent = NtAutocompleteComponent_1 = __decorate$2([
            core.Component({
                selector: 'nt-autocomplete',
                template: "<!--\n<nt-overlay\n  overlayClass=\"nt-autocomplete-overlay\"\n  [origin]=\"origin\"\n  [positionPairs]=\"_positionPairs\"\n  (afterOpen)=\"_afterOpen($event)\"\n  (afterClosed)=\"_afterClosed($event)\"\n  (beforeOpen)=\"_beforeOpen($event)\"\n  (beforeClosed)=\"_beforeClosed($event)\"\n  (positionChange)=\"_positionChange($event)\"\n  (keydownEvents)=\"_handleKeydown($event)\">\n  <div #paneElement\n      class=\"nt-select-pane\"\n      [class.folded]=\"state === 'folded'\"\n      [style.width.px]=\"width\">\n    <ng-content select=\"nt-option\"></ng-content>\n    <div class=\"filter-empty\" [hidden]=\"!optionEmpty\">\n      {{ filterNotFound }}\n    </div>\n  </div>\n</nt-overlay> -->\n<ng-template>\n  <div class=\"nt-autocomplete-panel\" role=\"listbox\" [id]=\"id\" [ngClass]=\"_classList\" #panel>\n    <ng-content></ng-content>\n  </div>\n</ng-template>\n",
                encapsulation: core.ViewEncapsulation.None,
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                exportAs: 'ntAutocomplete',
                host: {
                    'class': 'nt-autocomplete'
                },
                providers: [
                    { provide: core$1.NT_OPTION_PARENT_COMPONENT, useExisting: NtAutocompleteComponent_1 }
                ]
            }),
            __param$1(2, core.Inject(NT_AUTOCOMPLETE_DEFAULT_OPTIONS))
        ], NtAutocompleteComponent);
        return NtAutocompleteComponent;
    }());

    var __decorate$3 = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var NtAutocompleteModule = (function () {
        function NtAutocompleteModule() {
        }
        NtAutocompleteModule = __decorate$3([
            core.NgModule({
                imports: [
                    common.CommonModule,
                    core$1.NtOptionModule
                ],
                exports: [
                    NtAutocompleteComponent,
                    NtAutocompleteTriggerDirective,
                    NtAutocompleteOriginDirective,
                    core$1.NtOptionModule
                ],
                declarations: [
                    NtAutocompleteComponent,
                    NtAutocompleteTriggerDirective,
                    NtAutocompleteOriginDirective
                ],
                providers: [NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER]
            })
        ], NtAutocompleteModule);
        return NtAutocompleteModule;
    }());

    exports.MAT_AUTOCOMPLETE_VALUE_ACCESSOR = MAT_AUTOCOMPLETE_VALUE_ACCESSOR;
    exports.NT_AUTOCOMPLETE_DEFAULT_OPTIONS = NT_AUTOCOMPLETE_DEFAULT_OPTIONS;
    exports.NT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY = NT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY;
    exports.NT_AUTOCOMPLETE_SCROLL_STRATEGY = NT_AUTOCOMPLETE_SCROLL_STRATEGY;
    exports.NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY = NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY;
    exports.NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER = NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER;
    exports.NtAutocompleteComponent = NtAutocompleteComponent;
    exports.NtAutocompleteModule = NtAutocompleteModule;
    exports.NtAutocompleteOriginDirective = NtAutocompleteOriginDirective;
    exports.NtAutocompleteSelectedEvent = NtAutocompleteSelectedEvent;
    exports.NtAutocompleteTriggerDirective = NtAutocompleteTriggerDirective;
    exports.getMatAutocompleteMissingPanelError = getMatAutocompleteMissingPanelError;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=autocomplete.umd.js.map
