import { AriaLivePoliteness } from '@angular/cdk/a11y';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ToastPosition } from '@msfa-enums/toast-position.enum';
import { CustomError } from '@msfa-models/error/custom-error';
import { ErrorService } from '@msfa-services/error.service';
import { Observable } from 'rxjs';

@Component({
  selector: 'msfa-toast-list',
  templateUrl: './toast-list.component.html',
  styleUrls: ['./toast-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ToastListComponent {
  @Input() ariaLivePoliteness: AriaLivePoliteness = 'assertive';
  @Input() ariaAtomic = true;
  @Input() position: ToastPosition = ToastPosition.TOP_RIGHT;

  errors$: Observable<CustomError[]> = this.errorService.errors$;

  constructor(private errorService: ErrorService) {}

  get className(): string {
    return `toast-list toast-list--${this.position}`;
  }

  removeError(error: CustomError): void {
    this.errorService.remove(error);
  }
}
