import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/esnext.iterator.filter.js";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _FcrDialogApi;
var _excluded = ["rootClassName", "content", "type", "children"];
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.map.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/esnext.map.delete-all.js";
import "core-js/modules/esnext.map.emplace.js";
import "core-js/modules/esnext.map.every.js";
import "core-js/modules/esnext.map.filter.js";
import "core-js/modules/esnext.map.find.js";
import "core-js/modules/esnext.map.find-key.js";
import "core-js/modules/esnext.map.includes.js";
import "core-js/modules/esnext.map.key-of.js";
import "core-js/modules/esnext.map.map-keys.js";
import "core-js/modules/esnext.map.map-values.js";
import "core-js/modules/esnext.map.merge.js";
import "core-js/modules/esnext.map.reduce.js";
import "core-js/modules/esnext.map.some.js";
import "core-js/modules/esnext.map.update.js";
import "core-js/modules/web.dom-collections.for-each.js";
import "core-js/modules/web.dom-collections.iterator.js";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import classNames from 'classnames';
import React from 'react';
import ReactDOM, { unmountComponentAtNode } from 'react-dom';
import { v4 as uuidv4 } from 'uuid';
import { BaseDialog, FcrConfirmDialog } from '.';
import { jsx as _jsx } from "react/jsx-runtime";
var DialogType = /*#__PURE__*/function (DialogType) {
  DialogType["CONFIRM"] = "confirm";
  DialogType["INFO"] = "info";
  DialogType["ERROR"] = "error";
  DialogType["WARNING"] = "warning";
  DialogType["SUCCESS"] = "success";
  DialogType["CLASS"] = "class";
  DialogType["INJECT"] = "inject";
  return DialogType;
}(DialogType || {});
var FcrDialog = function FcrDialog(props) {
  var rootClassName = props.rootClassName,
    content = props.content,
    type = props.type,
    children = props.children,
    other = _objectWithoutProperties(props, _excluded);
  switch (type) {
    case 'confirm':
      return /*#__PURE__*/_jsx(FcrConfirmDialog, _objectSpread(_objectSpread({
        classNames: classNames('confirm-dialog', rootClassName)
      }, other), {}, {
        children: content || children
      }));
    case 'warning':
      return /*#__PURE__*/_jsx(FcrConfirmDialog, _objectSpread(_objectSpread({
        classNames: classNames('warning-dialog', rootClassName)
      }, other), {}, {
        cancelButtonVisible: false,
        children: content || children
      }));
    case 'inject':
      return /*#__PURE__*/_jsx("div", {
        className: classNames('inject-dialog', rootClassName),
        children: content || children
      });
    default:
      return /*#__PURE__*/_jsx(BaseDialog, _objectSpread(_objectSpread({
        classNames: classNames('info-dialog', rootClassName)
      }, other), {}, {
        children: content || children
      }));
  }
};
export var FcrDialogApi = /*#__PURE__*/function () {
  function FcrDialogApi() {
    _classCallCheck(this, FcrDialogApi);
  }
  return _createClass(FcrDialogApi, null, [{
    key: "_createDialog",
    value: function _createDialog(config, type) {
      if (config.id && this._dialogs.has(config.id)) {
        return;
      }
      if (!config.id) config.id = uuidv4();
      var newConfig = _objectSpread(_objectSpread({}, config), {}, {
        dialogProps: _objectSpread(_objectSpread({}, config.dialogProps), {}, {
          type: type,
          visible: true
        })
      });
      this._dialogs.set(newConfig.id || config.id, newConfig);
      this._render(newConfig);
    }
  }, {
    key: "open",
    value: function open(config) {
      this._createDialog(config, DialogType.INFO);
    }
  }, {
    key: "injectOpen",
    value: function injectOpen(config) {
      this._createDialog(config, DialogType.INJECT);
    }
  }, {
    key: "confirm",
    value: function confirm(config) {
      this._createDialog(config, DialogType.CONFIRM);
    }
  }, {
    key: "warning",
    value: function warning(config) {
      this._createDialog(config, DialogType.WARNING);
    }
  }, {
    key: "info",
    value: function info(config) {
      this._createDialog(config, DialogType.INFO);
    }
  }, {
    key: "close",
    value: function close(id) {
      var dialog = this._dialogs.get(id);
      if (dialog) {
        this._unmountDialog(dialog);
        this._dialogs["delete"](id);
      }
    }
  }, {
    key: "closeAll",
    value: function closeAll() {
      this._dialogs.forEach(this._unmountDialog);
      this._dialogs.clear();
    }
  }]);
}();
_FcrDialogApi = FcrDialogApi;
_defineProperty(FcrDialogApi, "_dialogs", new Map());
_defineProperty(FcrDialogApi, "_dialogContainerCls", 'fcr-dialog-container');
_defineProperty(FcrDialogApi, "_unmountDialog", function (dialog) {
  if (dialog.portal) {
    unmountComponentAtNode(dialog.portal);
    if (dialog.portal.parentNode) {
      dialog.portal.parentNode.removeChild(dialog.portal);
    }
  }
});
_defineProperty(FcrDialogApi, "_render", function (dialog) {
  dialog.portal = document.createElement('div');
  dialog.portal.className = _FcrDialogApi._dialogContainerCls;
  document.body.appendChild(dialog.portal);
  ReactDOM.render(/*#__PURE__*/_jsx(FcrDialog, _objectSpread(_objectSpread({}, dialog.dialogProps), {}, {
    onClose: function onClose() {
      if (dialog.id) {
        _FcrDialogApi.close(dialog.id);
      } else {
        _FcrDialogApi.closeAll();
      }
    }
  })), dialog.portal);
});