import { Build, Component, h, Listen, Prop, State, } from "@stencil/core";
import state from "../../../store";
import getParameter from "../../../helpers/getParameter";
import { toastController } from "@ionic/core";
export class AppJobNew {
  constructor() {
    this.referring = false;
  }
  async onSuccess(event) {
    if (event.detail.name === "recommendation") {
      this.to = null;
      this.name = null;
      (await toastController.create({
        message: `Successfully sent recommendation(s).`,
        duration: 3000,
      })).present();
    }
  }
  onBeforeSubmit(formData) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
    return {
      templateId: "BaGYHYB6q7UBmgvoPATx",
      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: (formData === null || formData === void 0 ? void 0 : formData.name) || "there",
        url: `${state.config.url}?referredBy=${(_c = state.profile) === null || _c === void 0 ? void 0 : _c.id}`,
        partner: {
          id: (_d = state === null || state === void 0 ? void 0 : state.session) === null || _d === void 0 ? void 0 : _d.uid,
          name: `${((_e = state === null || state === void 0 ? void 0 : state.profile) === null || _e === void 0 ? void 0 : _e.firstName) || ""} ${((_f = state === null || state === void 0 ? void 0 : state.profile) === null || _f === void 0 ? void 0 : _f.lastName) || ""}`,
          company: ((_h = (_g = state === null || state === void 0 ? void 0 : state.profile) === null || _g === void 0 ? void 0 : _g.company) === null || _h === void 0 ? void 0 : _h.name) || "The Flood Team",
          title: ((_j = state === null || state === void 0 ? void 0 : state.profile) === null || _j === void 0 ? void 0 : _j.type) || "Mitigation Specialist",
          phone: (_k = state === null || state === void 0 ? void 0 : state.profile) === null || _k === void 0 ? void 0 : _k.phone,
          location: (_m = (_l = state === null || state === void 0 ? void 0 : state.profile) === null || _l === void 0 ? void 0 : _l.location) === null || _m === void 0 ? void 0 : _m.name,
        },
      },
    };
  }
  componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
  }
  render() {
    var _a;
    return [
      h("ion-content", { class: "ion-padding" },
        h("floodteam-title-bar", null,
          h("ion-router-link", { href: "/jobs" }, "Jobs")),
        h("ion-grid", null,
          h("ion-row", null,
            h("ion-col", { size: "12", sizeMd: "6" },
              h("h1", { class: "title" }, this.referring ? "Refer A Flood" : "Add Job"),
              h("floodteam-book-now", { referring: this.referring, referralId: (_a = state === null || state === void 0 ? void 0 : state.session) === null || _a === void 0 ? void 0 : _a.uid, token: getParameter("token"), locationId: this.locationId || getParameter("location") })),
            h("ion-col", { size: "12", sizeMd: "6" },
              h("h1", { class: "title" }, "Recommend Us"),
              h("ion-card", null,
                h("ion-card-content", { class: "ion-padding" },
                  h("p", null, "Enter the email or phone of the person you would like to recommend The Flood Team water damage restoration services to and we will send them an email detailing how we can help."),
                  h("br", null),
                  h("fireenjin-form", { hideControls: true, name: "recommendation", 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: "name", placeholder: "Customer's Name", value: this.name }),
                          h("fireenjin-input", { name: "to", placeholder: "Customer's Email", value: this.to }))),
                      h("ion-row", null,
                        h("ion-col", null,
                          h("ion-button", { size: "default", expand: "block", type: "submit" },
                            "Send",
                            h("ion-icon", { name: "send", slot: "end" })))))))))))),
      h("floodteam-navigation-footer", null),
    ];
  }
  static get is() { return "app-job-new"; }
  static get originalStyleUrls() { return {
    "$": ["app-job-new.css"]
  }; }
  static get styleUrls() { return {
    "$": ["app-job-new.css"]
  }; }
  static get properties() { return {
    "referring": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "referring",
      "reflect": false,
      "defaultValue": "false"
    },
    "locationId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "location-id",
      "reflect": false
    }
  }; }
  static get states() { return {
    "to": {},
    "name": {}
  }; }
  static get listeners() { return [{
      "name": "fireenjinSuccess",
      "method": "onSuccess",
      "target": "body",
      "capture": false,
      "passive": false
    }]; }
}
//# sourceMappingURL=app-job-new.js.map