import { r as registerInstance, h, H as Host } from './index-8dc1a0b7.js';
import { c as coreState } from './core-6e4b87fa.js';
import './_commonjsHelpers-66ac50f5.js';
import './index-2f7827f5.js';
import { r as runState } from './runStore-08a7baa7.js';
import { a as authStore } from './authStore-62b9ecb0.js';
import { s as src } from './index-313b8a90.js';
import { d as userRegisterMutationGQL } from './Mutations-823a697d.js';

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

export { RegisterForm as auth_form_register };
