'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 _reactImmutableProptypes = require('react-immutable-proptypes');

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _Tag = require('@instructure/ui-elements/lib/components/Tag');

var _Tag2 = _interopRequireDefault(_Tag);

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.TagDisplay__styles__tags {\n  float: right;\n}\n\n[dir="ltr"] .TagDisplay__styles__tags {\n  float: right;\n}\n\n[dir="rtl"] .TagDisplay__styles__tags {\n  float: right;\n}\n';
  },
  'tags': 'TagDisplay__styles__tags'
};
var TagDisplay = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp = _class2 = function (_Component) {
  (0, _inherits3.default)(TagDisplay, _Component);

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

  (0, _createClass3.default)(TagDisplay, [{
    key: 'render',
    value: function render() {
      if (this.props.tagAssociations == null) {
        return null;
      }

      var display = this.props.display;

      var count = this.props.tagAssociations.size;
      var extra = count - display;
      var visible = this.props.tagAssociations.take(display).map(function (t) {
        return _react2.default.createElement(_Tag2.default, {
          margin: '0 xx-small 0 0',
          key: t.get('id'),
          text: t.get('tag_value')
        });
      });

      return _react2.default.createElement(
        'div',
        { className: styles.tags },
        visible,
        extra > 0 && _react2.default.createElement(_Tag2.default, {
          theme: { defaultBackground: '#FFFFFF' },
          text: '+' + extra })
      );
    }
  }]);
  TagDisplay.displayName = 'TagDisplay'
  ;
  return TagDisplay;
}(_react.Component), _class2.propTypes = {
  display: _propTypes2.default.number,
  tagAssociations: _reactImmutableProptypes2.default.listOf(_reactImmutableProptypes2.default.map)
}, _class2.defaultProps = {
  display: 2,
  tagAssociations: null
}, _temp)) || _class);
exports.default = TagDisplay;