import _styled from "styled-components";
var _excluded = ["attachedToRef", "children", "clickType", "initialIsOpen", "onHide", "onShow"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo } from 'react';
import { useClickMenu, CLICK_BUTTON } from '../../hooks/useClickMenu';
import { StyledContextMenu } from './partials/StyledContextMenu';
export var ContextMenu = function ContextMenu(_ref) {
  var attachedToRef = _ref.attachedToRef,
    children = _ref.children,
    _ref$clickType = _ref.clickType,
    clickType = _ref$clickType === void 0 ? CLICK_BUTTON.RIGHT : _ref$clickType,
    _ref$initialIsOpen = _ref.initialIsOpen,
    initialIsOpen = _ref$initialIsOpen === void 0 ? false : _ref$initialIsOpen,
    onHide = _ref.onHide,
    onShow = _ref.onShow,
    rest = _objectWithoutProperties(_ref, _excluded);
  var _useClickMenu = useClickMenu({
      attachedToRef: attachedToRef,
      clickType: clickType,
      initialIsOpen: initialIsOpen,
      onHide: onHide,
      onShow: onShow
    }),
    isOpen = _useClickMenu.isOpen,
    floatingElementRef = _useClickMenu.floatingElementRef,
    styles = _useClickMenu.styles,
    attributes = _useClickMenu.attributes;
  var hasIcons = useMemo(function () {
    return !!React.Children.toArray(children).filter(function (child) {
      var _props;
      return child === null || child === void 0 ? void 0 : (_props = child.props) === null || _props === void 0 ? void 0 : _props.icon;
    }).length;
  }, [children]);
  return /*#__PURE__*/React.createElement(_StyledStyledContextMenu, _extends({
    ref: floatingElementRef,
    $hasIcons: hasIcons,
    $isOpen: isOpen
  }, attributes.popper, {
    role: "menu"
  }, rest, {
    $_css: styles.popper
  }), children);
};
ContextMenu.displayName = 'ContextMenu';
var _StyledStyledContextMenu = _styled(StyledContextMenu).withConfig({
  displayName: "ContextMenu___StyledStyledContextMenu",
  componentId: "sc-73zjkg-0"
})(["", ""], function (p) {
  return p.$_css;
});