'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, _temp2; /* eslint "jsx-a11y/click-events-have-key-events": "warn" */
/* eslint "jsx-a11y/no-static-element-interactions": "warn" */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

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 _presenter = require('../presenter');

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

var _theme2 = _interopRequireDefault(_theme);

var _formatMessage = require('../../../../../format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n._3cHMe0Qnx27MYMSHAXlMn5 {\n  flex-grow: 2;\n}\n\n.sXoXx1vjWf7NSptE9pFG7 {\n  flex-grow: 1;\n  text-align: right;\n}\n\n[dir="ltr"] .sXoXx1vjWf7NSptE9pFG7 {\n  text-align: right;\n}\n\n[dir="rtl"] .sXoXx1vjWf7NSptE9pFG7 {\n  text-align: right;\n}\n\n._3vibkDqinhhFNQYFLDKQHY {\n  flex-grow: 1;\n}\n\n.LIlZWGYNEYLXY2L2irTOB {\n  color: ' + theme.itemContainerColor + ';\n  display: flex;\n  width: 100%;\n  padding: ' + theme.itemContainerPadding + ';\n  border: dotted ' + theme.itemContainerBorderWidth + ';\n  border-color: ' + theme.itemContainerBorderColor + ';\n}\n\n.RlCxX9NtmUjJ-x7obkALK {\n  margin: ' + theme.summaryMargin + ';\n  margin-left: ' + theme.summaryMarginLeft + ';\n  display: flex;\n  flex-grow: 1;\n}\n';
  },
  'middleSection': '_3cHMe0Qnx27MYMSHAXlMn5',
  'endSection': 'sXoXx1vjWf7NSptE9pFG7',
  'questionCount': '_3vibkDqinhhFNQYFLDKQHY',
  'itemsContainer': 'LIlZWGYNEYLXY2L2irTOB',
  'summary': 'RlCxX9NtmUjJ-x7obkALK'
};
var Summary = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(Summary, _Component);

  function Summary() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, Summary);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Summary.__proto__ || Object.getPrototypeOf(Summary)).call.apply(_ref, [this].concat(args))), _this), _this.handleShowItems = function () {
      if (_this.props.isDragging) {
        return;
      }
      _this.props.setSidebarStimulusIsShowing(_this.props.stimulusId, !_this.props.isShowingItems);
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(Summary, [{
    key: 'getCountText',
    value: function getCountText() {
      var _props = this.props,
          isDragging = _props.isDragging,
          startPosition = _props.startPosition,
          numberOfItems = _props.numberOfItems;


      if (isDragging) {
        if (numberOfItems > 1) {
          return (0, _formatMessage2.default)('Questions {first, number} - {second, number} Included', { first: startPosition, second: startPosition + numberOfItems - 1 });
        }
        return (0, _formatMessage2.default)('Question {first, number} Included', { first: startPosition });
      }

      if (numberOfItems > 1) {
        return (0, _formatMessage2.default)('Questions {first, number} - {second, number}', { first: startPosition, second: startPosition + numberOfItems - 1 });
      }
      return (0, _formatMessage2.default)('Question {first, number}', { first: startPosition });
    }

    // =============
    //   RENDERING
    // =============

  }, {
    key: 'renderEndSectionContent',
    value: function renderEndSectionContent() {
      var _props2 = this.props,
          isDragging = _props2.isDragging,
          isShowingItems = _props2.isShowingItems;

      if (!isDragging) {
        return _react2.default.createElement(
          _Text2.default,
          { size: 'small', weight: 'light' },
          isShowingItems ? (0, _formatMessage2.default)('Collapse') : (0, _formatMessage2.default)('Expand')
        );
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var isDragging = this.props.isDragging;


      if (!isDragging && this.props.numberOfItems <= _presenter.DISPLAY_AS_SUMMARY_LIMIT) {
        return null;
      }

      return _react2.default.createElement(
        'div',
        { onClick: this.handleShowItems, className: styles.summary },
        _react2.default.createElement(
          'div',
          { className: styles.itemsContainer },
          _react2.default.createElement(
            'div',
            { className: styles.questionCount },
            _react2.default.createElement(
              _Text2.default,
              { size: 'small', weight: 'light' },
              this.getCountText()
            )
          ),
          _react2.default.createElement('div', { className: styles.middleSection }),
          _react2.default.createElement(
            'div',
            { className: styles.endSection },
            this.renderEndSectionContent()
          )
        )
      );
    }
  }]);
  Summary.displayName = 'Summary'
  ;
  return Summary;
}(_react.Component), _class2.propTypes = {
  // Passed in by parent
  startPosition: _propTypes2.default.number.isRequired,
  /* This is used for when the stimulus is being dragged in build */
  isDragging: _propTypes2.default.bool,
  numberOfItems: _propTypes2.default.number.isRequired,
  isShowingItems: _propTypes2.default.bool,
  stimulusId: _propTypes2.default.string.isRequired,
  // from connected component
  setSidebarStimulusIsShowing: _propTypes2.default.func.isRequired
}, _class2.defaultProps = {
  isDragging: false,
  isShowingItems: false
}, _temp2)) || _class);
exports.default = Summary;