"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 _getPrototypeOf3 = _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 _Text = _interopRequireDefault(require("@instructure/ui-elements/lib/components/Text"));

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

var _presenter = require("../presenter");

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

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var _dec,
    _class,
    _class2,
    _temp,
    _default_pl_number = Intl.NumberFormat("pl", { style: "decimal" }).format;

var styles = {
  componentId: 'dhBxf',
  template: function template(theme) {
    return "\n\n.dhBxf_cltt{flex-grow:2}\n\n.dhBxf_eXht{flex-grow:1;text-align:right}\n\n[dir=ltr] .dhBxf_eXht,[dir=rtl] .dhBxf_eXht{text-align:right}\n\n.dhBxf_flYR{flex-grow:1}\n\n.dhBxf_dMbU{border:dotted ".concat(theme.itemContainerBorderWidth || 'inherit', ";border-color:").concat(theme.itemContainerBorderColor || 'inherit', ";color:").concat(theme.itemContainerColor || 'inherit', ";display:flex;padding:").concat(theme.itemContainerPadding || 'inherit', ";width:100%}\n\n.dhBxf_doNn{display:flex;flex-grow:1;margin:").concat(theme.summaryMargin || 'inherit', ";margin-left:").concat(theme.summaryMarginLeft || 'inherit', "}");
  },
  'middleSection': 'dhBxf_cltt',
  'endSection': 'dhBxf_eXht',
  'questionCount': 'dhBxf_flYR',
  'itemsContainer': 'dhBxf_dMbU',
  'summary': 'dhBxf_doNn'
};
var Summary = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(Summary, _Component);

  function Summary() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(Summary)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.handleShowItems = function () {
      if (_this.props.isDragging) {
        return;
      }

      _this.props.setSidebarStimulusIsShowing(_this.props.stimulusId, !_this.props.isShowingItems);
    };

    return _this;
  }

  (0, _createClass2.default)(Summary, [{
    key: "getCountText",
    value: function getCountText() {
      var _this$props = this.props,
          isDragging = _this$props.isDragging,
          startPosition = _this$props.startPosition,
          numberOfItems = _this$props.numberOfItems;

      if (isDragging) {
        if (numberOfItems > 1) {
          return "Pytania " + _default_pl_number(startPosition) + " - " + _default_pl_number(startPosition + numberOfItems - 1) + " zawarto";
        }

        return "Pytanie " + _default_pl_number(startPosition) + " zawarto";
      }

      if (numberOfItems > 1) {
        return "Pytania " + _default_pl_number(startPosition) + " - " + _default_pl_number(startPosition + numberOfItems - 1);
      }

      return "Pytanie " + _default_pl_number(startPosition);
    } // =============
    //   RENDERING
    // =============

  }, {
    key: "renderEndSectionContent",
    value: function renderEndSectionContent() {
      var _this$props2 = this.props,
          isDragging = _this$props2.isDragging,
          isShowingItems = _this$props2.isShowingItems;

      if (!isDragging) {
        return _react.default.createElement(_Text.default, {
          size: "small",
          weight: "light"
        }, isShowingItems ? "Zwi\u0144" : "Rozwi\u0144");
      }
    }
  }, {
    key: "render",
    value: function render() {
      var isDragging = this.props.isDragging;

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

      return _react.default.createElement("div", {
        onClick: this.handleShowItems,
        className: styles.summary
      }, _react.default.createElement("div", {
        className: styles.itemsContainer
      }, _react.default.createElement("div", {
        className: styles.questionCount
      }, _react.default.createElement(_Text.default, {
        size: "small",
        weight: "light"
      }, this.getCountText())), _react.default.createElement("div", {
        className: styles.middleSection
      }), _react.default.createElement("div", {
        className: styles.endSection
      }, this.renderEndSectionContent())));
    }
  }]);
  Summary.displayName = "Summary";
  return Summary;
}(_react.Component), _class2.propTypes = {
  // Passed in by parent
  startPosition: _propTypes.default.number.isRequired,

  /* This is used for when the stimulus is being dragged in build */
  isDragging: _propTypes.default.bool,
  numberOfItems: _propTypes.default.number.isRequired,
  isShowingItems: _propTypes.default.bool,
  stimulusId: _propTypes.default.string.isRequired,
  // from connected component
  setSidebarStimulusIsShowing: _propTypes.default.func.isRequired
}, _class2.defaultProps = {
  isDragging: false,
  isShowingItems: false
}, _temp)) || _class);
exports.default = Summary;