"use strict";

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