import _getOr from "lodash/fp/getOr";
import _orderBy from "lodash/fp/orderBy";
import _filter from "lodash/fp/filter";
import _pipe from "lodash/fp/pipe";
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 AnswersPropTypes = process.env.NODE_ENV !== "production" ? PropTypes.arrayOf(PropTypes.shape({
  onClick: PropTypes.func,
  order: PropTypes.number,
  selected: PropTypes.bool,
  title: PropTypes.string,
  help: PropTypes.string
})) : {};
const EmptyView = ({
  help
}) => /*#__PURE__*/React.createElement("span", {
  className: style.emptySpan
}, help);
EmptyView.propTypes = process.env.NODE_ENV !== "production" ? {
  help: PropTypes.string
} : {};
const Choices = ({
  answers
}) => {
  const answersViews = answers.map((answer, key) => {
    const {
      onClick,
      title,
      selected
    } = answer;
    const checkboxId = `checkbox-drag-${key}`;
    return /*#__PURE__*/React.createElement("div", {
      className: classnames(selected ? style.invisibleAnswer : style.unselected, style.innerHTML),
      "data-name": "answer",
      key: key,
      onClick: onClick
    }, /*#__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", {
    className: style.choices
  }, answersViews);
};
Choices.propTypes = process.env.NODE_ENV !== "production" ? {
  answers: AnswersPropTypes
} : {};
const SelectedAnswerSections = ({
  answers,
  help,
  backgroundColor
}) => {
  const selectedAnswers = _pipe(_filter('selected'), _orderBy('order', 'asc'))(answers);
  const selectedAnswersViews = selectedAnswers.map((answer, key) => {
    const {
      onClick,
      title
    } = answer;
    return /*#__PURE__*/React.createElement("div", {
      "data-selected": "true",
      onClick: onClick,
      key: key,
      "data-name": "selectedAnswer",
      className: style.selected,
      style: {
        boxShadow: `0px 4px 16px ${getShadowBoxColorFromPrimary(backgroundColor)}`
      }
    }, /*#__PURE__*/React.createElement("div", {
      "data-name": "answerBackground",
      style: {
        backgroundColor
      },
      className: style.background
    }), /*#__PURE__*/React.createElement("div", {
      className: style.content
    }, /*#__PURE__*/React.createElement("span", {
      "data-name": "answerContent",
      className: classnames(style.selectedAnswerText, style.innerHTML),
      title: title
      // eslint-disable-next-line react/no-danger
      ,
      dangerouslySetInnerHTML: {
        __html: title
      }
    })));
  });
  if (selectedAnswersViews.length > 0) {
    return /*#__PURE__*/React.createElement("div", {
      className: style.selectedAnswers
    }, selectedAnswersViews);
  } else {
    return /*#__PURE__*/React.createElement("div", {
      className: style.emptyAnswers
    }, /*#__PURE__*/React.createElement(EmptyView, {
      help: help
    }));
  }
};
SelectedAnswerSections.propTypes = process.env.NODE_ENV !== "production" ? {
  answers: AnswersPropTypes,
  help: EmptyView.propTypes.help,
  backgroundColor: PropTypes.string
} : {};
const QcmDrag = ({
  answers,
  help,
  groupAriaLabel
}, legacyContext) => {
  const skin = GetSkinFromContext(legacyContext);
  const primarySkinColor = _getOr('#00B0FF', 'common.primary', skin);
  return /*#__PURE__*/React.createElement("div", {
    className: style.wrapper,
    role: "group",
    "aria-label": groupAriaLabel
  }, /*#__PURE__*/React.createElement(SelectedAnswerSections, {
    answers: answers,
    help: help,
    backgroundColor: primarySkinColor
  }), /*#__PURE__*/React.createElement("div", {
    "data-name": "qcm-drag-answers",
    className: style.answers
  }, /*#__PURE__*/React.createElement(Choices, {
    answers: answers
  })));
};
QcmDrag.propTypes = process.env.NODE_ENV !== "production" ? {
  answers: AnswersPropTypes,
  help: SelectedAnswerSections.propTypes.help,
  groupAriaLabel: PropTypes.string
} : {};
QcmDrag.contextTypes = {
  skin: Provider.childContextTypes.skin
};
export default QcmDrag;
//# sourceMappingURL=index.js.map