"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _Trigger = _interopRequireDefault(require("./components/Trigger/Trigger"));
var _Content = _interopRequireDefault(require("./components/Content/Content"));
var _usePopover = require("./hooks/usePopover");
var _PopoverNext = require("./PopoverNext.context");
var _PopoverNextSt = require("./PopoverNext.st.css.js");
var _deprecationLog = _interopRequireDefault(require("../utils/deprecationLog"));
var _excluded = ["children", "appendTo", "dataHook", "className", "onMouseEnter", "onMouseLeave", "onShow", "onHide", "onKeyDown", "fluid", "open", "skin", "theme", "shown", "dataListType"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/PopoverNext/PopoverNext.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; }
function PopoverNext(_ref) {
  var {
      children,
      appendTo,
      dataHook,
      className,
      onMouseEnter,
      onMouseLeave,
      onShow,
      onHide,
      onKeyDown,
      fluid,
      open = false,
      skin = 'light',
      theme,
      // deprecated
      shown,
      // deprecated
      dataListType
    } = _ref,
    restOptions = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var rootRef = (0, _react.useRef)(null);
  var prevOpenRef = (0, _react.useRef)(undefined);
  var popover = (0, _usePopover.usePopover)(_objectSpread(_objectSpread({}, restOptions), {}, {
    skin: theme || skin,
    open: shown !== null && shown !== void 0 ? shown : open,
    appendTo,
    onMouseEnter,
    onMouseLeave,
    dataHook,
    rootRef
  }));
  (0, _react.useEffect)(() => {
    if (theme) {
      (0, _deprecationLog.default)('<PopoverNext /> - `theme` prop is deprecated and will be removed in next major version, please use `skin` instead');
    }
    if (shown !== undefined) {
      (0, _deprecationLog.default)('<PopoverNext /> - `shown` prop is deprecated and will be removed in next major version, please use `open` instead');
    }
  }, [theme, shown]);
  (0, _react.useEffect)(() => {
    if (prevOpenRef.current === undefined) {
      prevOpenRef.current = popover.open;
      if (popover.open) {
        onShow == null || onShow();
      }
      return;
    }
    if (popover.open !== prevOpenRef.current) {
      prevOpenRef.current = popover.open;
      if (popover.open) {
        onShow == null || onShow();
      } else {
        onHide == null || onHide();
      }
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [popover.open]);
  return /*#__PURE__*/_react.default.createElement(_PopoverNext.PopoverNextContext.Provider, {
    value: popover,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 76,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    ref: rootRef,
    "data-hook": dataHook,
    "data-popover-root": true,
    "data-list-type": dataListType,
    className: (0, _PopoverNextSt.st)(_PopoverNextSt.classes.root, {
      fluid
    }, className),
    onKeyDown: onKeyDown,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 77,
      columnNumber: 7
    }
  }, children));
}
PopoverNext.displayName = 'PopoverNext';
PopoverNext.Trigger = _Trigger.default;
PopoverNext.Content = _Content.default;
var _default = exports.default = PopoverNext;
//# sourceMappingURL=PopoverNext.js.map