import { Component, Event, h, Prop } from '@stencil/core';
export class DvnFieldInputRange {
  render() {
    const { disabled, errors, field, value } = this;
    const { preview } = field;
    const hasError = errors && errors.length > 0;
    const error = hasError ? errors[0] : undefined;
    const options = [];
    for (let i = field.min; i <= field.max; i += field.step) {
      options.push(i);
    }
    if (preview) {
      return (h("div", null,
        value,
        h("div", null, error)));
    }
    // const name = Math.random().toString(36).substr(2, 5);
    // render select
    if (field.inputType === 'select') {
      return (h("dvn-select", { disabled: disabled || field.disabled, feedback: hasError ? 'error' : undefined, leaned: true, value: value }, options.map(option => (h("dvn-select-option", { value: `${option}` }, option)))));
    }
    if (field.inputType === 'stars') {
      return (h("dvn-rating-stars", { disabled: disabled || field.disabled, options: options, value: Number(value) }));
    }
    return (h("dvn-radio-group", { disabled: disabled || field.disabled, inline: true, leaned: true, options: options.map(o => ({ label: `${o}`, value: `${o}` })), value: value }));
  }
  static get is() { return "dvn-field-input-range"; }
  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": "RangeField",
        "resolved": "RangeField",
        "references": {
          "RangeField": {
            "location": "import",
            "path": "../range"
          }
        }
      },
      "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": {}
      }
    }]; }
}
