import { Build, Component, Event, h, Listen, Prop, } from "@stencil/core";
import totalsForJob from "../../../helpers/totalsForJob";
import state from "../../../store";
export class AppScope {
  async fetchJob() {
    if (!this.jobId)
      return;
    this.fireenjinFetch.emit({
      endpoint: "findJob",
      params: {
        id: this.jobId,
        withPayments: false,
        withUsers: true,
        withSites: true,
        withPayModel: true,
        withPhotos: true,
        withEfiles: true,
        withPayables: false,
        withReadings: true,
      },
    });
  }
  async componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    this.fireenjinTrigger.emit({
      name: "subscribe",
      payload: {
        collection: "jobs",
        id: this.jobId,
        callback: () => {
          this.fetchJob();
        },
      },
    });
    this.fetchJob();
  }
  disconnectedCallback() {
    state.job = null;
    state.site = null;
    this.fireenjinTrigger.emit({
      name: "unsubscribe",
      payload: {
        collection: "jobs",
        id: this.jobId,
      },
    });
  }
  render() {
    return [
      h("ion-content", { class: "ion-padding" },
        h("floodteam-title-bar", { back: `/jobs/${this.jobId}` },
          h("ion-text", null, "Scope"),
          h("ion-buttons", { slot: "end" },
            h("ion-button", { fill: "outline", size: "small", onClick: () => this.floodteamOpenModal.emit({
                component: "modal-render-template",
                componentProps: {
                  templateId: "tA7FCnTudK0Sd887IeuU",
                  headerTitle: "Invoice",
                  data: {
                    job: state.job,
                    totals: totalsForJob(state.job),
                  },
                },
              }) }, "Preview Invoice"))),
        h("floodteam-form-scope", { jobId: this.jobId })),
      h("floodteam-navigation-footer", null),
    ];
  }
  static get is() { return "app-scope"; }
  static get originalStyleUrls() { return {
    "$": ["app-scope.css"]
  }; }
  static get styleUrls() { return {
    "$": ["app-scope.css"]
  }; }
  static get properties() { return {
    "jobId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "job-id",
      "reflect": false
    }
  }; }
  static get events() { return [{
      "method": "fireenjinTrigger",
      "name": "fireenjinTrigger",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "FireEnjinTriggerInput",
        "resolved": "FireEnjinTriggerInput",
        "references": {
          "FireEnjinTriggerInput": {
            "location": "import",
            "path": "@fireenjin/sdk"
          }
        }
      }
    }, {
      "method": "fireenjinFetch",
      "name": "fireenjinFetch",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "floodteamOpenModal",
      "name": "floodteamOpenModal",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "{\n    component: string;\n    componentProps?: { templateId?: string; headerTitle?: string; data?: any };\n    cssClass?: string;\n  }",
        "resolved": "{ component: string; componentProps?: { templateId?: string; headerTitle?: string; data?: any; }; cssClass?: string; }",
        "references": {}
      }
    }]; }
  static get listeners() { return [{
      "name": "ionRouteDidChange",
      "method": "componentDidLoad",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
//# sourceMappingURL=app-scope.js.map