import _find from "lodash/fp/find";
import _map from "lodash/fp/map";
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React from 'react';
import PropTypes from 'prop-types';
import parseTemplateString from '../../../util/parse-template-string';
import DropDown from '../drop-down';
import FreeText from '../free-text';
import style from './style.css';
const Template = ({
  template,
  answers,
  groupAriaLabel
}) => {
  const totalTemplate = parseTemplateString(template);
  const templateCompose = _map.convert({
    cap: false
  })((part, key) => {
    const type = part.type;
    if (type === 'string') {
      return /*#__PURE__*/React.createElement("span", {
        key: key,
        className: style.textPart
        // eslint-disable-next-line react/no-danger
        ,
        dangerouslySetInnerHTML: {
          __html: part.value
        }
      });
    }
    if (type === 'answerField') {
      const field = _find({
        name: part.value
      }, answers);
      if (!field) return null;
      const {
        type: fieldType,
        ...fieldProps
      } = field;
      const fieldView = fieldType === 'text' ? /*#__PURE__*/React.createElement(FreeText, _extends({}, fieldProps, {
        className: style.text
      })) : /*#__PURE__*/React.createElement(DropDown, _extends({}, fieldProps, {
        theme: "player"
      }));
      return /*#__PURE__*/React.createElement("div", {
        className: style.answerType,
        key: part.value
      }, fieldView);
    }
  }, totalTemplate);
  return /*#__PURE__*/React.createElement("div", {
    "data-name": "template-wrapper",
    className: style.wrapper,
    role: "group",
    "aria-label": groupAriaLabel,
    title: groupAriaLabel
  }, templateCompose);
};
const TextPropTypes = process.env.NODE_ENV !== "production" ? {
  ...DropDown.propTypes,
  type: PropTypes.string
} : {};
Template.propTypes = process.env.NODE_ENV !== "production" ? {
  template: PropTypes.string,
  answers: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape(DropDown.propTypes), PropTypes.shape(TextPropTypes)])),
  groupAriaLabel: PropTypes.string
} : {};
export default Template;
//# sourceMappingURL=index.js.map