'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-3e5ae956.js');
const fuse_esm = require('./fuse.esm-847a739f.js');
const store = require('./store-6277c8f4.js');
require('./index-b020f7d8.js');

const pageHomeCss = "";

const PageHome = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  async search(event) {
    var _a, _b;
    const query = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value;
    if (!((_b = store.state === null || store.state === void 0 ? void 0 : store.state.templates) === null || _b === void 0 ? void 0 : _b.length) || !(query === null || query === void 0 ? void 0 : query.length)) {
      this.searchResults = null;
      return;
    }
    const fuse = new fuse_esm.Fuse((store.state === null || store.state === void 0 ? void 0 : store.state.templates) || [], {
      keys: ["subject", "description"],
      fieldNormWeight: 1,
      sortFn: (a, b) => {
        var _a, _b, _c, _d;
        return ((_a = a === null || a === void 0 ? void 0 : a.item) === null || _a === void 0 ? void 0 : _a.type) > ((_b = b === null || b === void 0 ? void 0 : b.item) === null || _b === void 0 ? void 0 : _b.type)
          ? 1
          : ((_c = b === null || b === void 0 ? void 0 : b.item) === null || _c === void 0 ? void 0 : _c.type) > ((_d = a === null || a === void 0 ? void 0 : a.item) === null || _d === void 0 ? void 0 : _d.type)
            ? -1
            : 0;
      },
    });
    this.searchResults = await fuse.search(query).map((result) => result === null || result === void 0 ? void 0 : result.item);
  }
  async cancel() {
    this.searchResults = null;
  }
  render() {
    const templates = this.searchResults || (store.state === null || store.state === void 0 ? void 0 : store.state.templates) || [];
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", { size: "8" }, index.h("ion-searchbar", null)), index.h("ion-col", { size: "4" }, index.h("ion-button", { expand: "block", class: "ion-float-right", href: "/templates/new" }, "Add Template")))), index.h("ion-card", null, index.h("ion-list", { class: "ion-no-padding" }, templates.map((template, index$1) => {
        var _a;
        return [
          ((_a = templates === null || templates === void 0 ? void 0 : templates[index$1 - 1]) === null || _a === void 0 ? void 0 : _a.type) !== (template === null || template === void 0 ? void 0 : template.type) && (index.h("ion-item-divider", { color: "primary" }, template.type)),
          index.h("ion-item", { href: `/templates/${template === null || template === void 0 ? void 0 : template.id}`, detail: true }, index.h("ion-label", null, index.h("h2", null, (template === null || template === void 0 ? void 0 : template.subject) || ""), index.h("p", null, (template === null || template === void 0 ? void 0 : template.description) || "No Description on File..."))),
        ];
      })))),
      index.h("app-footer", null),
    ];
  }
};
PageHome.style = pageHomeCss;

exports.fireenjin_mx_page_home = PageHome;
