"use strict";

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

exports.__esModule = true;
exports.CTAContainer = void 0;

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

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

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 _classnames = _interopRequireDefault(require("classnames"));

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

var _CTADropdown = require("./CTADropdown");

var _ButtonToolbar = _interopRequireDefault(require("react-bootstrap/lib/ButtonToolbar"));

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

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

  var _proto = CTAContainer.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        visibleAmount = _this$props.visibleAmount,
        className = _this$props.className,
        testAutomationId = _this$props.testAutomationId,
        children = _this$props.children,
        props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["visibleAmount", "className", "testAutomationId", "children"]);
    var classNames = (0, _classnames.default)(className, 'cta-toolbar');

    var head = _lodash.default.take(children, visibleAmount);

    var tail = _lodash.default.takeRight(children, children.length - visibleAmount);

    var showDropdown = tail.length > 0;
    var dropdown;

    if (showDropdown) {
      dropdown = _react.default.createElement(_CTADropdown.CTADropdown, {
        testAutomationId: "moreActionDropdown"
      }, tail);
    }

    return _react.default.createElement(_ButtonToolbar.default, (0, _extends2.default)({
      "data-test-automation-id": testAutomationId,
      className: classNames
    }, props), head, dropdown);
  };

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

exports.CTAContainer = CTAContainer;
(0, _defineProperty2.default)(CTAContainer, "propTypes", {
  visibleAmount: _propTypes.default.number,
  testAutomationId: _propTypes.default.string,
  className: _propTypes.default.string,
  children: _propTypes.default.node
});
(0, _defineProperty2.default)(CTAContainer, "defaultProps", {
  visibleAmount: 2,
  testAutomationId: 'CATContainer',
  className: null,
  children: null
});