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 './runStore-08a7baa7.js';
import { a as authStore } from './authStore-62b9ecb0.js';
import { s as src } from './index-313b8a90.js';
import { b as userEditMutationGQL } from './Mutations-823a697d.js';
import { u as userByIdGQL } from './Queries-fb64dd39.js';

const AdminUserForm = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.error = false;
    this.user = null;
    this.userRoles = [
      { key: "admin", value: "admin" },
      { key: "user", value: "user" },
    ];
  }
  async formEventHandler({ detail }) {
    console.log("sendForm", detail);
    const input = {};
    Object.keys(detail).map((key) => {
      input[key] = detail[key].value;
    });
    await coreState.client.mutate({
      mutation: src(userEditMutationGQL),
      variables: {
        id: this.formId,
        userInput: input,
      },
    });
  }
  async queryData() {
    const request = await coreState.client.query({
      query: src(userByIdGQL),
      variables: {
        id: this.formId,
      },
    });
    if (request.data.userById) {
      this.user = request.data.userById;
      //Map over the roles and see if we match any we need to select
      this.userRoles.map((role) => {
        this.user.role.map((userRole) => {
          if (role.key === userRole)
            role["selected"] = true;
        });
      });
    }
  }
  async componentWillRender() {
    if (authStore.identity)
      await this.queryData();
  }
  render() {
    return (h(Host, null, authStore.identity ? (h("corejam-box", { p: 8, rounded: "md", bWidth: 1, bColor: "gray-200", max: "md", mx: "auto", px: 4, lgPx: 0, flex: true, justify: "between", mb: 24 }, h("corejam-box", { w: "5", mx: "auto" }, h("corejam-box", { pb: 4, mb: 8, bWidthBottom: 1, bColor: "gray-400" }, h("corejam-type", { as: "h2", size: "xl" }, "User Edit")), h("corejam-form-container", { name: "userForm" }, h("corejam-box", null, h("corejam-box", null, h("corejam-form-input", { name: "email", type: "text", formId: "userForm", value: this.user.email, label: "Email" })), h("corejam-box", null, h("corejam-form-input", { name: "active", type: "checkbox", formId: "userForm", label: "Active", checked: this.user.active })), h("corejam-box", null, h("corejam-form-select", { name: "roles", options: this.userRoles, multiple: true, formId: "userForm" })), h("corejam-box", null, h("corejam-form-input", { name: "password", type: "password", formId: "userForm", label: "Password" })), h("corejam-box", null, h("corejam-form-submit", { formId: "userForm" }, h("button", { type: "submit" }, "Edit")))))))) : null));
  }
};

export { AdminUserForm as auth_admin_user_form };
