'use strict';

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

const index = require('./index-9f0649b4.js');
const index$1 = require('./index-08204db6.js');
const hardwareBackButton = require('./overlays-a2727821.js');
const store = require('./store-6aa30f89.js');
const getCache = require('./getCache-0269c4d0.js');
const isAdmin = require('./isAdmin-a2437175.js');
require('./helpers-c2496722.js');
require('./ionic-global-838555f5.js');
require('./animation-ee586546.js');
require('./index-bac05b73.js');
require('./getHandlebarsHelpers-93797155.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-ba857994.js');
require('./localforage-af1b8c0e.js');

async function getJobFromCache(id) {
  const jobCache = await getCache.getCache("floodteam:jobs", {});
  return (jobCache === null || jobCache === void 0 ? void 0 : jobCache[id]) || null;
}

const appJobCss = "";

const 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.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, _u, _v, _w;
    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)) {
      if ((_b = this.modalEl) === null || _b === void 0 ? void 0 : _b.dismiss)
        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" &&
      ((_e = (_d = (_c = event === null || event === void 0 ? void 0 : event.detail) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.job) === null || _e === void 0 ? void 0 : _e.id) === this.jobId) {
      this.userRoleMap = {};
      if ((_g = (_f = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _f === void 0 ? void 0 : _f.customer) === null || _g === void 0 ? void 0 : _g.id)
        this.userRoleMap[(_h = store.state.job) === null || _h === void 0 ? void 0 : _h.customer.id] = "customer";
      if ((_k = (_j = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _j === void 0 ? void 0 : _j.manager) === null || _k === void 0 ? void 0 : _k.id)
        this.userRoleMap[(_l = store.state.job) === null || _l === void 0 ? void 0 : _l.manager.id] = "manager";
      if ((_o = (_m = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _m === void 0 ? void 0 : _m.referral) === null || _o === void 0 ? void 0 : _o.id)
        this.userRoleMap[store.state.job.referral.id] = "referral";
      if ((_q = (_p = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _p === void 0 ? void 0 : _p.success) === null || _q === void 0 ? void 0 : _q.id)
        this.userRoleMap[store.state.job.success.id] = "success";
      this.userRoleMap = { ...this.userRoleMap };
      const efiles = [];
      for (const efile of ((_r = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _r === void 0 ? void 0 : _r.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, _c;
        this.selectedReadingDate = ((_b = (_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.readings) === null || _b === void 0 ? void 0 : _b.length)
          ? (_c = store.state.job) === null || _c === void 0 ? void 0 : _c.readings[0].name
          : null;
        this.readingsGraphData();
      }, 1000);
    }
    else if (((_s = event === null || event === void 0 ? void 0 : event.detail) === null || _s === void 0 ? void 0 : _s.endpoint) === "generatePdf") {
      const toast = await hardwareBackButton.toastController.create({
        message: "File has been added to Efile.",
        duration: 3000,
      });
      toast.present();
      this.efileLoading = false;
    }
    else if (((_t = event === null || event === void 0 ? void 0 : event.detail) === null || _t === void 0 ? void 0 : _t.endpoint) === "listPayModels") {
      this.payModels = ((_w = (_v = (_u = event === null || event === void 0 ? void 0 : event.detail) === null || _u === void 0 ? void 0 : _u.data) === null || _v === void 0 ? void 0 : _v.listPayModels) === null || _w === void 0 ? void 0 : _w.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 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _b === void 0 ? void 0 : _b.id,
        zip: (_d = (_c = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.zip,
        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 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.id,
        modelId: (_b = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _b === void 0 ? void 0 : _b.matterportModelId,
      },
    });
    this.modalEl.present();
  }
  async openSiteEditModal(site, options) {
    var _a, _b, _c;
    store.state.site = site;
    if (this.isSiteModalOpen)
      return;
    this.modalEl = await hardwareBackButton.modalController.create({
      component: "modal-site-edit",
      cssClass: "modal-site-edit",
      backdropDismiss: false,
      componentProps: {
        site,
        jobId: (_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.id,
        siteId: ((_b = store.state === null || store.state === void 0 ? void 0 : store.state.site) === null || _b === void 0 ? void 0 : _b.id) || null,
        sites: (options === null || options === void 0 ? void 0 : options.sites) || ((_c = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _c === void 0 ? void 0 : _c.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, _b;
    this.popoverEl = await hardwareBackButton.popoverController.create({
      component: "popover-reading-select",
      componentProps: {
        readings: ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.readings)
          ? Object.values((_b = store.state.job) === null || _b === void 0 ? void 0 : _b.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 = store.state === null || store.state === void 0 ? void 0 : store.state.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: store.state.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 = store.state === null || store.state === void 0 ? void 0 : store.state.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: store.state.job,
      },
    });
    this.modalEl.present();
  }
  readingsGraphData() {
    var _a, _b, _c;
    const graphData = [];
    if (this.readingsView === "temperature") {
      graphData.push({
        data: (((_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.readings) ? (_b = store.state.job) === null || _b === void 0 ? void 0 : _b.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 ((_c = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _c === void 0 ? void 0 : _c.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 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: store.state.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: {
        templateId: "0xtJNtGRrT3GIosbN7iP",
        job: store.state.job,
        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 = store.state === null || store.state === void 0 ? void 0 : store.state.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,
        job: store.state.job,
        templateId,
      },
    });
    this.modalEl.present();
  }
  async fetchJob() {
    if (!this.jobId)
      return;
    this.fireenjinFetch.emit({
      endpoint: "findJob",
      cacheKey: "jobs",
      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) {
    var _a, _b;
    this.efileLoading = true;
    this.fireenjinSubmit.emit({
      endpoint: "generatePdf",
      data: {
        filename,
        jobId: this.jobId,
        templateId,
        invoiceType: ((_b = (_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.serviceTypes) === null || _b === void 0 ? void 0 : _b[0]) || "water",
      },
    });
  }
  formatUSD(amount) {
    const formatter = new Intl.NumberFormat("en-US", {
      style: "currency",
      currency: "USD",
      minimumFractionDigits: 2,
    });
    return formatter.format(amount ? amount : 0);
  }
  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;
    const 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: JSON.parse(JSON.stringify(store.state.job)),
      },
    };
    console.log(data);
    this.fireenjinSubmit.emit({
      endpoint: "sendTemplateEmail",
      data,
    });
  }
  getData() {
    this.fireenjinTrigger.emit({
      name: "subscribe",
      payload: {
        collection: "jobs",
        id: this.jobId,
        callback: () => {
          this.fetchJob();
          this.getActivityFeed();
        },
      },
    });
    this.fetchJob();
    this.fetchPayModels();
  }
  async componentWillLoad() {
    store.state.job = await getJobFromCache(this.jobId);
  }
  getActivityFeed() {
    var _a;
    console.log(store.state);
    store.state.feedFetchData = {
      myFeed: (_a = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _a === void 0 ? void 0 : _a.uid,
      jobId: this.jobId,
    };
  }
  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, _15, _16, _17, _18, _19, _20, _21, _22, _23;
    const selectedWeather = (_d = (_c = (_b = (_a = store.state === null || store.state === void 0 ? void 0 : store.state.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;
    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", null, index.h("floodteam-title-bar", null, ((_e = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _e === void 0 ? void 0 : _e.title) || "???"))), index.h("ion-row", null, index.h("ion-col", { class: "ion-align-self-center" }, index.h("flooteam-chip-bar", null, index.h("floodteam-select-job-service-types", { jobId: this.jobId, value: ((_f = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _f === void 0 ? void 0 : _f.serviceTypes) || [] }), index.h("floodteam-select-status", { jobId: this.jobId, value: (_g = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _g === void 0 ? void 0 : _g.status }), ((_h = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _h === void 0 ? void 0 : _h.status) === "lost" && (index.h("floodteam-select-lost-reason", { jobId: this.jobId, value: (_j = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _j === void 0 ? void 0 : _j.lostReason })), index.h("floodteam-select-location", { jobId: this.jobId, value: (_l = (_k = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _k === void 0 ? void 0 : _k.location) === null || _l === void 0 ? void 0 : _l.id }), index.h("ion-router-link", { href: `geo:${(_o = (_m = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _m === void 0 ? void 0 : _m.address) === null || _o === void 0 ? void 0 : _o.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: `/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"))), ((_p = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _p === void 0 ? void 0 : _p.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")))), isAdmin.isAdmin() && (index.h("ion-chip", { onClick: () => this.openJobEdit("payment") }, index.h("ion-icon", { class: "ft-icon-style", name: "logo-usd" }), index.h("ion-label", null, "Owed ", this.formatUSD(((_q = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _q === void 0 ? void 0 : _q.amountOwed) || 0)))), index.h("ion-router-link", { href: `/pay/${this.jobId}` }, index.h("ion-chip", null, index.h("ion-icon", { class: "ft-icon-style", name: "cash" }), 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 ${((_r = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _r === void 0 ? void 0 : _r.category) || 0} - ${((_s = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _s === void 0 ? void 0 : _s.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: ((_u = (_t = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _t === void 0 ? void 0 : _t.sites) === null || _u === void 0 ? void 0 : _u.length) ? "0px" : "8px",
          paddingTop: ((_w = (_v = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _v === void 0 ? void 0 : _v.sites) === null || _w === void 0 ? void 0 : _w.length) ? "0px" : "8px",
        } }, ((_y = (_x = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _x === void 0 ? void 0 : _x.sites) === null || _y === void 0 ? void 0 : _y.length) ? ((_z = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _z === void 0 ? void 0 : _z.sites.map((site) => (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"))), ((_1 = (_0 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _0 === void 0 ? void 0 : _0.readings) === null || _1 === void 0 ? void 0 : _1.length) ? (index.h("fireenjin-graph", { type: "line", labels: (((_2 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _2 === void 0 ? void 0 : _2.readings)
          ? (_3 = store.state.job) === null || _3 === void 0 ? void 0 : _3.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, ((_5 = (_4 = selectedWeather === null || selectedWeather === void 0 ? void 0 : selectedWeather.conditions) === null || _4 === void 0 ? void 0 : _4[0]) === null || _5 === void 0 ? void 0 : _5.icon) && (index.h("ion-img", { style: {
          height: "50px",
          width: "50px",
          marginRight: "0",
        }, slot: "start", src: `/assets/images/${((_7 = (_6 = selectedWeather === null || selectedWeather === void 0 ? void 0 : selectedWeather.conditions) === null || _6 === void 0 ? void 0 : _6[0]) === null || _7 === void 0 ? void 0 : _7.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" } }, (_9 = (_8 = selectedWeather === null || selectedWeather === void 0 ? void 0 : selectedWeather.conditions) === null || _8 === void 0 ? void 0 : _8[0]) === null || _9 === void 0 ? void 0 : _9.description)))), (((_10 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _10 === void 0 ? void 0 : _10.sites) ? (_11 = store.state.job) === null || _11 === void 0 ? void 0 : _11.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 = store.state === null || store.state === void 0 ? void 0 : store.state.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 = store.state === null || store.state === void 0 ? void 0 : store.state.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) }, ((_13 = (_12 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _12 === void 0 ? void 0 : _12.users) === null || _13 === void 0 ? void 0 : _13.length) ? ((_14 = store.state.job) === null || _14 === void 0 ? void 0 : _14.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 = store.state === null || store.state === void 0 ? void 0 : store.state.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"), ((_15 = this.preparingEfiles) === null || _15 === void 0 ? void 0 : _15.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", ((_16 = this.preparingEfiles) === null || _16 === void 0 ? void 0 : _16.length) || 0))) : (index.h("ion-text", { color: ((_18 = (_17 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _17 === void 0 ? void 0 : _17.efiles) === null || _18 === void 0 ? void 0 : _18.length) > 0
          ? "primary"
          : "medium", slot: "end" }, ((_20 = (_19 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _19 === void 0 ? void 0 : _19.efiles) === null || _20 === void 0 ? void 0 : _20.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"))), ((_21 = this.efiles) === null || _21 === void 0 ? void 0 : _21.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.templates || [])
        .filter((template) => {
        var _a, _b, _c, _d, _e;
        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")) ||
            ((_e = (_d = (_c = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _c === void 0 ? void 0 : _c.serviceTypes) === null || _d === void 0 ? void 0 : _d.some) === null || _e === void 0 ? void 0 : _e.call(_d, (serviceType) => { var _a, _b; return (_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, serviceType); })));
      })
        .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 = store.state === null || store.state === void 0 ? void 0 : store.state.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, index.h("floodteam-title-bar", { back: "/jobs", disableUnderline: true }, index.h("ion-breadcrumbs", null, index.h("ion-breadcrumb", { href: "/jobs" }, index.h("ion-icon", { class: "ft-icon-style", slot: "start", name: "water" }), "Jobs"), index.h("ion-breadcrumb", { href: "#", onClick: () => {
          var _a;
          return this.fireenjinTrigger.emit({
            name: "pin",
            payload: {
              icon: "water",
              href: `/jobs/${this.jobId}`,
              name: ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.title) || "New Job",
            },
          });
        } }, index.h("ion-icon", { color: ((_22 = ((store.state === null || store.state === void 0 ? void 0 : store.state.pins) || [])
          .map((pin) => pin === null || pin === void 0 ? void 0 : pin.href)) === null || _22 === void 0 ? void 0 : _22.includes(`/jobs/${this.jobId}`))
          ? "primary"
          : null, slot: "start", name: "pin" }), ((_23 = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _23 === void 0 ? void 0 : _23.title) || "???")), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { color: "primary", fill: "solid", onClick: () => this.openJobEdit() }, "Edit")))),
    ];
  }
  get jobPageEl() { return index.getElement(this); }
};
AppJob.style = appJobCss;

exports.app_job = AppJob;
