"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

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

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

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

var _PresentationContent = _interopRequireDefault(require("@instructure/ui-a11y/lib/components/PresentationContent"));

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

var _lib = _interopRequireDefault(require("@instructure/ui-themeable/lib"));

var _theme = _interopRequireDefault(require("./theme"));

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'fGOwX',
  template: function template(theme) {
    return "\n\n.quiz-core__Legend--containerColumn {\n  border: ".concat(theme.containerBorderWidth || 'inherit', " solid ").concat(theme.containerBorderColor || 'inherit', ";\n}\n\n.quiz-core__Legend--containerRow {\n  margin: 0 calc(-1 * ").concat(theme.seriesContainerRowMargin || 'inherit', ");\n}\n\n.quiz-core__Legend--seriesContainer {\n  flex-direction: row;\n  align-items: center;\n  margin: ").concat(theme.seriesContainerMargin || 'inherit', ";\n}\n\n.quiz-core__Legend--containerColumn .quiz-core__Legend--seriesContainer {\n  display: flex;\n}\n\n.quiz-core__Legend--containerRow .quiz-core__Legend--seriesContainer {\n  display: inline-flex;\n  padding: 0 ").concat(theme.seriesContainerRowMargin || 'inherit', ";\n}\n\n.quiz-core__Legend--seriesSwatchContainer {\n  width: 1.2rem;\n  height: 1.2rem;\n  margin-right: ").concat(theme.seriesSwatchMargin || 'inherit', ";\n  display: flex;\n}\n\n.quiz-core__Legend--seriesSwatch {\n  flex: 1;\n}\n\n.quiz-core__Legend--seriesLabel {\n  font-family: ").concat(theme.seriesLabelFontFamily || 'inherit', ";\n  font-size: ").concat(theme.seriesLabelFontSize || 'inherit', ";\n  white-space: nowrap;\n}\n");
  },
  'containerColumn': 'quiz-core__Legend--containerColumn',
  'containerRow': 'quiz-core__Legend--containerRow',
  'seriesContainer': 'quiz-core__Legend--seriesContainer',
  'seriesSwatchContainer': 'quiz-core__Legend--seriesSwatchContainer',
  'seriesSwatch': 'quiz-core__Legend--seriesSwatch',
  'seriesLabel': 'quiz-core__Legend--seriesLabel'
};
var Legend = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(Legend, _Component);

  function Legend() {
    (0, _classCallCheck2.default)(this, Legend);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Legend).apply(this, arguments));
  }

  (0, _createClass2.default)(Legend, [{
    key: "renderSeries",
    value: function renderSeries(series, index) {
      return _react.default.createElement("div", {
        key: index,
        className: styles.seriesContainer
      }, _react.default.createElement("div", {
        className: styles.seriesSwatchContainer
      }, _react.default.createElement("div", {
        className: (0, _classnames.default)([styles.seriesSwatch, series.className])
      })), _react.default.createElement("div", {
        className: styles.seriesLabel
      }, series.label));
    }
  }, {
    key: "render",
    value: function render() {
      var variant = this.props.variant;
      var containerClass = variant === 'row' ? styles.containerRow : styles.containerColumn;
      return _react.default.createElement(_PresentationContent.default, null, _react.default.createElement("div", {
        className: containerClass
      }, this.props.series.map(this.renderSeries)));
    }
  }]);
  Legend.displayName = "Legend";
  return Legend;
}(_react.Component), _class2.propTypes = {
  series: _propTypes.default.arrayOf(_propTypes.default.shape({
    label: _propTypes.default.string.isRequired,
    className: _propTypes.default.string.isRequired
  })),
  variant: _propTypes.default.oneOf(['column', 'row'])
}, _class2.defaultProps = {
  series: [],
  variant: 'column'
}, _temp)) || _class);
exports.default = Legend;