'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');
require('./runStore-bfd81991.js');
const authStore = require('./authStore-cabcfab4.js');
const index$1 = require('./index-66ca60fa.js');
const Mutations = require('./Mutations-7f7eb38b.js');
const Queries = require('./Queries-c8cfdb6c.js');

const AdminUserForm = class {
  constructor(hostRef) {
    index.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 core.coreState.client.mutate({
      mutation: index$1.src(Mutations.userEditMutationGQL),
      variables: {
        id: this.formId,
        userInput: input,
      },
    });
  }
  async queryData() {
    const request = await core.coreState.client.query({
      query: index$1.src(Queries.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.authStore.identity)
      await this.queryData();
  }
  render() {
    return (index.h(index.Host, null, authStore.authStore.identity ? (index.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 }, index.h("corejam-box", { w: "5", mx: "auto" }, index.h("corejam-box", { pb: 4, mb: 8, bWidthBottom: 1, bColor: "gray-400" }, index.h("corejam-type", { as: "h2", size: "xl" }, "User Edit")), index.h("corejam-form-container", { name: "userForm" }, index.h("corejam-box", null, index.h("corejam-box", null, index.h("corejam-form-input", { name: "email", type: "text", formId: "userForm", value: this.user.email, label: "Email" })), index.h("corejam-box", null, index.h("corejam-form-input", { name: "active", type: "checkbox", formId: "userForm", label: "Active", checked: this.user.active })), index.h("corejam-box", null, index.h("corejam-form-select", { name: "roles", options: this.userRoles, multiple: true, formId: "userForm" })), index.h("corejam-box", null, index.h("corejam-form-input", { name: "password", type: "password", formId: "userForm", label: "Password" })), index.h("corejam-box", null, index.h("corejam-form-submit", { formId: "userForm" }, index.h("button", { type: "submit" }, "Edit")))))))) : null));
  }
};

exports.auth_admin_user_form = AdminUserForm;
