'use strict';

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

const index = require('./index-fd2bbf0b.js');
const fuse_esm = require('./fuse.esm-580ef9a3.js');
const store = require('./store-f2110833.js');
require('./index-81aa1bcb.js');
require('./getCache-c039a6ae.js');

const appTemplateListCss = "";

let AppTemplateList = 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.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.templates, {
      keys: ["subject", "description"],
    });
    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.templates || [];
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/templates" }, "Templates"), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { fill: "solid", color: "primary", href: "/templates/new" }, "Add"))), index.h("fireenjin-search-bar", { ref: (el) => (this.filterBarEl = el), paginationEl: this.paginationEl, filters: [
          {
            name: "tags",
            label: "Tags",
            icon: "pricetags",
            multiple: true,
            options: [
              {
                label: "Imported",
                value: "imported",
              },
            ],
          },
        ] }), index.h("ion-card", null, index.h("ion-list", { class: "ion-no-padding" }, templates
        .sort(function (a, b) {
        var _a, _b, _c, _d;
        var subjectA = ((_b = (_a = a === null || a === void 0 ? void 0 : a.subject) === null || _a === void 0 ? void 0 : _a.toUpperCase) === null || _b === void 0 ? void 0 : _b.call(_a)) || "";
        var subjectB = ((_d = (_c = b === null || b === void 0 ? void 0 : b.subject) === null || _c === void 0 ? void 0 : _c.toUpperCase) === null || _d === void 0 ? void 0 : _d.call(_c)) || "";
        if (subjectA < subjectB) {
          return -1;
        }
        if (subjectA > subjectB) {
          return 1;
        }
        // names must be equal
        return 0;
      })
        .sort(function (a, b) {
        var _a, _b, _c, _d;
        var typeA = ((_b = (_a = a === null || a === void 0 ? void 0 : a.type) === null || _a === void 0 ? void 0 : _a.toUpperCase) === null || _b === void 0 ? void 0 : _b.call(_a)) || "";
        var typeB = ((_d = (_c = b === null || b === void 0 ? void 0 : b.type) === null || _c === void 0 ? void 0 : _c.toUpperCase) === null || _d === void 0 ? void 0 : _d.call(_c)) || "";
        if (typeA < typeB) {
          return -1;
        }
        if (typeA > typeB) {
          return 1;
        }
        // names must be equal
        return 0;
      })
        .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", null, 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("floodteam-navigation-footer", null),
    ];
  }
};
AppTemplateList.style = appTemplateListCss;

exports.app_template_list = AppTemplateList;

//# sourceMappingURL=app-template-list.cjs.entry.js.map