import { Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { BehaviorSubject, map, Subject } from 'rxjs';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/forms";
import * as i3 from "@mintplayer/ng-bootstrap/form";
import * as i4 from "@mintplayer/ng-bootstrap/dropdown";
import * as i5 from "@mintplayer/ng-bootstrap/has-overlay";
import * as i6 from "@mintplayer/ng-bootstrap/dropdown-menu";
import * as i7 from "@mintplayer/ng-bootstrap/progress-bar";
export class BsTypeaheadComponent {
    constructor() {
        this.isOpen = false;
        this.suggestions$ = new BehaviorSubject([]);
        this.isLoading$ = new BehaviorSubject(false);
        this.destroyed$ = new Subject();
        this.searchterm = '';
        this.isLoadingText = 'Loading...';
        this.noSuggestionsText = 'No suggestions found';
        this.provideSuggestions = new EventEmitter();
        this.suggestionSelected = new EventEmitter();
        this.searchtermChange = new EventEmitter();
        this.submitted = new EventEmitter();
        this.showNoSuggestions$ = this.suggestions$
            .pipe(map(suggestions => suggestions.length === 0));
    }
    onProvideSuggestions(value) {
        this.searchtermChange.emit(value);
        if (value === '') {
            this.isOpen = false;
            this.suggestions$.next([]);
        }
        else {
            this.isLoading$.next(true);
            this.isOpen = true;
            this.provideSuggestions.emit(value);
        }
    }
    set suggestions(value) {
        this.isLoading$.next(false);
        this.suggestions$.next(value);
    }
    suggestionClicked(suggestion) {
        this.searchterm = suggestion.text;
        this.searchtermChange.emit(this.searchterm);
        this.isOpen = false;
        this.suggestionSelected.emit(suggestion);
    }
    onSubmit() {
        this.isOpen = false;
        this.submitted.emit(this.searchterm);
    }
    focus() {
        this.textbox.nativeElement.focus();
    }
}
BsTypeaheadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTypeaheadComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
BsTypeaheadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: BsTypeaheadComponent, selector: "bs-typeahead", inputs: { searchterm: "searchterm", isLoadingText: "isLoadingText", noSuggestionsText: "noSuggestionsText", suggestions: "suggestions" }, outputs: { provideSuggestions: "provideSuggestions", suggestionSelected: "suggestionSelected", searchtermChange: "searchtermChange", submitted: "submitted" }, viewQueries: [{ propertyName: "textbox", first: true, predicate: ["textbox"], descendants: true }], ngImport: i0, template: "<!-- <bs-dropdown [(isOpen)]=\"isOpen\" [hasBackdrop]=\"false\"></bs-dropdown> -->\n<bs-has-overlay></bs-has-overlay>\n<bs-form>\n    <div bsDropdown [(isOpen)]=\"isOpen\" [hasBackdrop]=\"false\" [sameDropdownWidth]=\"true\">\n        <input type=\"text\" #textbox [(ngModel)]=\"searchterm\" (ngModelChange)=\"onProvideSuggestions($event)\" (keyup.enter)=\"onSubmit()\" />\n        <bs-dropdown-menu *bsDropdownMenu>\n            <bs-progress *ngIf=\"isLoading$ | async\" [height]=\"2\" [isIndeterminate]=\"true\"></bs-progress>\n            <bs-dropdown-item *ngIf=\"isLoading$ | async\" [disabled]=\"true\">\n                {{ isLoadingText }}\n            </bs-dropdown-item>\n            <ng-container *ngIf=\"(isLoading$ | async) === false\">\n                <bs-dropdown-item *ngIf=\"showNoSuggestions$ | async\" [disabled]=\"true\">\n                    {{ noSuggestionsText }}\n                </bs-dropdown-item>\n                <bs-dropdown-item *ngFor=\"let suggestion of (suggestions$ | async)\" (click)=\"suggestionClicked(suggestion)\">\n                    {{ suggestion.text }}\n                </bs-dropdown-item>\n            </ng-container>\n        </bs-dropdown-menu>\n    </div>\n</bs-form>", styles: ["bs-progress{margin-top:-8px;margin-bottom:6px}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i3.BsFormComponent, selector: "bs-form", outputs: ["submitted"] }, { kind: "directive", type: i3.BsFormControlDirective, selector: "bs-form input:not(.no-form-control), bs-form textarea:not(.no-form-control)" }, { kind: "directive", type: i4.BsDropdownDirective, selector: "[bsDropdown]", inputs: ["hasBackdrop", "sameWidth", "closeOnClickOutside", "sameDropdownWidth", "isOpen"], outputs: ["isOpenChange"] }, { kind: "directive", type: i4.BsDropdownMenuDirective, selector: "[bsDropdownMenu]" }, { kind: "component", type: i5.BsHasOverlayComponent, selector: "bs-has-overlay" }, { kind: "component", type: i6.BsDropdownMenuComponent, selector: "bs-dropdown-menu", inputs: ["maxHeight"] }, { kind: "component", type: i6.BsDropdownItemComponent, selector: "bs-dropdown-item", inputs: ["isSelected", "disabled"] }, { kind: "component", type: i7.BsProgressComponent, selector: "bs-progress", inputs: ["height", "isIndeterminate"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTypeaheadComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-typeahead', template: "<!-- <bs-dropdown [(isOpen)]=\"isOpen\" [hasBackdrop]=\"false\"></bs-dropdown> -->\n<bs-has-overlay></bs-has-overlay>\n<bs-form>\n    <div bsDropdown [(isOpen)]=\"isOpen\" [hasBackdrop]=\"false\" [sameDropdownWidth]=\"true\">\n        <input type=\"text\" #textbox [(ngModel)]=\"searchterm\" (ngModelChange)=\"onProvideSuggestions($event)\" (keyup.enter)=\"onSubmit()\" />\n        <bs-dropdown-menu *bsDropdownMenu>\n            <bs-progress *ngIf=\"isLoading$ | async\" [height]=\"2\" [isIndeterminate]=\"true\"></bs-progress>\n            <bs-dropdown-item *ngIf=\"isLoading$ | async\" [disabled]=\"true\">\n                {{ isLoadingText }}\n            </bs-dropdown-item>\n            <ng-container *ngIf=\"(isLoading$ | async) === false\">\n                <bs-dropdown-item *ngIf=\"showNoSuggestions$ | async\" [disabled]=\"true\">\n                    {{ noSuggestionsText }}\n                </bs-dropdown-item>\n                <bs-dropdown-item *ngFor=\"let suggestion of (suggestions$ | async)\" (click)=\"suggestionClicked(suggestion)\">\n                    {{ suggestion.text }}\n                </bs-dropdown-item>\n            </ng-container>\n        </bs-dropdown-menu>\n    </div>\n</bs-form>", styles: ["bs-progress{margin-top:-8px;margin-bottom:6px}\n"] }]
        }], ctorParameters: function () { return []; }, propDecorators: { textbox: [{
                type: ViewChild,
                args: ['textbox']
            }], searchterm: [{
                type: Input
            }], isLoadingText: [{
                type: Input
            }], noSuggestionsText: [{
                type: Input
            }], provideSuggestions: [{
                type: Output
            }], suggestionSelected: [{
                type: Output
            }], searchtermChange: [{
                type: Output
            }], submitted: [{
                type: Output
            }], suggestions: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 