'use strict';

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

const index = require('./index-fd2bbf0b.js');
const index$1 = require('./index-6d879294.js');
const hardwareBackButton = require('./overlays-de05dc6a.js');
const store = require('./store-03756ad8.js');
require('./helpers-c2496722.js');
require('./ionic-global-1340f737.js');
require('./animation-ee586546.js');
require('./index-81aa1bcb.js');
require('./getCache-c039a6ae.js');
require('./_commonjsHelpers-a5111d61.js');
require('./logic-d8c34975.js');
require('./index-6307644b.js');

const appJobCss = "";

let AppJob = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.feedFetchData = {
      orderBy: "createdAt",
      orderDirection: "desc",
    };
    this.userRoleMap = {};
    this.showingEfileHistory = [];
    this.isUploading = false;
    this.efileLoading = false;
    this.isSending = false;
    this.activityFeed = [];
    this.isSiteModalOpen = false;
    this.isEndOfFeed = false;
    this.payModels = [];
    this.feedLimit = 10;
    this.currentSlide = 0;
    this.showControls = null;
    this.isUploadingPhoto = false;
    this.readingsView = "readings";
    this.preparingEfiles = [];
  }
  async onSlideChange(event) {
    this.currentSlide =
      (await event.target.getActiveIndex()) + 1;
  }
  async onSuccess(event) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
    if (event.detail.endpoint === "upload") {
      this.isUploadingPhoto = false;
    }
    else if (event.detail.endpoint === "addEfile") {
      this.isUploading = false;
    }
    else if (event.detail.endpoint === "editJob") {
      this.modalEl.dismiss();
    }
    else if (event.detail.endpoint === "addUserToJob") {
      this.modalEl.dismiss();
    }
    else if (event.detail.endpoint === "addEfile") {
      // FLIP THE SWITCH OFF HERE
      this.isUploading = false;
    }
    else if (["sendTemplateEmail", "editJob", "addUserToJob"].includes((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint)) {
      this.modalEl.dismiss();
    }
    else if (event.detail.endpoint === "addNote") {
      const paginationEl = this.activityFeedEl.querySelector("fireenjin-pagination");
      if (paginationEl) {
        setTimeout(() => {
          paginationEl.getResults();
        }, 2000);
      }
    }
    else if (event.detail.endpoint === "findJob" &&
      ((_d = (_c = (_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.job) === null || _d === void 0 ? void 0 : _d.id) === this.jobId) {
      this.job = (_f = (_e = event === null || event === void 0 ? void 0 : event.detail) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.job;
      if ((_h = (_g = this.job) === null || _g === void 0 ? void 0 : _g.customer) === null || _h === void 0 ? void 0 : _h.id)
        this.userRoleMap[this.job.customer.id] = "customer";
      if ((_k = (_j = this.job) === null || _j === void 0 ? void 0 : _j.manager) === null || _k === void 0 ? void 0 : _k.id)
        this.userRoleMap[this.job.manager.id] = "manager";
      if ((_m = (_l = this.job) === null || _l === void 0 ? void 0 : _l.referral) === null || _m === void 0 ? void 0 : _m.id)
        this.userRoleMap[this.job.referral.id] = "referral";
      const efiles = [];
      for (const efile of ((_o = this.job) === null || _o === void 0 ? void 0 : _o.efiles) || []) {
        const existingFileIndex = efiles.findIndex((file) => { var _a, _b; return ((_a = file === null || file === void 0 ? void 0 : file.template) === null || _a === void 0 ? void 0 : _a.id) === ((_b = efile === null || efile === void 0 ? void 0 : efile.template) === null || _b === void 0 ? void 0 : _b.id); });
        if (existingFileIndex >= 0) {
          efiles[existingFileIndex].history.push(efile);
        }
        else {
          efiles.push({ ...efile, history: [] });
        }
      }
      this.efiles = efiles;
      setTimeout(() => {
        var _a, _b;
        this.selectedReadingDate = ((_b = (_a = this.job) === null || _a === void 0 ? void 0 : _a.readings) === null || _b === void 0 ? void 0 : _b.length)
          ? this.job.readings[0].name
          : null;
        this.readingsGraphData();
      }, 1000);
    }
    else if (((_p = event === null || event === void 0 ? void 0 : event.detail) === null || _p === void 0 ? void 0 : _p.endpoint) === "generatePdf") {
      const toast = await hardwareBackButton.toastController.create({
        message: "File has been added to Efile.",
        duration: 3000,
      });
      toast.present();
      this.efileLoading = false;
    }
    else if (((_q = event === null || event === void 0 ? void 0 : event.detail) === null || _q === void 0 ? void 0 : _q.endpoint) === "listPayModels") {
      this.payModels = ((_t = (_s = (_r = event === null || event === void 0 ? void 0 : event.detail) === null || _r === void 0 ? void 0 : _r.data) === null || _s === void 0 ? void 0 : _s.listPayModels) === null || _t === void 0 ? void 0 : _t.payModels) || [];
    }
  }
  async onSlideTap(_event) {
    this.openSiteEditModal();
  }
  onCloseModa() {
    this.isSiteModalOpen = false;
  }
  async openReadingModal(event) {
    var _a, _b, _c, _d, _e, _f;
    if (!["addReading", "addDot"].includes((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.name))
      return;
    const modalEl = await hardwareBackButton.modalController.create({
      component: "modal-take-readings",
      componentProps: {
        jobId: (_b = this.job) === null || _b === void 0 ? void 0 : _b.id,
        zip: (_d = (_c = this.job) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.zip,
        job: this.job,
        dotForm: ((_e = event === null || event === void 0 ? void 0 : event.detail) === null || _e === void 0 ? void 0 : _e.name) === "addDot",
        closeOnFinish: ((_f = event === null || event === void 0 ? void 0 : event.detail) === null || _f === void 0 ? void 0 : _f.name) === "addDot",
      },
    });
    await modalEl.present();
  }
  onOpenSiteEditModal(event) {
    this.openSiteEditModal(event.detail.site, {
      selectedTab: event.detail.selectedTab,
    });
  }
  onSelect(event) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.name) === "readingId" && !((_b = this.modalEl) === null || _b === void 0 ? void 0 : _b.isConnected)) {
      if ((_c = event === null || event === void 0 ? void 0 : event.detail) === null || _c === void 0 ? void 0 : _c.reading) {
        console.log((_e = (_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.reading) === null || _e === void 0 ? void 0 : _e.name);
        this.selectedReadingDate = (_g = (_f = event === null || event === void 0 ? void 0 : event.detail) === null || _f === void 0 ? void 0 : _f.reading) === null || _g === void 0 ? void 0 : _g.name;
      }
      else {
        this.openReadingModal();
      }
      this.popoverEl.dismiss();
    }
    else if (((_h = event === null || event === void 0 ? void 0 : event.detail) === null || _h === void 0 ? void 0 : _h.name) === "user" && ((_k = (_j = event === null || event === void 0 ? void 0 : event.detail) === null || _j === void 0 ? void 0 : _j.user) === null || _k === void 0 ? void 0 : _k.id)) {
      this.sendEmail(event, (_m = (_l = event === null || event === void 0 ? void 0 : event.detail) === null || _l === void 0 ? void 0 : _l.user) === null || _m === void 0 ? void 0 : _m.id);
      this.popoverEl.dismiss();
    }
  }
  onChange(event) {
    var _a, _b, _c, _d;
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "readingsView") {
      this.readingsView = event.target.value;
      this.readingsGraphData();
    }
    if ((_d = (_c = (_b = event === null || event === void 0 ? void 0 : event.target) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.includes) === null || _d === void 0 ? void 0 : _d.call(_c, "efile-")) {
      this.preparingEfiles = this.preparingEfiles.includes(event.target.value)
        ? this.preparingEfiles.filter((url) => event.target.value !== url)
        : [...new Set([...this.preparingEfiles, event.target.value])];
      console.log(event.target.value);
    }
  }
  async removeEfileFromJob(efile) {
    if (confirm(`Are you sure you want to remove this file from the job?`)) {
      this.fireenjinSubmit.emit({
        endpoint: "deleteEfile",
        id: efile.id,
      });
    }
    if (this.efileListEl)
      this.efileListEl.closeSlidingItems();
  }
  async openMatterportModal() {
    var _a, _b;
    this.modalEl = await hardwareBackButton.modalController.create({
      component: "modal-matterport",
      cssClass: "modal-matterport",
      backdropDismiss: false,
      componentProps: {
        jobId: (_a = this.job) === null || _a === void 0 ? void 0 : _a.id,
        modelId: (_b = this.job) === null || _b === void 0 ? void 0 : _b.matterportModelId,
      },
    });
    this.modalEl.present();
  }
  async openSiteEditModal(site, options) {
    var _a, _b;
    if (this.isSiteModalOpen)
      return;
    this.modalEl = await hardwareBackButton.modalController.create({
      component: "modal-site-edit",
      cssClass: "modal-site-edit",
      backdropDismiss: false,
      componentProps: {
        site,
        jobId: (_a = this.job) === null || _a === void 0 ? void 0 : _a.id,
        siteId: (site === null || site === void 0 ? void 0 : site.id) || null,
        sites: (options === null || options === void 0 ? void 0 : options.sites)
          ? options.sites
          : ((_b = this.job) === null || _b === void 0 ? void 0 : _b.sites)
            ? this.job.sites
            : [],
        currentSlide: (options === null || options === void 0 ? void 0 : options.currentSlide) ? options.currentSlide : null,
        viewGallery: typeof (options === null || options === void 0 ? void 0 : options.viewGallery) === "boolean"
          ? !!(options === null || options === void 0 ? void 0 : options.viewGallery)
          : true,
        showProgress: !!(options === null || options === void 0 ? void 0 : options.showProgress),
        selectedTab: (options === null || options === void 0 ? void 0 : options.selectedTab) ? options.selectedTab : null,
        photo: (options === null || options === void 0 ? void 0 : options.photo) ? options.photo : null,
        photoUploading: !!(options === null || options === void 0 ? void 0 : options.photoUploading),
      },
    });
    this.modalEl.present();
    this.isSiteModalOpen = true;
  }
  async openReadingSelect(event) {
    var _a;
    this.popoverEl = await hardwareBackButton.popoverController.create({
      component: "popover-reading-select",
      componentProps: {
        readings: ((_a = this.job) === null || _a === void 0 ? void 0 : _a.readings) ? Object.values(this.job.readings) : [],
      },
      event,
    });
    return this.popoverEl.present();
  }
  async removeUserFromJob(user) {
    var _a;
    if (confirm(`Are you sure you want to remove ${(user === null || user === void 0 ? void 0 : user.firstName) ? user.firstName : "this user"} from the job?`))
      this.fireenjinSubmit.emit({
        endpoint: "removeUserFromJob",
        data: {
          jobId: (_a = this.job) === null || _a === void 0 ? void 0 : _a.id,
          userId: user.id,
        },
      });
    if (this.userListEl)
      this.userListEl.closeSlidingItems();
  }
  async openaddReadingPopover(event) {
    this.popoverEl = await hardwareBackButton.popoverController.create({
      event,
      cssClass: "popover-add-reading",
      component: "popover-add-reading",
      componentProps: {
        job: this.job,
      },
    });
    this.popoverEl.present();
  }
  async openUserSelect(event) {
    var _a;
    this.popoverEl = await hardwareBackButton.popoverController.create({
      event,
      cssClass: "popover-user-select",
      component: "popover-user-select",
      componentProps: {
        jobId: this.jobId,
        users: ((_a = this.job) === null || _a === void 0 ? void 0 : _a.users) || [],
      },
    });
    this.popoverEl.present();
  }
  async openUserSearch() {
    this.modalEl = await hardwareBackButton.modalController.create({
      cssClass: "modal-search-users",
      component: "modal-search-users",
      componentProps: {
        job: this.job,
      },
    });
    this.modalEl.present();
  }
  readingsGraphData() {
    var _a, _b;
    const graphData = [];
    if (this.readingsView === "temperature") {
      graphData.push({
        data: (((_a = this.job) === null || _a === void 0 ? void 0 : _a.readings) ? this.job.readings.reverse() : []).map((reading) => { var _a; return ((_a = reading === null || reading === void 0 ? void 0 : reading.weather) === null || _a === void 0 ? void 0 : _a.temperature) ? reading.weather.temperature : 0; }),
      });
    }
    const dotReadings = {};
    for (const reading of ((_b = this.job) === null || _b === void 0 ? void 0 : _b.readings) || []) {
      for (const site of (reading === null || reading === void 0 ? void 0 : reading.sites) || []) {
        for (const dot of (site === null || site === void 0 ? void 0 : site.dots) || []) {
          if (!dotReadings[dot === null || dot === void 0 ? void 0 : dot.id])
            dotReadings[dot === null || dot === void 0 ? void 0 : dot.id] = [];
          dotReadings[dot === null || dot === void 0 ? void 0 : dot.id].push(dot === null || dot === void 0 ? void 0 : dot.moistureContent);
        }
      }
    }
    for (const [dotId, readings] of Object.entries(dotReadings)) {
      if (!dotId || !(readings === null || readings === void 0 ? void 0 : readings.length))
        continue;
      graphData.push({
        data: readings.map((reading) => (reading === null || reading === void 0 ? void 0 : reading[this.readingsView]) || 0),
      });
    }
    return graphData;
  }
  async refreshResults() {
    await this.feedPaginationEl.clearResults();
    await this.feedPaginationEl.getResults();
  }
  async openFileUpload(event) {
    console.log(event);
  }
  async openMenu() {
    index$1.menuController.open();
  }
  async openJobEdit(step) {
    this.modalEl = await hardwareBackButton.modalController.create({
      component: "modal-job-edit",
      cssClass: "modal-edit-job",
      backdropDismiss: false,
      componentProps: {
        step,
        job: this.job,
        payModels: this.payModels,
      },
    });
    this.modalEl.present();
  }
  async openSendEfileModal(event) {
    var _a;
    event.preventDefault();
    event.stopPropagation();
    this.modalEl = await hardwareBackButton.modalController.create({
      component: "modal-send-email",
      cssClass: "modal-send-email",
      backdropDismiss: false,
      componentProps: {
        templateFilter: (template) => { var _a, _b; return !(template === null || template === void 0 ? void 0 : template.partial) && ((_b = (_a = template === null || template === void 0 ? void 0 : template.tags) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, "job")); },
        attachments: this.preparingEfiles,
        users: ((_a = this.job) === null || _a === void 0 ? void 0 : _a.users) || [],
      },
    });
    this.modalEl.present();
  }
  async openEsignModal(event, templateId) {
    event.preventDefault();
    event.stopPropagation();
    this.modalEl = await hardwareBackButton.modalController.create({
      component: "modal-esign",
      cssClass: "modal-esign",
      backdropDismiss: false,
      componentProps: {
        jobId: this.jobId,
        templateId,
      },
    });
    this.modalEl.present();
  }
  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 fetchPayModels() {
    this.fireenjinFetch.emit({
      endpoint: "listPayModels",
      params: {
        data: {
          limit: 10,
        },
      },
    });
  }
  async generatePdf(templateId, filename = null) {
    this.efileLoading = true;
    this.fireenjinSubmit.emit({
      endpoint: "generatePdf",
      data: {
        filename,
        jobId: this.jobId,
        templateId,
      },
    });
  }
  formatUSD(amount) {
    const formatter = new Intl.NumberFormat("en-US", {
      style: "currency",
      currency: "USD",
      minimumFractionDigits: 2,
    });
    return formatter.format(amount ? amount : 0);
  }
  formatDate(date) {
    const d = typeof date === "string" ? new Date(date) : date;
    let month = "" + (d.getMonth() + 1);
    let day = "" + d.getDate();
    const year = d.getFullYear();
    if (month.length < 2)
      month = "0" + month;
    if (day.length < 2)
      day = "0" + day;
    return [year, month, day].join("-");
  }
  send(event, template) {
    event.preventDefault();
    event.stopPropagation();
    this.template = template;
    this.isSending = true;
    this.openUserSelect(event);
  }
  async sendEmail(event, userId) {
    var _a, _b, _c, _d, _e;
    event.preventDefault();
    event.stopPropagation();
    if (!((_a = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _a === void 0 ? void 0 : _a.uid))
      return;
    this.fireenjinSubmit.emit({
      endpoint: "sendTemplateEmail",
      data: {
        templateId: "ltEEAQ9Q1J7Jkn6wIIEH",
        userIds: [userId],
        data: {
          app: {
            url: window.location.origin ,
          },
          template: {
            id: ((_b = this.template) === null || _b === void 0 ? void 0 : _b.id) || null,
            description: ((_c = this.template) === null || _c === void 0 ? void 0 : _c.description) || null,
            subject: ((_d = this.template) === null || _d === void 0 ? void 0 : _d.description) || null,
            tags: ((_e = this.template) === null || _e === void 0 ? void 0 : _e.tags) || [],
          },
          job: this.job,
        },
      },
    });
  }
  getData() {
    this.fireenjinTrigger.emit({
      name: "subscribe",
      payload: {
        collection: "jobs",
        id: this.jobId,
        callback: () => {
          this.fetchJob();
        },
      },
    });
    this.fetchJob();
    this.fetchPayModels();
  }
  async componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.getData();
  }
  disconnectedCallback() {
    this.fireenjinTrigger.emit({
      name: "unsubscribe",
      payload: {
        collection: "jobs",
        id: this.jobId,
      },
    });
  }
  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, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
    const selectedWeather = (_d = (_c = (_b = (_a = this.job) === null || _a === void 0 ? void 0 : _a.readings) === null || _b === void 0 ? void 0 : _b.find) === null || _c === void 0 ? void 0 : _c.call(_b, (reading) => reading.name === this.selectedReadingDate)) === null || _d === void 0 ? void 0 : _d.weather;
    const sortedSites = ((_f = (_e = this.job) === null || _e === void 0 ? void 0 : _e.sites) === null || _f === void 0 ? void 0 : _f.length)
      ? this.job.sites.sort((a, b) => (a.chamber > b.chamber ? 1 : -1))
      : [];
    return [
      index.h("ion-content", null, index.h("ion-grid", { style: {
          display: "block",
          maxWidth: "1200px",
          margin: "0 auto",
        } }, index.h("ion-row", null, index.h("ion-col", { class: "ion-align-self-center" }, index.h("floodteam-title-bar", { pin: {
          icon: "water",
          href: `/jobs/${this.jobId}`,
          name: ((_g = this.job) === null || _g === void 0 ? void 0 : _g.title) || "New Job",
        } }, index.h("ion-router-link", { href: "#", onClick: () => this.openJobEdit() }, (_h = this.job) === null || _h === void 0 ? void 0 : _h.title)), index.h("flooteam-chip-bar", null, index.h("floodteam-select-status", { jobId: this.jobId, value: (_j = this.job) === null || _j === void 0 ? void 0 : _j.status }), index.h("floodteam-select-location", { jobId: this.jobId, value: (_l = (_k = this.job) === null || _k === void 0 ? void 0 : _k.location) === null || _l === void 0 ? void 0 : _l.id }), index.h("ion-router-link", { href: `/jobs/${this.jobId}/scope` }, index.h("ion-chip", null, index.h("ion-icon", { class: "ft-icon-style", name: "list" }), index.h("ion-label", null, "View Scope"))), ((_m = this.job) === null || _m === void 0 ? void 0 : _m.matterportModelId) && (index.h("ion-router-link", { href: "#", onClick: () => this.openMatterportModal() }, index.h("ion-chip", null, index.h("ion-icon", { class: "ft-icon-style", name: "cube" }), index.h("ion-label", null, "Matterport Model")))), index.h("ion-router-link", { href: `geo:${(_p = (_o = this.job) === null || _o === void 0 ? void 0 : _o.address) === null || _p === void 0 ? void 0 : _p.full}` }, index.h("ion-chip", null, index.h("ion-icon", { class: "ft-icon-style", name: "map" }), index.h("ion-label", null, "Map"))), index.h("ion-router-link", { href: `/pay/${this.jobId}` }, index.h("ion-chip", null, index.h("ion-icon", { class: "ft-icon-style", name: "logo-usd" }), index.h("ion-label", null, "Epay"))), index.h("ion-chip", { onClick: () => this.openJobEdit("cause") }, index.h("ion-icon", { class: "ft-icon-style", name: "water" }), index.h("ion-label", null, `Cat ${((_q = this.job) === null || _q === void 0 ? void 0 : _q.category) || 0} - ${((_r = this.job) === null || _r === void 0 ? void 0 : _r.cause) || "Unknown"}`))))), index.h("ion-row", { class: "ion-no-padding ion-no-margin" }, index.h("ion-col", { size: "12", sizeMd: "6", class: "ion-no-padding ion-no-margin" }, index.h("floodteam-title-bar", { icon: "cube", heading: 4, disableUnderline: true }, index.h("ion-text", null, "Sites"), index.h("ion-button", { fill: "outline", href: "#", slot: "end", size: "small", onClick: () => this.openSiteEditModal() }, "Add")), index.h("ion-card", { class: "site-card" }, index.h("ion-list", { lines: "full", style: {
          paddingBottom: ((_t = (_s = this.job) === null || _s === void 0 ? void 0 : _s.sites) === null || _t === void 0 ? void 0 : _t.length) ? "0px" : "8px",
          paddingTop: ((_v = (_u = this.job) === null || _u === void 0 ? void 0 : _u.sites) === null || _v === void 0 ? void 0 : _v.length) ? "0px" : "8px",
        } }, (sortedSites === null || sortedSites === void 0 ? void 0 : sortedSites.length) ? (sortedSites
        .sort((a, b) => (a.name > b.name ? 1 : -1))
        .map((site, index$1) => {
        var _a;
        return [
          (site === null || site === void 0 ? void 0 : site.chamber) !==
            ((_a = sortedSites === null || sortedSites === void 0 ? void 0 : sortedSites[index$1 - 1]) === null || _a === void 0 ? void 0 : _a.chamber) && (index.h("ion-item-divider", null, "Chamber ", site.chamber)),
          index.h("floodteam-item-site", { onClick: (event) => {
              event.preventDefault();
              event.stopPropagation();
              this.openSiteEditModal(site);
            }, site: site }),
        ];
      })) : (index.h("floodteam-fallback", { message: "No Sites Added...", icon: "cube" }))))), index.h("ion-col", { size: "12", sizeMd: "6" }, index.h("floodteam-title-bar", { heading: 4, icon: "thermometer", disableUnderline: true }, index.h("ion-text", null, "Readings"), index.h("ion-button", { fill: "outline", href: "#", slot: "end", size: "small", onClick: (event) => this.openaddReadingPopover(event) }, "Add")), index.h("ion-card", null, index.h("ion-item", null, index.h("ion-select", { placeholder: "Select a View", name: "readingsView", interfaceOptions: {
          header: "Select a View",
        }, value: this.readingsView }, index.h("ion-select-option", { value: "readings" }, "MC Readings"), index.h("ion-select-option", { value: "grainsPerPound" }, "Grains Per Pound"), index.h("ion-select-option", { value: "temperature" }, "Temperature"), index.h("ion-select-option", { value: "evaporationPotential" }, "Evaporation Potential"))), ((_x = (_w = this.job) === null || _w === void 0 ? void 0 : _w.readings) === null || _x === void 0 ? void 0 : _x.length) ? (index.h("fireenjin-graph", { type: "line", labels: (((_y = this.job) === null || _y === void 0 ? void 0 : _y.readings)
          ? this.job.readings.reverse()
          : []).map((reading) => reading.name), datasets: this.readingsGraphData() })) : (index.h("floodteam-fallback", { icon: "bar-chart", message: "No Readings Added..." })), index.h("ion-list", null, index.h("ion-item-divider", null, "Moisture Content", index.h("ion-button", { fill: "clear", slot: "end", onClick: (event) => this.openReadingSelect(event) }, this.selectedReadingDate || "None", index.h("ion-icon", { slot: "end", name: "today" }))), index.h("div", null, selectedWeather && (index.h("ion-item", null, ((_0 = (_z = selectedWeather === null || selectedWeather === void 0 ? void 0 : selectedWeather.conditions) === null || _z === void 0 ? void 0 : _z[0]) === null || _0 === void 0 ? void 0 : _0.icon) && (index.h("ion-img", { style: {
          height: "50px",
          width: "50px",
          marginRight: "0",
        }, slot: "start", src: `/assets/images/${((_2 = (_1 = selectedWeather === null || selectedWeather === void 0 ? void 0 : selectedWeather.conditions) === null || _1 === void 0 ? void 0 : _1[0]) === null || _2 === void 0 ? void 0 : _2.icon)
          ? "weather/" +
            selectedWeather.conditions[0].icon
          : "icon"}.png` })), index.h("ion-label", null, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", { class: "ion-text-left" }, index.h("ion-icon", { color: "success", name: "arrow-up", style: { opacity: "0.6" } }), selectedWeather === null || selectedWeather === void 0 ? void 0 :
        selectedWeather.temperatureMax, "\u00B0"), index.h("ion-col", { class: "ion-text-left" }, selectedWeather === null || selectedWeather === void 0 ? void 0 :
        selectedWeather.temperatureMin, "\u00B0", index.h("ion-icon", { color: "danger", name: "arrow-down", style: { opacity: "0.6" } })))), index.h("p", { style: { textIndent: "15px" } }, (_4 = (_3 = selectedWeather === null || selectedWeather === void 0 ? void 0 : selectedWeather.conditions) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.description)))), (((_5 = this.job) === null || _5 === void 0 ? void 0 : _5.sites) ? this.job.sites : [])
        .filter((site) => { var _a; return (_a = site === null || site === void 0 ? void 0 : site.dots) === null || _a === void 0 ? void 0 : _a.length; })
        .map((site) => [
        index.h("ion-item-divider", { style: { display: "block" } }, site === null || site === void 0 ? void 0 :
          site.name, index.h("ion-chip", { disabled: true, slot: "end" }, (site === null || site === void 0 ? void 0 : site.chamber) || 0, index.h("ion-icon", { name: "grid" }))),
        index.h("ion-grid", null, index.h("ion-row", null, ((site === null || site === void 0 ? void 0 : site.dots) ? site.dots : []).map((dot, index$1) => {
          var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
          return (index.h("ion-col", null, index.h("div", { class: "floodteam-dot", style: { color: "var(--ion-text-color)" } }, (dot === null || dot === void 0 ? void 0 : dot.name) || index$1 + 1, ((_l = (_k = (_j = (_h = (_g = (_f = (_e = (_d = (_c = (_b = (_a = this.job) === null || _a === void 0 ? void 0 : _a.readings) === null || _b === void 0 ? void 0 : _b.find) === null || _c === void 0 ? void 0 : _c.call(_b, (reading) => (reading === null || reading === void 0 ? void 0 : reading.name) ===
            this.selectedReadingDate)) === null || _d === void 0 ? void 0 : _d.sites) === null || _e === void 0 ? void 0 : _e.find) === null || _f === void 0 ? void 0 : _f.call(_e, (readingSite) => (readingSite === null || readingSite === void 0 ? void 0 : readingSite.id) === (site === null || site === void 0 ? void 0 : site.id))) === null || _g === void 0 ? void 0 : _g.dots) === null || _h === void 0 ? void 0 : _h.find) === null || _j === void 0 ? void 0 : _j.call(_h, (readingDot) => (readingDot === null || readingDot === void 0 ? void 0 : readingDot.id) === (dot === null || dot === void 0 ? void 0 : dot.id))) === null || _k === void 0 ? void 0 : _k.moistureContent) === null || _l === void 0 ? void 0 : _l[this.readingsView]) && (index.h("ion-badge", { style: {
              position: "absolute",
              bottom: "0px",
              right: "0px",
            } }, (_x = (_w = (_v = (_u = (_t = (_s = (_r = (_q = (_p = (_o = (_m = this.job) === null || _m === void 0 ? void 0 : _m.readings) === null || _o === void 0 ? void 0 : _o.find) === null || _p === void 0 ? void 0 : _p.call(_o, (reading) => (reading === null || reading === void 0 ? void 0 : reading.name) ===
            this.selectedReadingDate)) === null || _q === void 0 ? void 0 : _q.sites) === null || _r === void 0 ? void 0 : _r.find) === null || _s === void 0 ? void 0 : _s.call(_r, (readingSite) => (readingSite === null || readingSite === void 0 ? void 0 : readingSite.id) === (site === null || site === void 0 ? void 0 : site.id))) === null || _t === void 0 ? void 0 : _t.dots) === null || _u === void 0 ? void 0 : _u.find) === null || _v === void 0 ? void 0 : _v.call(_u, (readingDot) => (readingDot === null || readingDot === void 0 ? void 0 : readingDot.id) === (dot === null || dot === void 0 ? void 0 : dot.id))) === null || _w === void 0 ? void 0 : _w.moistureContent) === null || _x === void 0 ? void 0 :
            _x[this.readingsView], this.readingsView === "temperature" ? (index.h("span", null, "\u00B0")) : (""))))));
        }))),
      ]))))), index.h("ion-col", { size: "12", sizeMd: "6" }, index.h("floodteam-title-bar", { heading: 4, disableUnderline: true, icon: "people" }, index.h("ion-text", null, "Users"), index.h("ion-button", { fill: "outline", href: "#", slot: "end", size: "small", onClick: () => this.openUserSearch() }, "Add")), index.h("ion-card", null, index.h("ion-list", { ref: (el) => (this.userListEl = el) }, ((_7 = (_6 = this.job) === null || _6 === void 0 ? void 0 : _6.users) === null || _7 === void 0 ? void 0 : _7.length) ? (this.job.users.map((user) => {
        var _a;
        return (index.h("floodteam-item-user", { role: this.userRoleMap[user === null || user === void 0 ? void 0 : user.id] || null, user: user, jobId: (_a = this.job) === null || _a === void 0 ? void 0 : _a.id }));
      })) : (index.h("floodteam-fallback", { icon: "people", message: "No Users Added..." }))))), index.h("ion-col", { size: "12", sizeMd: "6" }, index.h("floodteam-title-bar", { heading: 4, icon: "file-tray-full", disableUnderline: true }, index.h("ion-text", null, "Efiles"), index.h("ion-button", { fill: "outline", href: "#", slot: "end", size: "small", onClick: () => {
          (this.isUploading = true),
            this.fireenjinTrigger.emit({
              name: "upload",
              multiple: true,
              payload: {
                jobId: this.jobId,
              },
            });
        } }, "Add")), index.h("ion-card", null, index.h("ion-accordion-group", null, index.h("ion-accordion", null, index.h("ion-item", { slot: "header" }, index.h("ion-icon", { name: "file-tray-full", slot: "start" }), index.h("ion-label", null, "Inbox"), ((_8 = this.preparingEfiles) === null || _8 === void 0 ? void 0 : _8.length) ? (index.h("ion-button", { onClick: (event) => this.openSendEfileModal(event), slot: "end", fill: "solid", color: "primary", size: "small" }, index.h("ion-label", null, "Send "), index.h("ion-text", { slot: "end" }, "\u00A0", ((_9 = this.preparingEfiles) === null || _9 === void 0 ? void 0 : _9.length) || 0))) : (index.h("ion-text", { color: ((_11 = (_10 = this.job) === null || _10 === void 0 ? void 0 : _10.efiles) === null || _11 === void 0 ? void 0 : _11.length) > 0 ? "primary" : "medium", slot: "end" }, ((_13 = (_12 = this.job) === null || _12 === void 0 ? void 0 : _12.efiles) === null || _13 === void 0 ? void 0 : _13.length) || 0))), index.h("ion-list", { class: {
          "is-loading": this.efileLoading,
        }, slot: "content", ref: (el) => (this.efileListEl = el) }, index.h("fireenjin-chip-bar", null, index.h("ion-chip", { onClick: () => this.generatePdf("CcLLkmgyUfeQvQVEWnLp", "Photos Pdf") }, index.h("ion-icon", { class: "ft-icon-style", name: "document-text-outline" }), index.h("ion-label", null, "Photo PDF")), index.h("ion-chip", { onClick: () => this.generatePdf("QMzg5GspcjqouWNxArbh", "Readings PDF") }, index.h("ion-icon", { class: "ft-icon-style", name: "document-text-outline" }), index.h("ion-label", null, "Readings PDF")), index.h("ion-chip", { onClick: () => this.generatePdf("tA7FCnTudK0Sd887IeuU", "Invoice PDF") }, index.h("ion-icon", { class: "ft-icon-style", name: "document-text-outline" }), index.h("ion-label", null, "Invoice PDF"))), ((_14 = this.efiles) === null || _14 === void 0 ? void 0 : _14.length) ? (this.efiles
        .sort((a, b) => ((a === null || a === void 0 ? void 0 : a.name) > (b === null || b === void 0 ? void 0 : b.name) ? 1 : -1))
        .map((efile) => {
        var _a, _b;
        return [
          index.h("ion-item-sliding", null, index.h("ion-item", { detail: true, target: "_blank", href: efile === null || efile === void 0 ? void 0 : efile.url }, index.h("ion-checkbox", { slot: "start", name: `efile-${efile === null || efile === void 0 ? void 0 : efile.id}`, value: efile === null || efile === void 0 ? void 0 : efile.url }), index.h("ion-label", { class: "ion-text-wrap" }, index.h("p", null, efile === null || efile === void 0 ? void 0 : efile.name)), ((_a = efile === null || efile === void 0 ? void 0 : efile.history) === null || _a === void 0 ? void 0 : _a.length) ? (index.h("ion-button", { size: "large", color: "primary", fill: "clear", slot: "end", onClick: (event) => {
              var _a;
              event.preventDefault();
              event.stopPropagation();
              if ((_a = this.showingEfileHistory) === null || _a === void 0 ? void 0 : _a.includes(efile.id)) {
                this.showingEfileHistory =
                  this.showingEfileHistory.filter((efileId) => efileId !== (efile === null || efile === void 0 ? void 0 : efile.id));
              }
              else {
                this.showingEfileHistory = [
                  ...this.showingEfileHistory,
                  efile.id,
                ];
              }
            } }, index.h("ion-icon", { name: "time", slot: "icon-only" }))) : ("")), index.h("ion-item-options", null, index.h("ion-item-option", { color: "danger", onClick: () => this.removeEfileFromJob(efile) }, index.h("ion-icon", { slot: "end", name: "close-circle" }), "Remove"))),
          !!((_b = efile === null || efile === void 0 ? void 0 : efile.history) === null || _b === void 0 ? void 0 : _b.length) && (index.h("ion-list", { style: {
              display: this.showingEfileHistory.includes(efile.id)
                ? "block"
                : "none",
            } }, efile.history.map((oldEfile) => (index.h("ion-item-sliding", null, index.h("ion-item", { detail: true, target: "_blank", href: oldEfile.url }, index.h("ion-checkbox", { slot: "start", name: `efile-${oldEfile.id}`, value: oldEfile.url }), index.h("ion-label", { class: "ion-text-wrap" }, index.h("p", null, oldEfile.name))), index.h("ion-item-options", null, index.h("ion-item-option", { color: "danger", onClick: () => this.removeEfileFromJob(oldEfile) }, index.h("ion-icon", { slot: "end", name: "close-circle" }), "Remove"))))))),
        ];
      })) : (index.h("floodteam-fallback", { icon: "file-tray-full", message: "No Files Uploaded..." })))), index.h("ion-accordion", null, index.h("ion-item", { slot: "header" }, index.h("ion-icon", { slot: "start", name: "create" }), index.h("ion-label", null, "Contracts")), index.h("ion-list", { slot: "content" }, ((store.state === null || store.state === void 0 ? void 0 : store.state.templates) || [])
        .filter((template) => {
        var _a, _b;
        return (template === null || template === void 0 ? void 0 : template.type) === "contract" &&
          ((_b = (_a = template === null || template === void 0 ? void 0 : template.tags) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, "job"));
      })
        .map((contract) => {
        var _a, _b;
        return (index.h("ion-item", { detail: true, onClick: (event) => this.openEsignModal(event, contract === null || contract === void 0 ? void 0 : contract.id), href: `${(_a = store.state.config) === null || _a === void 0 ? void 0 : _a.url}/jobs/${this.jobId}/sign/${contract === null || contract === void 0 ? void 0 : contract.id}` }, (((_b = this.job) === null || _b === void 0 ? void 0 : _b.efiles) || [])
          .map((efile) => {
          var _a;
          return (_a = efile === null || efile === void 0 ? void 0 : efile.template) === null || _a === void 0 ? void 0 : _a.id;
        })
          .includes(contract === null || contract === void 0 ? void 0 : contract.id) && (index.h("ion-icon", { style: { marginRight: "10px" }, name: "checkmark-circle", color: "primary", slot: "start" })), index.h("ion-label", { class: "ion-text-wrap" }, index.h("p", null, (contract === null || contract === void 0 ? void 0 : contract.subject)
          ? contract.subject
          : "No Name...")), index.h("ion-button", { slot: "end", color: "primary", fill: "clear", size: "small", onClick: (event) => this.send(event, contract) }, index.h("ion-icon", { slot: "start", name: "mail" }), "Send")));
      }))))))))),
      index.h("floodteam-navigation-footer", null),
    ];
  }
  get jobPageEl() { return index.getElement(this); }
};
AppJob.style = appJobCss;

exports.app_job = AppJob;

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