"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: "Ajustes de tempo",
        assistiveText: "4 op\xE7\xF5es dispon\xEDveis. Use as teclas de seta para navegar pelas op\xE7\xF5es.",
        selectedOption: timeAdjustmentType,
        onChange: this.onChangeTimeAdjustmentType
      }, _react.default.createElement("option", {
        value: "none"
      }, "Nenhum"), _react.default.createElement("option", {
        value: "extraTimeEnabled"
      }, "DAR tempo adicional"), _react.default.createElement("option", {
        value: "disableTimer"
      }, "Remover limite de tempo (ilimitado)"), _react.default.createElement("option", {
        value: "timerMultiplierEnabled"
      }, "Multiplicador de limite de tempo")), 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;