import { Highlightable, ListKeyManagerOption } from '@angular/cdk/a11y';
import {
  Component,
  ChangeDetectionStrategy,
  Output,
  EventEmitter,
  Input,
  ViewEncapsulation,
  HostBinding,
  HostListener,
} from '@angular/core';

@Component({
  selector: '[uiAutocompleteItem]',
  templateUrl: 'autocomplete-item.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
})
export class UiAutocompleteItemComponent implements Highlightable {
  @HostBinding('class.ui-autocomplete-item') clazz = true;

  @Input('uiAutocompleteItem')
  item: any;

  @HostBinding('class.active')
  isActive = false;

  @Input()
  @HostBinding('disabled')
  disabled = false;

  onClick = (item: any) => {};

  constructor() {}

  @HostListener('click')
  handleClickEvent() {
    this.onClick?.call(null, this.item);
  }

  registerOnClick(fn: (item: any) => void) {
    this.onClick = fn;
  }

  setActiveStyles(): void {
    this.isActive = true;
  }

  setInactiveStyles(): void {
    this.isActive = false;
  }
}
