import { Component, h, Host, Prop, Element } from '@stencil/core';
export class Field {
  constructor() {
    /**
     * Text of the inputs label
     */
    this.label = '';
    /**
     * If `true` a asterix (*) is added to the label text
     */
    this.required = false;
    /**
     * If `true` the component takes the whole width
     */
    this.expanded = false;
    /**
     * If `true` the field loses opacity
     */
    this.disabled = false;
    /**
     * Validation message text
     */
    this.validationMessage = '';
    /**
     * Baloise icon for the right side of the input
     */
    this.iconRight = '';
    /**
     * Baloise icon for the left side of the input
     */
    this.iconLeft = '';
    /**
     * If `true` the field can be used on blue background.
     */
    this.inverted = false;
    /**
     * If `true` a loading spinner is visible at the end of the input
     */
    this.loading = false;
  }
  get buildIconLeftTemplate() {
    if (this.iconLeft) {
      return h("bal-icon", { name: this.iconLeft, isLeft: true, size: "medium" });
    }
    return '';
  }
  get buildIconRightTemplate() {
    if (this.iconRight) {
      return h("bal-icon", { name: this.iconRight, isRight: true, size: "medium" });
    }
    return '';
  }
  render() {
    return (h(Host, { class: {
        'is-expanded': this.expanded,
      } },
      h("div", { class: {
          'form': true,
          'is-inverted': this.inverted,
          'is-disabled': this.disabled,
        } },
        h("label", { class: "label", htmlFor: this.findInputId() },
          this.label,
          this.required === true ? ' *' : '',
          h("slot", { name: "hint" })),
        h("div", { class: {
            'control': true,
            'has-icons-left': !!this.iconLeft,
            'has-icons-right': !!this.iconRight,
            'is-loading': this.loading,
          } },
          h("slot", null),
          this.buildIconLeftTemplate,
          this.buildIconRightTemplate),
        h("p", { class: "help is-danger" }, this.validationMessage))));
  }
  findInputId() {
    const inputElement = this.element.querySelector('input.input');
    return inputElement && inputElement.id ? inputElement.id : '';
  }
  static get is() { return "bal-field"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["bal-field.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["bal-field.css"]
  }; }
  static get properties() { return {
    "label": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Text of the inputs label"
      },
      "attribute": "label",
      "reflect": false,
      "defaultValue": "''"
    },
    "required": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` a asterix (*) is added to the label text"
      },
      "attribute": "required",
      "reflect": false,
      "defaultValue": "false"
    },
    "expanded": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` the component takes the whole width"
      },
      "attribute": "expanded",
      "reflect": false,
      "defaultValue": "false"
    },
    "disabled": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` the field loses opacity"
      },
      "attribute": "disabled",
      "reflect": false,
      "defaultValue": "false"
    },
    "validationMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Validation message text"
      },
      "attribute": "validation-message",
      "reflect": false,
      "defaultValue": "''"
    },
    "iconRight": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Baloise icon for the right side of the input"
      },
      "attribute": "icon-right",
      "reflect": false,
      "defaultValue": "''"
    },
    "iconLeft": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Baloise icon for the left side of the input"
      },
      "attribute": "icon-left",
      "reflect": false,
      "defaultValue": "''"
    },
    "inverted": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` the field can be used on blue background."
      },
      "attribute": "inverted",
      "reflect": false,
      "defaultValue": "false"
    },
    "loading": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` a loading spinner is visible at the end of the input"
      },
      "attribute": "loading",
      "reflect": false,
      "defaultValue": "false"
    }
  }; }
  static get elementRef() { return "element"; }
}
