'use strict';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.GridRowActions = exports.AlignTypes = void 0;

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _lodash = _interopRequireDefault(require("lodash"));

var _ButtonGroup = _interopRequireDefault(require("react-bootstrap/lib/ButtonGroup"));

var _Button = require("./Button");

/** @alias GridRowActions~AlignTypes */
var AlignClassNameMaps = {
  left: 'pull-left',
  right: 'pull-right',
  none: 'grid-row-inline-action-group'
};
/** @name GridRowActions~AlignTypes */

var AlignTypes = _lodash.default.mapValues(AlignClassNameMaps, function (val, key) {
  return key;
});

exports.AlignTypes = AlignTypes;

var GridRowActions =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(GridRowActions, _React$Component);

  function GridRowActions() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = GridRowActions.prototype;

  _proto.getAlignClassName = function getAlignClassName() {
    return AlignClassNameMaps.hasOwnProperty(this.props.align) ? AlignClassNameMaps[this.props.align] : AlignClassNameMaps.right;
  };

  _proto.render = function render() {
    var legacyActions = this.props.actions.map(function (action, i) {
      return _react.default.createElement(_Button.Button, {
        bsStyle: "link",
        "data-test-automation-id": action.testAutomationId,
        onClick: action.onClick,
        key: i
      }, action.text);
    });
    return _react.default.createElement(_ButtonGroup.default, {
      className: this.getAlignClassName() + " rc-gridRowActions"
    }, legacyActions.concat(this.props.children || []));
  };

  return GridRowActions;
}(_react.default.Component);

exports.GridRowActions = GridRowActions;
(0, _defineProperty2.default)(GridRowActions, "propTypes", {
  actions: _propTypes.default.array,
  align: _propTypes.default.oneOf(_lodash.default.keys(AlignClassNameMaps)),
  children: _propTypes.default.node
});
(0, _defineProperty2.default)(GridRowActions, "defaultProps", {
  actions: [],
  align: AlignTypes.right,
  children: null
});
(0, _defineProperty2.default)(GridRowActions, "AlignTypes", AlignTypes);