import { Component, Event, h, Listen, Prop, State, Watch } from '@stencil/core';
import { StateOfReminder } from '../../utils/utils';
export class AddonReminder {
  constructor() {
    this.userInfo = { name: 'Nome', surname: 'Cognome', date: 'creato oggi', image: '' };
    this.state = '';
    this.badgeErrorOn = false;
    this.isFirstTime = true;
    this.reminderInfo = {
      name: 'Promemoria',
      description: 'Descrizione',
      hour: '01',
      minute: '01',
      duration: '00',
      date: '01/01/2021'
    };
    this.reminderDone = false;
    this.status = StateOfReminder.create;
  }
  catchUndoReminder(ev) {
    if (ev) {
      this.undoReminderEmitter.emit(true);
    }
  }
  // @Watch('reminderInfo')
  // updateReminderInfo(){
  //   this.reminderInfoState = this.reminderInfo;
  // }
  sendOutputData(ev) {
    let outputToChange = Object.assign({}, ev.detail);
    let arrayDate = ev.detail.date.split('/');
    let newHour = ev.detail.hour + ev.detail.duration;
    outputToChange.dateTime = new Date(arrayDate[2], arrayDate[1], arrayDate[0], ev.detail.hour, ev.detail.minute);
    outputToChange.dateTimeEnd = new Date(arrayDate[2], arrayDate[1], arrayDate[0], newHour, ev.detail.minute);
    this.outputDataEmitter.emit(outputToChange);
  }
  editOutputData(ev) {
    let outputToChange = Object.assign({}, ev.detail);
    let arrayDate = ev.detail.date.split('/');
    let newHour = ev.detail.hour + ev.detail.duration;
    outputToChange.dateTime = new Date(arrayDate[2], arrayDate[1], arrayDate[0], ev.detail.hour, ev.detail.minute);
    outputToChange.dateTimeEnd = new Date(arrayDate[2], arrayDate[1], arrayDate[0], newHour, ev.detail.minute);
    this.editOutputDataEmitter.emit(outputToChange);
  }
  catchErrorFromUncomplitedDate(ev) {
    this.badgeErrorOn = ev.detail === true;
  }
  setReminderDone(ev) {
    this.reminderDone = ev.detail;
  }
  changeStat(ev) {
    if (ev.detail === 'edit') {
      this.status = StateOfReminder.edit;
    }
    else {
      this.deleteAddonReminderEmitter.emit(true);
    }
  }
  createReminder() {
    this.status = StateOfReminder.view;
  }
  takeInfoFromBody(ev) {
    let reminder = Object.assign({}, this.reminderInfo);
    if (ev.detail.hour) {
      reminder.hour = ev.detail.hour;
    }
    if (ev.detail.minute) {
      reminder.minute = ev.detail.minute;
    }
    if (ev.detail.duration) {
      reminder.duration = ev.detail.duration;
    }
    if (ev.detail.description) {
      reminder.description = ev.detail.description;
    }
    if (ev.detail.date) {
      reminder.date = ev.detail.date;
    }
    this.reminderInfo = Object.assign({}, reminder);
  }
  takeInfoFromHeder(ev) {
    let reminder = Object.assign({}, this.reminderInfo);
    reminder.name = ev.detail;
    this.reminderInfo = Object.assign({}, reminder);
  }
  componentWillRender() {
    if (this.isFirstTime) {
      if (this.state) {
        if (this.state === 'view') {
          this.status = StateOfReminder.view;
        }
        else if (this.state === 'create') {
          this.status = StateOfReminder.create;
        }
        else {
          this.status = StateOfReminder.edit;
        }
      }
      else {
        this.status = StateOfReminder.create;
      }
      this.isFirstTime = false;
    }
  }
  validationOfData(newValue) {
    if (newValue.hour && newValue.minute && newValue.duration && newValue.description && newValue.date && newValue.name) {
      this.badgeErrorOn = false;
      this.validation = true;
    }
    else {
      this.validation = false;
    }
  }
  render() {
    return (h("div", { class: "reminder-container" },
      h("addon-reminder-header", { addonReminderTitle: this.reminderInfo.name, creationDate: this.reminderInfo.date, state: this.status }),
      h("addon-reminder-body", { date: this.reminderInfo.date, reminderDoneValue: this.reminderDone, addonReminderInfoFromParent: this.reminderInfo, state: this.status, descriptionText: this.reminderInfo.description }),
      h("addon-reminder-footer", { author: this.userInfo, submitValidation: this.validation, reminderAddonInfo: this.reminderInfo, state: this.status }),
      h("div", { class: { 'badge-error': true, 'hidden': !this.badgeErrorOn } },
        h("synbee-badge-error", null))));
  }
  static get is() { return "addon-reminder"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["addon-reminder.css"]
  }; }
  static get styleUrls() { return {
    "$": ["addon-reminder.css"]
  }; }
  static get properties() { return {
    "userInfo": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "AuthorStencilDTO",
        "resolved": "AuthorStencilDTO",
        "references": {
          "AuthorStencilDTO": {
            "location": "import",
            "path": "../../interfaces"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "{name: 'Nome', surname:'Cognome', date:'creato oggi', image:''}"
    },
    "state": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "state",
      "reflect": false,
      "defaultValue": "''"
    },
    "reminderInfo": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "{\n    name: string;\n    description: string;\n    hour: string;\n    minute: string;\n    duration: string;\n    date: string;\n  }",
        "resolved": "{ name: string; description: string; hour: string; minute: string; duration: string; date: string; }",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "{\n    name: 'Promemoria',\n    description: 'Descrizione',\n    hour: '01',\n    minute: '01',\n    duration: '00',\n    date: '01/01/2021'\n  }"
    }
  }; }
  static get states() { return {
    "reminderInfoState": {},
    "reminderDone": {},
    "status": {}
  }; }
  static get events() { return [{
      "method": "undoReminderEmitter",
      "name": "undoReminderEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }, {
      "method": "outputDataEmitter",
      "name": "outputDataEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "AddonReminderStencilDTO",
        "resolved": "AddonReminderStencilDTO",
        "references": {
          "AddonReminderStencilDTO": {
            "location": "import",
            "path": "../../interfaces"
          }
        }
      }
    }, {
      "method": "deleteAddonReminderEmitter",
      "name": "deleteAddonReminderEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }, {
      "method": "editOutputDataEmitter",
      "name": "editOutputDataEmitter",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "AddonReminderStencilDTO",
        "resolved": "AddonReminderStencilDTO",
        "references": {
          "AddonReminderStencilDTO": {
            "location": "import",
            "path": "../../interfaces"
          }
        }
      }
    }]; }
  static get watchers() { return [{
      "propName": "reminderInfo",
      "methodName": "validationOfData"
    }]; }
  static get listeners() { return [{
      "name": "undoReminderEmitter",
      "method": "catchUndoReminder",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "createReminderEmitterFromSubmit",
      "method": "sendOutputData",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "editReminderEmitterFromSubmit",
      "method": "editOutputData",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "errorEmitter",
      "method": "catchErrorFromUncomplitedDate",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "reminderDoneEmitter",
      "method": "setReminderDone",
      "target": undefined,
      "capture": true,
      "passive": true
    }, {
      "name": "changeStatusToAddonReminder",
      "method": "changeStat",
      "target": undefined,
      "capture": true,
      "passive": true
    }, {
      "name": "createReminderEmitter",
      "method": "createReminder",
      "target": undefined,
      "capture": true,
      "passive": true
    }, {
      "name": "addonReminderInfoFromBodyEmitter",
      "method": "takeInfoFromBody",
      "target": undefined,
      "capture": true,
      "passive": true
    }, {
      "name": "addonReminderInfoFromHeaderEmitter",
      "method": "takeInfoFromHeder",
      "target": undefined,
      "capture": true,
      "passive": true
    }]; }
}
