import { r as registerInstance, h } from './index-33e43734.js';
import { F as Fuse } from './fuse.esm-7454d4cc.js';
import { s as state } from './store-163687da.js';
import './index-91eb4513.js';
import './getCache-721d3aa5.js';

const appTemplateListCss = "";

let AppTemplateList = class {
  constructor(hostRef) {
    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 = 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(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 || state.templates || [];
    return [
      h("ion-content", { class: "ion-padding" }, h("floodteam-title-bar", null, h("ion-router-link", { href: "/templates" }, "Templates"), h("ion-buttons", { slot: "end" }, h("ion-button", { fill: "solid", color: "primary", href: "/templates/new" }, "Add"))), 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",
              },
            ],
          },
        ] }), h("ion-card", null, 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) => {
        var _a;
        return [
          ((_a = templates === null || templates === void 0 ? void 0 : templates[index - 1]) === null || _a === void 0 ? void 0 : _a.type) !== (template === null || template === void 0 ? void 0 : template.type) && (h("ion-item-divider", null, template.type)),
          h("ion-item", { href: `/templates/${template === null || template === void 0 ? void 0 : template.id}`, detail: true }, h("ion-label", null, h("h2", null, (template === null || template === void 0 ? void 0 : template.subject) || ""), h("p", null, (template === null || template === void 0 ? void 0 : template.description) || "No Description on File..."))),
        ];
      })))),
      h("floodteam-navigation-footer", null),
    ];
  }
};
AppTemplateList.style = appTemplateListCss;

export { AppTemplateList as app_template_list };

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