import { Component, h, Listen, Prop, State, } from "@stencil/core";
export class AppImport {
  constructor() {
    this.results = [];
  }
  onSuccess(event) {
    var _a, _b, _c, _d;
    console.log(event);
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) !== "importer")
      return;
    this.results = ((_d = (_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.importer) === null || _d === void 0 ? void 0 : _d.results) || [];
  }
  onChange(event) {
    var _a, _b;
    console.log(event);
    const targetEl = event === null || event === void 0 ? void 0 : event.target;
    if ((targetEl === null || targetEl === void 0 ? void 0 : targetEl.tagName) === "ION-SEARCHBAR") {
      this.query = ((_b = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.length) > 0 ? event.target.value : null;
    }
  }
  render() {
    return [
      h("ion-content", { class: "ion-padding" },
        h("floodteam-title-bar", null,
          h("ion-router-link", { href: "/imports" }, "Import")),
        h("fireenjin-form", { endpoint: "importer", beforeSubmit: (data) => ({
            ...data,
            limit: parseInt(data === null || data === void 0 ? void 0 : data.limit) > 0 ? parseInt(data.limit) : null,
          }) },
          h("ion-card", null,
            h("ion-card-header", null,
              h("ion-grid", null,
                h("ion-row", null,
                  h("ion-col", null,
                    h("ion-item", null,
                      h("ion-label", { position: "stacked" }, "Import"),
                      h("ion-select", { name: "type" },
                        h("ion-select-option", { value: "ftms-users" }, "FTMS Users"),
                        h("ion-select-option", { value: "ftms-jobs" }, "FTMS Jobs")))),
                  h("ion-col", null,
                    h("fireenjin-input", { label: "Limit", labelPosition: "stacked", name: "limit", type: "number", step: "1", min: "0" }))))),
            h("ion-card-content", null,
              h("ion-searchbar", { color: "light", placeholder: "Search Results" }),
              h("div", { class: "table-responsive" },
                h("table", { class: "table" },
                  h("tbody", null, (this.results || []).map((result, index) => [
                    index === 0 && (h("tr", { style: {
                        color: "var(--ion-text-color)",
                        borderBottom: "1px solid var(--ion-color-light-shade)",
                      } }, Object.keys(result).map((columnName) => (h("td", null, columnName))))),
                    h("tr", null, Object.values(result).map((value) => {
                      return (h("td", null, ["string", "number"].includes(typeof value) ? (value) : (value === null || value === void 0 ? void 0 : value._path) ? (value._path.segments.join("/")) : (h("code", null, JSON.stringify(value, null, 4)))));
                    })),
                  ])))))))),
      h("floodteam-navigation-footer", null),
    ];
  }
  static get is() { return "app-import"; }
  static get originalStyleUrls() { return {
    "$": ["app-import.css"]
  }; }
  static get styleUrls() { return {
    "$": ["app-import.css"]
  }; }
  static get properties() { return {
    "importId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "import-id",
      "reflect": false
    }
  }; }
  static get states() { return {
    "results": {},
    "query": {}
  }; }
  static get listeners() { return [{
      "name": "fireenjinSuccess",
      "method": "onSuccess",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "ionChange",
      "method": "onChange",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
//# sourceMappingURL=app-import.js.map