'use strict';

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

const index = require('./index-22fd9091.js');
const core = require('./core-787915c4.js');
require('./_commonjsHelpers-5cfcba41.js');
require('./index-a20d8492.js');
const runStore = require('./runStore-bfd81991.js');
const authStore = require('./authStore-cabcfab4.js');
const index$1 = require('./index-66ca60fa.js');
const Mutations = require('./Mutations-7f7eb38b.js');

const RegisterForm = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.formId = "register";
  }
  async formEventHandler({ detail }) {
    if (detail.formId != this.formId)
      return;
    const request = await core.coreState.client.mutate({
      mutation: index$1.src(Mutations.userRegisterMutationGQL),
      variables: {
        data: {
          email: detail.email.value,
          password: detail.password.value,
          passwordConfirm: detail.passwordConfirm.value,
        },
      },
    });
    if (request.data.userRegister) {
      this.onSuccess ? this.onSuccess() : runStore.runState.router.push("/login");
    }
    else {
      this.onFail ? this.onFail() : null;
    }
  }
  componentWillLoad() {
    if (authStore.authStore.identity)
      runStore.runState.router.push("/");
  }
  render() {
    return (index.h(index.Host, null, index.h("corejam-box", { p: 8, max: "md", mx: "auto", px: 4, lgPx: 0, flex: true, justify: "between", mb: 24 }, index.h("corejam-box", { w: "5", mx: "auto" }, index.h("corejam-form-container", { name: this.formId }, index.h("corejam-box", null, index.h("corejam-form-input", { required: true, name: "email", type: "email", formId: this.formId, label: "Email" }), index.h("corejam-box", null, index.h("corejam-form-input", { name: "password", type: "password", formId: this.formId, label: "Password" })), index.h("corejam-box", null, index.h("corejam-form-input", { name: "passwordConfirm", type: "password", formId: this.formId, label: "Confirm Password" })), index.h("corejam-box", null, index.h("corejam-form-input", { type: "checkbox", formId: this.formId, label: "I agree to the terms & conditions" })), index.h("corejam-box", null, index.h("corejam-form-submit", { formId: this.formId }, index.h("button", { type: "submit" }, "Register")))))))));
  }
};

exports.auth_form_register = RegisterForm;
