import { r as registerInstance, e as createEvent, h } from './index-ee578edf.js';
import { S as StateOfReminder } from './utils-cc62d8e2.js';

const addonReminderCss = ":host{display:flex;background-color:red;height:560px;border-radius:10px;margin-bottom:30px}.reminder-container{display:flex;flex-direction:column;background-color:blue;height:auto;width:100%;border-radius:10px}.badge-error{position:center;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;height:50px;margin:0 auto}.hidden{display:none}";

const AddonReminder = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.undoReminderOutEmitter = createEvent(this, "undoReminderOutEmitter", 7);
    this.outputDataEmitter = createEvent(this, "outputDataEmitter", 7);
    this.deleteAddonReminderEmitter = createEvent(this, "deleteAddonReminderEmitter", 7);
    this.collapseReminder = createEvent(this, "collapseReminder", 7);
    this.reminderDoneSetter = createEvent(this, "reminderDoneSetter", 7);
    this.editOutputDataEmitter = createEvent(this, "editOutputDataEmitter", 7);
    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;
  }
  // @Watch('reminderInfo')
  // updateReminderInfo(){
  //   this.reminderInfoState = this.reminderInfo;
  // }
  catchUndoReminder() {
    if (this.status === StateOfReminder.edit) {
      this.status = StateOfReminder.view;
    }
    else {
      this.undoReminderOutEmitter.emit(true);
    }
  }
  catchCloseAction(ev) {
    this.collapseReminder.emit(ev.detail);
  }
  sendOutputData(ev) {
    let outputToChange = Object.assign({}, ev.detail);
    let arrayDate = ev.detail.date.split('/');
    let month;
    if (arrayDate[1].startsWith('0')) {
      month = parseInt(arrayDate[1].replace('0', ''));
      month = month - 1;
    }
    else {
      month = parseInt(arrayDate[1]);
      month = month - 1;
    }
    let newHour = parseInt(ev.detail.hour.startsWith('0') ? ev.detail.hour.replace('0', '') : ev.detail.hour) + parseInt(ev.detail.duration.startsWith('0') ? ev.detail.duration.replace('0', '') : ev.detail.duration);
    outputToChange.dateTime = new Date(arrayDate[2], month, arrayDate[0], ev.detail.hour.startsWith('0') ? ev.detail.hour.replace('0', '') : ev.detail.hour, ev.detail.minute);
    outputToChange.dateTimeEnd = new Date(arrayDate[2], month, 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 month;
    if (arrayDate[1].startsWith('0')) {
      month = parseInt(arrayDate[1].replace('0', ''));
      month = month - 1;
    }
    else {
      month = parseInt(arrayDate[1]);
      month = month - 1;
    }
    let newHour = parseInt(ev.detail.hour.startsWith('0') ? ev.detail.hour.replace('0', '') : ev.detail.hour) + parseInt(ev.detail.duration.startsWith('0') ? ev.detail.duration.replace('0', '') : ev.detail.duration);
    outputToChange.dateTime = new Date(arrayDate[2], month, arrayDate[0], ev.detail.hour.startsWith('0') ? ev.detail.hour.replace('0', '') : ev.detail.hour, ev.detail.minute);
    outputToChange.dateTimeEnd = new Date(arrayDate[2], month, arrayDate[0], newHour, ev.detail.minute);
    this.editOutputDataEmitter.emit(outputToChange);
  }
  catchErrorFromUncomplitedDate(ev) {
    this.badgeErrorOn = ev.detail === true;
  }
  setReminderDone(ev) {
    this.reminderDone = ev.detail;
    this.reminderDoneSetter.emit(this.reminderDone);
  }
  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);
  }
  stateDetectionChange() {
    if (this.state === 'view') {
      this.status = StateOfReminder.view;
    }
  }
  componentWillRender() {
    if (this.isFirstTime) {
      if (this.state) {
        if (this.state === 'view') {
          this.status = StateOfReminder.view;
        }
        else if (this.state === 'create') {
          this.status = StateOfReminder.create;
          this.reminderInfo.description = '';
        }
        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", { reminderDoneProp: this.reminderDone, 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 watchers() { return {
    "state": ["stateDetectionChange"],
    "reminderInfo": ["validationOfData"]
  }; }
};
AddonReminder.style = addonReminderCss;

export { AddonReminder as addon_reminder };
