'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-1141a245.js');

const DvnFieldInputSingleChoice = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.change = index.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 (index.h("div", null, selectedOption ? selectedOption.label : '', index.h("div", null, error)));
    }
    // const name = Math.random().toString(36).substr(2, 5);
    // render select
    if (field.inputType === 'select') {
      return (index.h("dvn-select", { dataAdapter: field.dataAdapter, dataProvider: field.dataProvider, disabled: disabled || field.disabled, feedback: hasError ? 'error' : undefined, leaned: true, value: value, width: "100%" }, field.placeholder &&
        index.h("dvn-select-option", null, field.placeholder), options.map(option => (index.h("dvn-select-option", { value: option.value }, option.label)))));
    }
    // render select
    if (field.inputType === 'radioCard') {
      return (index.h("dvn-radio-card-group", { options: options, value: value }));
    }
    return (index.h("dvn-radio-group", { disabled: disabled || field.disabled, leaned: true, options: options, value: value }));
  }
};

exports.dvn_field_input_single_choice = DvnFieldInputSingleChoice;
