"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Popper = void 0;

var _react = _interopRequireWildcard(require("react"));

var _uuid = require("uuid");

var _reactPopper = require("react-popper");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var Popper = function Popper(_ref) {
  var reference = _ref.reference,
      placement = _ref.placement,
      children = _ref.children,
      isVisible = _ref.isVisible;
  var popperId = (0, _react.useMemo)(function () {
    return "popper-".concat((0, _uuid.v4)());
  }, []);
  return /*#__PURE__*/_react["default"].createElement(_reactPopper.Manager, null, /*#__PURE__*/_react["default"].createElement(_reactPopper.Reference, null, function (_ref2) {
    var ref = _ref2.ref;
    return reference({
      ref: ref,
      referenceProps: {
        'aria-describedby': popperId
      }
    });
  }), /*#__PURE__*/_react["default"].createElement(_reactPopper.Popper, {
    placement: placement
  }, function (_ref3) {
    var ref = _ref3.ref,
        style = _ref3.style,
        popperPlacement = _ref3.placement,
        arrowProps = _ref3.arrowProps;
    return isVisible ? children({
      ref: ref,
      style: style,
      placement: popperPlacement,
      arrowProps: arrowProps,
      popperId: popperId
    }) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null);
  }));
};

exports.Popper = Popper;
Popper.displayName = 'Popper';