"use strict";

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

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

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

var _scale = _interopRequireDefault(require("./scale"));

var _Link = _interopRequireDefault(require("@material-ui/core/Link"));

var _Collapse = _interopRequireDefault(require("@material-ui/core/Collapse"));

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

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 Main = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(Main, _React$Component);

  var _super = _createSuper(Main);

  function Main(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, Main);
    _this = _super.call(this, props);
    _this.state = {
      rubricOpen: false,
      linkPrefix: 'Show'
    };
    _this.toggleRubric = _this.toggleRubric.bind((0, _assertThisInitialized2["default"])(_this));
    return _this;
  }

  (0, _createClass2["default"])(Main, [{
    key: "toggleRubric",
    value: function toggleRubric() {
      this.setState({
        rubricOpen: !this.state.rubricOpen
      });
      this.setState({
        linkPrefix: this.state.rubricOpen ? 'Show' : 'Hide'
      });
    }
  }, {
    key: "render",
    value: function render() {
      var model = this.props.model;
      var animationsDisabled = this.props.animationsDisabled;

      var _ref = model || {},
          extraCSSRules = _ref.extraCSSRules,
          halfScoring = _ref.halfScoring,
          scales = _ref.scales,
          visible = _ref.visible,
          pointLabels = _ref.pointLabels,
          description = _ref.description,
          standards = _ref.standards,
          arrowsDisabled = _ref.arrowsDisabled;

      animationsDisabled = animationsDisabled || model.animationsDisabled;

      if (!scales || !visible) {
        return null;
      }

      var rubricItem = /*#__PURE__*/_react["default"].createElement(_renderUi.UiLayout, {
        extraCSSRules: extraCSSRules,
        style: {
          fontFamily: 'Cerebri Sans',
          color: _renderUi.color.text(),
          backgroundColor: _renderUi.color.background()
        }
      }, halfScoring ? /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          marginBottom: '16px'
        }
      }, "* Half-point or in-between scores are permitted under this rubric.") : null, scales.map(function (scale, scaleIndex) {
        return /*#__PURE__*/_react["default"].createElement(_scale["default"], {
          key: "scale_".concat(scaleIndex),
          scale: scale,
          scaleIndex: scaleIndex,
          showPointsLabels: pointLabels,
          showDescription: description,
          showStandards: standards,
          arrowsDisabled: arrowsDisabled
        });
      }));

      if (animationsDisabled) {
        return rubricItem;
      }

      return /*#__PURE__*/_react["default"].createElement(_renderUi.UiLayout, {
        extraCSSRules: extraCSSRules,
        style: {
          color: _renderUi.color.text(),
          backgroundColor: _renderUi.color.background()
        }
      }, /*#__PURE__*/_react["default"].createElement(_Link["default"], {
        style: {
          backgroundColor: _renderUi.color.background()
        },
        href: this.dudUrl,
        onClick: this.toggleRubric
      }, this.state.linkPrefix, " Rubric"), /*#__PURE__*/_react["default"].createElement(_Collapse["default"], {
        style: {
          marginTop: '16px'
        },
        "in": this.state.rubricOpen,
        timeout: "auto"
      }, rubricItem));
    }
  }]);
  return Main;
}(_react["default"].Component);

Main.propTypes = {
  model: _propTypes["default"].shape({
    halfScoring: _propTypes["default"].bool,
    scales: _propTypes["default"].arrayOf(_propTypes["default"].shape({
      excludeZero: _propTypes["default"].bool,
      maxPoints: _propTypes["default"].number,
      scorePointsLabels: _propTypes["default"].arrayOf(_propTypes["default"].string),
      traitLabel: _propTypes["default"].string,
      traits: _propTypes["default"].arrayOf(_propTypes["default"].shape({
        name: _propTypes["default"].string,
        description: _propTypes["default"].string,
        scorePointsDescriptors: _propTypes["default"].arrayOf(_propTypes["default"].string),
        standards: _propTypes["default"].arrayOf(_propTypes["default"].string)
      }))
    })),
    visible: _propTypes["default"].bool,
    pointLabels: _propTypes["default"].bool,
    description: _propTypes["default"].bool,
    standards: _propTypes["default"].bool,
    animationsDisabled: _propTypes["default"].bool
  }),
  animationsDisabled: _propTypes["default"].bool
};
var _default = Main;
exports["default"] = _default;
//# sourceMappingURL=main.js.map