import { h, Host } from '@stencil/core';
import { getHostAttrs, genId } from '../../utils/index';
/**
 * Displays a <bs-select> field with a corresponding <bs-label> and <bs-hint>.
 *
 * @docsPage
 */
export class BsSelectField {
  constructor() {
    /** Native attributes to pass through to the select element. */
    this.attrs = {};
    this.disabled = false;
    this.error = undefined;
    this.errorMsg = undefined;
    this.inputId = undefined;
    this.label = undefined;
    this.hint = undefined;
    this.hints = undefined;
    this.placeholder = '';
    this.required = undefined;
    this.value = undefined;
    this.passAttrs = '';
    this.data = [];
    this.hintId = null;
  }
  get hintMsg() {
    return this.errorMsg || this.hint || this.hintDeprecated || undefined;
  }
  // Temporary holdover; removing this very soon
  get hintDeprecated() {
    var _a, _b;
    return ((_b = (_a = this.hints) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '\n')) || this.hints;
  }
  get inputIdAttr() {
    return this.inputId || this.inputIdGen;
  }
  componentWillLoad() {
    this.inputIdGen = this.inputId || genId();
    this.hintId = this.hintMsg ? genId() : null;
    this.attrs = getHostAttrs(this.hostEl, [
      'autocomplete',
      'max',
      'min',
      'maxlength',
      'minlength',
      'name',
      'placeholder',
      ...this.passAttrs.split(',')
    ]);
  }
  get validValue() {
    return this.value;
  }
  render() {
    return (h(Host, null, this.label && (h("bs-label", { for: this.inputIdAttr, disabled: this.disabled, required: this.required }, this.label)), h("bs-select", Object.assign({ disabled: this.disabled, error: this.error, "hint-id": this.hintId, "input-id": this.inputIdAttr, "pass-attrs": this.passAttrs, required: this.required, value: this.validValue }, this.attrs), h("option", { selected: !this.validValue, disabled: false }, this.placeholder), this.data.map(option => (h("option", { value: option.value, selected: this.validValue === option.value, disabled: option.disabled }, option.label)))), this.hintMsg && (h("bs-field-details", { error: this.error, "error-msg": this.errorMsg, hint: this.hint || this.hintDeprecated, "hint-id": this.hintId }))));
  }
  static get is() { return "bs-select-field"; }
  static get originalStyleUrls() {
    return {
      "$": ["bs-select-field.scss"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["bs-select-field.css"]
    };
  }
  static get properties() {
    return {
      "disabled": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Sets the disabled state on select, disabled styles on label."
        },
        "attribute": "disabled",
        "reflect": false,
        "defaultValue": "false"
      },
      "error": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Applies error styles to the select."
        },
        "attribute": "error",
        "reflect": false
      },
      "errorMsg": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Pass error text."
        },
        "attribute": "error-msg",
        "reflect": false
      },
      "inputId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Pass id for the input element.  Will also be applied to label attribute."
        },
        "attribute": "input-id",
        "reflect": false
      },
      "label": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Pass label text."
        },
        "attribute": "label",
        "reflect": false
      },
      "hint": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Pass helper text."
        },
        "attribute": "hint",
        "reflect": false
      },
      "hints": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string | string[]",
          "resolved": "string | string[]",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "DEPRECATED.  Use `hint` and/or `errorMsg`."
        },
        "attribute": "hints",
        "reflect": false
      },
      "placeholder": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Pass a default placeholder option, which will have no value."
        },
        "attribute": "placeholder",
        "reflect": false,
        "defaultValue": "''"
      },
      "required": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Sets the required state on the select, append required* indicator to label."
        },
        "attribute": "required",
        "reflect": false
      },
      "value": {
        "type": "any",
        "mutable": false,
        "complexType": {
          "original": "string | number",
          "resolved": "number | string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Sets the select value."
        },
        "attribute": "value",
        "reflect": false
      },
      "passAttrs": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "List additional attributes by name (comma-separated) to pass through to <select>."
        },
        "attribute": "pass-attrs",
        "reflect": false,
        "defaultValue": "''"
      },
      "data": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "OptionProps[]",
          "resolved": "OptionProps[]",
          "references": {
            "OptionProps": {
              "location": "import",
              "path": "../../types/propTypes"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "mapTo",
              "text": "OptionProps"
            }],
          "text": ""
        },
        "defaultValue": "[]"
      }
    };
  }
  static get states() {
    return {
      "hintId": {}
    };
  }
  static get elementRef() { return "hostEl"; }
}
//# sourceMappingURL=bs-select-field.js.map
