"use strict";

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

var _typeof = require("@babel/runtime/helpers/typeof");

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

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

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

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

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

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

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

var _styles = require("@material-ui/core/styles");

var _react = _interopRequireDefault(require("react"));

var _reactTransitionGroup = require("react-transition-group");

var _classnames = _interopRequireDefault(require("classnames"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var color = _interopRequireWildcard(require("./color"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var styleSheet = {
  corespringFeedback: {
    transformOrigin: '0% 0px 0px',
    width: '100%',
    display: 'block',
    overflow: 'hidden',
    '&:.incorrect': {
      color: '#946202'
    }
  },
  content: {
    '-webkit-font-smoothing': 'antialiased',
    backgroundColor: "var(--feedback-bg-color, ".concat(color.disabled(), ")"),
    borderRadius: '4px',
    fontFamily: '"Roboto", "Noto", sans-serif',
    lineHeight: '25px',
    margin: '0px',
    padding: '10px',
    verticalAlign: 'middle',
    color: 'var(--feedback-color, white)'
  },
  correct: {
    backgroundColor: "var(--feedback-correct-bg-color, ".concat(color.correct(), ")")
  },
  incorrect: {
    backgroundColor: "var(--feedback-incorrect-bg-color, ".concat(color.incorrect(), ")")
  },
  feedbackEnter: {
    height: '1px'
  },
  feedbackEnterActive: {
    height: '45px',
    transition: 'height 500ms'
  },
  feedbackLeave: {
    height: '45px'
  },
  feedbackLeaveActive: {
    height: '1px',
    transition: 'height 200ms'
  }
};

var Feedback = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(Feedback, _React$Component);

  var _super = _createSuper(Feedback);

  function Feedback() {
    (0, _classCallCheck2["default"])(this, Feedback);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(Feedback, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          correctness = _this$props.correctness,
          feedback = _this$props.feedback,
          classes = _this$props.classes;

      function chooseFeedback(correctness) {
        if (correctness && feedback) {
          return /*#__PURE__*/_react["default"].createElement(_reactTransitionGroup.CSSTransition, {
            classNames: {
              enter: classes.feedbackEnter,
              enterActive: classes.feedbackEnterActive,
              leave: classes.feedbackLeave,
              leaveActive: classes.feedbackLeaveActive
            },
            key: "hasFeedback",
            timeout: {
              enter: 500,
              exit: 300
            }
          }, /*#__PURE__*/_react["default"].createElement("div", {
            className: classes.corespringFeedback
          }, /*#__PURE__*/_react["default"].createElement("div", {
            className: (0, _classnames["default"])(classes.content, classes[correctness]),
            dangerouslySetInnerHTML: {
              __html: feedback
            }
          })));
        } else {
          return null;
        }
      }

      return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_reactTransitionGroup.TransitionGroup, null, chooseFeedback(correctness)));
    }
  }]);
  return Feedback;
}(_react["default"].Component);

exports.Feedback = Feedback;
(0, _defineProperty2["default"])(Feedback, "propTypes", {
  correctness: _propTypes["default"].string,
  feedback: _propTypes["default"].string,
  classes: _propTypes["default"].object.isRequired
});

var _default = (0, _styles.withStyles)(styleSheet, {
  name: 'Feedback'
})(Feedback);

exports["default"] = _default;
//# sourceMappingURL=feedback.js.map