import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { Router } from '@angular/router';
import { UserNotification, UserNotificationService } from '../../services/user-notification.service';
import { TranslatePipe } from '../../../../../i18n/translate.pipe';

@Component({
  selector: 'app-floating-notifications',
  standalone: true,
  imports: [TranslatePipe],
  templateUrl: './floating-notifications.component.html',
  styleUrls: ['./floating-notifications.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class FloatingNotificationsComponent {
  private readonly notificationsService = inject(UserNotificationService);
  private readonly router = inject(Router);

  readonly notifications = this.notificationsService.notifications;

  dismiss(id: string): void {
    this.notificationsService.dismiss(id);
  }

  navigate(note: UserNotification): void {
    if (note.route) {
      void this.router.navigate(note.route);
    }
    this.dismiss(note.id);
  }
}
