import { Component, EventEmitter, Input, Output } from '@angular/core';

@Component({
  selector: 'filter-button-group-with-count',
  standalone: true,
  imports: [],
  templateUrl: './filter-button-group-with-count.component.html',
  styleUrl: './filter-button-group-with-count.component.less',
})
export class FilterButtonGroupWithCountComponent<T = any> {
  @Input() emptyAbleToSelect = false;
  @Input() label = '';
  @Input() colon = true;
  @Input() labelMarginRight = '0px';
  @Input() options: OptionWithCount<T>[] = [];
  @Input() activeValue: T | null = null;
  @Output() change = new EventEmitter<T>();

  handleChange(value: T) {
    if (!this.emptyAbleToSelect && this.options.find(o => o.value === value)?.count === 0) {
      return;
    }
    this.change.emit(value);
  }
}
