import { pubSubService as t, PUB_SUB_EVENTS as a } from "./index-pub-sub.js";
import { translationService as i } from "./index-translation.service.js";
class o {
  /**
   * Close
   */
  closeEv(e) {
    t.$pub(a.reactSnackbarClose, {
      id: e
    });
  }
  /**
   * Open
   */
  open({
    type: e,
    title: r,
    message: s,
    onClose: n
  }) {
    const c = `${Math.random()}`;
    return t.$pub(a.reactSnackbarOpen, {
      type: e,
      title: r,
      message: s,
      onClose: n
    }), c;
  }
  /**
   * Open Success
   */
  openWarningSnackbar(e, r) {
    this.open({
      type: "warning",
      title: "",
      message: this.parseMessage(e),
      onClose: r
    });
  }
  /**
   * Open Success
   */
  openSuccessSnackbar(e, r) {
    this.open({
      type: "success",
      title: "",
      message: this.parseMessage(e),
      onClose: r
    });
  }
  /**
   * Open Error
   */
  openErrorSnackbar(e, r) {
    this.open({
      type: "danger",
      title: "",
      message: this.parseMessage(e),
      onClose: r
    });
  }
  /**
   * On
   */
  on(e, r) {
    document.addEventListener(e, (s) => r(s.detail));
  }
  /**
   * Parse message
   */
  parseMessage(e) {
    if (typeof e != "string") {
      const {
        text: r,
        replacements: s
      } = e;
      return i.get(r, s).value;
    }
    return e;
  }
}
const u = new o();
export {
  u as snackbarService
};
