'use strict';

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

const index = require('./index-51e8292e.js');
const student_service = require('./student.service-7e5385be.js');
const overlays = require('./overlays-32df265a.js');
require('./httpService-d2e7bf8f.js');
require('./auth.store-1e630a7d.js');
require('./environment-config.service-c8ff1f3d.js');
require('./token.service-7a41953d.js');
require('./localstorage.service-6346a41d.js');
require('./ionic-global-2cde9d3a.js');
require('./hardware-back-button-92d97ff8.js');
require('./helpers-c2496722.js');

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

const SparkleFeedback = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.formControls = {
      type: {
        isValid: true,
        value: 1,
        validate: value => {
          if (value) {
            return true;
          }
          else {
            return false;
          }
        },
      },
      note: {
        isValid: false,
        value: '',
        validate: value => {
          if (value) {
            return true;
          }
          else {
            return false;
          }
        },
      }
    };
    this.submitted = true;
  }
  async onSubmit(e) {
    e.preventDefault();
    this.submitted = true;
    let isFormValid = true;
    //Run all validation functions
    for (let controlName in this.formControls) {
      let control = this.formControls[controlName];
      control.validate(control.value);
      if (!control.isValid) {
        isFormValid = false;
      }
    }
    if (isFormValid) {
      let result = await student_service.StudentService.getInstance().submitFeedback({
        Note: this.formControls.note.value,
        Type: this.formControls.type.value
      });
      console.log(result);
      if (result.Succeeded) {
        const toast = await overlays.toastController.create({
          message: "Feedback submitted successfully",
          duration: 3000
        });
        toast.present();
        this.dismiss();
      }
      else {
        const toast = await overlays.toastController.create({
          message: result.Message,
          duration: 3000
        });
        toast.present();
      }
    }
  }
  dismiss(data) {
    // dismiss the closest modal and optionally pass back data
    this.el.closest('ion-modal').dismiss({
      'dismissed': true
    });
  }
  changeFormValue(controlName, value) {
    this.formControls = Object.assign(Object.assign({}, this.formControls), { [controlName]: Object.assign(Object.assign({}, this.formControls[controlName]), { value: value, isValid: this.formControls[controlName].validate(value) }) });
  }
  render() {
    return (index.h(index.Host, null, index.h("ion-header", { translucent: true }, index.h("ion-toolbar", null, index.h("ion-title", null, "Feedback"), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { onClick: () => this.dismiss() }, "Close")))), index.h("ion-content", { class: "ion-padding" }, index.h("form", { onSubmit: (e) => this.onSubmit(e), novalidate: true }, index.h("ion-list", null, index.h("ion-radio-group", { value: this.formControls.type.value, onChange: (e) => this.changeFormValue("type", +e.target.value) }, index.h("ion-list-header", null, index.h("ion-label", null, "Feedback Type")), index.h("ion-item", null, index.h("ion-label", null, "Comments"), index.h("ion-radio", { value: 1 })), index.h("ion-item", null, index.h("ion-label", null, "Suggestions"), index.h("ion-radio", { value: 2 })), index.h("ion-item", null, index.h("ion-label", null, "Questions"), index.h("ion-radio", { value: 3 }))), index.h("ion-item", null, index.h("ion-label", { position: "floating" }, "Notes"), index.h("ion-textarea", { value: this.formControls.note.value, onChange: (e) => this.changeFormValue("note", e.target.value) })), index.h("br", null), index.h("ion-button", { color: "primary", type: "submit" }, "Submit"))))));
  }
  get el() { return index.getElement(this); }
};
SparkleFeedback.style = sparkleFeedbackCss;

exports.sparkle_feedback = SparkleFeedback;
