"use strict";

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

var _preact = require("preact");

var _formFields = require("./form-fields");

var _listTextareaField = require("./list-textarea-field");

var _medicationField = require("./medication-field");

var _multiMedicationEntryField = require("./multi-medication-entry-field");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const fieldMap = {
  multiButton: _formFields.SelectButtons,
  choices: _formFields.SelectButtons,
  longText: _formFields.TextareaField,
  checkbox: _formFields.CheckboxField,
  medications: _multiMedicationEntryField.MultiMedicationEntryField,
  medication: _medicationField.MedicationEntryField,
  signature: _formFields.SignatureField,
  incrementor: _formFields.IncrementButtonField,
  timeIncrementor: _formFields.TimeIncrementField,
  select: _formFields.SelectField,
  decimal: _formFields.DecimalInputField,
  listTextarea: _listTextareaField.ListTextareaField
};

const Question = ({
  item,
  updateValue,
  removeSuggestion,
  otherFieldTypes
}) => {
  if (item.hidden) {
    return null;
  } // if item has "choices" (very common in our app)
  // don't require specifying `type: 'choices'`


  const itemType = item.type || (item.choices ? 'choices' : 'text');
  const MatchedComponent = otherFieldTypes && otherFieldTypes[itemType] || fieldMap[itemType] || _formFields.InputField;

  const props = _objectSpread({
    item,
    updateValue,
    removeSuggestion
  }, item.fieldSpecificProps || {});

  return (0, _preact.h)(MatchedComponent, props);
};

exports.Question = Question;