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); }

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 from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import Icon from "react-oui-icons";
import Button from "../../Button";
import BlockList from "../../BlockList";

function ListItem(_ref) {
  var buttonText = _ref.buttonText,
      className = _ref.className,
      description = _ref.description,
      id = _ref.id,
      name = _ref.name,
      onButtonClick = _ref.onButtonClick,
      _onClick = _ref.onClick,
      testSection = _ref.testSection,
      hasFauxFocus = _ref.hasFauxFocus,
      props = _objectWithoutProperties(_ref, ["buttonText", "className", "description", "id", "name", "onButtonClick", "onClick", "testSection", "hasFauxFocus"]);

  return React.createElement(BlockList.Item, _extends({
    className: className,
    hasFauxFocus: hasFauxFocus,
    onClick: function onClick(event) {
      return _onClick(event, id, name, description);
    } // eslint-disable-line react/jsx-no-bind
    ,
    testSection: testSection
  }, props), React.createElement("div", {
    className: "flex flex-align--center"
  }, React.createElement("div", {
    className: "push--right flex"
  }, React.createElement(Icon, {
    name: "add"
  })), React.createElement("div", {
    className: classNames("flex--1", {
      "push-half--ends": !description
    })
  }, React.createElement("div", null, name), !!description && React.createElement("div", {
    className: "muted micro"
  }, description)), !!buttonText && !!onButtonClick && React.createElement(Button, {
    size: "tiny",
    style: "outline",
    width: "default",
    onClick: function onClick(event) {
      // eslint-disable-line react/jsx-no-bind
      // Prevent the outer Blocklist.Item's onClick from being called
      event.stopPropagation();
      onButtonClick(event, id, name, description);
    }
  }, buttonText)));
}

ListItem.propTypes = {
  /* Optional Button text - must be present for optional button to show up */
  buttonText: PropTypes.string,

  /** CSS class names. */
  className: PropTypes.string,

  /* Description of ListItem */
  description: PropTypes.string,

  /* Boolean to set faux focus of a list item */
  hasFauxFocus: PropTypes.bool,

  /* ID used to pass into functions calls */
  id: PropTypes.number,

  /* Name of entity */
  name: PropTypes.string.isRequired,

  /**
   * Optional function, intentionally not in defaultProps
   *  - Secondary function for additional action (e.g. "View entity")
   *  - Called with the following arguments: event, id, name, description
   **/
  onButtonClick: PropTypes.func,

  /*
   * Primary function that is called with the following arguments:
   * - event, id, name, description
   **/
  onClick: PropTypes.func.isRequired,

  /* String value for the outermost container's data-test-section attribute */
  testSection: PropTypes.string
};
ListItem.defaultProps = {
  buttonText: "",
  description: "",
  hasFauxFocus: false,
  id: 0,
  testSection: ""
};
export default ListItem;