import _pt from "prop-types";

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React from "react";
import classNames from "classnames";
import Row from "../Layout/Row";
import HelpPopover from "../HelpPopover";
import Col from "../Layout/Col";
import Container from "../Layout/Container";
export var SummaryBar = React.forwardRef(function (_ref, ref) {
  var className = _ref.className,
      columns = _ref.columns,
      extraInfo = _ref.extraInfo,
      testSection = _ref.testSection,
      title = _ref.title,
      props = _objectWithoutProperties(_ref, ["className", "columns", "extraInfo", "testSection", "title"]);

  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.createElement(Col, {
      key: idx,
      border: border,
      "data-test-section": "".concat(testSection, "-col-").concat(idx, "-header")
    }, React.createElement("div", {
      className: "flex min-width--100"
    }, child.header && React.createElement("div", {
      className: "muted micro weight--bold push-half--bottom"
    }, child.header), child.headerHelpTooltip && React.createElement("div", {
      className: "muted oui-summary-bar-col-header__help-popover"
    }, React.createElement(HelpPopover, {
      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.createElement(Col, {
      key: idx,
      border: border,
      "data-test-section": "".concat(testSection, "-col-").concat(idx, "-content")
    }, React.createElement("div", {
      className: "flex min-width--100"
    }, child.bodyContent && React.createElement("div", {
      className: classNames(colorClass, {
        "beta weight--normal": child.bodyContent.isNumber,
        micro: !child.bodyContent.isNumber
      })
    }, child.bodyContent.value), child.bodyContent && child.bodyContent.helpTooltip && React.createElement("div", {
      className: "muted push-half--left push-half--top"
    }, React.createElement(HelpPopover, {
      horizontalAttachment: "left",
      verticalAttachment: "middle"
    }, child.bodyContent.helpTooltip))));
  });
  return React.createElement("div", _extends({
    ref: ref,
    className: classNames("width--1-1", className),
    "data-test-section": testSection
  }, props), React.createElement("div", {
    className: "flex flex-align--end"
  }, React.createElement("div", {
    className: "color--base push-half--bottom push-double--right gamma"
  }, title), extraInfo && React.createElement("p", {
    className: "muted micro anchor--right push-half--bottom"
  }, extraInfo)), React.createElement(Container, {
    paddedContent: "around",
    fluid: true
  }, React.createElement(Row, {
    shouldWrap: false,
    border: "top",
    paddedContent: "top"
  }, columnHeaders), React.createElement(Row, {
    shouldWrap: false,
    border: "bottom",
    paddedContent: "bottom"
  }, columnContent)));
});
SummaryBar.displayName = "SummaryBar";
SummaryBar.propTypes = {
  title: _pt.string.isRequired,
  testSection: _pt.string.isRequired,
  extraInfo: _pt.string,
  className: _pt.string,

  /** 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;
  }
};
export default SummaryBar;