import { h } from './index-ecdfb761.js';
import { r as registerField } from './FieldGenerator-3ae403b2.js';
import { B as BaseField } from './BaseField-0b01dc2c.js';

class MultipleChoiceFieldOption {
  constructor(label, value) {
    this.label = label;
    this.value = value;
  }
}
class MultipleChoiceField extends BaseField {
  constructor(id, title, options, description, inputType = 'checkbox', placeholder) {
    super(id, 'multiple-choice');
    this.title = title;
    this.description = description;
    this.options = options;
    this.inputType = inputType;
    this.placeholder = placeholder;
  }
  showPreview() {
    this.preview = true;
    return this;
  }
  getOptionOfValue(value) {
    if (!this.optionsByValue) {
      this.optionsByValue = {};
      for (let i = 0; i < this.options.length; i += 1) {
        this.optionsByValue[this.options[i].value] = this.options[i];
      }
    }
    return this.optionsByValue[value] || { label: value, value };
  }
}
MultipleChoiceField.type = 'multiple-choice';

const render = (field, value, errors, disabled, onFieldChange, onFieldBlur) => h("dvn-field-input-multiple-choice", { disabled: disabled, errors: errors, field: field, onChange: (e) => onFieldChange(field, e.detail), onBlur: () => onFieldBlur(field), value: value });
// register 'multiple-choice' key for json form generations
registerField('multiple-choice', render);

export { MultipleChoiceField as M, MultipleChoiceFieldOption as a };
