import _getOr from "lodash/fp/getOr";
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Provider, { GetSkinFromContext } from '../../../atom/provider';
import { getShadowBoxColorFromPrimary } from '../../../util/get-shadow-box-color-from-primary';
import style from './style.css';
const QCMImage = (props, legacyContext) => {
  const {
    answers,
    groupAriaLabel
  } = props;
  const skin = GetSkinFromContext(legacyContext);
  const primarySkinColor = _getOr('#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.createElement("div", {
      onClick: onClick,
      "data-selected": selected,
      "data-name": "answerGraphic",
      style: {
        ...(selected && {
          boxShadow: `0 4px 16px ${getShadowBoxColorFromPrimary(primarySkinColor)}`
        })
      },
      className: selected ? style.selected : style.answer,
      key: key
    }, /*#__PURE__*/React.createElement("div", {
      "data-name": "answerBackground",
      style: {
        backgroundColor: selected ? primarySkinColor : '#F4F4F5'
      },
      className: style.background
    }), /*#__PURE__*/React.createElement("div", {
      "data-name": "answerContent",
      className: style.content
    }, /*#__PURE__*/React.createElement("div", {
      className: style.imageWrapper,
      "data-name": "answerImage",
      "aria-label": ariaLabel || title,
      title: ariaLabel || title,
      style: {
        backgroundImage: `url(${image})`
      }
    }), /*#__PURE__*/React.createElement("div", {
      "data-name": "answerText",
      className: style.titleWrapper
    }, /*#__PURE__*/React.createElement("div", {
      title: title,
      className: classnames(style.title, style.innerHTML)
    }, /*#__PURE__*/React.createElement("label", {
      htmlFor: checkboxId
    }, /*#__PURE__*/React.createElement("input", {
      id: checkboxId,
      type: "checkbox",
      value: title,
      title: title,
      "aria-label": title,
      checked: selected,
      onChange: onClick,
      className: style.hiddenCheckbox
    }), title)))));
  });
  return /*#__PURE__*/React.createElement("div", {
    "data-name": "qcm-graphic-wrapper",
    className: style.wrapper,
    role: "group",
    "aria-label": groupAriaLabel,
    title: groupAriaLabel
  }, answersViews);
};
QCMImage.contextTypes = {
  skin: Provider.childContextTypes.skin
};
QCMImage.propTypes = process.env.NODE_ENV !== "production" ? {
  answers: PropTypes.arrayOf(PropTypes.shape({
    title: PropTypes.string,
    selected: PropTypes.bool,
    onClick: PropTypes.func,
    image: PropTypes.string,
    ariaLabel: PropTypes.string
  })),
  groupAriaLabel: PropTypes.string
} : {};
export default QCMImage;
//# sourceMappingURL=index.js.map