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

exports.auth_form_login = LoginForm;
