"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _index = _interopRequireDefault(require("../questions/mobile/switch/index.native"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const convertType = modelType => {
  switch (modelType) {
    case 'freeText':
      return 'basic';
    case 'dropDown':
      return 'template';
    default:
      return modelType;
  }
};
const convertToChoices = (answers = []) => answers.map((answer, index) => ({
  _id: `${index}`,
  label: answer.title,
  value: answer.title,
  onPress: answer.onClick || answer.onChange,
  selected: answer.selected,
  media: answer.image ? {
    type: 'img',
    src: [{
      url: answer.image
    }]
  } : undefined,
  // ---- custom properties for template choice
  type: answer.type,
  name: answer.name,
  items: answer.options && answer.options.map(({
    name,
    selected,
    value
  }) => ({
    text: name,
    selected,
    value,
    _id: name
  }))
}));
const Answer = props => {
  const {
    model: {
      answers,
      onChange,
      template,
      type,
      onSliderChange,
      minLabel,
      maxLabel,
      title
    }
  } = props;
  const switchProps = {
    type: convertType(type)
  };
  if (type === 'freeText') {
    switchProps.onInputValueChange = onChange;
  }
  if (type === 'qcm' || type === 'qcmDrag' || type === 'qcmGraphic' || type === 'template') {
    switchProps.choices = convertToChoices(answers);
  }
  if (type === 'template') {
    switchProps.template = template;
  }
  if (type === 'slider') {
    switchProps.onSliderChange = onSliderChange;
    switchProps.min = minLabel ? Number.parseInt(minLabel.split(' ')[0]) : 0;
    switchProps.max = maxLabel ? Number.parseInt(maxLabel.split(' ')[0]) : 1;
    switchProps.value = title ? Number.parseInt(title.split(' ')[0]) : 0;
    switchProps.unit = minLabel ? minLabel.split(' ')[1] : '';
  }
  return /*#__PURE__*/_react.default.createElement(_index.default, switchProps);
};
var _default = exports.default = Answer;
//# sourceMappingURL=index.native.js.map