"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.SummaryBar = void 0;

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _Row = _interopRequireDefault(require("../Layout/Row"));

var _HelpPopover = _interopRequireDefault(require("../HelpPopover"));

var _Col = _interopRequireDefault(require("../Layout/Col"));

var _Container = _interopRequireDefault(require("../Layout/Container"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var SummaryBar = _react["default"].forwardRef(function (props, ref) {
  var title = props.title,
      columns = props.columns,
      extraInfo = props.extraInfo,
      testSection = props.testSection;
  var maxNumColumns = Math.min(columns.length, 5);
  var columnsToRender = columns.slice(0, 5);
  var columnHeaders = columnsToRender.map(function (child, idx) {
    var border;

    if (idx !== maxNumColumns - 1) {
      border = 'right';
    }

    return _react["default"].createElement(_Col["default"], {
      key: idx,
      border: border,
      "data-test-section": "".concat(testSection, "-col-").concat(idx, "-header")
    }, _react["default"].createElement("div", {
      className: "flex min-width--100"
    }, child.header && _react["default"].createElement("div", {
      className: "muted micro weight--bold push-half--bottom"
    }, child.header), child.headerHelpTooltip && _react["default"].createElement("div", {
      className: 'muted oui-summary-bar-col-header__help-popover'
    }, _react["default"].createElement(_HelpPopover["default"], {
      horizontalAttachment: "left",
      verticalAttachment: "middle"
    }, child.headerHelpTooltip))));
  });
  var columnContent = columnsToRender.map(function (child, idx) {
    var border;

    if (idx !== maxNumColumns - 1) {
      border = 'right';
    }

    var colorClass = child.bodyContent ? child.bodyContent.color === 'green' ? 'color--good-news' : child.bodyContent.color === 'red' ? 'color--bad-news' : 'color--base' : '';
    return _react["default"].createElement(_Col["default"], {
      key: idx,
      border: border,
      "data-test-section": "".concat(testSection, "-col-").concat(idx, "-content")
    }, _react["default"].createElement("div", {
      className: "flex min-width--100"
    }, child.bodyContent && _react["default"].createElement("div", {
      className: (0, _classnames["default"])(colorClass, {
        'beta weight--normal': child.bodyContent.isNumber,
        'micro': !child.bodyContent.isNumber
      })
    }, child.bodyContent.value), child.bodyContent && child.bodyContent.helpTooltip && _react["default"].createElement("div", {
      className: 'muted push-half--left push-half--top'
    }, _react["default"].createElement(_HelpPopover["default"], {
      horizontalAttachment: "left",
      verticalAttachment: "middle"
    }, child.bodyContent.helpTooltip))));
  });
  return _react["default"].createElement("div", {
    ref: ref,
    className: "width--1-1",
    "data-test-section": testSection
  }, _react["default"].createElement("div", {
    className: "flex flex-align--end"
  }, _react["default"].createElement("div", {
    className: "color--base push-half--bottom push-double--right gamma"
  }, title), extraInfo && _react["default"].createElement("p", {
    className: "muted micro anchor--right push-half--bottom"
  }, extraInfo)), _react["default"].createElement(_Container["default"], {
    paddedContent: 'around',
    fluid: true
  }, _react["default"].createElement(_Row["default"], {
    shouldWrap: false,
    border: "top",
    paddedContent: "top"
  }, columnHeaders), _react["default"].createElement(_Row["default"], {
    shouldWrap: false,
    border: "bottom",
    paddedContent: "bottom"
  }, columnContent)));
});

exports.SummaryBar = SummaryBar;
SummaryBar.displayName = "SummaryBar";
SummaryBar.propTypes = {
  testSection: _propTypes["default"].string.isRequired,
  extraInfo: _propTypes["default"].string,
  title: _propTypes["default"].string.isRequired,

  /** Content columns where summary info is displayed. Requires 2-5 columns.
   *  @param {Object} props Object of props
   *  @returns {Error} Error or null
   */
  columns: function verifyNumberOfColumns(props) {
    if (props.columns.length > 5) {
      return new Error('Number of columns must not exceed 5, only 5 will be shown.');
    } else if (props.columns.length < 2) {
      return new Error('Number of columns must be greater than 1.');
    }

    return null;
  }
};
var _default = SummaryBar;
exports["default"] = _default;