import { Component, Element, Event, h, Host, Listen, Method, Prop, State } from '@stencil/core';
export class DvnFieldInputCellText {
  async focus() {
    var _a, _b;
    (_b = (_a = this.el.querySelector('dvn-input')) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
  }
  ;
  handleKeyDown(e) {
    if (e.key === 'Escape') {
      this.cellFormCancel.emit();
      this.internalValue = this.value;
    }
    else if (e.key === 'Enter') {
      if (this.internalValue !== this.value) {
        this.cellFormSubmit.emit({ value: this.internalValue });
      }
      this.cellFormCancel.emit();
    }
  }
  componentWillLoad() {
    this.internalValue = this.value;
  }
  render() {
    const { disabled, errors, field, value } = this;
    const hasError = errors && errors.length > 0;
    return (h(Host, null,
      h("dvn-input", { id: field.id, type: field.inputType || 'text', disabled: disabled || field.disabled, placeholder: field.placeholder, onChange: (e) => {
          e.stopImmediatePropagation();
          this.internalValue = e.detail;
        }, onBlur: (e) => {
          e.stopImmediatePropagation();
          if (this.internalValue !== this.value) {
            this.cellFormSubmit.emit({ value: this.internalValue });
          }
          this.cellFormCancel.emit();
        }, value: value, feedback: hasError ? 'error' : undefined, leaned: true, autoComplete: field.autoComplete, overrideStyle: { width: '100%', 'min-width': '0' }, scale: "small" })));
  }
  static get is() { return "dvn-field-input-cell-text"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-field-input-cell-text.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-field-input-cell-text.css"]
  }; }
  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": "TextField",
        "resolved": "TextField",
        "references": {
          "TextField": {
            "location": "import",
            "path": "@dvn/core/doldurma/src/fields/text"
          }
        }
      },
      "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 states() { return {
    "internalValue": {}
  }; }
  static get events() { return [{
      "method": "cellFormCancel",
      "name": "cellFormCancel",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "cellFormSubmit",
      "name": "cellFormSubmit",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get methods() { return {
    "focus": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "",
        "tags": []
      }
    }
  }; }
  static get elementRef() { return "el"; }
  static get listeners() { return [{
      "name": "keydown",
      "method": "handleKeyDown",
      "target": "document",
      "capture": false,
      "passive": false
    }]; }
}
