"use strict";

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

var _reactIntl = require("react-intl");

var _utils = require("../../utils");

var _default = function _default(_ref) {
  var config = _ref.config,
      fillProps = _ref.fillProps;
  var _config$choices = config.choices,
      choices = _config$choices === void 0 ? [] : _config$choices,
      choicesDisabled = config.choicesDisabled,
      placeholder = config.placeholder,
      defaults = config["default"],
      _config$selectType = config.selectType,
      selectType = _config$selectType === void 0 ? 'string' : _config$selectType,
      autocomplete = config.autocomplete,
      _config$autoSort = config.autoSort,
      autoSort = _config$autoSort === void 0 ? false : _config$autoSort,
      widget = config.widget;
  var choicesSorted = (0, _utils.sortChoices)(choices, autoSort);
  return {
    schema: choicesSorted.length || autocomplete ? {
      "default": defaults,
      "enum": choicesSorted.map(function (v, i) {
        var _v$enum;

        return (_v$enum = v === null || v === void 0 ? void 0 : v["enum"]) !== null && _v$enum !== void 0 ? _v$enum : String(i);
      }),
      enumNames: choicesSorted.map(function (v) {
        return typeof v === 'object' ? v.enumNames : v;
      }),
      type: selectType
    } : // Empty list of choices (enums) matches incorrectly when used in
    // dynamic list item, when oneOf has multiple fields with same key.
    {
      type: selectType,
      "default": '',
      readOnly: true
    },
    uiSchema: {
      'ui:placeholder': placeholder,
      'ui:widget': choices.length && widget ? (0, _utils.ensureValueIsAvailable)(widget.endsWith('Row') ? widget.slice(0, -3) : widget, widgets) : // If enums are not set, the widget may throw error.
      undefined,
      // 'ui:field': autocomplete ? AutocompleteSelectField : undefined,
      'ui:enumDisabled': choicesDisabled,
      'ui:options': {
        inline: widget && widget.endsWith('Row'),
        showScore: fillProps === null || fillProps === void 0 ? void 0 : fillProps.showScores
      }
    }
  };
};

exports["default"] = _default;
var name = (0, _reactIntl.defineMessage)({
  id: "r/LS4F",
  defaultMessage: [{
    "type": 0,
    "value": "Valinta"
  }]
});
exports.name = name;
var elementType = 'field';
exports.elementType = elementType;
var widgets = [{
  value: 'select',
  message: (0, _reactIntl.defineMessage)({
    id: "1GAb3J",
    defaultMessage: [{
      "type": 0,
      "value": "Valintalista"
    }]
  })
}, {
  value: 'radio',
  message: (0, _reactIntl.defineMessage)({
    id: "jxSL/l",
    defaultMessage: [{
      "type": 0,
      "value": "Radiopainikkeet allekkain"
    }]
  })
}, {
  value: 'radioRow',
  message: (0, _reactIntl.defineMessage)({
    id: "4SG/Av",
    defaultMessage: [{
      "type": 0,
      "value": "Radiopainikkeet rivissä"
    }]
  })
}];
exports.widgets = widgets;
//# sourceMappingURL=select.cjs.map