"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _getOr = _interopRequireDefault(require("lodash/fp/getOr"));
var _maxBy = _interopRequireDefault(require("lodash/fp/maxBy"));
var _provider = _interopRequireWildcard(require("../../../atom/provider"));
var _getShadowBoxColorFromPrimary = require("../../../util/get-shadow-box-color-from-primary");
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const QCM = (props, legacyContext) => {
  const {
    answers,
    groupAriaLabel
  } = props;
  const longestAnswer = (0, _maxBy.default)(({
    title
  }) => title.length, answers);
  const skin = (0, _provider.GetSkinFromContext)(legacyContext);
  const primarySkinColor = (0, _getOr.default)('#00B0FF', 'common.primary', skin);
  const answersViews = (0, _react.useMemo)(() => answers.map((answer, key) => {
    const {
      onClick,
      title,
      selected,
      'aria-label': ariaLabel
    } = answer;
    const longAnswerClass = longestAnswer.title === title ? _style.default.longestAnswer : _style.default.answer;
    const selectedAnswerClass = selected ? _style.default.selectedAnswer : _style.default.unselectedAnswer;
    return /*#__PURE__*/_react.default.createElement("div", {
      "data-name": "answer",
      "aria-label": ariaLabel || title,
      title: ariaLabel || title,
      className: (0, _classnames.default)(longAnswerClass, _style.default.innerHTML, selectedAnswerClass),
      onClick: onClick,
      style: {
        ...(selected && {
          boxShadow: `0 4px 16px ${(0, _getShadowBoxColorFromPrimary.getShadowBoxColorFromPrimary)(primarySkinColor)}`
        })
      },
      "data-selected": selected,
      key: key
    }, /*#__PURE__*/_react.default.createElement("div", {
      "data-name": "answer-background",
      style: {
        backgroundColor: selected ? primarySkinColor : '#F4F4F5' /* cm_grey_75 */
      },
      className: _style.default.background
    }), /*#__PURE__*/_react.default.createElement("span", {
      "data-name": "answer-label",
      className: _style.default.answerText
      // eslint-disable-next-line react/no-danger
      ,
      dangerouslySetInnerHTML: {
        __html: title
      }
    }));
  }), [answers, longestAnswer, primarySkinColor]);
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "qcm",
    className: _style.default.wrapper,
    role: "group",
    "aria-label": groupAriaLabel,
    title: groupAriaLabel
  }, answersViews);
};
QCM.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
QCM.propTypes = process.env.NODE_ENV !== "production" ? {
  answers: _propTypes.default.arrayOf(_propTypes.default.shape({
    title: _propTypes.default.string,
    selected: _propTypes.default.bool,
    onClick: _propTypes.default.func,
    'aria-label': _propTypes.default.string
  })),
  groupAriaLabel: _propTypes.default.string
} : {};
var _default = exports.default = QCM;
//# sourceMappingURL=index.js.map