'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 appInventoryCss = "";

const AppInventoryItem = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.itemId = undefined;
    this.item = 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) === "findInventory") {
      this.item = ((_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.inventory) || null;
    }
    else if (((_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.endpoint) === "editInventory") {
      (await hardwareBackButton.toastController.create({
        message: "Item 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) === "addInventory" &&
      this.itemId === "new") {
      const routerEl = document.querySelector("ion-router");
      this.itemId = ((_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.addInventory) === null || _h === void 0 ? void 0 : _h.id) || "new";
      if (routerEl)
        routerEl.push(`/inventory/${this.itemId}`);
    }
  }
  async fetchInventory() {
    this.fireenjinFetch.emit({
      endpoint: "findInventory",
      params: {
        id: this.itemId,
      },
    });
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.fetchInventory();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/inventory" }, "Inventory")), index.h("ion-card", { style: {
          overflow: "visible",
        } }, index.h("ion-card-header", null, ((_a = this.item) === null || _a === void 0 ? void 0 : _a.id) ? "Edit" : "Add", " ", ((_b = this.item) === null || _b === void 0 ? void 0 : _b.name) || "Item"), index.h("fireenjin-form", { resetButton: "Clear", resetButtonColor: "medium", ref: (el) => (this.formEl = el), endpoint: this.itemId === "new" ? "addInventory" : "editInventory", documentId: this.itemId === "new" ? null : this.itemId }, 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.item) === null || _c === void 0 ? void 0 : _c.name, required: true })), index.h("ion-col", { "size-md": "6", size: "10" }, index.h("fireenjin-select", { label: "FloodTeam Location", labelPosition: "stacked", name: "locationId", options: ((store.state === null || store.state === void 0 ? void 0 : store.state.locations) || []).map((location) => ({
          label: (location === null || location === void 0 ? void 0 : location.name) || "No Location Name",
          value: location === null || location === void 0 ? void 0 : location.id,
        })), value: (_e = (_d = this.item) === null || _d === void 0 ? void 0 : _d.location) === null || _e === void 0 ? void 0 : _e.id })), index.h("ion-col", { "size-md": "6", size: "10" }, index.h("fireenjin-select", { "data-fill": true, labelPosition: "stacked", name: "equipment", options: [{ label: "equipmentsss", value: null }], label: "Equipment", value: (_g = (_f = this.item) === null || _f === void 0 ? void 0 : _f.equipment) === null || _g === void 0 ? void 0 : _g.id, required: true })), index.h("ion-col", { "size-md": "4", size: "10" }, index.h("fireenjin-input", { "data-fill": true, labelPosition: "stacked", type: "text", name: "code", label: "Code", value: (_h = this.item) === null || _h === void 0 ? void 0 : _h.code, required: true })), index.h("ion-col", { "size-md": "4", size: "10" }, index.h("fireenjin-input", { "data-fill": true, labelPosition: "stacked", type: "number", name: "inStock", label: "In Stock", value: ((_j = this.item) === null || _j === void 0 ? void 0 : _j.inStock) || 0, required: true })), index.h("ion-col", { "size-md": "4", size: "10" }, index.h("fireenjin-input", { "data-fill": true, labelPosition: "stacked", type: "number", name: "retockBelow", label: "Restock Below", value: ((_k = this.item) === null || _k === void 0 ? void 0 : _k.restockBelow) || 0, required: true })), index.h("ion-col", { size: "10" }, index.h("fireenjin-select-tags", { name: "tags", label: "Tags", labelPosition: "stacked", value: (_l = this.item) === null || _l === void 0 ? void 0 : _l.tags, allowAdding: true, options: [
          {
            label: "Important",
            value: "important",
          },
        ] }))))))),
      index.h("floodteam-navigation-footer", null, index.h("floodteam-title-bar", { back: "/inventory" }, index.h("ion-breadcrumbs", null, index.h("ion-breadcrumb", { href: "/inventory" }, index.h("ion-icon", { class: "ft-icon-style", slot: "start", name: "barcode-outline" }), "Inventory"), index.h("ion-breadcrumb", { onClick: () => {
          var _a;
          return this.fireenjinTrigger.emit({
            name: "pin",
            payload: {
              icon: "flash",
              href: `/inventory/${this.itemId}`,
              name: ((_a = this.item) === null || _a === void 0 ? void 0 : _a.name) || "Add an Item",
            },
          });
        } }, index.h("ion-icon", { color: ((_m = ((store.state === null || store.state === void 0 ? void 0 : store.state.pins) || [])
          .map((pin) => pin === null || pin === void 0 ? void 0 : pin.href)) === null || _m === void 0 ? void 0 : _m.includes(`/inventory/${this.itemId}`))
          ? "primary"
          : null, slot: "start", name: "pin" }), (this.itemId === "new" && "Add an Item") ||
        ((_o = this.item) === null || _o === void 0 ? void 0 : _o.name) ||
        "Edit Item")))),
    ];
  }
};
AppInventoryItem.style = appInventoryCss;

exports.app_inventory = AppInventoryItem;
