"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireDefault(require("react"));

var _input = _interopRequireDefault(require("./components/input"));

var _withMask = require("./with-mask");

// eslint-disable-next-line react/display-name
var _default = (0, _withMask.withMask)('input', function (props) {
  return function (node, data, onChange) {
    var dataset = node.data ? node.data.dataset || {} : {};

    if (dataset.component === 'input') {
      // eslint-disable-next-line react/prop-types
      var adjustedLimit = props.adjustedLimit,
          disabled = props.disabled,
          feedback = props.feedback,
          showCorrectAnswer = props.showCorrectAnswer,
          maxLength = props.maxLength,
          spellCheck = props.spellCheck; // the first answer is the correct one
      // eslint-disable-next-line react/prop-types

      var correctAnswer = (props.choices && dataset && props.choices[dataset.id] || [])[0];
      var finalValue = showCorrectAnswer ? correctAnswer && correctAnswer.label : data[dataset.id] || '';
      var width = maxLength && maxLength[dataset.id];
      return /*#__PURE__*/_react["default"].createElement(_input["default"], {
        key: "".concat(node.type, "-input-").concat(dataset.id),
        correct: feedback && feedback[dataset.id] && feedback[dataset.id] === 'correct',
        disabled: showCorrectAnswer || disabled,
        value: finalValue,
        id: dataset.id,
        onChange: onChange,
        showCorrectAnswer: showCorrectAnswer,
        width: width,
        charactersLimit: adjustedLimit ? width : 25,
        isConstructedResponse: true,
        spellCheck: spellCheck
      });
    }
  };
});

exports["default"] = _default;
//# sourceMappingURL=constructed-response.js.map