'use strict';

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

const index = require('./index-ee190ee0.js');
const formatUSD = require('./formatUSD-65108a08.js');
const store = require('./store-27073b3b.js');
const getServiceTypes = require('./getServiceTypes-7a4ee228.js');
const hardwareBackButton = require('./overlays-6a64deff.js');
require('./index-4901314f.js');
require('./getHandlebarsHelpers-8ef28401.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-ba857994.js');
require('./localforage-af1b8c0e.js');
require('./ionic-global-542e0609.js');
require('./helpers-905b0d22.js');

const appServiceListCss = "";

const AppServiceList = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.floodteamCloseModal = index.createEvent(this, "floodteamCloseModal", 7);
    this.fetchData = undefined;
    this.paginationEl = undefined;
    this.query = undefined;
    this.selectedIds = [];
    this.selectedServices = [];
    this.services = [];
    this.filter = {
      tab: null,
    };
  }
  onSearchInput(event) {
    this.query = event.target.value;
  }
  onTrigger(event) {
    var _a, _b, _c, _d, _e;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.name) !== "set")
      return;
    // Start Here replace key and value
    const key = (_c = (_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.payload) === null || _c === void 0 ? void 0 : _c.name;
    const value = (_e = (_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.value;
    this.fetchData = { ...this.fetchData, [key]: value };
    // this.refreshFetchData();
  }
  onCodeChange(event) {
    var _a, _b;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.name) === "bulkEdit")
      return;
    for (const id of this.selectedIds) {
      this.fireenjinSubmit.emit({
        name: "bulkEdit",
        endpoint: "editService",
        params: {
          id,
          data: ((_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.data) || {},
        },
      });
    }
    this.floodteamCloseModal.emit();
  }
  async toggleService(event) {
    var _a, _b;
    event.preventDefault();
    event.stopPropagation();
    const selectedIds = this.selectedIds;
    console.log(event);
    if (this.selectedIds.includes((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value)) {
      selectedIds.splice(this.selectedIds.indexOf(event.target.value), 1);
    }
    else {
      selectedIds.push((_b = event === null || event === void 0 ? void 0 : event.target) === null || _b === void 0 ? void 0 : _b.value);
    }
    this.selectedIds = selectedIds;
    console.log(this.selectedIds);
  }
  async openCodeEditor(name, value) {
    const modalEl = await hardwareBackButton.modalController.create({
      component: "fireenjin-mx-modal-code-editor",
      cssClass: "fireenjin-mx-modal-code-editor-wrapper",
      componentProps: {
        pageTitle: name === "autofill" ? "Set Auto-Fill" : "Set Smart Scoping",
        name,
        language: "json",
        value,
        endpoint: "",
        documentId: true,
      },
    });
    await modalEl.present();
    return modalEl;
  }
  render() {
    var _a, _b, _c;
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/services" }, "Services"), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { fill: "solid", color: "primary", href: "/services/new" }, "Add"))), index.h("fireenjin-search-bar", { paginationEl: this.paginationEl, filters: ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.claims) === null || _a === void 0 ? void 0 : _a.tester) || ((_b = store.state === null || store.state === void 0 ? void 0 : store.state.claims) === null || _b === void 0 ? void 0 : _b.admin)
          ? [
            {
              name: "tabs",
              label: "Tab",
              icon: "albums",
              multiple: true,
              options: getServiceTypes.getServiceTypes(),
              value: (_c = this.filter) === null || _c === void 0 ? void 0 : _c.tab,
            },
          ]
          : null }), index.h("ion-card", { class: "list-card" }, index.h("ion-list", { class: "ion-no-padding" }, index.h("fireenjin-pagination", { ref: (el) => this.paginationEl = el, name: "services", approxItemHeight: 84, endpoint: "listServices", pageKey: "name", orderBy: "name", orderDirection: "asc", fetchData: this.fetchData, resultsKey: "services", limit: 50, query: this.query, renderItem: (service) => (index.h("ion-item", { href: `/services/${service.id}`, detail: true }, index.h("ion-checkbox", { id: `toggle.${(service === null || service === void 0 ? void 0 : service.id) || ""}`, slot: "start", onClick: (event) => this.toggleService(event), value: service === null || service === void 0 ? void 0 : service.id, checked: this.selectedIds.includes(service === null || service === void 0 ? void 0 : service.id) }), index.h("ion-label", null, index.h("h2", null, (service === null || service === void 0 ? void 0 : service.name) || "", " "), index.h("div", null, Object.entries((service === null || service === void 0 ? void 0 : service.prices) || {}).map(([name, amount]) => (index.h("ion-chip", null, index.h("ion-label", null, name || "", ":", " ", index.h("ion-text", { color: "success", slot: "end" }, formatUSD.formatUSD(amount || 0)))))))))) })))),
      index.h("floodteam-navigation-footer", null, index.h("fireenjin-chip-bar", null, index.h("ion-chip", { onClick: () => this.fireenjinTrigger.emit({
          name: "import",
          type: "services",
        }) }, index.h("ion-icon", { class: "ft-icon-style", name: "cloud-upload" }), index.h("ion-label", null, "Import from CSV")), index.h("ion-chip", { onClick: () => this.fireenjinTrigger.emit({
          name: "export",
          collection: "services",
        }) }, index.h("ion-icon", { name: "cloud-download", class: "ft-icon-style" }), index.h("ion-label", null, "Export to CSV")), index.h("ion-chip", { onClick: () => this.openCodeEditor("autofill", null) }, index.h("ion-icon", { class: "ft-icon-style", name: "code" }), index.h("ion-label", null, "Set Auto-Fill")), index.h("ion-chip", { onClick: () => this.openCodeEditor("smartScoping", null) }, index.h("ion-icon", { class: "ft-icon-style", name: "code" }), index.h("ion-label", null, "Set Smart Scoping")))),
    ];
  }
};
AppServiceList.style = appServiceListCss;

exports.app_service_list = AppServiceList;
