'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 _AccessibleContent = require('@instructure/ui-a11y/lib/components/AccessibleContent');

var _AccessibleContent2 = _interopRequireDefault(_AccessibleContent);

var _Tooltip = require('@instructure/ui-overlays/lib/components/Tooltip');

var _Tooltip2 = _interopRequireDefault(_Tooltip);

var _Text = require('@instructure/ui-elements/lib/components/Text');

var _Text2 = _interopRequireDefault(_Text);

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.j-CsdjPl6IvQTulP7m8_t {\n  cursor: pointer;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  white-space: pre-wrap;\n}\n';
  },
  'itemBody': 'j-CsdjPl6IvQTulP7m8_t'
};


var DISPLAY_TOOLTIP_LIMIT = 80;

var Title = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp = _class2 = function (_Component) {
  (0, _inherits3.default)(Title, _Component);

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

  (0, _createClass3.default)(Title, [{
    key: 'renderTitle',
    value: function renderTitle() {
      var title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props.title;

      return _react2.default.createElement(
        'div',
        { className: styles.itemBody },
        _react2.default.createElement(
          _Text2.default,
          null,
          title
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      var title = this.props.title;

      // Shorten title if necessary

      if (title.length > DISPLAY_TOOLTIP_LIMIT) {
        var truncatedTitle = title.substring(0, DISPLAY_TOOLTIP_LIMIT) + '...';
        return _react2.default.createElement(
          _AccessibleContent2.default,
          { alt: title },
          _react2.default.createElement(
            _Tooltip2.default,
            { tip: title },
            this.renderTitle(truncatedTitle)
          )
        );
      }
      return this.renderTitle();
    }
  }]);
  Title.displayName = 'Title'
  ;
  return Title;
}(_react.Component), _class2.propTypes = {
  title: _propTypes2.default.string.isRequired
}, _temp)) || _class);
exports.default = Title;