'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class, _class2, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _PresentationContent2 = _interopRequireDefault(_PresentationContent);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

var _lib2 = _interopRequireDefault(_lib);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.Legend__styles__containerColumn {\n  border: ' + theme.containerBorderWidth + ' solid ' + theme.containerBorderColor + ';\n}\n\n.Legend__styles__containerRow {\n  margin: 0 calc(-1 * ' + theme.seriesContainerRowMargin + ');\n}\n\n.Legend__styles__seriesContainer {\n  flex-direction: row;\n  align-items: center;\n  margin: ' + theme.seriesContainerMargin + ';\n}\n\n.Legend__styles__containerColumn .Legend__styles__seriesContainer {\n  display: flex;\n}\n\n.Legend__styles__containerRow .Legend__styles__seriesContainer {\n  display: inline-flex;\n  padding: 0 ' + theme.seriesContainerRowMargin + ';\n}\n\n.Legend__styles__seriesSwatchContainer {\n  width: 1.2rem;\n  height: 1.2rem;\n  margin-right: ' + theme.seriesSwatchMargin + ';\n  display: flex;\n}\n\n.Legend__styles__seriesSwatch {\n  flex: 1;\n}\n\n.Legend__styles__seriesLabel {\n  font-family: ' + theme.seriesLabelFontFamily + ';\n  font-size: ' + theme.seriesLabelFontSize + ';\n  white-space: nowrap;\n}\n';
  },
  'containerColumn': 'Legend__styles__containerColumn',
  'containerRow': 'Legend__styles__containerRow',
  'seriesContainer': 'Legend__styles__seriesContainer',
  'seriesSwatchContainer': 'Legend__styles__seriesSwatchContainer',
  'seriesSwatch': 'Legend__styles__seriesSwatch',
  'seriesLabel': 'Legend__styles__seriesLabel'
};
var Legend = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp = _class2 = function (_Component) {
  (0, _inherits3.default)(Legend, _Component);

  function Legend() {
    (0, _classCallCheck3.default)(this, Legend);
    return (0, _possibleConstructorReturn3.default)(this, (Legend.__proto__ || Object.getPrototypeOf(Legend)).apply(this, arguments));
  }

  (0, _createClass3.default)(Legend, [{
    key: 'renderSeries',
    value: function renderSeries(series, index) {
      return _react2.default.createElement(
        'div',
        { key: index, className: styles.seriesContainer },
        _react2.default.createElement(
          'div',
          { className: styles.seriesSwatchContainer },
          _react2.default.createElement('div', { className: (0, _classnames2.default)([styles.seriesSwatch, series.className]) })
        ),
        _react2.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 _react2.default.createElement(
        _PresentationContent2.default,
        null,
        _react2.default.createElement(
          'div',
          { className: containerClass },
          this.props.series.map(this.renderSeries)
        )
      );
    }
  }]);
  Legend.displayName = 'Legend'
  ;
  return Legend;
}(_react.Component), _class2.propTypes = {
  series: _propTypes2.default.arrayOf(_propTypes2.default.shape({
    label: _propTypes2.default.string.isRequired,
    className: _propTypes2.default.string.isRequired
  })),
  variant: _propTypes2.default.oneOf(['column', 'row'])
}, _class2.defaultProps = {
  series: [],
  variant: 'column'
}, _temp)) || _class);
exports.default = Legend;