import { Host, h } from '@stencil/core';
import { getHostAttrs, genId } from '../../utils';
/**
 * @docsPage
 */
export class BsTextareaField {
  constructor() {
    /** Native attributes to pass through to the input element. */
    this.attrs = {};
    this.charMax = undefined;
    this.disabled = false;
    this.error = undefined;
    this.errorMsg = undefined;
    this.hint = undefined;
    this.hints = undefined;
    this.inputId = undefined;
    this.label = undefined;
    this.placeholder = undefined;
    this.required = undefined;
    this.rows = 6;
    this.value = '';
    this.passAttrs = '';
    this.hintId = null;
  }
  get charCount() {
    var _a;
    return ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) || 0;
  }
  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',
      'cols',
      'maxlength',
      'minlength',
      'name',
      ...this.passAttrs.split(',')
    ]);
  }
  render() {
    return (h(Host, null, this.label && (h("bs-label", { for: this.inputIdAttr, disabled: this.disabled, required: this.required }, this.label)), h("bs-textarea", Object.assign({ disabled: this.disabled, error: this.error, "hint-id": this.hintId, "input-id": this.inputIdAttr, "pass-attrs": this.passAttrs, placeholder: this.placeholder, required: this.required, rows: this.rows, value: this.value }, this.attrs)), (this.hintMsg || this.charMax) && (h("bs-field-details", { "char-count": this.charCount, "char-max": this.charMax, error: this.error, "error-msg": this.errorMsg, hint: this.hint || this.hintDeprecated, "hint-id": this.hintId }))));
  }
  static get is() { return "bs-textarea-field"; }
  static get originalStyleUrls() {
    return {
      "$": ["bs-textarea-field.scss"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["bs-textarea-field.css"]
    };
  }
  static get properties() {
    return {
      "charMax": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Sets the maximum value this textarea will allow. Will also display character count if present. This does not set maxlength, so users are able to enter text that is longer and edit it down. Enforcement of length must be by the developer."
        },
        "attribute": "char-max",
        "reflect": false
      },
      "disabled": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Sets the disabled state on textarea, 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 input."
        },
        "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
      },
      "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
      },
      "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
      },
      "placeholder": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Placeholder attribute - same as native attribute."
        },
        "attribute": "placeholder",
        "reflect": false
      },
      "required": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Sets the required state on the textarea, append required* indicator to label."
        },
        "attribute": "required",
        "reflect": false
      },
      "rows": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Sets the `rows` attribute on the textarea."
        },
        "attribute": "rows",
        "reflect": false,
        "defaultValue": "6"
      },
      "value": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Sets the textarea value."
        },
        "attribute": "value",
        "reflect": false,
        "defaultValue": "''"
      },
      "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 <input>."
        },
        "attribute": "pass-attrs",
        "reflect": false,
        "defaultValue": "''"
      }
    };
  }
  static get states() {
    return {
      "hintId": {}
    };
  }
  static get elementRef() { return "hostEl"; }
}
//# sourceMappingURL=bs-textarea-field.js.map
