text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.EuiPortal = exports.INSERT_POSITIONS = exports.insertPositions = void 0;
  
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
  
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  
  var _react = _interopRequireDefault(require("react"));
  
  var _propTypes = _interopRequireDefault(require("prop-types"));
  
  var _reactDom = require("react-dom");
  
  var _common = require("../common");
  
  /*
   * Licensed to Elasticsearch B.V. under one or more contributor
   * license agreements. See the NOTICE file distributed with
   * this work for additional information regarding copyright
   * ownership. Elasticsearch B.V. licenses this file to you under
   * the Apache License, Version 2.0 (the "License"); you may
   * not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  
  /**
   * NOTE: We can't test this component because Enzyme doesn't support rendering
   * into portals.
   */
  var insertPositions = {
    after: 'afterend',
    before: 'beforebegin'
  };
  exports.insertPositions = insertPositions;
  var INSERT_POSITIONS = (0, _common.keysOf)(insertPositions);
  exports.INSERT_POSITIONS = INSERT_POSITIONS;
  
  var EuiPortal =
  /*#__PURE__*/
  function (_React$Component) {
    (0, _inherits2.default)(EuiPortal, _React$Component);
  
    function EuiPortal(props) {
      var _this;
  
      (0, _classCallCheck2.default)(this, EuiPortal);
      _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(EuiPortal).call(this, props));
      (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "portalNode", void 0);
      var insert = _this.props.insert;
      _this.portalNode = document.createElement('div');
  
      if (insert == null) {
        // no insertion defined, append to body
        document.body.appendChild(_this.portalNode);
      } else {
        // inserting before or after an element
        var sibling = insert.sibling,
            position = insert.position;
        sibling.insertAdjacentElement(insertPositions[position], _this.portalNode);
      }
  
      return _this;
    }
  
    (0, _createClass2.default)(EuiPortal, [{
      key: "componentDidMount",
      value: function componentDidMount() {
        this.updatePortalRef(this.portalNode);
      }
    }, {
      key: "componentWillUnmount",
      value: function componentWillUnmount() {
        if (this.portalNode.parentNode) {
          this.portalNode.parentNode.removeChild(this.portalNode);
        }
  
        this.updatePortalRef(null);
      }
    }, {
      key: "updatePortalRef",
      value: function updatePortalRef(ref) {
        if (this.props.portalRef) {
          this.props.portalRef(ref);
        }
      }
    }, {
      key: "render",
      value: function render() {
        return (0, _reactDom.createPortal)(this.props.children, this.portalNode);
      }
    }]);
    return EuiPortal;
  }(_react.default.Component);
  
  exports.EuiPortal = EuiPortal;
  EuiPortal.propTypes = {
    children: _propTypes.default.node.isRequired,
    insert: _propTypes.default.shape({
      sibling: _propTypes.default.any.isRequired,
      position: _propTypes.default.oneOf(["after", "before"]).isRequired
    }),
    portalRef: _propTypes.default.func
  };
  EuiPortal.__docgenInfo = {
    "description": "",
    "methods": [{
      "name": "updatePortalRef",
      "docblock": null,
      "modifiers": [],
      "params": [{
        "name": "ref",
        "type": null
      }],
      "returns": null
    }],
    "displayName": "EuiPortal",
    "props": {
      "children": {
        "type": {
          "name": "node"
        },
        "required": true,
        "description": ""
      },
      "insert": {
        "type": {
          "name": "shape",
          "value": {
            "sibling": {
              "name": "any",
              "required": true
            },
            "position": {
              "name": "enum",
              "value": [{
                "value": "\"after\"",
                "computed": false
              }, {
                "value": "\"before\"",
                "computed": false
              }],
              "required": true
            }
          }
        },
        "required": false,
        "description": ""
      },
      "portalRef": {
        "type": {
          "name": "func"
        },
        "required": false,
        "description": ""
      }
    }
  };