import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-ecdfb761.js';

const dvnFieldInputCellTextCss = "dvn-field-input-cell-text{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;height:100%}";

const DvnFieldInputCellText = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.cellFormCancel = createEvent(this, "cellFormCancel", 7);
    this.cellFormSubmit = createEvent(this, "cellFormSubmit", 7);
  }
  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" })));
  }
  get el() { return getElement(this); }
};
DvnFieldInputCellText.style = dvnFieldInputCellTextCss;

export { DvnFieldInputCellText as dvn_field_input_cell_text };
