function _extends() { _extends = Object.assign || 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); }

import React from 'react';
import { MenuContext } from './Menu';
import { Text } from '../../primitives';
import { usePropsConfig, themeTools } from '../../../theme';
import { TouchableItem } from './TouchableItem';
export const MenuItem = ({
  children,
  onPress,
  style,
  textStyle,
  ...props
}) => {
  const {
    closeMenu,
    closeOnSelect
  } = React.useContext(MenuContext);
  const newProps = usePropsConfig('MenuItem', props);
  let allProps = { ...newProps,
    ...(newProps.isDisabled ? newProps._disabled : {})
  };
  const [textProps, touchProps] = themeTools.extractInObject(allProps, ['color', 'fontWeight', 'fontStyle', 'fontFamily', 'fontSize', 'padding', 'px', 'py', 'textAlign']);
  return /*#__PURE__*/React.createElement(TouchableItem, _extends({}, touchProps, {
    style: style,
    onPress: e => {
      if (!props.isDisabled) {
        onPress && onPress(e);

        if (closeOnSelect) {
          closeMenu();
        }
      }
    }
  }), /*#__PURE__*/React.createElement(React.Fragment, null, React.Children.map(children, (child, index) => {
    if (typeof child === 'string') {
      return /*#__PURE__*/React.createElement(Text, _extends({}, textProps, {
        key: "menu-item-".concat(index),
        style: textStyle
      }), child);
    } else {
      return child;
    }
  })));
};
//# sourceMappingURL=MenuItem.js.map