'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');
require('./Mutations-7f7eb38b.js');
const Queries = require('./Queries-c8cfdb6c.js');

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

const CorejamPagination = class {
  constructor(hostRef) {
    index.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(index.h("corejam-box", { px: 4, bWidthRight: 1, bColor: "gray-200" }, index.h("corejam-base-link", { href: `${i}`, decoration: "none" }, index.h("corejam-type", Object.assign({}, props), i.toString()))));
    }
    return elements;
  }
  render() {
    return (index.h(index.Host, null, index.h("corejam-box", { flex: true, w: "12", mt: 8, justify: "between", bWidthTop: 1, bColor: "gray-300", pt: 4 }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24" }, index.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" })), index.h("corejam-box", { flex: true, direction: "row" }, this.renderPaginate()), index.h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24" }, index.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"]
  }; }
};

exports.auth_admin_user_list = AuthAdminUserList;
exports.corejam_pagination = CorejamPagination;
