"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TickCorrectnessIndicator = exports.SmallCorrectPointIndicator = exports.CorrectnessIndicator = void 0;

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

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

var _Check = _interopRequireDefault(require("@material-ui/icons/Check"));

var _Close = _interopRequireDefault(require("@material-ui/icons/Close"));

var CorrectnessIndicator = function CorrectnessIndicator(_ref) {
  var scale = _ref.scale,
      x = _ref.x,
      y = _ref.y,
      classes = _ref.classes,
      r = _ref.r,
      correctness = _ref.correctness,
      interactive = _ref.interactive;
  if (!correctness || !interactive) return null;
  var cx = scale ? scale.x(x) : x;
  var cy = scale ? scale.y(y) : y;
  var isCorrect = correctness.value === 'correct';
  var iconClass = isCorrect ? classes.correctIcon : classes.incorrectIcon; // the icon is 16px + 2px padding + 1px border, so total size is 22px

  return /*#__PURE__*/_react["default"].createElement("foreignObject", {
    x: cx - 11,
    y: cy - 11,
    width: 22,
    height: 22
  }, isCorrect ? /*#__PURE__*/_react["default"].createElement(_Check["default"], {
    className: (0, _classnames["default"])(classes.correctnessIcon, iconClass),
    title: correctness.label
  }) : /*#__PURE__*/_react["default"].createElement(_Close["default"], {
    className: (0, _classnames["default"])(classes.correctnessIcon, iconClass),
    title: correctness.label
  }));
};

exports.CorrectnessIndicator = CorrectnessIndicator;

var SmallCorrectPointIndicator = function SmallCorrectPointIndicator(_ref2) {
  var scale = _ref2.scale,
      x = _ref2.x,
      r = _ref2.r,
      correctness = _ref2.correctness,
      classes = _ref2.classes,
      correctData = _ref2.correctData,
      label = _ref2.label;

  if (correctness && correctness.value === 'incorrect') {
    var _correctData$find;

    var correctVal = parseFloat((_correctData$find = correctData.find(function (d) {
      return d.label === label;
    })) === null || _correctData$find === void 0 ? void 0 : _correctData$find.value);
    if (isNaN(correctVal)) return null;
    var correctPxY = scale.y(correctVal);
    var yToRender = correctPxY - 7.5;
    var xToRender = scale.x(x) - 7.5; // small circle has 10px font + 2px padding + 1px border, so total size is 15px

    return /*#__PURE__*/_react["default"].createElement("foreignObject", {
      x: xToRender,
      y: yToRender,
      width: 15,
      height: 15
    }, /*#__PURE__*/_react["default"].createElement(_Check["default"], {
      className: (0, _classnames["default"])(classes.correctnessIcon, classes.correctIcon, classes.smallIcon),
      title: correctness.label
    }));
  }

  return null;
};

exports.SmallCorrectPointIndicator = SmallCorrectPointIndicator;

var TickCorrectnessIndicator = function TickCorrectnessIndicator(_ref3) {
  var classes = _ref3.classes,
      correctness = _ref3.correctness,
      interactive = _ref3.interactive;
  if (!correctness || !interactive) return null;
  return correctness.value === 'correct' ? /*#__PURE__*/_react["default"].createElement(_Check["default"], {
    className: (0, _classnames["default"])(classes.correctnessIcon, classes.correctIcon),
    title: correctness.label
  }) : /*#__PURE__*/_react["default"].createElement(_Close["default"], {
    className: (0, _classnames["default"])(classes.correctnessIcon, classes.incorrectIcon),
    title: correctness.label
  });
};

exports.TickCorrectnessIndicator = TickCorrectnessIndicator;
//# sourceMappingURL=correctness-indicators.js.map