import { r as registerInstance, e as createEvent, B as Build, h } from './index-e0adbd54.js';
import { t as toastController } from './overlays-b83a89c7.js';
import { s as state } from './store-4342e5d4.js';
import './ionic-global-3272af31.js';
import './helpers-06537f39.js';
import './index-96e8c812.js';
import './getHandlebarsHelpers-c1e27d99.js';
import './_commonjsHelpers-44457d8d.js';
import './index-e6b3332e.js';
import './localforage-394b59fa.js';

const appInventoryCss = "";

const AppInventoryItem = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fireenjinFetch = createEvent(this, "fireenjinFetch", 7);
    this.fireenjinTrigger = 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 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 (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    this.fetchInventory();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
    return [
      h("ion-content", { class: "ion-padding" }, h("floodteam-title-bar", null, h("ion-router-link", { href: "/inventory" }, "Inventory")), h("ion-card", { style: {
          overflow: "visible",
        } }, 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"), 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 }, h("ion-grid", null, h("ion-row", null, h("ion-col", { size: "10" }, 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 })), h("ion-col", { "size-md": "6", size: "10" }, h("fireenjin-select", { label: "FloodTeam Location", labelPosition: "stacked", name: "locationId", options: ((state === null || state === void 0 ? void 0 : 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 })), h("ion-col", { "size-md": "6", size: "10" }, 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 })), h("ion-col", { "size-md": "4", size: "10" }, 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 })), h("ion-col", { "size-md": "4", size: "10" }, 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 })), h("ion-col", { "size-md": "4", size: "10" }, 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 })), h("ion-col", { size: "10" }, 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",
          },
        ] }))))))),
      h("floodteam-navigation-footer", null, h("floodteam-title-bar", { back: "/inventory" }, h("ion-breadcrumbs", null, h("ion-breadcrumb", { href: "/inventory" }, h("ion-icon", { class: "ft-icon-style", slot: "start", name: "barcode-outline" }), "Inventory"), 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",
            },
          });
        } }, h("ion-icon", { color: ((_m = ((state === null || state === void 0 ? void 0 : 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;

export { AppInventoryItem as app_inventory };
