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

const appMaterial = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.materialId = undefined;
    this.material = {};
  }
  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) === "findMaterial") {
      this.material = ((_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.material) || null;
    }
    else if (((_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.endpoint) === "editMaterial") {
      (await hardwareBackButton.toastController.create({
        message: "Material 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) === "addMaterial" &&
      this.materialId === "new") {
      const routerEl = document.querySelector("ion-router");
      this.materialId = ((_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.addMaterial) === null || _h === void 0 ? void 0 : _h.id) || "new";
      if (routerEl)
        routerEl.push(`/materials/${this.materialId}`);
    }
  }
  async fetchMaterial() {
    this.fireenjinFetch.emit({
      endpoint: "findMaterial",
      params: {
        id: this.materialId,
      },
    });
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.fetchMaterial();
  }
  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: "/materials" }, "Materials")), index.h("ion-card", { style: {
          overflow: "visible",
        } }, index.h("fireenjin-form", { resetButton: "Clear", resetButtonColor: "medium", ref: (el) => (this.formEl = el), endpoint: this.materialId === "new" ? "addMaterial" : "editMaterial", documentId: this.materialId === "new" ? null : this.materialId }, 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: (_a = this.material) === null || _a === void 0 ? void 0 : _a.name, required: true }))))))),
      index.h("floodteam-navigation-footer", null, index.h("floodteam-title-bar", { back: "/materials" }, index.h("ion-breadcrumbs", null, index.h("ion-breadcrumb", { href: "/materials" }, index.h("ion-icon", { class: "ft-icon-style", slot: "start", name: "construct" }), "Materials"), index.h("ion-breadcrumb", { onClick: () => {
          var _a;
          return this.fireenjinTrigger.emit({
            name: "pin",
            payload: {
              icon: "flash",
              href: `/materials/${this.materialId}`,
              name: ((_a = this.material) === null || _a === void 0 ? void 0 : _a.name) || "Add a Material",
            },
          });
        } }, index.h("ion-icon", { color: ((_b = ((store.state === null || store.state === void 0 ? void 0 : store.state.pins) || [])
          .map((pin) => pin === null || pin === void 0 ? void 0 : pin.href)) === null || _b === void 0 ? void 0 : _b.includes(`/materials/${this.materialId}`))
          ? "primary"
          : null, slot: "start", name: "pin" }), ((_c = this.material) === null || _c === void 0 ? void 0 : _c.name) || "Edit Material")))),
      ,
    ];
  }
};
appMaterial.style = appMaterialCss;

exports.app_material = appMaterial;
