"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.Main = 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 _react = _interopRequireDefault(require("react"));

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

var _rubric = require("@pie-lib/rubric");

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

var _Radio = _interopRequireDefault(require("@material-ui/core/Radio"));

var _RadioGroup = _interopRequireDefault(require("@material-ui/core/RadioGroup"));

var _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));

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

var _renderUi = require("@pie-lib/render-ui");

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

var _rubricLabels;

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 styles = {
  root: {
    width: 'fit-content',
    paddingRight: '24px',
    boxSizing: 'border-box',
    '&:hover': {
      background: 'var(--pie-secondary-background, rgba(241,241,241,1))'
    }
  },
  customColor: {
    color: "".concat(_renderUi.color.tertiary(), " !important")
  }
};
var rubricLabels = (_rubricLabels = {}, (0, _defineProperty2["default"])(_rubricLabels, _rubric.RUBRIC_TYPES.MULTI_TRAIT_RUBRIC, 'Multi Trait Rubric'), (0, _defineProperty2["default"])(_rubricLabels, _rubric.RUBRIC_TYPES.SIMPLE_RUBRIC, 'Simple Rubric'), (0, _defineProperty2["default"])(_rubricLabels, _rubric.RUBRIC_TYPES.RUBRICLESS, 'Rubricless'), _rubricLabels);

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), "onModelChanged", function (model) {
      var onModelChanged = _this.props.onModelChanged;
      return onModelChanged(model);
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChangeRubricType", function (e) {
      var model = _this.props.model;
      var rubricType = e.target.value;

      _this.onModelChanged(_objectSpread(_objectSpread({}, model), {}, {
        rubricType: rubricType
      }));
    });
    return _this;
  }

  (0, _createClass2["default"])(Main, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          model = _this$props.model,
          configuration = _this$props.configuration,
          canUpdateModel = _this$props.canUpdateModel,
          classes = _this$props.classes;

      var _ref = model || {},
          extraCSSRules = _ref.extraCSSRules,
          _ref$rubrics = _ref.rubrics,
          rubrics = _ref$rubrics === void 0 ? {} : _ref$rubrics;

      var rubricType = model.rubricType;
      var _configuration$conten = configuration.contentDimensions,
          contentDimensions = _configuration$conten === void 0 ? {} : _configuration$conten,
          _configuration$rubric = configuration.rubricOptions,
          rubricOptions = _configuration$rubric === void 0 ? [] : _configuration$rubric,
          multiTraitRubric = configuration.multiTraitRubric,
          simpleRubric = configuration.simpleRubric,
          rubricless = configuration.rubricless,
          width = configuration.width;
      var rubricTag = '';

      if (!rubricType) {
        rubricType = _rubric.RUBRIC_TYPES.SIMPLE_RUBRIC;
      }

      var isRubricTypeAvailable = rubricOptions.indexOf(rubricType) > -1;

      if (canUpdateModel) {
        switch (rubricType) {
          case _rubric.RUBRIC_TYPES.SIMPLE_RUBRIC:
          default:
            rubricTag = /*#__PURE__*/_react["default"].createElement("rubric-configure", {
              id: "simpleRubric",
              key: "simple-rubric",
              ref: function ref(_ref2) {
                if (_ref2) {
                  _this2.simpleRubric = _ref2;
                  _this2.simpleRubric.model = _objectSpread(_objectSpread({}, rubrics.simpleRubric), {}, {
                    errors: model.errors || {}
                  });
                  _this2.simpleRubric.configuration = _objectSpread(_objectSpread({}, simpleRubric), {}, {
                    width: width
                  });
                }
              }
            });
            break;

          case _rubric.RUBRIC_TYPES.MULTI_TRAIT_RUBRIC:
            rubricTag = /*#__PURE__*/_react["default"].createElement("multi-trait-rubric-configure", {
              id: "multiTraitRubric",
              key: "multi-trait-rubric",
              ref: function ref(_ref3) {
                if (_ref3) {
                  _this2.multiTraitRubric = _ref3;
                  _this2.multiTraitRubric.model = _objectSpread(_objectSpread({}, rubrics.multiTraitRubric), {}, {
                    errors: model.errors || {}
                  });
                  _this2.multiTraitRubric.configuration = _objectSpread(_objectSpread({}, multiTraitRubric), {}, {
                    width: width || multiTraitRubric.width
                  });
                }
              }
            });
            break;

          case _rubric.RUBRIC_TYPES.RUBRICLESS:
            rubricTag = /*#__PURE__*/_react["default"].createElement("rubric-configure", {
              id: "rubricless",
              key: "rubricless",
              ref: function ref(_ref4) {
                if (_ref4) {
                  _this2.rubricless = _ref4;
                  _this2.rubricless.model = rubrics.rubricless;
                  _this2.rubricless.configuration = _objectSpread(_objectSpread({}, rubricless), {}, {
                    width: width
                  });
                }
              }
            });
            break;
        }
      }

      return /*#__PURE__*/_react["default"].createElement(_configUi.layout.ConfigLayout, {
        extraCSSRules: extraCSSRules,
        dimensions: contentDimensions,
        hideSettings: true,
        settings: null
      }, /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
        "aria-label": "rubric-type",
        name: "rubricType",
        value: model.rubricType,
        onChange: this.onChangeRubricType
      }, rubricOptions.length > 1 && rubricOptions.map(function (availableRubric, i) {
        return /*#__PURE__*/_react["default"].createElement(_FormControlLabel["default"], {
          key: i,
          value: availableRubric,
          control: /*#__PURE__*/_react["default"].createElement(_Radio["default"], {
            className: classes.customColor,
            checked: rubricType === availableRubric
          }),
          label: rubricLabels[availableRubric],
          classes: {
            root: classes.root
          }
        });
      })), isRubricTypeAvailable && rubricTag);
    }
  }]);
  return Main;
}(_react["default"].Component);

exports.Main = Main;
(0, _defineProperty2["default"])(Main, "propTypes", {
  classes: _propTypes["default"].object,
  canUpdateModel: _propTypes["default"].bool,
  configuration: _propTypes["default"].object,
  model: _propTypes["default"].object,
  onModelChanged: _propTypes["default"].func,
  onConfigurationChanged: _propTypes["default"].func
});

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

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