import { Component, Event, h, Prop } from '@stencil/core';
export class DvnFieldInputSingleChoice {
  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 }));
  }
  static get is() { return "dvn-field-input-single-choice"; }
  static get properties() { return {
    "disabled": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "disabled",
      "reflect": false
    },
    "field": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "SingleChoiceField",
        "resolved": "SingleChoiceField",
        "references": {
          "SingleChoiceField": {
            "location": "import",
            "path": "../single-choice"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "errors": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "any[]",
        "resolved": "any[]",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "value": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "value",
      "reflect": false
    }
  }; }
  static get events() { return [{
      "method": "change",
      "name": "change",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
}
