import { Component, Event, h, Prop, Watch, Element } from '@stencil/core';
export class UxplTextInput {
  valueChanged() {
    var _a;
    if ((_a = this.textInput) === null || _a === void 0 ? void 0 : _a.value) {
      this.uxplChanged.emit(this.textInput.value);
      this.valChange.emit(this.textInput.value);
    }
  }
  // propagate value change from view to model
  inputChanged(ev) {
    let val = ev.target && ev.target.value;
    // check valid
    if ((this.min && val < this.min) || (this.max && val > this.max)) {
      // invalid
      this.textInput.value = undefined;
    }
    else {
      this.value = val;
      this.changed.emit(this.value);
    }
  }
  componentWillLoad() {
  }
  componentDidLoad() {
  }
  render() {
    return (h("div", { class: "tc-input-container", part: "input-container" },
      h("div", { class: {
          "tc-form-field": true,
          'tc-input': true,
          'tc-error': this.valid == false
        }, part: "form-field" },
        this.hint ?
          h("label", null, this.hint)
          : h("div", null),
        h("input", { ref: (el) => this.textInput = el, type: this.type, class: "tc-input", min: this.min, max: this.max, value: this.value, placeholder: this.placeholder ? this.placeholder : 'Enter text', disabled: this.disabled, required: this.required, onInput: this.inputChanged.bind(this), onKeyUp: (e) => this.keys.emit(e.key), part: "input-element" }),
        h("label", null, this.label))));
  }
  static get is() { return "uxpl-text-input"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["uxpl-text-input.css"]
  }; }
  static get styleUrls() { return {
    "$": ["uxpl-text-input.css"]
  }; }
  static get properties() { return {
    "label": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "label"
      },
      "attribute": "label",
      "reflect": false
    },
    "type": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "type"
      },
      "attribute": "type",
      "reflect": false
    },
    "value": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "value"
      },
      "attribute": "value",
      "reflect": false
    },
    "placeholder": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "placeholder"
      },
      "attribute": "placeholder",
      "reflect": false
    },
    "disabled": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "disabled"
      },
      "attribute": "disabled",
      "reflect": false
    },
    "required": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "required"
      },
      "attribute": "required",
      "reflect": false
    },
    "valid": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "valid"
      },
      "attribute": "valid",
      "reflect": false
    },
    "hint": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "hint"
      },
      "attribute": "hint",
      "reflect": false
    },
    "min": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "min"
      },
      "attribute": "min",
      "reflect": false
    },
    "max": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "valid"
      },
      "attribute": "max",
      "reflect": false
    }
  }; }
  static get events() { return [{
      "method": "changed",
      "name": "changed",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Value changed"
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "valChange",
      "name": "valChange",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Value changed"
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "uxplChanged",
      "name": "uxplChanged",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Value changed"
      },
      "complexType": {
        "original": "string | number",
        "resolved": "number | string",
        "references": {}
      }
    }, {
      "method": "keys",
      "name": "keys",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Key typed changed"
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }]; }
  static get elementRef() { return "el"; }
  static get watchers() { return [{
      "propName": "value",
      "methodName": "valueChanged"
    }]; }
}
