"use strict";

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