import { Component, Event, h, Listen, Prop, State, } from "@stencil/core";
import { toastController } from "@ionic/core";
export class AppUser {
  constructor() {
    this.user = {};
    this.jobs = [];
  }
  async onSuccess(event) {
    var _a, _b, _c, _d, _e, _f;
    if (event.detail.endpoint === "addUser") {
      const routerEl = document.querySelector("ion-router");
      if (!routerEl || !((_c = (_b = (_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.addUser) === null || _c === void 0 ? void 0 : _c.id))
        return;
      routerEl.push(`/users/${event.detail.data.addUser.id}`);
    }
    else if (event.detail.endpoint === "editUser") {
      this.presentToast();
    }
    else if (((_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.endpoint) === "findUser") {
      this.user = (_f = (_e = event === null || event === void 0 ? void 0 : event.detail) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.user;
    }
  }
  async presentToast() {
    const toast = await toastController.create({
      message: "The user has been updated.",
      duration: 2000,
    });
    toast.present();
  }
  render() {
    return [
      h("ion-content", { scrollEvents: true, class: "ion-padding" },
        h("floodteam-title-bar", { pin: {
            icon: "person",
            href: `/users/${this.userId}`,
            name: this.user.firstName || "User",
          } },
          h("ion-router-link", { href: "/users" }, "Users")),
        h("ion-grid", null,
          h("ion-row", null,
            h("ion-col", null,
              h("ion-card", { class: "ion-padding" },
                h("floodteam-form-user", { userId: this.userId, showPhoto: true }))),
            h("ion-col", null,
              h("fireenjin-pagination", { ref: (el) => (this.paginationEl = el), disableVirtualScroll: true, listEl: ({ result: job }) => (h("floodteam-item-job", { job: job })), endpoint: "listJobs", limit: 4, fetchParams: {
                  withPayables: true,
                }, fetchData: { userId: this.userId }, resultsKey: "jobs", query: this.query, removeDuplicates: true }))))),
      h("floodteam-navigation-footer", null),
    ];
  }
  static get is() { return "app-user"; }
  static get originalStyleUrls() { return {
    "$": ["app-user.css"]
  }; }
  static get styleUrls() { return {
    "$": ["app-user.css"]
  }; }
  static get properties() { return {
    "userId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "user-id",
      "reflect": false
    }
  }; }
  static get states() { return {
    "user": {},
    "query": {},
    "paginationEl": {},
    "jobs": {}
  }; }
  static get events() { return [{
      "method": "floodteamOpenModal",
      "name": "floodteamOpenModal",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "floodteamCloseModal",
      "name": "floodteamCloseModal",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "fireenjinFetch",
      "name": "fireenjinFetch",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "FireEnjinFetchEvent",
        "resolved": "FireEnjinFetchEvent",
        "references": {
          "FireEnjinFetchEvent": {
            "location": "import",
            "path": "@fireenjin/sdk"
          }
        }
      }
    }]; }
  static get listeners() { return [{
      "name": "fireenjinSuccess",
      "method": "onSuccess",
      "target": "body",
      "capture": false,
      "passive": false
    }]; }
}
