import { Component, Event, Listen, Prop, h, } from "@stencil/core";
import state from "../../../store";
export class AppPay {
  constructor() {
    this.user = {};
  }
  async onSuccess(event) {
    var _a, _b, _c, _d, _e;
    if (event.detail.endpoint === "findJob" &&
      ((_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.job) === null || _c === void 0 ? void 0 : _c.id) === this.jobId) {
      this.job = (_e = (_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.job;
    }
  }
  async fetchJob() {
    if (!this.jobId)
      return;
    this.fireenjinFetch.emit({
      endpoint: "findJob",
      params: {
        id: this.jobId,
        withPayments: true,
        withUsers: true,
        withSites: true,
        withPayModel: true,
        withPhotos: true,
        withEfiles: true,
        withPayables: false,
        withReadings: true,
      },
    });
  }
  componentDidLoad() {
    if (!this.job && this.jobId)
      this.fetchJob();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
    return [
      h("ion-content", { class: "ion-padding" },
        h("floodteam-title-bar", { back: `/jobs/${this.jobId}`, icon: "logo-usd" },
          h("ion-router-link", { href: "/payments" }, "Payments")),
        h("floodteam-epay", { jobId: this.jobId, stripeKey: ((_a = this.job) === null || _a === void 0 ? void 0 : _a.isFranchise) && ((_d = (_c = (_b = state.config) === null || _b === void 0 ? void 0 : _b.franchise) === null || _c === void 0 ? void 0 : _c.stripe) === null || _d === void 0 ? void 0 : _d.key)
            ? state.config.franchise.stripe.key
            : (_f = (_e = state.config) === null || _e === void 0 ? void 0 : _e.stripe) === null || _f === void 0 ? void 0 : _f.key, dadeKey: this.job.isFranchise && ((_j = (_h = (_g = state.config) === null || _g === void 0 ? void 0 : _g.franchise) === null || _h === void 0 ? void 0 : _h.dade) === null || _j === void 0 ? void 0 : _j.apiKey)
            ? state.config.franchise.dade.apiKey
            : (_l = (_k = state.config) === null || _k === void 0 ? void 0 : _k.dade) === null || _l === void 0 ? void 0 : _l.apiKey, dadeUrl: this.job.isFranchise && ((_p = (_o = (_m = state.config) === null || _m === void 0 ? void 0 : _m.franchise) === null || _o === void 0 ? void 0 : _o.dade) === null || _p === void 0 ? void 0 : _p.url)
            ? state.config.franchise.dade.url
            : (_r = (_q = state.config) === null || _q === void 0 ? void 0 : _q.dade) === null || _r === void 0 ? void 0 : _r.url, userId: (_s = state === null || state === void 0 ? void 0 : state.session) === null || _s === void 0 ? void 0 : _s.uid })),
      h("floodteam-navigation-footer", null),
    ];
  }
  static get is() { return "app-pay"; }
  static get originalStyleUrls() { return {
    "$": ["app-pay.css"]
  }; }
  static get styleUrls() { return {
    "$": ["app-pay.css"]
  }; }
  static get properties() { return {
    "user": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Partial<User>",
        "resolved": "{ __typename?: \"User\"; active?: boolean; address?: Address; billingAddress?: Address; birthday?: string; certifications?: Certification[]; company?: Company; createdAt?: string; createdBy?: User; email?: string; feed?: Feed[]; firstName?: string; floodbotId?: string; friends?: User[]; id?: string; isFranchise?: boolean; isFranchiseOwner?: boolean; isOnboarded?: boolean; isSearchable?: boolean; isSetup?: boolean; isStripeOAuth?: boolean; jobs?: Job[]; lastName?: string; lastOnline?: string; location?: Location; online?: boolean; phone?: string; photo?: string; plaidAccessToken?: string; rating?: number; referredBy?: User; role?: string; slackHandle?: string; stripeId?: string; tags?: string[]; trade?: string; type?: string; updatedAt?: string; updatedBy?: User; vehicles?: Vehicle[]; }",
        "references": {
          "Partial": {
            "location": "global"
          },
          "User": {
            "location": "import",
            "path": "../../../sdk"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "{}"
    },
    "jobId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "job-id",
      "reflect": false
    },
    "job": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "Job",
        "resolved": "{ __typename?: \"Job\"; address?: Address; afterhours?: boolean; amountBilled?: number; amountDeducted?: number; amountOwed?: number; amountPaid?: number; appointment?: Appointment; appointments?: Appointment[]; attributionToken?: Token; category?: number; cause?: string; claimNumber?: string; createdAt?: string; createdBy?: User; customer?: User; dateOfLoss?: string; efileCount?: number; efiles?: Efile[]; feed?: Feed[]; id?: string; invoices?: Invoice[]; isFranchise?: boolean; isInsured?: boolean; isSearchable?: boolean; location?: Location; manager?: User; matterportModelId?: string; payModel?: PayModel; payables?: Payable[]; payments?: Payment[]; phone?: string; photos?: Photo[]; picture?: string; propertyAge?: number; ratings?: Rating[]; readings?: Reading[]; referral?: User; services?: ScopeService[]; sites?: Site[]; status?: string; tags?: string[]; title?: string; type?: string; updatedAt?: string; updatedBy?: User; userIds?: string[]; users?: User[]; weather?: Weather[]; weatherIds?: string[]; }",
        "references": {
          "Job": {
            "location": "import",
            "path": "../../../sdk"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get events() { return [{
      "method": "fireenjinFetch",
      "name": "fireenjinFetch",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "FireEnjinFetchEvent",
        "resolved": "FireEnjinFetchEvent",
        "references": {
          "FireEnjinFetchEvent": {
            "location": "import",
            "path": "@fireenjin/sdk"
          }
        }
      }
    }]; }
  static get listeners() { return [{
      "name": "fireenjinSuccess",
      "method": "onSuccess",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
//# sourceMappingURL=app-pay.js.map