import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
import { IUiInputGroup, UiInput, UiInputGroup } from '../../tree';

@Component({
  selector: 'ui-filter-filter-group-filter',
  templateUrl: 'filter-filter-group-filter.component.html',
  styleUrls: ['filter-filter-group-filter.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UiFilterFilterGroupFilterComponent {
  private _inputGroup: UiInputGroup;

  @Input()
  set inputGroup(value: IUiInputGroup) {
    if (value instanceof UiInputGroup) {
      this._inputGroup = value;
    } else {
      this._inputGroup = UiInputGroup.create(value);
    }
  }

  get uiInputGroup() {
    return this._inputGroup;
  }

  private _activeInput: UiInput;

  get activeInput() {
    return this.uiInputGroup?.input?.find((f) => f?.key === this._activeInput?.key) || this.uiInputGroup?.input?.find((f) => f);
  }

  get isFirstInputSelected() {
    return this.activeInput === this.uiInputGroup?.input?.find((f) => f);
  }

  constructor() {}

  setActiveInput(input: UiInput) {
    this._activeInput = input;
  }
}
