import { toastController } from "@ionic/core";
import { Build, h, } from "@stencil/core";
import state from "../../../store";
export class AppEquipment {
  constructor() {
    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 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 (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    this.fetchEquipment();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    return [
      h("ion-content", { class: "ion-padding" }, h("floodteam-title-bar", null, h("ion-router-link", { href: "/equipment" }, "Equipment")), h("ion-card", { style: {
          overflow: "visible",
        } }, 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"), 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 }, 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.tool) === null || _c === void 0 ? void 0 : _c.name, required: true })), h("ion-col", { "size-md": "6", size: "10" }, 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 })), h("ion-col", { "size-md": "6", size: "10" }, 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 })), h("ion-col", { size: "10" }, 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",
          },
        ] }))))))),
      h("floodteam-navigation-footer", null, h("floodteam-title-bar", { back: "/equipment" }, h("ion-breadcrumbs", null, h("ion-breadcrumb", { href: "/equipment" }, h("ion-icon", { class: "ft-icon-style", slot: "start", name: "hammer" }), "Equipment"), 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",
            },
          });
        } }, h("ion-icon", { color: ((_g = ((state === null || state === void 0 ? void 0 : 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")))),
    ];
  }
  static get is() { return "app-equipment"; }
  static get originalStyleUrls() {
    return {
      "$": ["app-equipment.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["app-equipment.css"]
    };
  }
  static get properties() {
    return {
      "toolId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "tool-id",
        "reflect": false
      }
    };
  }
  static get states() {
    return {
      "tool": {}
    };
  }
  static get events() {
    return [{
        "method": "fireenjinFetch",
        "name": "fireenjinFetch",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }, {
        "method": "fireenjinTrigger",
        "name": "fireenjinTrigger",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "FireEnjinTriggerInput",
          "resolved": "FireEnjinTriggerInput<any>",
          "references": {
            "FireEnjinTriggerInput": {
              "location": "import",
              "path": "@fireenjin/sdk"
            }
          }
        }
      }];
  }
  static get listeners() {
    return [{
        "name": "fireenjinSuccess",
        "method": "onSuccess",
        "target": "document",
        "capture": false,
        "passive": false
      }];
  }
}
