'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
require('core-js/modules/es.array.concat.js');
var React = require('react');
var PropTypes = require('prop-types');
var classnames = require('classnames');
var Settings = require('../../../constants/Settings.js');
var TableViewItemPropTypes = require('./TableViewItemPropTypes.js');
var iconsReact = require('@carbon/icons-react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  isCompact: PropTypes__default.default.bool.isRequired,
  activeViewEdited: PropTypes__default.default.bool.isRequired,
  isSelected: PropTypes__default.default.bool.isRequired,
  item: TableViewItemPropTypes.isRequired,
  i18n: PropTypes__default.default.shape({
    view: PropTypes__default.default.string,
    edited: PropTypes__default.default.string
  }).isRequired,
  testID: PropTypes__default.default.string
};
var defaultProps = {
  testID: 'TableViewDropdownItem'
};
var TableViewDropdownItem = function TableViewDropdownItem(_ref) {
  var _ref$item = _ref.item,
    customAction = _ref$item.customAction,
    text = _ref$item.text,
    Icon = _ref$item.icon,
    tooltip = _ref$item.tooltip,
    isSelected = _ref.isSelected,
    activeViewEdited = _ref.activeViewEdited,
    i18n = _ref.i18n,
    isCompact = _ref.isCompact,
    testID = _ref.testID;
  var showEdited = isSelected && activeViewEdited && !customAction;
  var editedPostfix = " - ".concat(i18n.edited);
  return /*#__PURE__*/React__default.default.createElement("div", {
    "data-testid": testID,
    title: "".concat(tooltip || text).concat(showEdited ? editedPostfix : ''),
    className: classnames__default.default("".concat(iotPrefix, "--view-dropdown__item"), _defineProperty__default.default({}, "".concat(iotPrefix, "--view-dropdown__item-link"), customAction))
  }, isSelected && !isCompact ? /*#__PURE__*/React__default.default.createElement("span", {
    className: "".concat(iotPrefix, "--view-dropdown__button-prefix")
  }, /*#__PURE__*/React__default.default.createElement(iconsReact.View, {
    size: 20
  }), /*#__PURE__*/React__default.default.createElement("span", null, "".concat(i18n.view, ": "))) : null, /*#__PURE__*/React__default.default.createElement("span", null, text, showEdited ? /*#__PURE__*/React__default.default.createElement("span", {
    className: "".concat(iotPrefix, "--view-dropdown__edited-text")
  }, editedPostfix) : null), Icon && !isCompact ? /*#__PURE__*/React__default.default.createElement(Icon, {
    className: classnames__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--view-dropdown__item-link-icon"), customAction))
  }) : null);
};
TableViewDropdownItem.propTypes = propTypes;
TableViewDropdownItem.defaultProps = defaultProps;
TableViewDropdownItem.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TableViewDropdownItem",
  "props": {
    "testID": {
      "defaultValue": {
        "value": "'TableViewDropdownItem'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isCompact": {
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "activeViewEdited": {
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "isSelected": {
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "item": {
      "description": "",
      "type": {
        "name": "custom",
        "raw": "TableViewItemPropType.isRequired"
      },
      "required": false
    },
    "i18n": {
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "view": {
            "name": "string",
            "required": false
          },
          "edited": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": true
    }
  }
};
var TableViewDropdownItem$1 = TableViewDropdownItem;

module.exports = TableViewDropdownItem$1;
