'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-fd2bbf0b.js');
const hardwareBackButton = require('./overlays-de05dc6a.js');
const store = require('./store-f2110833.js');
require('./ionic-global-1340f737.js');
require('./helpers-c2496722.js');
require('./index-81aa1bcb.js');
require('./getCache-c039a6ae.js');

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

const appUserCss = "app-user ion-card,app-user ion-card ion-list{overflow:visible !important;contain:none !important}";

let AppUser = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.floodteamOpenModal = index.createEvent(this, "floodteamOpenModal", 7);
    this.floodteamCloseModal = index.createEvent(this, "floodteamCloseModal", 7);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.user = {};
    this.jobs = [];
  }
  async onSuccess(event) {
    var _a, _b, _c;
    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();
    }
  }
  async presentToast() {
    const toast = await hardwareBackButton.toastController.create({
      message: "The user has been updated.",
      duration: 2000,
    });
    toast.present();
  }
  async componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    if (this.userId) {
      await this.fireenjinFetch.emit({
        endpoint: "findUser",
        params: {
          id: this.userId,
          withFriends: true,
          withRoles: false,
        },
      });
      // this.floodteamOpenModal.emit({
      //   component: "modal-note",
      //   componentProps: {}
      // });
      // setTimeout(() => this.floodteamCloseModal.emit(), 5000);
    }
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
    return [
      index.h("ion-content", { scrollEvents: true, class: "ion-padding" }, index.h("floodteam-title-bar", { pin: {
          icon: "person",
          href: `/users/${this.userId}`,
          name: this.user.firstName || "User",
        } }, index.h("ion-router-link", { href: "/users" }, "Users")), index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", null, index.h("ion-card", { class: "ion-padding" }, index.h("fireenjin-form", { endpoint: this.userId === "new" ? "addUser" : "editUser", documentId: this.userId === "new" ? null : this.userId, resetButton: null }, index.h("ion-list", null, index.h("fireenjin-input-photo", { name: "photo", value: ((_a = this.user) === null || _a === void 0 ? void 0 : _a.photo)
          ? this.user.photo
          : "/assets/svg/ft-person-suit.svg" }), index.h("ion-grid", null, ((_b = store.state === null || store.state === void 0 ? void 0 : store.state.claims) === null || _b === void 0 ? void 0 : _b.admin) && (index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-select", { label: "Team Role", name: "role", options: (_c = store.state === null || store.state === void 0 ? void 0 : store.state.roles) === null || _c === void 0 ? void 0 : _c.map((role) => ({
          label: capitalizeFirstLetter(role),
          value: role,
        })), value: (_d = this.user) === null || _d === void 0 ? void 0 : _d.role })))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "firstName", label: "First Name", labelPosition: "stacked", value: (_e = this.user) === null || _e === void 0 ? void 0 : _e.firstName })), index.h("ion-col", null, index.h("fireenjin-input", { name: "lastName", labelPosition: "stacked", label: "Last Name", value: (_f = this.user) === null || _f === void 0 ? void 0 : _f.lastName }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "email", labelPosition: "stacked", label: "Email Address", value: (_g = this.user) === null || _g === void 0 ? void 0 : _g.email }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "phone", label: "Phone Number", labelPosition: "stacked", value: (_h = this.user) === null || _h === void 0 ? void 0 : _h.phone }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "slackHandle", label: "Slack Handle", labelPosition: "stacked", value: (_j = this.user) === null || _j === void 0 ? void 0 : _j.slackHandle }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input-address", { name: "address", label: "Address", labelPosition: "stacked", value: (_k = this.user) === null || _k === void 0 ? void 0 : _k.address, googleMapsKey: (_m = (_l = store.state === null || store.state === void 0 ? void 0 : store.state.config) === null || _l === void 0 ? void 0 : _l.firebase) === null || _m === void 0 ? void 0 : _m.apiKey }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input-address", { name: "billingAddress", label: "Billing Address", labelPosition: "stacked", value: (_o = this.user) === null || _o === void 0 ? void 0 : _o.billingAddress, googleMapsKey: (_q = (_p = store.state === null || store.state === void 0 ? void 0 : store.state.config) === null || _p === void 0 ? void 0 : _p.firebase) === null || _q === void 0 ? void 0 : _q.apiKey }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-select", { label: "Location", name: "locationId", options: ((store.state === null || store.state === void 0 ? void 0 : store.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: (_s = (_r = this.user) === null || _r === void 0 ? void 0 : _r.location) === null || _s === void 0 ? void 0 : _s.id }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-select", { name: "companyId", label: "Company", labelPosition: "stacked", value: (_u = (_t = this.user) === null || _t === void 0 ? void 0 : _t.company) === null || _u === void 0 ? void 0 : _u.id, endpoint: "listCompanies", limit: 100, resultsKey: "companies" }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-select-tags", { name: "tags", labelPosition: "stacked", label: "Tags", value: ((_v = this.user) === null || _v === void 0 ? void 0 : _v.tags) ? this.user.tags : [], multiple: true, allowAdding: true, options: [
          {
            label: "Important",
            value: "important",
          },
          {
            label: "Referral",
            value: "referral",
          },
          {
            label: "Plumber",
            value: "plumber",
          },
          {
            label: "Staff",
            value: "staff",
          },
          {
            label: "Agent",
            value: "agent",
          },
          {
            label: "Property Manager",
            value: "property manager",
          },
          {
            label: "PEU",
            value: "peu",
          },
        ] }))))), index.h("ion-button", { fill: "clear", class: "ion-float-left", href: `/users/${this.userId}/jobs` }, "View Jobs")))), index.h("ion-col", null, index.h("fireenjin-pagination", { ref: (el) => (this.paginationEl = el), disableVirtualScroll: true, listEl: ({ result: job }) => (index.h("floodteam-item-job", { job: job })), endpoint: "listJobs", limit: 4, fetchParams: {
          withPayables: true,
        }, fetchData: { userId: this.userId }, resultsKey: "jobs", query: this.query, removeDuplicates: true }))))),
      index.h("floodteam-navigation-footer", null),
    ];
  }
};
AppUser.style = appUserCss;

exports.app_user = AppUser;

//# sourceMappingURL=app-user.cjs.entry.js.map