import {
AfterContentInit,
Component,
ContentChildren,
EventEmitter, HostListener,
Input,
OnDestroy,
Output,
QueryList
} from "@angular/core";
import {InputComponent} from "../input/input.component";
import {EntitiesSelectionComponent} from "../../searchPages/searchUtils/entitiesSelection.component";
@Component({
selector: 'advanced-search-input',
template: `
0" class="search-input" [class.dark]="dark" [ngClass]="searchInputClass" [class.small-vertical]="smallVertical">
`
})
export class AdvancedSearchInputComponent implements AfterContentInit, OnDestroy {
@ContentChildren(InputComponent) inputs: QueryList;
@ContentChildren(EntitiesSelectionComponent) entities: QueryList;
@Input() disabled: boolean = false;
@Input() searchInputClass: string = 'inner';
@Input() dark: boolean;
@Input() smallVertical: boolean = false;
@Output() searchEmitter: EventEmitter = new EventEmitter();
@HostListener('window:keydown', ['$event'])
keyEvent(event: KeyboardEvent) {
let input: InputComponent | EntitiesSelectionComponent = this.inputs.toArray().find(input => input.focused);
if(!input) {
input = this.entities.toArray().find(input => input.input.focused);
}
if(input) {
if(event.code === 'Enter') {
if(input instanceof EntitiesSelectionComponent) {
input.input.focus(false, event);
} else {
input.focus(false, event);
}
event.preventDefault();
this.searchEmitter.emit();
}
}
}
constructor() {
}
ngAfterContentInit() {
this.inputs.forEach(input => {
input.inputClass = 'advanced-search';
});
}
ngOnDestroy() {
}
get length() {
return this.inputs.length + this.entities.length;
}
}