"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.FeedbackType = exports.FeedbackSelector = 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 _editableHtml = _interopRequireDefault(require("../../editable-html"));

var _renderUi = require("../../render-ui");

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

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

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

var _group = _interopRequireDefault(require("./group"));

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; } }

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; }

var feedbackLabels = {
  "default": 'Simple Feedback',
  none: 'No Feedback',
  custom: 'Customized Feedback'
};

var holder = function holder(theme, extras) {
  return _objectSpread({
    marginTop: '0px',
    background: theme.palette.grey[300],
    padding: theme.spacing.unit,
    marginBottom: theme.spacing.unit * 2,
    borderRadius: '4px'
  }, extras);
};

var style = function style(theme) {
  return {
    feedbackSelector: {
      marginBottom: theme.spacing.unit
    },
    label: {
      cursor: 'pointer'
    },
    inputContainerLabel: {
      transform: 'translateY(-20%)'
    },
    feedbackInputContainer: {
      paddingBottom: 0
    },
    customHolder: holder(theme, {
      background: theme.palette.grey[300],
      padding: 0
    }),
    defaultHolder: holder(theme, {
      fontFamily: theme.typography.fontFamily,
      padding: theme.spacing.unit * 2,
      cursor: 'default'
    }),
    editor: {
      fontFamily: theme.typography.fontFamily
    },
    group: {
      paddingTop: theme.spacing.unit
    }
  };
};

var FeedbackType = {
  type: _propTypes["default"].oneOf(['default', 'custom', 'none']),
  "default": _propTypes["default"].string,
  custom: _propTypes["default"].string
};
exports.FeedbackType = FeedbackType;

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

  var _super = _createSuper(FeedbackSelector);

  function FeedbackSelector() {
    var _this;

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

    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), "changeType", function (type) {
      var _this$props = _this.props,
          onChange = _this$props.onChange,
          feedback = _this$props.feedback;
      onChange(_objectSpread(_objectSpread({}, feedback), {}, {
        type: type
      }));
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeCustom", function (custom) {
      var _this$props2 = _this.props,
          onChange = _this$props2.onChange,
          feedback = _this$props2.feedback;
      onChange(_objectSpread(_objectSpread({}, feedback), {}, {
        type: 'custom',
        custom: custom
      }));
    });
    return _this;
  }

  (0, _createClass2["default"])(FeedbackSelector, [{
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
          keys = _this$props3.keys,
          classes = _this$props3.classes,
          label = _this$props3.label,
          feedback = _this$props3.feedback,
          toolbarOpts = _this$props3.toolbarOpts,
          _this$props3$mathMlOp = _this$props3.mathMlOptions,
          mathMlOptions = _this$props3$mathMlOp === void 0 ? {} : _this$props3$mathMlOp;
      var feedbackKeys = keys || Object.keys(feedbackLabels);
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.feedbackSelector
      }, /*#__PURE__*/_react["default"].createElement(_renderUi.InputContainer, {
        label: label,
        className: classes.feedbackInputContainer,
        extraClasses: {
          label: classes.inputContainerLabel
        }
      }, /*#__PURE__*/_react["default"].createElement(_group["default"], {
        className: classes.group,
        keys: feedbackKeys,
        label: label,
        value: feedback.type,
        onChange: this.changeType,
        feedbackLabels: feedbackLabels
      })), feedback.type === 'custom' && /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.customHolder
      }, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
        className: classes.editor,
        onChange: this.changeCustom,
        markup: feedback.custom || '',
        toolbarOpts: toolbarOpts,
        languageCharactersProps: [{
          language: 'spanish'
        }, {
          language: 'special'
        }],
        mathMlOptions: mathMlOptions
      })), feedback.type === 'default' && /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.defaultHolder
      }, " ", feedback["default"]));
    }
  }]);
  return FeedbackSelector;
}(_react["default"].Component);

exports.FeedbackSelector = FeedbackSelector;
(0, _defineProperty2["default"])(FeedbackSelector, "propTypes", {
  keys: _propTypes["default"].arrayOf(_propTypes["default"].string),
  classes: _propTypes["default"].object.isRequired,
  label: _propTypes["default"].string.isRequired,
  feedback: _propTypes["default"].shape(FeedbackType).isRequired,
  onChange: _propTypes["default"].func.isRequired,
  toolbarOpts: _propTypes["default"].object
});

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

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