'use strict';

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

const index = require('./index-ee190ee0.js');
const hardwareBackButton = require('./overlays-6a64deff.js');
const store = require('./store-5a3b44dc.js');
require('./ionic-global-542e0609.js');
require('./helpers-905b0d22.js');
require('./index-4901314f.js');
require('./getHandlebarsHelpers-8ef28401.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-ba857994.js');
require('./localforage-af1b8c0e.js');

const appEquipmentCss = "";

const AppEquipment = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.toolId = undefined;
    this.tool = undefined;
  }
  async onSuccess(event) {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "findEquipment") {
      this.tool = ((_c = (_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.equipment) || null;
    }
    else if (((_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.endpoint) === "editEquipment") {
      (await hardwareBackButton.toastController.create({
        message: "equipment saved successfully!",
        duration: 3000,
      })).present();
    }
    else if (((_e = event === null || event === void 0 ? void 0 : event.detail) === null || _e === void 0 ? void 0 : _e.endpoint) === "addEquipment" &&
      this.toolId === "new") {
      const routerEl = document.querySelector("ion-router");
      this.toolId = ((_h = (_g = (_f = event === null || event === void 0 ? void 0 : event.detail) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.addEquipment) === null || _h === void 0 ? void 0 : _h.id) || "new";
      if (routerEl)
        routerEl.push(`/equipment/${this.toolId}`);
    }
  }
  async fetchEquipment() {
    this.fireenjinFetch.emit({
      endpoint: "findEquipment",
      params: {
        id: this.toolId,
      },
    });
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.fetchEquipment();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/equipment" }, "Equipment")), index.h("ion-card", { style: {
          overflow: "visible",
        } }, index.h("ion-card-header", null, ((_a = this.tool) === null || _a === void 0 ? void 0 : _a.id) ? "Edit" : "Add", " ", ((_b = this.tool) === null || _b === void 0 ? void 0 : _b.name) || "Equipment"), index.h("fireenjin-form", { resetButton: "Clear", resetButtonColor: "medium", ref: (el) => (this.formEl = el), endpoint: this.toolId === "new" ? "addEquipment" : "editEquipment", documentId: this.toolId === "new" ? null : this.toolId }, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", { size: "10" }, index.h("fireenjin-input", { "data-fill": true, labelPosition: "stacked", type: "text", name: "name", label: "Name", value: (_c = this.tool) === null || _c === void 0 ? void 0 : _c.name, required: true })), index.h("ion-col", { "size-md": "6", size: "10" }, index.h("fireenjin-select", { "data-fill": true, labelPosition: "stacked", name: "type", options: [
          {
            label: "Equipment",
            value: "equipment",
          },
          {
            label: "Restockable",
            value: "restockable",
          },
          {
            label: "Vehicle",
            value: "vehicle",
          },
        ], label: "Type", value: (_d = this.tool) === null || _d === void 0 ? void 0 : _d.type, required: true })), index.h("ion-col", { "size-md": "6", size: "10" }, index.h("fireenjin-select", { "data-fill": true, labelPosition: "stacked", name: "group", options: [
          {
            label: "Matterport",
            value: "matterport",
          },
          {
            label: "Dehumidifier",
            value: "dehumidifier",
          },
          {
            label: "Fan",
            value: "fan",
          },
          {
            label: "Moisture Meter",
            value: "moistureMeter",
          },
          {
            label: "Vacuum",
            value: "vacuum",
          },
        ], label: "Group", value: (_e = this.tool) === null || _e === void 0 ? void 0 : _e.group, required: true })), index.h("ion-col", { size: "10" }, index.h("fireenjin-select-tags", { name: "tags", label: "Tags", labelPosition: "stacked", value: (_f = this.tool) === null || _f === void 0 ? void 0 : _f.tags, allowAdding: true, options: [
          {
            label: "Important",
            value: "important",
          },
        ] }))))))),
      index.h("floodteam-navigation-footer", null, index.h("floodteam-title-bar", { back: "/equipment" }, index.h("ion-breadcrumbs", null, index.h("ion-breadcrumb", { href: "/equipment" }, index.h("ion-icon", { class: "ft-icon-style", slot: "start", name: "hammer" }), "Equipment"), index.h("ion-breadcrumb", { onClick: () => {
          var _a;
          return this.fireenjinTrigger.emit({
            name: "pin",
            payload: {
              icon: "flash",
              href: `/equipment/${this.toolId}`,
              name: ((_a = this.tool) === null || _a === void 0 ? void 0 : _a.name) || "Add Equipment",
            },
          });
        } }, index.h("ion-icon", { color: ((_g = ((store.state === null || store.state === void 0 ? void 0 : store.state.pins) || [])
          .map((pin) => pin === null || pin === void 0 ? void 0 : pin.href)) === null || _g === void 0 ? void 0 : _g.includes(`/equipment/${this.toolId}`))
          ? "primary"
          : null, slot: "start", name: "pin" }), (this.toolId === "new" && "Add Equipment") ||
        ((_h = this.tool) === null || _h === void 0 ? void 0 : _h.name) ||
        "Edit Equipment")))),
    ];
  }
};
AppEquipment.style = appEquipmentCss;

exports.app_equipment = AppEquipment;
