import { action, makeObservable, observable } from 'mobx';
import { ToastConfig } from '@wix/bex-core';

export class ToastState {
  configs = observable.array([] as ToastConfig[], {
    deep: false,
  });

  constructor() {
    makeObservable(this, {
      showToast: action.bound,
      remove: action.bound,
    });
  }

  remove(config: ToastConfig) {
    this.configs.remove(config);
  }

  showToast(config: ToastConfig) {
    this.configs.push(config);

    return {
      remove: () => {
        this.configs.remove(config);
      },
    };
  }
}
