"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DynamicApp = void 0;
exports.checkDynamic = checkDynamic;
exports.dynamicStore = exports.dynamicApp = void 0;
var _vue = _interopRequireDefault(require("vue"));
var _core = require("@vxe-ui/core");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
var dynamicContainerElem;
var DynamicApp = exports.DynamicApp = _vue.default.extend({
  data: function data() {
    var modals = [];
    var drawers = [];
    return {
      modals: modals,
      drawers: drawers,
      globalLoading: null,
      globalWatermark: null,
      globalContextMenu: null
    };
  },
  methods: {
    renderVN: function renderVN(h) {
      var $xeDynamicApp = this;
      var VxeUIModalComponent = _core.VxeUI.getComponent('vxe-modal');
      var VxeUIDrawerComponent = _core.VxeUI.getComponent('vxe-drawer');
      var VxeUILoadingComponent = _core.VxeUI.getComponent('vxe-loading');
      var VxeUIWatermarkComponent = _core.VxeUI.getComponent('vxe-watermark');
      var VxeUIContextMenuComponent = _core.VxeUI.getComponent('vxe-context-menu');
      var modals = $xeDynamicApp.modals,
        drawers = $xeDynamicApp.drawers,
        globalLoading = $xeDynamicApp.globalLoading,
        globalWatermark = $xeDynamicApp.globalWatermark,
        globalContextMenu = $xeDynamicApp.globalContextMenu;
      var cmOns;
      if (globalContextMenu) {
        var events = globalContextMenu.events || {};
        var _optionClick = events.optionClick,
          _show = events.show,
          _hide = events.hide;
        cmOns = {
          show: function show(params) {
            var $contextMenu = params.$contextMenu;
            if (_show) {
              _show.call($contextMenu, params);
            }
          },
          hide: function hide(params) {
            var $contextMenu = params.$contextMenu;
            if (_hide) {
              _hide.call($contextMenu, params);
            }
            dynamicStore.globalContextMenu = null;
          },
          'option-click': function optionClick(params) {
            var $contextMenu = params.$contextMenu;
            if (_optionClick) {
              _optionClick.call($contextMenu, params);
            }
          }
        };
      }
      return h('div', {}, [modals.length ? h('div', {
        key: 1,
        class: 'vxe-dynamics--modal'
      }, modals.map(function (item) {
        return h(VxeUIModalComponent, {
          key: item.key,
          props: item.props,
          on: item.on
        });
      })) : (0, _core.renderEmptyElement)($xeDynamicApp), drawers.length ? h('div', {
        key: 2,
        class: 'vxe-dynamics--drawer'
      }, drawers.map(function (item) {
        return h(VxeUIDrawerComponent, {
          key: item.key,
          props: item.props,
          on: item.on
        });
      })) : (0, _core.renderEmptyElement)($xeDynamicApp), globalWatermark ? h(VxeUIWatermarkComponent, {
        key: 'gw',
        props: globalWatermark
      }) : (0, _core.renderEmptyElement)($xeDynamicApp), globalLoading ? h(VxeUILoadingComponent, {
        key: 'gl',
        props: globalLoading
      }) : (0, _core.renderEmptyElement)($xeDynamicApp), globalContextMenu ? h(VxeUIContextMenuComponent, {
        key: 'cm',
        props: globalContextMenu,
        on: cmOns
      }) : (0, _core.renderEmptyElement)($xeDynamicApp)]);
    }
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
var dynamicApp = exports.dynamicApp = DynamicApp;
var dynamicStore = exports.dynamicStore = new DynamicApp();
function checkDynamic() {
  if (!dynamicContainerElem) {
    dynamicContainerElem = document.createElement('div');
    dynamicContainerElem.className = 'vxe-dynamics';
    document.body.appendChild(dynamicContainerElem);
    dynamicStore.$mount(dynamicContainerElem);
  }
}