import { Injectable } from '@angular/core';

import {
  MatSnackBar,
  MatSnackBarConfig,
  MatSnackBarRef,
  SimpleSnackBar
} from '@angular/material';
import { ComponentType } from '@angular/cdk/portal';

@Injectable({
  providedIn: 'root'
})
export class SnackBarService {
  public constructor(private matSnackBar: MatSnackBar) {}

  public open(
    message: string,
    action?: string,
    config?: MatSnackBarConfig
  ): MatSnackBarRef<SimpleSnackBar> {
    return this.matSnackBar.open(message, action, config);
  }

  public openFromComponent<T, D = any>(
    componentRef: ComponentType<T>,
    config?: MatSnackBarConfig<D>
  ): MatSnackBarRef<T> {
    return this.matSnackBar.openFromComponent<T>(componentRef, config);
  }
}
