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 './Mutations-823a697d.js';
import { p as paginateUsersGQL } from './Queries-fb64dd39.js';

const AuthAdminUserList = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.activePage = 1;
    this.tableHeader = ["Email", "Role", "Status", "Date Created"];
  }
  rerenderForPage() {
    this.queryData();
  }
  async queryData() {
    const request = await coreState.client.query({
      query: src(paginateUsersGQL),
      variables: {
        page: this.page,
        size: 15,
      },
    });
    this._data = request.data.paginateUsers;
  }
  async componentWillRender() {
    if (authStore.identity)
      await this.queryData();
  }
  render() {
    if (!authStore.identity)
      return h("corejam-box", { mx: "auto" }, "Not authorized");
    return (h(Host, null, h("corejam-box", { max: "xl", flex: true, direction: "col", mx: "auto" }, h("corejam-box", null, h("corejam-type", { as: "h2", size: "xl" }, "Users")), h("corejam-box", { flex: true, direction: "col" }, h("corejam-box", { px: 5, bColor: "gray-300", bWidth: 1, flex: true, pt: 3, pb: 3 }, this.tableHeader.map((header, i) => (h("corejam-box", { w: "3", key: i }, header)))), this._data.items.map((user, i) => {
      let bg = "";
      if (i % 2 == 0) {
        bg = "lightBlue-900";
      }
      return (h("corejam-box", { px: 5, bg: bg, bStyle: "solid", bColor: "gray-300", bWidth: 1, flex: true, pt: 3, pb: 3 }, h("corejam-box", { w: "3" }, h("corejam-base-link", { "data-cy": "user-link", href: `/admin/users/edit/${user.id}` }, h("corejam-type", null, user.email))), h("corejam-box", { w: "3" }, user.role), h("corejam-box", { w: "3" }, user.active), h("corejam-box", { w: "3" }, user.dateCreated)));
    })), h("corejam-box", { px: 5, bColor: "gray-300", bWidth: 1, flex: true, justify: "between", pt: 3, pb: 3 }, "Showing ", this._data.items.length, " of ", this._data.totalItems, " entries", h("corejam-pagination", { paginator: this._data })))));
  }
  static get watchers() { return {
    "page": ["rerenderForPage"]
  }; }
};

const CorejamPagination = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this._paginator = { currentPage: 1, lastPage: 5, items: [] };
  }
  watchPaginator() {
    this.setState();
  }
  setState() {
    if (this.paginator)
      this._paginator = typeof this.paginator === "string" ? JSON.parse(this.paginator) : this.paginator;
  }
  componentWillLoad() {
    this.setState();
  }
  renderPaginate() {
    const elements = [];
    for (let i = 1; i <= this._paginator.lastPage; i++) {
      const props = {
        color: "gray-400",
      };
      if (i === this._paginator.currentPage) {
        props["color"] = "gray-900";
      }
      elements.push(h("corejam-box", { px: 4, bWidthRight: 1, bColor: "gray-200" }, h("corejam-base-link", { href: `${i}`, decoration: "none" }, h("corejam-type", Object.assign({}, props), i.toString()))));
    }
    return elements;
  }
  render() {
    return (h(Host, null, h("corejam-box", { flex: true, w: "12", mt: 8, justify: "between", bWidthTop: 1, bColor: "gray-300", pt: 4 }, h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24" }, h("path", { class: "heroicon-ui", d: "M5.41 11H21a1 1 0 0 1 0 2H5.41l5.3 5.3a1 1 0 0 1-1.42 1.4l-7-7a1 1 0 0 1 0-1.4l7-7a1 1 0 0 1 1.42 1.4L5.4 11z" })), h("corejam-box", { flex: true, direction: "row" }, this.renderPaginate()), h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24" }, h("path", { class: "heroicon-ui", d: "M18.59 13H3a1 1 0 0 1 0-2h15.59l-5.3-5.3a1 1 0 1 1 1.42-1.4l7 7a1 1 0 0 1 0 1.4l-7 7a1 1 0 0 1-1.42-1.4l5.3-5.3z" })))));
  }
  static get watchers() { return {
    "paginator": ["watchPaginator"]
  }; }
};

export { AuthAdminUserList as auth_admin_user_list, CorejamPagination as corejam_pagination };
