"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.ContextMenuListItem = void 0;

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _behaviors = require("../../../behaviors");

var _branding = require("../../../../mixins/branding");

var _contextMenuListItem = require("./context-menu-list-item.css-rules");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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 StyledButton = (0, _styledComponents["default"])(_behaviors.UnstyledButton).withConfig({
  displayName: "StyledButton",
  componentId: "sc-1kepzvx-0"
})(["padding:10px 20px;font-size:", ";color:", ";outline:none;&:active{background:", ";color:", ";}&:hover{background-color:", ";color:", ";}"], _contextMenuListItem.getItemFontSize, _contextMenuListItem.getItemColor, (0, _contextMenuListItem.getItemBackgroundColor)('active'), (0, _branding.getPaletteColor)('white'), (0, _contextMenuListItem.getItemBackgroundColor)('hover'), (0, _branding.getPaletteColor)('white'));

var useContextMenuListItemState = function useContextMenuListItemState(_ref) {
  var onSelect = _ref.onSelect,
      item = _ref.item,
      closeMenu = _ref.closeMenu;
  var handleOnClick = (0, _react.useCallback)(function (event) {
    event.stopPropagation();

    if (typeof onSelect === 'function') {
      onSelect(item);
    }

    closeMenu();
  }, [onSelect, item, closeMenu]);
  return {
    handleOnClick: handleOnClick
  };
};

var ContextMenuListItem = function ContextMenuListItem(_ref2) {
  var onSelect = _ref2.onSelect,
      item = _ref2.item,
      closeMenu = _ref2.closeMenu,
      _ref2$colorName = _ref2.colorName,
      colorName = _ref2$colorName === void 0 ? 'greyscale-black' : _ref2$colorName,
      children = _ref2.children,
      danger = _ref2.danger;

  var _useContextMenuListIt = useContextMenuListItemState({
    onSelect: onSelect,
    item: item,
    closeMenu: closeMenu
  }),
      handleOnClick = _useContextMenuListIt.handleOnClick;

  return /*#__PURE__*/_react["default"].createElement(StyledButton, {
    insetFocus: true,
    hasTransition: false,
    onClick: handleOnClick,
    colorName: colorName,
    danger: danger
  }, children);
};

exports.ContextMenuListItem = ContextMenuListItem;