'use strict';

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

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

const appProfileCss = "";

let AppProfile = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.floodteamLogout = index.createEvent(this, "floodteamLogout", 7);
    this.floodteamShare = index.createEvent(this, "floodteamShare", 7);
    this.forceUpdate = index.createEvent(this, "forceUpdate", 7);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.user = store.state.profile;
  }
  onRouteChange(event) {
    const code = getParameter.getParameter("code");
    if (event.detail.to === "/stripe/success" && code) {
      setTimeout(async () => {
        var _a;
        if (!((_a = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _a === void 0 ? void 0 : _a.uid))
          return;
        try {
          await this.fireenjinSubmit.emit({
            endpoint: "createStripeOAuthToken",
            data: {
              id: store.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 hardwareBackButton.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 = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _c === void 0 ? void 0 : _c.uid,
          name: `${((_d = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _d === void 0 ? void 0 : _d.firstName) || ""} ${((_e = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _e === void 0 ? void 0 : _e.lastName) || ""}`,
          title: ((_f = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _f === void 0 ? void 0 : _f.type) || "Mitigation Specialist",
          phone: (_g = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _g === void 0 ? void 0 : _g.phone,
          location: (_j = (_h = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _h === void 0 ? void 0 : _h.location) === null || _j === void 0 ? void 0 : _j.name,
        },
      },
    };
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.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;
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", { icon: "person" }, index.h("ion-text", null, "Personal Info")), index.h("ion-card", null, index.h("ion-card-content", { class: "ion-padding" }, index.h("fireenjin-input-photo", { name: "profilePhoto", value: ((_a = store.state.profile) === null || _a === void 0 ? void 0 : _a.photo)
          ? store.state.profile.photo
          : "/assets/svg/ft-person-suit.svg" }), index.h("fireenjin-form", { name: "profile", endpoint: "editUser", documentId: (_b = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _b === void 0 ? void 0 : _b.uid, resetButton: "Logout", filterData: [
          "firstName",
          "lastName",
          "address",
          "phone",
          "billingAddress",
          "photo",
          "email",
          "slackHandle",
        ] }, index.h("ion-list", null, index.h("fireenjin-input", { name: "firstName", label: "First Name", labelPosition: "stacked", placeholder: "What is your first name?", value: (_c = store.state.profile) === null || _c === void 0 ? void 0 : _c.firstName }), index.h("fireenjin-input", { name: "lastName", label: "Last Name", labelPosition: "stacked", placeholder: "What is your last name?", value: (_d = store.state.profile) === null || _d === void 0 ? void 0 : _d.lastName }), index.h("fireenjin-input", { name: "email", label: "Email Address", labelPosition: "stacked", placeholder: "What is your primary email address?", value: (_e = store.state.profile) === null || _e === void 0 ? void 0 : _e.email }), index.h("fireenjin-input", { name: "phone", label: "Phone Number", labelPosition: "stacked", placeholder: "What is your primary phone number?", value: (_f = store.state.profile) === null || _f === void 0 ? void 0 : _f.phone }), index.h("fireenjin-input-address", { name: "address", labelPosition: "stacked", label: "Address", placeholder: "What is your home address?", googleMapsKey: (_h = (_g = store.state === null || store.state === void 0 ? void 0 : store.state.config) === null || _g === void 0 ? void 0 : _g.firebase) === null || _h === void 0 ? void 0 : _h.apiKey, value: (_j = store.state.profile) === null || _j === void 0 ? void 0 : _j.address }), index.h("fireenjin-input-address", { name: "billingAddress", labelPosition: "stacked", label: "Billing Address", placeholder: "What is your billing address?", googleMapsKey: (_l = (_k = store.state === null || store.state === void 0 ? void 0 : store.state.config) === null || _k === void 0 ? void 0 : _k.firebase) === null || _l === void 0 ? void 0 : _l.apiKey, value: (_m = store.state.profile) === null || _m === void 0 ? void 0 : _m.billingAddress }))))), index.h("floodteam-title-bar", { icon: "logo-usd" }, index.h("ion-text", null, "Payment Info")), ((_o = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _o === void 0 ? void 0 : _o.isSetup) ? (index.h("floodteam-payment-methods", { stripeKey: ((_p = store.state.profile) === null || _p === void 0 ? void 0 : _p.isFranchise)
          ? (_s = (_r = (_q = store.state.config) === null || _q === void 0 ? void 0 : _q.franchise) === null || _r === void 0 ? void 0 : _r.stripe) === null || _s === void 0 ? void 0 : _s.key
          : (_u = (_t = store.state.config) === null || _t === void 0 ? void 0 : _t.stripe) === null || _u === void 0 ? void 0 : _u.key, userId: (_v = store.state.profile) === null || _v === void 0 ? void 0 : _v.id })) : (index.h("ion-card", null, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", { style: { maxWidth: "200px", padding: "15px" } }, index.h("ion-icon", { src: "/assets/svg/ft-icon.svg", style: {
          width: "100%",
          display: "block",
          height: "100%",
          minHeight: "100px",
          fill: "var(--ion-text-color)",
        } })), index.h("ion-col", null, index.h("h2", { style: { color: "var(--ion-text-color)", marginTop: "8px" } }, "Your account is almost ready!"), index.h("p", { style: { padding: "10px 0" } }, "Please use the \"Setup Payments\" button below in order to finish setting up your account."), index.h("ion-button", { color: "success", href: "#", "data-trigger": "setupPayments" }, "Setup Payments")))))), index.h("floodteam-title-bar", { icon: "share" }, index.h("ion-text", null, "My Referral Link")), index.h("ion-card", null, index.h("ion-card-content", { class: "ion-padding" }, index.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."), index.h("br", null), index.h("fireenjin-form", { hideControls: true, name: "invite", endpoint: "sendTemplateEmail", disableEnterButton: true, beforeSubmit: this.onBeforeSubmit.bind(this) }, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "to", placeholder: "Comma separated list of emails", value: this.to }))), index.h("ion-row", null, index.h("ion-col", null, index.h("ion-button", { size: "default", expand: "block", fill: "clear", onClick: () => {
          var _a;
          return this.floodteamShare.emit({
            data: {
              url: `${store.state.config.url}?referredBy=${(_a = store.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", index.h("ion-icon", { name: "share-social", slot: "start" }))), index.h("ion-col", null, index.h("ion-button", { size: "default", expand: "block", type: "submit" }, "Send", index.h("ion-icon", { name: "send", slot: "end" })))))))), index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", { size: "7" }, index.h("ion-button", { color: "medium", fill: "clear", size: "small", onClick: () => this.forceUpdate.emit({}) }, "Check for Updates")), index.h("ion-col", { size: "5" }, index.h("ion-text", { color: "secondary", class: "ion-float-right" }, "v", ((_w = store.state === null || store.state === void 0 ? void 0 : store.state.manifest) === null || _w === void 0 ? void 0 : _w.version) || "Unknown"))))),
      index.h("floodteam-navigation-footer", null),
    ];
  }
};
AppProfile.style = appProfileCss;

exports.app_profile = AppProfile;

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