"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index_esm = require("../../../@vxe-ui/core/es/index.esm.js");
const XEUtils = require("xe-utils");
const drawer = require("./src/drawer.js");
const index = require("../dynamics/index.js");
function handleDrawer(options) {
  index.checkDynamic();
  return new Promise((resolve) => {
    if (options && options.id && drawer.allActiveDrawers.some((comp) => comp.props.id === options.id)) {
      resolve("exist");
    } else {
      const _onHide = options.onHide;
      const drawerOpts = Object.assign(options, {
        key: XEUtils.uniqueId(),
        modelValue: true,
        onHide(params) {
          const drawerList = index.dynamicStore.drawers;
          if (_onHide) {
            _onHide(params);
          }
          index.dynamicStore.drawers = drawerList.filter((item) => item.key !== drawerOpts.key);
          resolve(params.type);
        }
      });
      index.dynamicStore.drawers.push(drawerOpts);
    }
  });
}
function getDrawer(id) {
  return XEUtils.find(drawer.allActiveDrawers, ($drawer) => $drawer.props.id === id);
}
function closeDrawer(id) {
  const drawers = id ? [getDrawer(id)] : drawer.allActiveDrawers;
  const restPromises = [];
  drawers.forEach(($drawer) => {
    if ($drawer) {
      restPromises.push($drawer.close());
    }
  });
  return Promise.all(restPromises);
}
function openDrawer(options) {
  return handleDrawer(Object.assign({}, options));
}
const DrawerController = {
  get: getDrawer,
  close: closeDrawer,
  open: openDrawer
};
const VxeDrawer = Object.assign(drawer.default, {
  install: function(app) {
    app.component(drawer.default.name, drawer.default);
  }
});
index_esm.VxeUI.drawer = DrawerController;
index.dynamicApp.use(VxeDrawer);
index_esm.VxeUI.component(drawer.default);
const Drawer = VxeDrawer;
exports.Drawer = Drawer;
exports.DrawerController = DrawerController;
exports.VxeDrawer = VxeDrawer;
exports.default = VxeDrawer;
