import { r as registerInstance, d as createEvent, B as Build, h } from './index-33e43734.js';
import { s as state } from './store-163687da.js';
import { g as getParameter } from './getParameter-40990fd9.js';
import { t as toastController } from './overlays-97615cf7.js';
import './index-91eb4513.js';
import './getCache-721d3aa5.js';
import './ionic-global-bd76bde2.js';
import './helpers-a9270f9e.js';

const appProfileCss = "";

let AppProfile = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.floodteamLogout = createEvent(this, "floodteamLogout", 7);
    this.floodteamShare = createEvent(this, "floodteamShare", 7);
    this.forceUpdate = createEvent(this, "forceUpdate", 7);
    this.fireenjinSubmit = createEvent(this, "fireenjinSubmit", 7);
    this.user = state.profile;
  }
  onRouteChange(event) {
    const code = getParameter("code");
    if (event.detail.to === "/stripe/success" && code) {
      setTimeout(async () => {
        var _a;
        if (!((_a = state === null || state === void 0 ? void 0 : state.session) === null || _a === void 0 ? void 0 : _a.uid))
          return;
        try {
          await this.fireenjinSubmit.emit({
            endpoint: "createStripeOAuthToken",
            data: {
              id: state.session.uid,
              code,
            },
          });
        }
        catch (err) {
          console.log("Error connecting to Stripe Account!", err);
          document.querySelector("ion-router").push("/profile");
        }
      }, 2000);
    }
  }
  onReset(event) {
    var _a;
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "profile" &&
      confirm("Are you sure you want to logout?")) {
      this.floodteamLogout.emit();
    }
  }
  async onSuccess(event) {
    if (event.detail.name === "invite") {
      this.to = null;
      (await toastController.create({
        message: `Successfully sent invite(s).`,
        duration: 3000,
      })).present();
    }
  }
  onBeforeSubmit(formData) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j;
    return {
      templateId: "93t0jXODOEc6D1kJGOD5",
      from: "info@thefloodteam.com",
      emails: ((_b = (_a = formData === null || formData === void 0 ? void 0 : formData.to) === null || _a === void 0 ? void 0 : _a.split) === null || _b === void 0 ? void 0 : _b.call(_a)) || [],
      data: {
        firstName: "Partner",
        referrer: {
          id: (_c = state === null || state === void 0 ? void 0 : state.session) === null || _c === void 0 ? void 0 : _c.uid,
          name: `${((_d = state === null || state === void 0 ? void 0 : state.profile) === null || _d === void 0 ? void 0 : _d.firstName) || ""} ${((_e = state === null || state === void 0 ? void 0 : state.profile) === null || _e === void 0 ? void 0 : _e.lastName) || ""}`,
          title: ((_f = state === null || state === void 0 ? void 0 : state.profile) === null || _f === void 0 ? void 0 : _f.type) || "Mitigation Specialist",
          phone: (_g = state === null || state === void 0 ? void 0 : state.profile) === null || _g === void 0 ? void 0 : _g.phone,
          location: (_j = (_h = state === null || state === void 0 ? void 0 : state.profile) === null || _h === void 0 ? void 0 : _h.location) === null || _j === void 0 ? void 0 : _j.name,
        },
      },
    };
  }
  componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
    return [
      h("ion-content", { class: "ion-padding" }, h("floodteam-title-bar", { icon: "person" }, h("ion-text", null, "Personal Info")), h("ion-card", null, h("ion-card-content", { class: "ion-padding" }, h("fireenjin-input-photo", { color: "secondary", name: "profilePhoto", type: "user", documentId: (_a = state === null || state === void 0 ? void 0 : state.profile) === null || _a === void 0 ? void 0 : _a.id, initials: `${((_b = state === null || state === void 0 ? void 0 : state.profile) === null || _b === void 0 ? void 0 : _b.firstName)
          ? (_c = state === null || state === void 0 ? void 0 : state.profile) === null || _c === void 0 ? void 0 : _c.firstName.charAt(0)
          : ""}${((_d = state === null || state === void 0 ? void 0 : state.profile) === null || _d === void 0 ? void 0 : _d.lastName)
          ? (_e = state === null || state === void 0 ? void 0 : state.profile) === null || _e === void 0 ? void 0 : _e.lastName.charAt(0)
          : ""}`, value: (_f = state === null || state === void 0 ? void 0 : state.profile) === null || _f === void 0 ? void 0 : _f.photo }), h("fireenjin-form", { name: "profile", endpoint: "editUser", documentId: (_g = state === null || state === void 0 ? void 0 : state.session) === null || _g === void 0 ? void 0 : _g.uid, resetButton: "Logout", filterData: [
          "firstName",
          "lastName",
          "address",
          "phone",
          "billingAddress",
          "photo",
          "email",
          "slackHandle",
        ] }, h("ion-list", null, h("fireenjin-input", { name: "firstName", label: "First Name", labelPosition: "stacked", placeholder: "What is your first name?", value: (_h = state.profile) === null || _h === void 0 ? void 0 : _h.firstName }), h("fireenjin-input", { name: "lastName", label: "Last Name", labelPosition: "stacked", placeholder: "What is your last name?", value: (_j = state.profile) === null || _j === void 0 ? void 0 : _j.lastName }), h("fireenjin-input", { name: "email", label: "Email Address", labelPosition: "stacked", placeholder: "What is your primary email address?", value: (_k = state.profile) === null || _k === void 0 ? void 0 : _k.email }), h("fireenjin-input", { name: "phone", type: "phone", label: "Phone Number", labelPosition: "stacked", placeholder: "What is your primary phone number?", value: (_l = state.profile) === null || _l === void 0 ? void 0 : _l.phone }), h("fireenjin-input-address", { name: "address", labelPosition: "stacked", label: "Address", placeholder: "What is your home address?", googleMapsKey: (_o = (_m = state === null || state === void 0 ? void 0 : state.config) === null || _m === void 0 ? void 0 : _m.firebase) === null || _o === void 0 ? void 0 : _o.apiKey, value: (_p = state.profile) === null || _p === void 0 ? void 0 : _p.address }), h("fireenjin-input-address", { name: "billingAddress", labelPosition: "stacked", label: "Billing Address", placeholder: "What is your billing address?", googleMapsKey: (_r = (_q = state === null || state === void 0 ? void 0 : state.config) === null || _q === void 0 ? void 0 : _q.firebase) === null || _r === void 0 ? void 0 : _r.apiKey, value: (_s = state.profile) === null || _s === void 0 ? void 0 : _s.billingAddress }))))), h("floodteam-title-bar", { icon: "logo-usd" }, h("ion-text", null, "Payment Info")), ((_t = state === null || state === void 0 ? void 0 : state.profile) === null || _t === void 0 ? void 0 : _t.isSetup) ? (h("floodteam-payment-methods", { stripeKey: ((_u = state.profile) === null || _u === void 0 ? void 0 : _u.isFranchise)
          ? (_x = (_w = (_v = state.config) === null || _v === void 0 ? void 0 : _v.franchise) === null || _w === void 0 ? void 0 : _w.stripe) === null || _x === void 0 ? void 0 : _x.key
          : (_z = (_y = state.config) === null || _y === void 0 ? void 0 : _y.stripe) === null || _z === void 0 ? void 0 : _z.key, userId: (_0 = state.profile) === null || _0 === void 0 ? void 0 : _0.id })) : (h("ion-card", null, h("ion-grid", null, h("ion-row", null, h("ion-col", { style: { maxWidth: "200px", padding: "15px" } }, h("ion-icon", { src: "/assets/svg/ft-icon.svg", style: {
          width: "100%",
          display: "block",
          height: "100%",
          minHeight: "100px",
          fill: "var(--ion-text-color)",
        } })), h("ion-col", { class: "ion-padding-horizontal" }, h("h2", { style: { color: "var(--ion-text-color)", marginTop: "8px" } }, "Your account is almost ready!"), h("p", { style: { padding: "10px 0" } }, "Please use the \"Setup Payments\" button below in order to finish setting up your account."), h("ion-button", { class: "ion-float-right", href: "#", "data-trigger": "setupPayments" }, "Setup Payments", h("ion-icon", { slot: "end", name: "logo-usd" }))))))), h("floodteam-title-bar", { icon: "share" }, h("ion-text", null, "My Referral Link")), h("ion-card", null, h("ion-card-content", { class: "ion-padding" }, h("p", null, "Use one of the buttons below to invite users to The Flood Team App. Once a user logs in and finishes their onboarding they will be tied to you in the system."), h("br", null), h("fireenjin-form", { hideControls: true, name: "invite", endpoint: "sendTemplateEmail", disableEnterButton: true, beforeSubmit: this.onBeforeSubmit.bind(this) }, h("ion-grid", null, h("ion-row", null, h("ion-col", null, h("fireenjin-input", { name: "to", placeholder: "Comma separated list of emails", value: this.to }))), h("ion-row", null, h("ion-col", null, h("ion-button", { size: "default", expand: "block", fill: "clear", onClick: () => {
          var _a;
          return this.floodteamShare.emit({
            data: {
              url: `${state.config.url}?referredBy=${(_a = state.profile) === null || _a === void 0 ? void 0 : _a.id}`,
              text: "Hey, check out this new water remediation app from The Flood Team.",
              title: "Flood Team App",
            },
          });
        } }, "Share Link", h("ion-icon", { name: "share-social", slot: "start" }))), h("ion-col", null, h("ion-button", { size: "default", expand: "block", type: "submit" }, "Send", h("ion-icon", { name: "send", slot: "end" })))))))), h("ion-grid", null, h("ion-row", null, h("ion-col", { size: "7" }, h("ion-button", { fill: "clear", onClick: () => this.forceUpdate.emit({}) }, h("ion-label", null, h("h4", null, "v", ((_1 = state === null || state === void 0 ? void 0 : state.manifest) === null || _1 === void 0 ? void 0 : _1.version) || "Unknown"), h("small", null, "Check for Updates")))), h("ion-col", { size: "5" }, h("ion-button", { class: "theme-button", fill: "clear", onClick: () => (state.darkMode = !(state === null || state === void 0 ? void 0 : state.darkMode)) }, h("ion-label", null, "Theme"), h("ion-icon", { slot: "end", name: (state === null || state === void 0 ? void 0 : state.darkMode) ? "moon" : "sunny" }), h("ion-icon", { slot: "end", name: !(state === null || state === void 0 ? void 0 : state.darkMode) ? "moon" : "sunny" })))))),
      h("floodteam-navigation-footer", null),
    ];
  }
};
AppProfile.style = appProfileCss;

export { AppProfile as app_profile };

//# sourceMappingURL=app-profile.entry.js.map