"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@floating-ui/react");
var _usePopoverNextContext = require("../../hooks/usePopoverNextContext");
var _ContentSt = require("./Content.st.css.js");
var _PopoverNext = require("../../PopoverNext.constants");
var _context = require("../../../WixDesignSystemProvider/context");
var _excluded = ["style"],
  _excluded2 = ["className"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/PopoverNext/components/Content/Content.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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) { (0, _defineProperty2.default)(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; }
var Content = /*#__PURE__*/(0, _react.forwardRef)(function Content(_ref, propRef) {
  var {
      style
    } = _ref,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var {
    dataHook,
    placement,
    focusManagerEnabled,
    context,
    appendTo,
    portalRoot,
    zIndex,
    popoverStyles,
    interactions,
    open,
    skin,
    transitionStyles,
    overlay,
    style: styleFromUser,
    showArrow,
    contentClassName,
    arrowProps
  } = (0, _usePopoverNextContext.usePopoverNextContext)();
  var {
    contextClassName
  } = (0, _react.useContext)(_context.WixDesignSystemContext);
  var ref = (0, _react2.useMergeRefs)([context.refs.setFloating, propRef]);
  var _interactions$getFloa = interactions.getFloatingProps(props),
    {
      className
    } = _interactions$getFloa,
    floatingProps = (0, _objectWithoutProperties2.default)(_interactions$getFloa, _excluded2);
  if (!open) {
    return null;
  }
  var mergedStyles = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, popoverStyles), {}, {
    zIndex
  }, transitionStyles), styleFromUser), style);
  var content = /*#__PURE__*/_react.default.createElement(_react2.FloatingFocusManager, {
    context: context,
    disabled: !focusManagerEnabled,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 54,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, overlay === true ? /*#__PURE__*/_react.default.createElement(_react2.FloatingOverlay, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 56,
      columnNumber: 31
    }
  }) : overlay !== null && overlay !== void 0 ? overlay : null, /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
    ref: ref,
    "data-hook": "".concat(dataHook, "-content"),
    "data-zindex": zIndex,
    className: (0, _ContentSt.st)(_ContentSt.classes.root, {
      skin,
      placement,
      showArrow
    }, className, contextClassName),
    style: mergedStyles
  }, floatingProps, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 57,
      columnNumber: 11
    }
  }), showArrow && /*#__PURE__*/_react.default.createElement(_react2.FloatingArrow, (0, _extends2.default)({}, arrowProps, {
    className: (0, _ContentSt.st)(_ContentSt.classes.arrow, {
      skin
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 71,
      columnNumber: 15
    }
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _ContentSt.st)(_ContentSt.classes.contentWrapper, {}, contentClassName),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 76,
      columnNumber: 13
    }
  }, props.children))));
  if (appendTo === _PopoverNext.APPEND_TO.window || appendTo === _PopoverNext.APPEND_TO.viewport) {
    return /*#__PURE__*/_react.default.createElement(_react2.FloatingPortal, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 86,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement("div", {
      /*
       * TODO: [remove when major version bump]
       * for old popover click outside to work when new popover is used inside of it
       * (edge case where different WDS versions are used)
       */
      "data-hook": "popover-portal",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 87,
        columnNumber: 11
      }
    }, content));
  }
  if (portalRoot) {
    return /*#__PURE__*/_react.default.createElement(_react2.FloatingPortal, {
      root: portalRoot,
      preserveTabOrder: false,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 103,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement("div", {
      /*
       * TODO: [remove when major version bump]
       * for old popover click outside to work when new popover is used inside of it
       * (edge case where different WDS versions are used)
       */
      "data-hook": "popover-portal",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 104,
        columnNumber: 11
      }
    }, content));
  }
  return content;
});
var _default = exports.default = Content;
//# sourceMappingURL=Content.js.map