"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toastEventBus = exports.createToastService = exports.ToastPlugin = void 0;
var _vue = require("vue");
var _utils = require("@grozav/utils");
var _inkline = require("@inkline/inkline");
const toastEventBus = (0, _utils.createEventBus)();
exports.toastEventBus = toastEventBus;
const createToastService = () => ({
  show: options => {
    toastEventBus.emit("show", options);
  },
  hide: options => {
    toastEventBus.emit("hide", options);
  },
  hideAll: () => {
    toastEventBus.emit("hideAll", {});
  }
});
exports.createToastService = createToastService;
const ToastPlugin = {
  install: (app, {
    inkline
  }) => {
    const toastService = createToastService();
    const toastApp = (0, _vue.createApp)(_inkline.IToastContainer);
    toastApp.provide(_inkline.InklineKey, inkline);
    toastApp.use(_inkline.IconsPlugin);
    if (typeof window !== "undefined") {
      const containerId = "inkline-toast-container";
      let container = document.querySelector(`#${containerId}`);
      if (!container) {
        container = document.createElement("div");
        container.id = containerId;
        document.body.appendChild(container);
      }
      toastApp.mount(container);
    }
    app.config.globalProperties.$toast = toastService;
    app.provide(_inkline.InklineToastKey, toastService);
  }
};
exports.ToastPlugin = ToastPlugin;