import { r as registerInstance, h, H as Host } from './index-90c9237f.js';
import { c as coreState } from './core-942cabc2.js';
import './_commonjsHelpers-66ac50f5.js';
import { s as src } from './index-2108167f.js';
import './index-7e3ea926.js';
import { r as runState } from './runStore-901a7c5d.js';
import { a as authStore } from './authStore-2419a66f.js';
import { c as userAuthenticateMutationGQL } from './Mutations-823a697d.js';

const LoginForm = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.formId = "login";
  }
  componentWillLoad() {
    if (authStore.identity)
      runState.router.push("/");
  }
  async formEventHandler({ detail }) {
    if (detail.formId != this.formId)
      return;
    const request = await coreState.client.mutate({
      mutation: src(userAuthenticateMutationGQL),
      variables: {
        email: detail.email.value,
        password: detail.password.value,
      },
    });
    if (request.data.userAuthenticate) {
      authStore.identity = request.data.userAuthenticate;
      this.onSuccess ? this.onSuccess() : runState.router.push("/");
    }
    else {
      this.onFail ? this.onFail() : null;
    }
  }
  render() {
    return (h(Host, null, h("corejam-box", { p: 8, max: "md", mx: "auto", px: 4, lgPx: 0, flex: true, direction: "col", justify: "between", mb: 24 }, h("corejam-flash", null), h("corejam-box", { w: 5, mx: "auto" }, h("corejam-form-container", { name: this.formId }, h("corejam-box", null, h("corejam-form-input", { name: "email", type: "text", 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", { flex: true, direction: "col" }, h("corejam-box", null, h("corejam-form-submit", { formId: this.formId }, h("button", { type: "submit" }, "Login"))), h("corejam-box", null, h("corejam-base-link", { href: "/login/reset" }, "Reset Password")))))))));
  }
};

export { LoginForm as auth_form_login };
