"use strict";

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

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

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

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

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

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

var styles = function styles() {
  return {
    trait: {
      '&$traitName': {
        color: _renderUi.color.primaryDark(),
        verticalAlign: 'middle'
      }
    },
    noDescription: {
      color: _renderUi.color.secondaryBackground(),
      textAlign: 'center'
    },
    traitName: {}
  };
};

var Trait = function Trait(props) {
  var trait = props.trait,
      traitIndex = props.traitIndex,
      scaleIndex = props.scaleIndex,
      showStandards = props.showStandards,
      showDescription = props.showDescription,
      scorePointsValues = props.scorePointsValues,
      classes = props.classes;

  var _ref = trait || {},
      name = _ref.name,
      standards = _ref.standards,
      scorePointsDescriptors = _ref.scorePointsDescriptors,
      description = _ref.description;

  return /*#__PURE__*/_react["default"].createElement("tr", {
    key: "scale-".concat(scaleIndex, "-trait-").concat(traitIndex)
  }, /*#__PURE__*/_react["default"].createElement("td", {
    className: "".concat(classes.trait, " ").concat(classes.traitName)
  }, /*#__PURE__*/_react["default"].createElement("div", {
    dangerouslySetInnerHTML: {
      __html: name
    }
  })), showStandards ? /*#__PURE__*/_react["default"].createElement("td", null, /*#__PURE__*/_react["default"].createElement("div", {
    dangerouslySetInnerHTML: {
      __html: standards.join(',')
    }
  })) : null, showDescription ? /*#__PURE__*/_react["default"].createElement("td", null, /*#__PURE__*/_react["default"].createElement("div", {
    dangerouslySetInnerHTML: {
      __html: description
    }
  })) : null, scorePointsValues && scorePointsValues.map(function (scorePointValue, index) {
    var scoreDescriptor;

    try {
      scoreDescriptor = scorePointsDescriptors[scorePointsValues.length - index - 1] || '';
    } catch (e) {
      scoreDescriptor = '';
    }

    return /*#__PURE__*/_react["default"].createElement("td", {
      key: "table-cell-".concat(index)
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: !scoreDescriptor ? classes.noDescription : '',
      dangerouslySetInnerHTML: {
        __html: scoreDescriptor || 'No Description'
      }
    }));
  }));
};

Trait.propTypes = {
  classes: _propTypes["default"].object,
  showStandards: _propTypes["default"].bool,
  showDescription: _propTypes["default"].bool,
  scorePointsValues: _propTypes["default"].arrayOf(_propTypes["default"].number),
  scaleIndex: _propTypes["default"].number,
  traitIndex: _propTypes["default"].number,
  trait: _propTypes["default"].shape({
    name: _propTypes["default"].string,
    standards: _propTypes["default"].arrayOf(_propTypes["default"].string),
    scorePointsDescriptors: _propTypes["default"].arrayOf(_propTypes["default"].string),
    description: _propTypes["default"].string
  })
};

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

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