"use strict";

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

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

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

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 _react = _interopRequireDefault(require("react"));

var _index = require("./pie-toolbox-rubric/index");

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

var _configUi = require("@pie-lib/config-ui");

var _excluded = ["points", "sampleAnswers"];

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 Panel = _configUi.settings.Panel,
    toggle = _configUi.settings.toggle;

var styles = function styles(theme) {
  return {
    design: {
      fontFamily: 'Cerebri Sans',
      fontSize: theme.typography.fontSize
    }
  };
};

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

  var _super = _createSuper(Main);

  function Main() {
    var _this;

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

    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), "verifyRubriclessModel", function (m, config) {
      var _ref = config || {},
          _ref$rubricless = _ref.rubricless,
          rubricless = _ref$rubricless === void 0 ? false : _ref$rubricless;

      return rubricless ? function (_ref2) {
        var points = _ref2.points,
            sampleAnswers = _ref2.sampleAnswers,
            rest = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
        return rest;
      }(m) : m;
    });
    return _this;
  }

  (0, _createClass2["default"])(Main, [{
    key: "render",
    value: function render() {
      var _ref3 = this.props || {},
          model = _ref3.model,
          configuration = _ref3.configuration,
          onConfigurationChanged = _ref3.onConfigurationChanged,
          onModelChanged = _ref3.onModelChanged,
          imageSupport = _ref3.imageSupport;

      var _ref4 = configuration || {},
          _ref4$baseInputConfig = _ref4.baseInputConfiguration,
          baseInputConfiguration = _ref4$baseInputConfig === void 0 ? {} : _ref4$baseInputConfig,
          _ref4$contentDimensio = _ref4.contentDimensions,
          contentDimensions = _ref4$contentDimensio === void 0 ? {} : _ref4$contentDimensio,
          settingsPanelDisabled = _ref4.settingsPanelDisabled,
          _ref4$showExcludeZero = _ref4.showExcludeZero,
          showExcludeZero = _ref4$showExcludeZero === void 0 ? {} : _ref4$showExcludeZero,
          _ref4$showMaxPoint = _ref4.showMaxPoint,
          showMaxPoint = _ref4$showMaxPoint === void 0 ? {} : _ref4$showMaxPoint,
          _ref4$mathMlOptions = _ref4.mathMlOptions,
          mathMlOptions = _ref4$mathMlOptions === void 0 ? {} : _ref4$mathMlOptions,
          _ref4$rubricless = _ref4.rubricless,
          rubricless = _ref4$rubricless === void 0 ? false : _ref4$rubricless,
          rubriclessInstruction = _ref4.rubriclessInstruction,
          width = _ref4.width; // ensure to eliminate points and sampleAnswers in case of rubricless


      var value = this.verifyRubriclessModel(model, configuration);
      var extraCSSRules = model.extraCSSRules;
      var panelProperties = {
        excludeZeroEnabled: showExcludeZero.settings && toggle(showExcludeZero.label),
        maxPointsEnabled: showMaxPoint.settings && toggle(showMaxPoint.label),
        rubriclessInstructionEnabled: rubricless && rubriclessInstruction.settings && toggle(rubriclessInstruction.label)
      };

      var getPluginProps = function getPluginProps(props) {
        return Object.assign(_objectSpread({}, baseInputConfiguration), props || {});
      };

      return /*#__PURE__*/_react["default"].createElement(_configUi.layout.ConfigLayout, {
        extraCSSRules: extraCSSRules,
        dimensions: contentDimensions,
        hideSettings: settingsPanelDisabled,
        settings: /*#__PURE__*/_react["default"].createElement(Panel, {
          model: model,
          onChangeModel: onModelChanged,
          configuration: configuration,
          onChangeConfiguration: onConfigurationChanged,
          pluginOpts: getPluginProps(rubriclessInstruction === null || rubriclessInstruction === void 0 ? void 0 : rubriclessInstruction.inputConfiguration),
          groups: {
            Properties: panelProperties
          },
          imageSupport: imageSupport
        })
      }, /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          maxWidth: width
        }
      }, /*#__PURE__*/_react["default"].createElement(_index.Authoring, {
        value: value,
        config: configuration,
        onChange: onModelChanged,
        mathMlOptions: mathMlOptions,
        rubricless: rubricless,
        pluginOpts: baseInputConfiguration,
        imageSupport: imageSupport
      })));
    }
  }]);
  return Main;
}(_react["default"].Component);

var _default = (0, _styles.withStyles)(styles)(Main);

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