import { r as registerInstance, h, H as Host, e as getElement } from './index-c04b9ed5.js';
import { S as StudentService } from './student.service-0746418b.js';
import { t as toastController } from './overlays-3b4dca92.js';
import './httpService-7b75b095.js';
import './auth.store-dba2c2da.js';
import './environment-config.service-2b5d692b.js';
import './ionic-global-4903e23e.js';
import './hardware-back-button-fa04d6e9.js';
import './helpers-bf0e23d6.js';

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

const SparkleFeedback = class {
  constructor(hostRef) {
    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 StudentService.getInstance().submitFeedback({
        Note: this.formControls.note.value,
        Type: this.formControls.type.value
      });
      console.log(result);
      if (result.Succeeded) {
        const toast = await toastController.create({
          message: "Feedback submitted successfully",
          duration: 3000
        });
        toast.present();
        this.dismiss();
      }
      else {
        const toast = await 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 (h(Host, null, h("ion-header", { translucent: true }, h("ion-toolbar", null, h("ion-title", null, "Feedback"), h("ion-buttons", { slot: "end" }, h("ion-button", { onClick: () => this.dismiss() }, "Close")))), h("ion-content", { class: "ion-padding" }, h("form", { onSubmit: (e) => this.onSubmit(e), novalidate: true }, h("ion-list", null, h("ion-radio-group", { value: this.formControls.type.value, onChange: (e) => this.changeFormValue("type", +e.target.value) }, h("ion-list-header", null, h("ion-label", null, "Feedback Type")), h("ion-item", null, h("ion-label", null, "Comments"), h("ion-radio", { value: 1 })), h("ion-item", null, h("ion-label", null, "Suggestions"), h("ion-radio", { value: 2 })), h("ion-item", null, h("ion-label", null, "Questions"), h("ion-radio", { value: 3 }))), h("ion-item", null, h("ion-label", { position: "floating" }, "Notes"), h("ion-textarea", { value: this.formControls.note.value, onChange: (e) => this.changeFormValue("note", e.target.value) })), h("br", null), h("ion-button", { color: "primary", type: "submit" }, "Submit"))))));
  }
  get el() { return getElement(this); }
};
SparkleFeedback.style = sparkleFeedbackCss;

export { SparkleFeedback as sparkle_feedback };
