"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ContextMenu = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _SidebarItemButtonNext = _interopRequireDefault(require("../../SidebarItemNext/SidebarItemButtonNext"));
var _SidebarNextContext = require("../../SidebarNext/SidebarNextContext");
var _constants = require("../constants");
var _SidebarSubMenuNextSt = require("../SidebarSubMenuNext.st.css.js");
var _ContextMenuPopover = require("./ContextMenuPopover");
var _common = require("./common");
var _excluded = ["title", "suffix", "prefix", "children", "dataHook", "itemKey", "disabled", "onClick", "onExpand", "onCollapse", "onQuickNavOpen"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/SidebarSubMenuNext/components/ContextMenu.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 ContextMenu = _ref => {
  var {
      title,
      suffix,
      prefix,
      children,
      dataHook,
      itemKey,
      disabled,
      onClick,
      onExpand,
      onCollapse,
      onQuickNavOpen
    } = _ref,
    asComponentProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var context = (0, _react.useContext)(_SidebarNextContext.SidebarNextContext);
  var selected = context.selectedPath.includes(itemKey);
  var handleClick = (0, _react.useCallback)(event => {
    context.closeQuickNav == null || context.closeQuickNav();

    // @ts-ignore
    onClick == null || onClick(event, itemKey); // FIXME: this was never typed but implemented originally
  },
  // eslint-disable-next-line react-hooks/exhaustive-deps
  [context.closeQuickNav, onClick, itemKey]);
  return /*#__PURE__*/_react.default.createElement(_ContextMenuPopover.ContextMenuPopover, {
    dataHook: (0, _constants.getCompoundDataHook)(dataHook, _constants.dataHooks.submenuPopover),
    element: /*#__PURE__*/_react.default.createElement(_SidebarItemButtonNext.default, (0, _extends2.default)({
      prefix: prefix,
      suffix: (0, _common.getSuffixWithChevron)(suffix),
      onClick: handleClick,
      disabled: disabled,
      itemKey: itemKey,
      dataHook: (0, _constants.getCompoundDataHook)(dataHook, _constants.dataHooks.sidebarItem),
      className: (0, _SidebarSubMenuNextSt.st)(_SidebarSubMenuNextSt.classes.subMenu, {
        animation: 'closed',
        selected
      })
    }, asComponentProps, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 42,
        columnNumber: 9
      }
    }), title),
    content: /*#__PURE__*/_react.default.createElement(_SidebarNextContext.SidebarNextContext.Provider, {
      value: _objectSpread(_objectSpread({}, context), {}, {
        level: context.level + 1,
        parent: 'inContextMenu',
        inert: true,
        // popover items are not focusable
        isFirstLevelWithPrefix: context.level === 1 ? !!prefix : context.isFirstLevelWithPrefix
      }),
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 56,
        columnNumber: 9
      }
    }, children),
    disabled: disabled,
    onShow: onQuickNavOpen,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 39,
      columnNumber: 5
    }
  });
};
exports.ContextMenu = ContextMenu;
//# sourceMappingURL=ContextMenu.js.map