import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { ToastStore } from '../../interfaces/store/toast.interface';
import { toastActions } from './toast.actions';

@Injectable({
  providedIn: 'root',
})
export class ToastDispatchers {
  constructor(private store: Store<{ toast: ToastStore }>) {}

  setToasts(newState: ToastStore) {
    this.store.dispatch(toastActions.set_toasts({ toasts: newState }));
  }

  resetToasts() {
    this.store.dispatch(toastActions.reset_toasts());
  }

  showSuccess(toast: ToastStore['success']) {
    this.store.dispatch(toastActions.show_toast_success({ toast }));
  }

  hideSuccess() {
    this.store.dispatch(toastActions.hide_toast_success());
  }

  showWarn(toast: ToastStore['warn']) {
    this.store.dispatch(toastActions.show_toast_warn({ toast }));
  }

  hideWarn() {
    this.store.dispatch(toastActions.hide_toast_warn());
  }

  showError(toast: ToastStore['error']) {
    this.store.dispatch(toastActions.show_toast_error({ toast }));
  }

  hideError() {
    this.store.dispatch(toastActions.hide_toast_error());
  }
}
