import { Component, h, Prop, State, Event, Listen } from '@stencil/core';
import { StateOfReminder } from '../../utils/utils';
export class DescriptionInput {
  constructor() {
    this.text = '';
    this.selectionText = '';
  }
  componentWillRender() {
    this.status = this.state;
  }
  componentShouldUpdate() {
    this.status = this.state;
  }
  emitValueOfText(value) {
    if (value.inputType === 'deleteContentBackward') {
      if (this.selectionText) {
        this.textEmitter.emit({ inputType: 'deleteContentBackward', text: this.selectionText });
      }
      else {
        this.textEmitter.emit({ inputType: 'deleteContentBackward', text: '' });
      }
    }
    else {
      this.textEmitter.emit({ inputType: 'text', text: value.data });
    }
  }
  // checkForDelete(ev){
  //
  //     const key = ev.key; // const {key} = event; ES6+
  //     if (key === "Cancel" || key === "Delete") {
  //       console.log(this.text)
  //     }
  //
  // }
  render() {
    if (this.status === StateOfReminder.create) {
      return (h("div", { class: "description-container" },
        h("div", { class: "title" }, "Descrizione"),
        h("textarea", { onInput: (value) => this.emitValueOfText(value), class: "textarea-create" })));
    }
    else if (this.status === StateOfReminder.view) {
      return (h("div", { class: "description-container-view" },
        h("textarea", { class: "textarea-view" }, this.text)));
    }
    else {
      return (h("div", { class: "description-container" },
        h("div", { class: "title" }, "Descrizione"),
        h("textarea", { id: "mytext", onInput: (value) => this.emitValueOfText(value), class: "textarea-create" }, this.text)));
    }
  }
  handleSelection(event) {
    if (window.getSelection) {
      console.log(event);
      this.selectionText = window.getSelection().toString();
    }
  }
  static get is() { return "description-input"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["description-input.css"]
  }; }
  static get styleUrls() { return {
    "$": ["description-input.css"]
  }; }
  static get properties() { return {
    "state": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "StateOfReminder",
        "resolved": "StateOfReminder.create | StateOfReminder.edit | StateOfReminder.view",
        "references": {
          "StateOfReminder": {
            "location": "import",
            "path": "../../utils/utils"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "state",
      "reflect": false
    },
    "text": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "text",
      "reflect": false,
      "defaultValue": "''"
    }
  }; }
  static get states() { return {
    "status": {}
  }; }
  static get events() { return [{
      "method": "textEmitter",
      "name": "textEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "{ inputType: string, text: string }",
        "resolved": "{ inputType: string; text: string; }",
        "references": {}
      }
    }]; }
  static get listeners() { return [{
      "name": "mouseup",
      "method": "handleSelection",
      "target": "body",
      "capture": false,
      "passive": true
    }]; }
}
