"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ToastPlugin = void 0;
var _vue = require("vue");
var _constants = require("@inkline/inkline/constants");
var _IToastContainer = require("@inkline/inkline/components/IToastContainer");
var _plugins = require("@inkline/inkline/plugins");
const ToastPlugin = exports.ToastPlugin = {
  install: (app, {
    inkline
  }) => {
    app.config.globalProperties.$toast = _constants.toastService;
    app.provide(_constants.InklineToastKey, _constants.toastService);
    if (typeof window === "undefined") {
      return;
    }
    const containerId = _constants.defaultToastContainerId;
    const containerDataAttribute = `data-${containerId}`;
    let container = document.querySelector(`#${containerId}`);
    if (!container) {
      container = document.createElement("div");
      container.id = containerId;
      document.body.appendChild(container);
    }
    if (!container.hasAttribute(containerDataAttribute)) {
      const toastApp = (0, _vue.createApp)(_IToastContainer.IToastContainer, {
        eventBus: _constants.toastEventBus
      });
      toastApp.provide(_constants.InklineKey, inkline);
      toastApp.use(_plugins.IconsPlugin);
      container.setAttribute(containerDataAttribute, "");
      toastApp.mount(container);
    }
  }
};