"use strict";

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

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FeedbackConfig = void 0;
Object.defineProperty(exports, "FeedbackSelector", {
  enumerable: true,
  get: function get() {
    return _feedbackSelector["default"];
  }
});
exports["default"] = exports.buildDefaults = void 0;

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

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

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

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 _feedbackSelector = _interopRequireWildcard(require("./feedback-selector"));

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

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

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

var _ExpansionPanel = _interopRequireDefault(require("@material-ui/core/ExpansionPanel"));

var _ExpansionPanelSummary = _interopRequireDefault(require("@material-ui/core/ExpansionPanelSummary"));

var _ExpansionPanelDetails = _interopRequireDefault(require("@material-ui/core/ExpansionPanelDetails"));

var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));

var _ExpandMore = _interopRequireDefault(require("@material-ui/icons/ExpandMore"));

var _merge = _interopRequireDefault(require("lodash/merge"));

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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 style = {
  feedbackContainer: {
    display: 'flex',
    flex: 1,
    flexDirection: 'column'
  },
  panelDetails: {
    paddingTop: 0,
    paddingBottom: 0
  }
};

var buildDefaults = function buildDefaults(input) {
  return (0, _merge["default"])({}, {
    correct: {
      type: 'default',
      "default": 'Correct'
    },
    incorrect: {
      type: 'default',
      "default": 'Incorrect'
    },
    partial: {
      type: 'default',
      "default": 'Nearly'
    }
  }, input);
};

exports.buildDefaults = buildDefaults;

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

  var _super = _createSuper(FeedbackConfig);

  function FeedbackConfig() {
    var _this;

    (0, _classCallCheck2["default"])(this, FeedbackConfig);

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

    _this = _super.call.apply(_super, [this].concat(args));
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onCorrectChange", _this.onChange.bind((0, _assertThisInitialized2["default"])(_this), 'correct'));
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onIncorrectChange", _this.onChange.bind((0, _assertThisInitialized2["default"])(_this), 'incorrect'));
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onPartialChange", _this.onChange.bind((0, _assertThisInitialized2["default"])(_this), 'partial'));
    return _this;
  }

  (0, _createClass2["default"])(FeedbackConfig, [{
    key: "onChange",
    value: function onChange(key, config) {
      var _this$props = this.props,
          feedback = _this$props.feedback,
          onChange = _this$props.onChange;

      var update = _objectSpread(_objectSpread({}, feedback), {}, (0, _defineProperty2["default"])({}, key, config));

      onChange(update);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          classes = _this$props2.classes,
          className = _this$props2.className,
          allowPartial = _this$props2.allowPartial,
          feedback = _this$props2.feedback,
          toolbarOpts = _this$props2.toolbarOpts;
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: className
      }, /*#__PURE__*/_react["default"].createElement(_ExpansionPanel["default"], null, /*#__PURE__*/_react["default"].createElement(_ExpansionPanelSummary["default"], {
        expandIcon: /*#__PURE__*/_react["default"].createElement(_ExpandMore["default"], null)
      }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        className: classes.heading
      }, "Feedback")), /*#__PURE__*/_react["default"].createElement(_ExpansionPanelDetails["default"], {
        className: classes.panelDetails
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.feedbackContainer
      }, /*#__PURE__*/_react["default"].createElement(_feedbackSelector["default"], {
        label: "If correct, show",
        feedback: feedback.correct,
        onChange: this.onCorrectChange,
        toolbarOpts: toolbarOpts
      }), allowPartial && /*#__PURE__*/_react["default"].createElement(_feedbackSelector["default"], {
        label: "If partially correct, show",
        feedback: feedback.partial,
        onChange: this.onPartialChange,
        toolbarOpts: toolbarOpts
      }), /*#__PURE__*/_react["default"].createElement(_feedbackSelector["default"], {
        label: "If incorrect, show",
        feedback: feedback.incorrect,
        onChange: this.onIncorrectChange,
        toolbarOpts: toolbarOpts
      })))));
    }
  }]);
  return FeedbackConfig;
}(_react["default"].Component);

exports.FeedbackConfig = FeedbackConfig;
(0, _defineProperty2["default"])(FeedbackConfig, "propTypes", {
  allowPartial: _propTypes["default"].bool,
  className: _propTypes["default"].string,
  feedback: _propTypes["default"].shape({
    correct: _propTypes["default"].shape(_feedbackSelector.FeedbackType),
    incorrect: _propTypes["default"].shape(_feedbackSelector.FeedbackType),
    partial: _propTypes["default"].shape(_feedbackSelector.FeedbackType)
  }),
  onChange: _propTypes["default"].func.isRequired,
  classes: _propTypes["default"].object.isRequired,
  toolbarOpts: _propTypes["default"].object
});
(0, _defineProperty2["default"])(FeedbackConfig, "defaultProps", {
  allowPartial: true,
  feedback: buildDefaults()
});

var _default = (0, _styles.withStyles)(style)(FeedbackConfig);

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