'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var reactDom = require('react-dom');
var usePortal = require('@prom-ui/core/usePortal');

function _interopNamespaceCompat(e) {
    if (e && typeof e === 'object' && 'default' in e) return e;
    var n = Object.create(null);
    if (e) {
        Object.keys(e).forEach(function (k) {
            if (k !== 'default') {
                var d = Object.getOwnPropertyDescriptor(e, k);
                Object.defineProperty(n, k, d.get ? d : {
                    enumerable: true,
                    get: function () { return e[k]; }
                });
            }
        });
    }
    n.default = e;
    return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);

var PortalApp = function PortalApp(_ref) {
  var id = _ref.id,
    children = _ref.children;
  var target = usePortal.usePortal(id);
  if (target) {
    return /*#__PURE__*/reactDom.createPortal(children, target);
  }
  return children;
};
var Portal = function Portal(_ref2) {
  var _ref2$id = _ref2.id,
    id = _ref2$id === void 0 ? 'react-portal' : _ref2$id,
    _ref2$isActive = _ref2.isActive,
    isActive = _ref2$isActive === void 0 ? true : _ref2$isActive,
    children = _ref2.children;
  if (!isActive) {
    return children;
  }
  return /*#__PURE__*/React__namespace.createElement(PortalApp, {
    id: id
  }, children);
};
Portal.displayName = 'Portal';

exports.Portal = Portal;
