import { ElementRef, Directive, InjectionToken, forwardRef, ViewContainerRef, NgZone, ChangeDetectorRef, Inject, Optional, Input, EventEmitter, ViewChild, TemplateRef, ContentChildren, Output, Component, ViewEncapsulation, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { Subscription, Subject, defer, merge, of } from 'rxjs';
import { take, switchMap, filter, map, tap, delay } from 'rxjs/operators';
import { Directionality } from '@angular/cdk/bidi';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ESCAPE, ENTER, UP_ARROW, DOWN_ARROW, TAB } from '@angular/cdk/keycodes';
import { Overlay, OverlayConfig } from '@angular/cdk/overlay';
import { TemplatePortal } from '@angular/cdk/portal';
import { ViewportRuler } from '@angular/cdk/scrolling';
import { DOCUMENT, CommonModule } from '@angular/common';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { NtOptionSelectionChange, fromOutsideElementClick, NtOptionComponent, NT_OPTION_PARENT_COMPONENT, NtOptionModule } from '@ng-tangram/components/core';
import { BOTTOM_LEFT, TOP_LEFT } from '@ng-tangram/components/overlay';
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';

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: ElementRef }
    ]; };
    NtAutocompleteOriginDirective = __decorate([
        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 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],
    useFactory: NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY,
};
var MAT_AUTOCOMPLETE_VALUE_ACCESSOR = {
    provide: NG_VALUE_ACCESSOR,
    useExisting: 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 = Subscription.EMPTY;
        this._canOpenOnNextFocus = true;
        this._closeKeyEventStream = new 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 = defer(function () {
            if (_this.autocomplete && _this.autocomplete.options) {
                return merge.apply(void 0, __spread(_this.autocomplete.options.map(function (option) { return option.selectionChange; })));
            }
            return _this._zone.onStable
                .asObservable()
                .pipe(take(1), switchMap(function () { return _this.optionSelections; }));
        });
        this._scrollStrategy = scrollStrategy;
    }
    Object.defineProperty(NtAutocompleteTriggerDirective.prototype, "autocompleteDisabled", {
        get: function () { return this._autocompleteDisabled; },
        set: function (value) {
            this._autocompleteDisabled = 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 merge(this.optionSelections, this.autocomplete._keyManager.tabOut.pipe(filter(function () { return _this._overlayAttached; })), this._closeKeyEventStream, this._getOutsideClickStream(), this._overlayRef ?
                this._overlayRef.detachments().pipe(filter(function () { return _this._overlayAttached; })) :
                of()).pipe(map(function (event) { return event instanceof 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 === ESCAPE) {
            event.preventDefault();
        }
        if (this.activeOption && keyCode === ENTER && this.panelOpen) {
            this.activeOption.selectViaInteraction();
            this._resetActiveItem();
            event.preventDefault();
        }
        else if (this.autocomplete) {
            var prevActiveItem = this.autocomplete._keyManager.activeItem;
            var isArrowKey = keyCode === UP_ARROW || keyCode === DOWN_ARROW;
            if (this.panelOpen || keyCode === 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 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(take(1));
        var optionChanges = this.autocomplete.options.changes.pipe(tap(function () { return _this._positionStrategy.reapplyLastPosition(); }), delay(0));
        return merge(firstStable, optionChanges)
            .pipe(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;
        }), 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 TemplatePortal(this.autocomplete.template, this._viewContainerRef);
            overlayRef = this._overlay.create(this._getOverlayConfig());
            this._overlayRef = overlayRef;
            overlayRef.keydownEvents().subscribe(function (event) {
                if (event.keyCode === ESCAPE || (event.keyCode === 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 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 = [BOTTOM_LEFT, TOP_LEFT];
        var abovePositions = [TOP_LEFT, 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: ElementRef },
        { type: Overlay },
        { type: ViewContainerRef },
        { type: NgZone },
        { type: ChangeDetectorRef },
        { type: undefined, decorators: [{ type: Inject, args: [NT_AUTOCOMPLETE_SCROLL_STRATEGY,] }] },
        { type: Directionality, decorators: [{ type: Optional }] },
        { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] },
        { type: ViewportRuler }
    ]; };
    __decorate$1([
        Input('ntAutocomplete')
    ], NtAutocompleteTriggerDirective.prototype, "autocomplete", void 0);
    __decorate$1([
        Input('ntAutocompleteConnectedTo')
    ], NtAutocompleteTriggerDirective.prototype, "connectedTo", void 0);
    __decorate$1([
        Input('ntAutocompletePosition')
    ], NtAutocompleteTriggerDirective.prototype, "position", void 0);
    __decorate$1([
        Input('autocomplete')
    ], NtAutocompleteTriggerDirective.prototype, "autocompleteAttribute", void 0);
    __decorate$1([
        Input('ntAutocompleteDisabled')
    ], NtAutocompleteTriggerDirective.prototype, "autocompleteDisabled", null);
    NtAutocompleteTriggerDirective = __decorate$1([
        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, Inject(NT_AUTOCOMPLETE_SCROLL_STRATEGY)),
        __param(6, Optional()),
        __param(7, Optional()), __param(7, Inject(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 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 = Subscription.EMPTY;
        this.showPanel = false;
        this._isOpen = false;
        this.displayWith = null;
        this.optionSelected = new EventEmitter();
        this.opened = new EventEmitter();
        this.closed = new EventEmitter();
        this.optionActivated = new 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 = 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 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: ChangeDetectorRef },
        { type: ElementRef },
        { type: undefined, decorators: [{ type: Inject, args: [NT_AUTOCOMPLETE_DEFAULT_OPTIONS,] }] }
    ]; };
    __decorate$2([
        ViewChild(TemplateRef, { static: true })
    ], NtAutocompleteComponent.prototype, "template", void 0);
    __decorate$2([
        ViewChild('panel')
    ], NtAutocompleteComponent.prototype, "panel", void 0);
    __decorate$2([
        ContentChildren(NtOptionComponent, { descendants: true })
    ], NtAutocompleteComponent.prototype, "options", void 0);
    __decorate$2([
        Input()
    ], NtAutocompleteComponent.prototype, "displayWith", void 0);
    __decorate$2([
        Input()
    ], NtAutocompleteComponent.prototype, "autoActiveFirstOption", null);
    __decorate$2([
        Input()
    ], NtAutocompleteComponent.prototype, "panelWidth", void 0);
    __decorate$2([
        Output()
    ], NtAutocompleteComponent.prototype, "optionSelected", void 0);
    __decorate$2([
        Output()
    ], NtAutocompleteComponent.prototype, "opened", void 0);
    __decorate$2([
        Output()
    ], NtAutocompleteComponent.prototype, "closed", void 0);
    __decorate$2([
        Output()
    ], NtAutocompleteComponent.prototype, "optionActivated", void 0);
    __decorate$2([
        Input('class')
    ], NtAutocompleteComponent.prototype, "classList", null);
    NtAutocompleteComponent = NtAutocompleteComponent_1 = __decorate$2([
        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: ViewEncapsulation.None,
            changeDetection: ChangeDetectionStrategy.OnPush,
            exportAs: 'ntAutocomplete',
            host: {
                'class': 'nt-autocomplete'
            },
            providers: [
                { provide: NT_OPTION_PARENT_COMPONENT, useExisting: NtAutocompleteComponent_1 }
            ]
        }),
        __param$1(2, 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([
        NgModule({
            imports: [
                CommonModule,
                NtOptionModule
            ],
            exports: [
                NtAutocompleteComponent,
                NtAutocompleteTriggerDirective,
                NtAutocompleteOriginDirective,
                NtOptionModule
            ],
            declarations: [
                NtAutocompleteComponent,
                NtAutocompleteTriggerDirective,
                NtAutocompleteOriginDirective
            ],
            providers: [NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER]
        })
    ], NtAutocompleteModule);
    return NtAutocompleteModule;
}());

export { MAT_AUTOCOMPLETE_VALUE_ACCESSOR, NT_AUTOCOMPLETE_DEFAULT_OPTIONS, NT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY, NT_AUTOCOMPLETE_SCROLL_STRATEGY, NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY, NT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER, NtAutocompleteComponent, NtAutocompleteModule, NtAutocompleteOriginDirective, NtAutocompleteSelectedEvent, NtAutocompleteTriggerDirective, getMatAutocompleteMissingPanelError };
//# sourceMappingURL=autocomplete.js.map
