"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

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

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _popup = _interopRequireDefault(require("../popup"));

var _getLocale = require("../../utils/getLocale");

var _heart = _interopRequireDefault(require("./heart"));

require("./index.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var popPrecls = "heart-selector-pop";

function Confidence(props) {
  var _props$value = props.value,
      value = _props$value === void 0 ? 5 : _props$value,
      _props$editable = props.editable,
      editable = _props$editable === void 0 ? false : _props$editable,
      _props$onValueChange = props.onValueChange,
      onValueChange = _props$onValueChange === void 0 ? function (val) {
    return val;
  } : _props$onValueChange,
      _props$popupPlacement = props.popupPlacement,
      popupPlacement = _props$popupPlacement === void 0 ? "bottomRight" : _props$popupPlacement;
  var HEART_RANGE = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];

  var onHeartChangeHandler = function onHeartChangeHandler(_e, i) {
    onValueChange(i);
    popupRef.current.close();
  };

  var popupRef = (0, _react.useRef)();

  var PopupContent = /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(popPrecls)
  }, /*#__PURE__*/_react["default"].createElement("p", {
    className: "".concat(popPrecls, "-title")
  }, (0, _getLocale.getLocale)("OKR_MyO_Title_Plecore")), /*#__PURE__*/_react["default"].createElement("ul", {
    className: "".concat(popPrecls, "-list")
  }, HEART_RANGE.map(function (i, j) {
    return /*#__PURE__*/_react["default"].createElement("li", {
      key: j,
      className: (0, _classnames["default"])("".concat(popPrecls, "-list-item"), _defineProperty({}, "".concat(popPrecls, "-list-item--selected"), i == value)),
      onClick: function onClick(e) {
        return onHeartChangeHandler(e, i);
      }
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: (0, _classnames["default"])("".concat(popPrecls, "-heart"))
    }, /*#__PURE__*/_react["default"].createElement(_heart["default"], {
      i: i,
      confidence: value
    })), /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(popPrecls, "-score")
    }, i, " ", (0, _getLocale.getLocale)("Per_Set_Form_Quantifier_Points")));
  })));

  if (!editable) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])("titaui-kr-heart", {
        "titaui-kr-heart--editable": editable
      })
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "titaui-kr-heart-icon"
    }), /*#__PURE__*/_react["default"].createElement("span", {
      className: "titaui-kr-heart-text"
    }, value, " ", (0, _getLocale.getLocale)("Per_Set_Form_Quantifier_Points")));
  }

  return /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
    overlay: (0, _getLocale.getLocale)("OKR_MyO_Title_Changecindex"),
    placement: "top"
  }, /*#__PURE__*/_react["default"].createElement(_popup["default"], {
    popup: PopupContent,
    popupPlacement: popupPlacement,
    ref: popupRef
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("titaui-kr-heart", {
      "titaui-kr-heart--editable": editable
    })
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "titaui-kr-heart-icon"
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "titaui-kr-heart-text"
  }, value, " ", (0, _getLocale.getLocale)("Per_Set_Form_Quantifier_Points")))));
}

var _default = Confidence;
exports["default"] = _default;