import {
Component, ElementRef,
EventEmitter, HostListener,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
ViewChild
} from "@angular/core";
import {AbstractControl, FormArray, FormControl} from "@angular/forms";
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {Observable, of, Subscription} from "rxjs";
import {MatSelect} from "@angular/material/select";
import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete";
import {map, startWith} from "rxjs/operators";
import {MatChipInputEvent} from "@angular/material/chips";
export interface Option {
icon?: string,
iconClass?: string,
value: any,
label: string
}
@Component({
selector: '[dashboard-input]',
template: `
{{label + (required ? ' *' : '')}}
{{hint}}
{{placeholder}}
{{option.label}}
{{getLabel(chip.value)}}
{{option.label}}
{{formControl.errors.error}}
{{warning}}
{{note}}
{{label}}
`,
styleUrls: ['input.component.css']
})
export class InputComponent implements OnInit, OnDestroy, OnChanges {
/** Basic information */
@Input('formInput') formControl: AbstractControl;
@Input('type') type: 'text' | 'textarea' | 'select' | 'checkbox' | 'chips' = 'text';
@Input('label') label: string;
@Input('rows') rows: number = 3;
/** Select | chips available options */
@Input('options') options: Option[];
@Input('hint') hint = null;
@Input('placeholder') placeholder = '';
@Input() inputClass: string = 'input-box';
/** Extra element Right or Left of the input */
@Input() extraLeft: boolean = true;
@Input() gridSmall: boolean = false;
@Input() hideControl: boolean = false;
@Input() flex: 'middle' | 'top' | 'bottom' = 'middle';
/** Icon Right or Left on the input */
@Input() icon: string = null;
@Input() iconLeft: boolean = false;
/** Custom messages */
@Input() warning: string = null;
@Input() note: string = null;
/** Chip options */
@Input() removable: boolean = true;
@Input() addExtraChips: boolean = false;
@Input() smallChip: boolean = false;
@Input() panelWidth: number = 300;
@Input() panelClass: string = null;
@Input() showOptionsOnEmpty: boolean = true;
@Output() focusEmitter: EventEmitter = new EventEmitter();
/** Internal basic information */
public required: boolean = false;
private initValue: any;
/** Chips */
public filteredOptions: Observable