'use strict';

import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import ButtonGroup from 'react-bootstrap/lib/ButtonGroup';
import { Button } from './Button';
/** @alias GridRowActions~AlignTypes */

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

export var AlignTypes = _.mapValues(AlignClassNameMaps, function (val, key) {
  return key;
});
export var GridRowActions =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(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.createElement(Button, {
        bsStyle: "link",
        "data-test-automation-id": action.testAutomationId,
        onClick: action.onClick,
        key: i
      }, action.text);
    });
    return React.createElement(ButtonGroup, {
      className: this.getAlignClassName() + " rc-gridRowActions"
    }, legacyActions.concat(this.props.children || []));
  };

  return GridRowActions;
}(React.Component);

_defineProperty(GridRowActions, "propTypes", {
  actions: PropTypes.array,
  align: PropTypes.oneOf(_.keys(AlignClassNameMaps)),
  children: PropTypes.node
});

_defineProperty(GridRowActions, "defaultProps", {
  actions: [],
  align: AlignTypes.right,
  children: null
});

_defineProperty(GridRowActions, "AlignTypes", AlignTypes);