import { Component, Event, h, Listen, Prop, State } from '@stencil/core';
import { StateOfReminder } from '../../utils/utils';
export class AddonReminderFooter {
  constructor() {
    this.reminderDone = false;
    this.controlParam = false;
    this.submitValidation = false;
    this.reminderAddonInfo = null;
  }
  switchReminderDone() {
    if (this.status !== StateOfReminder.edit) {
      this.reminderDone = !this.reminderDone;
      this.reminderDoneEmitter.emit(this.reminderDone);
    }
  }
  componentWillRender() {
    this.status = this.state;
  }
  componentWillUpdate() {
    if (this.reminderAddonInfo.hour && this.reminderAddonInfo.minute && this.reminderAddonInfo.duration && this.reminderAddonInfo.description && this.reminderAddonInfo.date && this.reminderAddonInfo.name) {
      this.errorEmitter.emit(false);
      this.controlParam = true;
    }
    else {
      this.controlParam = false;
    }
  }
  componentShouldUpdate() {
    this.status = this.state;
  }
  // @Watch('reminderAddonInfo') validateReminderAddonInfo(newValue){
  //   if(newValue.hour && newValue.minute && newValue.duration && newValue.description && newValue.date && newValue.title) {
  //     this.errorEmitter.emit(false)
  //     this.controlParam = true;
  //   }
  //   else{
  //     this.controlParam = false;
  //
  //
  //   }
  // }
  undoReminder() {
    this.undoReminderEmitter.emit(true);
  }
  editReminder() {
    let output = Object.assign({}, this.reminderAddonInfo);
    output.author = this.author;
    this.editReminderEmitterFromSubmit.emit(output);
    this.createReminderEmitter.emit('view');
  }
  createReminder() {
    console.log('controlParam: ', this.submitValidation);
    if (this.submitValidation) {
      this.errorEmitter.emit(false);
      // this.addonService.otherService().pipe(switchMap(res => {
      //   return this.addonService.takeDataFromCreation();
      // }))subscribe(res => {
      //   res
      // })
      let output = Object.assign({}, this.reminderAddonInfo);
      output.author = this.author;
      this.createReminderEmitterFromSubmit.emit(output);
      this.createReminderEmitter.emit('view');
    }
    else {
      this.errorEmitter.emit(true);
    }
  }
  render() {
    if (this.status === StateOfReminder.create) {
      return (h("div", { class: "reminder-footer" },
        h("div", { class: "items-container" },
          "Azioni",
          h("div", { class: "buttons-container" },
            h("input-button", { onClick: () => this.undoReminder(), icon: false, text: "Annulla" }),
            h("input-button", { onClick: () => this.createReminder(), icon: true, dark: true, text: "Crea" })))));
    }
    else if (this.status === StateOfReminder.view) {
      return (h("div", { class: "reminder-footer" },
        h("div", { class: "author-container" },
          "Utenti",
          h("div", { class: "info-author" },
            h("synbee-avatar", null),
            h("div", { class: "text-info" },
              h("div", null,
                "Modificato da ",
                h("b", null,
                  this.author.name,
                  " ",
                  this.author.surname)),
              h("div", null, this.author.date)))),
        h("div", { class: "items-container-view" },
          "Azioni",
          h("div", { class: "buttons-container-view" },
            h("input-button", { size: "200px", class: { 'hidden': this.reminderDone }, icon: false, text: "Non completato" }),
            h("input-button", { size: "200px", class: { 'hidden': !this.reminderDone }, icon: false, dark: true, text: "Segna come completato" })))));
    }
    else {
      return (h("div", { class: "reminder-footer" },
        h("div", { class: "items-container" },
          "Azioni",
          h("div", { class: "buttons-container" },
            h("input-button", { onClick: () => this.undoReminder(), icon: false, text: "Annulla" }),
            h("input-button", { onClick: () => this.editReminder(), icon: true, dark: true, text: "Modifica" })))));
    }
  }
  static get is() { return "addon-reminder-footer"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["addon-reminder-footer.css"]
  }; }
  static get styleUrls() { return {
    "$": ["addon-reminder-footer.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
    },
    "submitValidation": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "submit-validation",
      "reflect": false,
      "defaultValue": "false"
    },
    "author": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "AuthorStencilDTO",
        "resolved": "AuthorStencilDTO",
        "references": {
          "AuthorStencilDTO": {
            "location": "import",
            "path": "../../interfaces"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "reminderAddonInfo": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "{name?: string, description?: string, hour?:string, minute?:string, duration?:string, date?: string}",
        "resolved": "{ name?: string; description?: string; hour?: string; minute?: string; duration?: string; date?: string; }",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "null"
    }
  }; }
  static get states() { return {
    "reminderAddonInfoState": {}
  }; }
  static get events() { return [{
      "method": "createReminderEmitter",
      "name": "createReminderEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "createReminderEmitterFromSubmit",
      "name": "createReminderEmitterFromSubmit",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "AddonReminderStencilDTO",
        "resolved": "AddonReminderStencilDTO",
        "references": {
          "AddonReminderStencilDTO": {
            "location": "import",
            "path": "../../interfaces"
          }
        }
      }
    }, {
      "method": "undoReminderEmitter",
      "name": "undoReminderEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }, {
      "method": "reminderDoneEmitter",
      "name": "reminderDoneEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }, {
      "method": "errorEmitter",
      "name": "errorEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }, {
      "method": "editReminderEmitterFromSubmit",
      "name": "editReminderEmitterFromSubmit",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "AddonReminderStencilDTO",
        "resolved": "AddonReminderStencilDTO",
        "references": {
          "AddonReminderStencilDTO": {
            "location": "import",
            "path": "../../interfaces"
          }
        }
      }
    }]; }
  static get listeners() { return [{
      "name": "toggleReminderEmitter",
      "method": "switchReminderDone",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
