"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));

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 _Select = _interopRequireDefault(require("@instructure/ui-forms/lib/components/Select"));

var _uiLayout = require("@instructure/ui-layout");

var _ExtraHoursMinutes = _interopRequireDefault(require("../ExtraHoursMinutes"));

var _ExtraTimeMultiplier = _interopRequireDefault(require("../ExtraTimeMultiplier"));

var _FormattedDuration = require("../../../../../common/components/shared/FormattedDuration");

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

var getTimeAdjustmentType = function getTimeAdjustmentType(timerSettings) {
  if (timerSettings.timerMultiplierEnabled) {
    return 'timerMultiplierEnabled';
  }

  if (timerSettings.extraTimeEnabled) {
    return 'extraTimeEnabled';
  }

  if (timerSettings.disableTimer) {
    return 'disableTimer';
  }

  return 'none';
};

var ExtraTimeSettings =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(ExtraTimeSettings, _Component);

  function ExtraTimeSettings() {
    var _getPrototypeOf2;

    var _this;

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

    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)(ExtraTimeSettings)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.onChangeTimeAdjustmentType = function (event, _ref) {
      var value = _ref.value;
      var timeAdjustments = {
        timerMultiplierEnabled: false,
        extraTimeEnabled: false,
        disableTimer: false
      };

      if (value !== 'none') {
        timeAdjustments[value] = true;
      }

      _this.props.onChange((0, _objectSpread2.default)({}, _this.props.timerSettings, timeAdjustments));
    };

    _this.onChangeExtraSeconds = function (seconds) {
      var update = (0, _objectSpread2.default)({}, _this.props.timerSettings, {
        extraTimeInSeconds: seconds
      });

      _this.props.onChange(update);
    };

    _this.onChangeMultiplier = function (multiplier) {
      var update = (0, _objectSpread2.default)({}, _this.props.timerSettings, {
        timerMultiplierValue: multiplier
      });

      _this.props.onChange(update);
    };

    return _this;
  }

  (0, _createClass2.default)(ExtraTimeSettings, [{
    key: "render",
    value: function render() {
      var timerSettings = this.props.timerSettings;
      var timeAdjustmentType = getTimeAdjustmentType(timerSettings);
      return _react.default.createElement(_uiLayout.View, {
        display: "block",
        margin: "medium none"
      }, _react.default.createElement(_Select.default, {
        label: "\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438 \u0432\u0440\u0435\u043C\u0435\u043D\u0438",
        assistiveText: "\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u044B 4 \u043E\u043F\u0446\u0438\u0438 \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u043A\u043B\u0430\u0432\u0438\u0448\u0438 \u0441\u043E \u0441\u0442\u0440\u0435\u043B\u043A\u0430\u043C\u0438 \u0434\u043B\u044F \u043D\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043F\u043E \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C.",
        selectedOption: timeAdjustmentType,
        onChange: this.onChangeTimeAdjustmentType,
        "data-automation": "sdk-moderation-time-dropdown"
      }, _react.default.createElement("option", {
        value: "none"
      }, "\u041D\u0435\u0442"), _react.default.createElement("option", {
        value: "extraTimeEnabled"
      }, "\u041F\u0440\u0435\u0434\u043E\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u0434\u043E\u043F\u043E\u043B\u043D\u0438\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u0432\u0440\u0435\u043C\u044F"), _react.default.createElement("option", {
        value: "disableTimer"
      }, "\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u043E\u0433\u0440\u0430\u043D\u0438\u0447\u0435\u043D\u0438\u0435 \u043F\u043E \u0432\u0440\u0435\u043C\u0435\u043D\u0438 (\u0431\u0435\u0437 \u043E\u0433\u0440\u0430\u043D\u0438\u0447\u0435\u043D\u0438\u044F)"), _react.default.createElement("option", {
        value: "timerMultiplierEnabled"
      }, "\u0423\u0432\u0435\u043B\u0438\u0447\u0438\u0442\u0435\u043B\u044C \u0434\u0438\u0430\u043F\u0430\u0437\u043E\u043D\u0430 \u043E\u0433\u0440\u0430\u043D\u0438\u0447\u0435\u043D\u0438\u044F \u043F\u043E \u0432\u0440\u0435\u043C\u0435\u043D\u0438")), timeAdjustmentType === 'extraTimeEnabled' && _react.default.createElement(_ExtraHoursMinutes.default, {
        onChange: this.onChangeExtraSeconds,
        extraTimeInSeconds: timerSettings.extraTimeInSeconds,
        maxTimeInSeconds: this.props.maxTimeInSeconds
      }), timeAdjustmentType === 'timerMultiplierEnabled' && _react.default.createElement(_ExtraTimeMultiplier.default, {
        onChange: this.onChangeMultiplier,
        timerMultiplierValue: timerSettings.timerMultiplierValue,
        maxMultiplier: this.props.maxMultiplier,
        minMultiplier: this.props.minMultiplier
      }));
    }
  }]);
  ExtraTimeSettings.displayName = "ExtraTimeSettings";
  return ExtraTimeSettings;
}(_react.Component);

ExtraTimeSettings.propTypes = {
  timerSettings: _propTypes.default.shape({
    disableTimer: _propTypes.default.bool,
    extraTimeEnabled: _propTypes.default.bool,
    extraTimeInSeconds: _propTypes.default.number,
    increaseTimeAllowance: _propTypes.default.bool,
    timerMultiplierEnabled: _propTypes.default.bool,
    timerMultiplierValue: _propTypes.default.number
  }).isRequired,
  onChange: _propTypes.default.func.isRequired,
  maxTimeInSeconds: _propTypes.default.number,
  maxMultiplier: _propTypes.default.number,
  minMultiplier: _propTypes.default.number
};
ExtraTimeSettings.defaultProps = {
  maxTimeInSeconds: 168 * _FormattedDuration.HOUR_IN_SECONDS,
  maxMultiplier: 99,
  minMultiplier: 1
};
var _default = ExtraTimeSettings;
exports.default = _default;