"use strict";

exports.__esModule = true;
exports.default = void 0;
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _provider = _interopRequireWildcard(require("../../../atom/provider"));
var _getShadowBoxColorFromPrimary = require("../../../util/get-shadow-box-color-from-primary");
var _style = _interopRequireDefault(require("./style.css"));
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; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const QCMImage = (props, legacyContext) => {
  const {
    answers,
    groupAriaLabel
  } = props;
  const skin = (0, _provider.GetSkinFromContext)(legacyContext);
  const primarySkinColor = (0, _getOr2.default)('#00B0FF', 'common.primary', skin);
  const answersViews = answers.map((answer, key) => {
    const {
      onClick,
      title,
      selected,
      image,
      ariaLabel
    } = answer;
    const checkboxId = `checkbox-graphic-${key}`;
    return /*#__PURE__*/_react.default.createElement("div", {
      onClick: onClick,
      "data-selected": selected,
      "data-name": "answerGraphic",
      style: {
        ...(selected && {
          boxShadow: `0 4px 16px ${(0, _getShadowBoxColorFromPrimary.getShadowBoxColorFromPrimary)(primarySkinColor)}`
        })
      },
      className: selected ? _style.default.selected : _style.default.answer,
      key: key
    }, /*#__PURE__*/_react.default.createElement("div", {
      "data-name": "answerBackground",
      style: {
        backgroundColor: selected ? primarySkinColor : '#F4F4F5'
      },
      className: _style.default.background
    }), /*#__PURE__*/_react.default.createElement("div", {
      "data-name": "answerContent",
      className: _style.default.content
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.imageWrapper,
      "data-name": "answerImage",
      "aria-label": ariaLabel || title,
      title: ariaLabel || title,
      style: {
        backgroundImage: `url(${image})`
      }
    }), /*#__PURE__*/_react.default.createElement("div", {
      "data-name": "answerText",
      className: _style.default.titleWrapper
    }, /*#__PURE__*/_react.default.createElement("div", {
      title: title,
      className: (0, _classnames.default)(_style.default.title, _style.default.innerHTML)
    }, /*#__PURE__*/_react.default.createElement("label", {
      htmlFor: checkboxId
    }, /*#__PURE__*/_react.default.createElement("input", {
      id: checkboxId,
      type: "checkbox",
      value: title,
      title: title,
      "aria-label": title,
      checked: selected,
      onChange: onClick,
      className: _style.default.hiddenCheckbox
    }), title)))));
  });
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "qcm-graphic-wrapper",
    className: _style.default.wrapper,
    role: "group",
    "aria-label": groupAriaLabel,
    title: groupAriaLabel
  }, answersViews);
};
QCMImage.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
QCMImage.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,
    image: _propTypes.default.string,
    ariaLabel: _propTypes.default.string
  })),
  groupAriaLabel: _propTypes.default.string
} : {};
var _default = exports.default = QCMImage;
//# sourceMappingURL=index.js.map