import { r as registerInstance, c as createEvent, h } from './index-acdc1ac0.js';

const DvnFieldInputSingleChoice = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.change = createEvent(this, "change", 7);
  }
  render() {
    const { disabled, errors, field, value } = this;
    const { options = [], preview } = field;
    const hasError = errors && errors.length > 0;
    const error = hasError ? errors[0] : undefined;
    if (preview) {
      const selectedOption = options.find(o => o.value === value);
      return (h("div", null, selectedOption ? selectedOption.label : '', h("div", null, error)));
    }
    // const name = Math.random().toString(36).substr(2, 5);
    // render select
    if (field.inputType === 'select') {
      return (h("dvn-select", { dataAdapter: field.dataAdapter, dataProvider: field.dataProvider, disabled: disabled || field.disabled, feedback: hasError ? 'error' : undefined, leaned: true, value: value }, options.map(option => (h("dvn-select-option", { value: option.value }, option.label)))));
    }
    // render select
    if (field.inputType === 'radioCard') {
      return (h("dvn-radio-card-group", { options: options, value: value }));
    }
    return (h("dvn-radio-group", { disabled: disabled || field.disabled, leaned: true, options: options, value: value }));
  }
};

export { DvnFieldInputSingleChoice as dvn_field_input_single_choice };
