import { r as registerInstance, d as createEvent, B as Build, h, H as Host } from './index-000d2977.js';
import { s as state } from './store-f6a9eb30.js';
import './getHandlebarsHelpers-91de4454.js';
import './_commonjsHelpers-4ed75ef8.js';
import './logic-88140d62.js';
import './index-d4e79b88.js';
import './localforage-9daa31d6.js';

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

const FormUser = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fireenjinFetch = createEvent(this, "fireenjinFetch", 7);
    this.showPhoto = false;
    this.hideControls = false;
  }
  onSuccess(event) {
    var _a, _b, _c;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) !== "findUser")
      return;
    this.user = (_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.user;
  }
  componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser) || !this.userId)
      return;
    this.fireenjinFetch.emit({
      endpoint: "findUser",
      params: {
        id: this.userId,
        withFriends: true,
        withRoles: false,
      },
    });
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
    return (h(Host, null, h("fireenjin-form", { hideControls: this.hideControls, endpoint: this.userId === "new" ? "addUser" : "editUser", documentId: this.userId === "new" ? null : this.userId, resetButton: null }, h("ion-list", null, this.showPhoto && (h("fireenjin-input-photo", { name: "photo", documentId: this.userId, value: ((_a = this.user) === null || _a === void 0 ? void 0 : _a.photo) || "/assets/svg/ft-person-suit.svg" })), h("ion-grid", null, ((_b = state === null || state === void 0 ? void 0 : state.claims) === null || _b === void 0 ? void 0 : _b.admin) && (h("ion-row", null, h("ion-col", null, h("fireenjin-select", { label: "Team Role", name: "role", options: ((state === null || state === void 0 ? void 0 : state.roles) || []).map((role) => ({
        label: capitalizeFirstLetter(role),
        value: role,
      })), value: (_c = this.user) === null || _c === void 0 ? void 0 : _c.role })))), h("ion-row", null, h("ion-col", null, h("fireenjin-input", { name: "firstName", label: "First Name", labelPosition: "stacked", value: (_d = this.user) === null || _d === void 0 ? void 0 : _d.firstName })), h("ion-col", null, h("fireenjin-input", { name: "lastName", labelPosition: "stacked", label: "Last Name", value: (_e = this.user) === null || _e === void 0 ? void 0 : _e.lastName }))), h("ion-row", null, h("ion-col", null, h("fireenjin-input", { name: "email", labelPosition: "stacked", label: "Email Address", value: (_f = this.user) === null || _f === void 0 ? void 0 : _f.email }))), h("ion-row", null, h("ion-col", null, h("fireenjin-input", { name: "phone", label: "Phone Number", labelPosition: "stacked", value: (_g = this.user) === null || _g === void 0 ? void 0 : _g.phone }))), h("ion-row", null, h("ion-col", null, h("fireenjin-input", { name: "slackHandle", label: "Slack Handle", labelPosition: "stacked", value: (_h = this.user) === null || _h === void 0 ? void 0 : _h.slackHandle }))), h("ion-row", null, h("ion-col", null, h("fireenjin-input-address", { name: "address", label: "Address", labelPosition: "stacked", value: (_j = this.user) === null || _j === void 0 ? void 0 : _j.address, googleMapsKey: (_l = (_k = state === null || state === void 0 ? void 0 : state.config) === null || _k === void 0 ? void 0 : _k.firebase) === null || _l === void 0 ? void 0 : _l.apiKey }))), h("ion-row", null, h("ion-col", null, h("fireenjin-input-address", { name: "billingAddress", label: "Billing Address", labelPosition: "stacked", value: (_m = this.user) === null || _m === void 0 ? void 0 : _m.billingAddress, googleMapsKey: (_p = (_o = state === null || state === void 0 ? void 0 : state.config) === null || _o === void 0 ? void 0 : _o.firebase) === null || _p === void 0 ? void 0 : _p.apiKey }))), h("ion-row", null, h("ion-col", null, h("fireenjin-select", { label: "Location", name: "locationId", options: ((state === null || state === void 0 ? void 0 : 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: (_r = (_q = this.user) === null || _q === void 0 ? void 0 : _q.location) === null || _r === void 0 ? void 0 : _r.id }))), h("ion-row", null, h("ion-col", null, h("fireenjin-select", { name: "companyId", label: "Company", labelPosition: "stacked", value: (_t = (_s = this.user) === null || _s === void 0 ? void 0 : _s.company) === null || _t === void 0 ? void 0 : _t.id, endpoint: "listCompanies", limit: 100, resultsKey: "companies" }))), h("ion-row", null, h("ion-col", null, h("fireenjin-select-tags", { name: "tags", labelPosition: "stacked", label: "Tags", value: ((_u = this.user) === null || _u === void 0 ? void 0 : _u.tags) || [], 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",
        },
      ] }))))))));
  }
};

export { FormUser as floodteam_form_user };
