import { Injectable, inject } from '@angular/core';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';

export type NotificationType = 'success' | 'error' | 'warning' | 'info';

@Injectable({
  providedIn: 'root',
})
export class NotificationService {
  private readonly snackBar = inject(MatSnackBar);

  private readonly defaultConfig: MatSnackBarConfig = {
    duration: 4000,
    horizontalPosition: 'end',
    verticalPosition: 'top',
  };

  success(message: string, action = 'Close'): void {
    this.show(message, action, 'success');
  }

  error(message: string, action = 'Close'): void {
    this.show(message, action, 'error');
  }

  warning(message: string, action = 'Close'): void {
    this.show(message, action, 'warning');
  }

  info(message: string, action = 'Close'): void {
    this.show(message, action, 'info');
  }

  private show(message: string, action: string, type: NotificationType): void {
    this.snackBar.open(message, action, {
      ...this.defaultConfig,
      panelClass: [`snackbar-${type}`],
    });
  }
}
