'use strict';

const index = require('./index-1141a245.js');
const FieldGenerator = require('./FieldGenerator-279a646b.js');
const BaseField = require('./BaseField-381327a9.js');

class SingleChoiceFieldOption {
  constructor(label, value, tint, description) {
    this.label = label;
    this.value = value;
    this.tint = tint;
    this.description = description;
  }
}
class SingleChoiceField extends BaseField.BaseField {
  constructor(id, title, options, description, inputType = 'radioButton', placeholder) {
    super(id, 'single-choice');
    this.title = title;
    this.options = options;
    this.inputType = inputType;
    this.description = description;
    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 };
  }
  setOptions(options) {
    this.options = options;
    return this;
  }
  setDataProvider(dataProvider) {
    this.dataProvider = dataProvider;
    return this;
  }
  setDataAdapter(dataAdapter) {
    this.dataAdapter = dataAdapter;
    return this;
  }
}
SingleChoiceField.type = 'single-choice';

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

exports.SingleChoiceField = SingleChoiceField;
exports.SingleChoiceFieldOption = SingleChoiceFieldOption;
