'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-56cc404a.js');
const assets_service = require('./assets.service-5098e79c.js');
const util = require('./util-dd1e6ff1.js');

const sparkleGoalFormCss = ":host{display:block}";

const SparkleGoalForm = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.title = {
      valid: false,
      value: ''
    };
    this.description = {
      valid: false,
      value: ''
    };
    this.category = {
      valid: false,
      value: ''
    };
    this.progress = 0;
    this.public = true;
    this.goalUpdateText = {
      valid: true,
      value: ''
    };
    this.submitted = false;
  }
  goalHanlder() {
    this.updateGoal();
  }
  ;
  componentWillLoad() {
    this.updateGoal();
  }
  updateGoal() {
    if (this.goal) {
      this.title = Object.assign(Object.assign({}, this.title), { value: this.goal.Title });
      this.description = Object.assign(Object.assign({}, this.description), { value: this.goal.Description });
      this.category = Object.assign(Object.assign({}, this.category), { value: this.goal.Category });
      this.progress = this.goal.Progress;
    }
  }
  handleTitle(ev) {
    this.validateTitle();
    this.title = Object.assign(Object.assign({}, this.title), { value: ev.target.value });
  }
  handleDescription(ev) {
    this.validateDescription();
    this.description = Object.assign(Object.assign({}, this.description), { value: ev.target.value });
  }
  handleCategory(ev) {
    this.validateCategoy();
    this.category = Object.assign(Object.assign({}, this.category), { value: ev.target.value });
  }
  handleGoalProgressInfo(ev) {
    this.goalUpdateText = Object.assign(Object.assign({}, this.goalUpdateText), { value: ev.target.value });
  }
  validateTitle() {
    if (this.title.value && this.title.value.length > 0) {
      this.title = Object.assign(Object.assign({}, this.title), { valid: true });
      return;
    }
    this.title = Object.assign(Object.assign({}, this.title), { valid: false });
  }
  validateDescription() {
    if (this.description.value && this.description.value.length > 0) {
      this.title = Object.assign(Object.assign({}, this.description), { valid: true });
      return;
    }
    this.description = Object.assign(Object.assign({}, this.description), { valid: false });
  }
  validateCategoy() {
    if (this.category.value && this.category.value.length > 0) {
      this.category = Object.assign(Object.assign({}, this.category), { valid: true });
      return;
    }
    this.category = Object.assign(Object.assign({}, this.category), { valid: false });
  }
  onSubmit(e) {
    e.preventDefault();
    console.log('clicked signup');
    this.validateTitle();
    this.validateDescription();
    this.validateCategoy();
    this.submitted = true;
  }
  async postToFeed() {
    this.submitted = true;
    const sparkleConfig = assets_service.EnvironmentConfigService.getInstance().get('sparkle');
    const tocData = await assets_service.AssetsService.getInstance().loadJsonFile(sparkleConfig.tocPath);
    var model = {
      CourseId: tocData.id,
      MiniAppId: util.SparkleGlobal.MY_GOALS_APP_ID,
      StudentAppDataId: this.goal.StudentAppDataId,
      PostText: util.MyGoalTemplate(this.goal.Title, this.goalUpdateText.value, this.progress),
      IsPublic: this.public,
      Percentage: this.progress,
      GoalText: this.goalUpdateText,
      IsProgress: true,
    };
    console.log(model);
    //this.store.dispatch(new fromRootStore.PostGoalProgress(model));
  }
  dismiss(data) {
    // dismiss the closest modal and optionally pass back data
    this.el.closest('ion-modal').dismiss({
      'dismissed': true
    });
  }
  renderEditBookingFields() {
    if (this.goal) {
      return (index.h("div", null, index.h("ion-item", null, index.h("ion-label", { position: "stacked", color: "primary" }, "Goal Progress Info"), index.h("ion-input", { name: "title", type: "text", value: this.goalUpdateText.value, onInput: (ev) => this.handleGoalProgressInfo(ev) })), index.h("ion-text", { color: "danger" }, index.h("p", { hidden: this.goalUpdateText.valid || this.submitted === false, class: "ion-padding-start" }, "Goal Progress text is required")), index.h("ion-item", null, index.h("ion-label", { position: "stacked" }, "Progress"), index.h("ion-range", { value: this.progress, min: 1, max: 100, step: 1, snaps: true, pin: true, onIonChange: (e) => this.progress = +e.detail.value }, index.h("ion-icon", { size: "small", slot: "start", name: "pulse" }), index.h("ion-icon", { name: "pulse", size: "small" }), index.h("strong", { slot: "end" }, this.progress))), index.h("ion-text", { color: "danger" }, index.h("p", { hidden: this.progress <= 0 || this.submitted === false, class: "ion-padding-start" }, "Min Progress value should be 1")), index.h("ion-item", { lines: "none" }, index.h("ion-label", null, "Share to Community Wall"), index.h("ion-checkbox", { slot: "start", onChange: (ev) => this.public = ev.detail.checked, checked: true }))));
    }
  }
  render() {
    return [
      index.h("div", null, index.h("ion-toolbar", { color: "primary" }, index.h("ion-buttons", { slot: "start" }, index.h("ion-back-button", { defaultHref: "home", onClick: () => this.dismiss() })), index.h("ion-title", null, "Add New Goal")), index.h("form", { class: "ion-padding", novalidate: true, onSubmit: (e) => this.onSubmit(e) }, index.h("ion-list", { "no-lines": true }, index.h("ion-item", null, index.h("ion-label", { position: "stacked", color: "primary" }, "Title"), index.h("ion-input", { name: "title", type: "text", value: this.title.value, onInput: (ev) => this.handleTitle(ev), required: true })), index.h("ion-text", { color: "danger" }, index.h("p", { hidden: this.title.valid || this.submitted === false, class: "ion-padding-start" }, "Title is required")), index.h("ion-item", null, index.h("ion-label", { position: "stacked", color: "primary" }, "Description"), index.h("ion-textarea", { name: "desciption", value: this.description.value, onInput: (ev) => this.handleDescription(ev), required: true })), index.h("ion-text", { color: "danger" }, index.h("p", { hidden: this.description.valid || this.submitted === false, class: "ion-padding-start" }, "Description is required")), index.h("ion-item", null, index.h("ion-label", null, "Category"), index.h("ion-select", { value: this.category.value }, index.h("ion-select-option", { value: "Emotional" }, "Emotional"), index.h("ion-select-option", { value: "Interpersonal" }, "Interpersonal"), index.h("ion-select-option", { value: "Learning" }, "Learning"), index.h("ion-select-option", { value: "Financial" }, "Financial"), index.h("ion-select-option", { value: "Physical" }, "Physical"))), index.h("ion-text", { color: "danger" }, index.h("p", { hidden: this.category.valid || this.submitted === false, class: "ion-padding-start" }, "Category is required")), this.renderEditBookingFields()), index.h("div", { class: "ion-padding" }, this.goal && index.h("ion-button", { type: "submit", expand: "block" }, "Update"), !this.goal && index.h("ion-button", { type: "submit", expand: "block" }, "Add"))))
    ];
  }
  get el() { return index.getElement(this); }
  static get watchers() { return {
    "goal": ["goalHanlder"]
  }; }
};
SparkleGoalForm.style = sparkleGoalFormCss;

exports.sparkle_goal_form = SparkleGoalForm;
