'use strict';

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

const index = require('./index-fd2bbf0b.js');
const store = require('./store-9988299d.js');
const getStatusOptions = require('./getStatusOptions-c4baa7ce.js');
const isInternalTeam = require('./isInternalTeam-69b6b147.js');
require('./index-81aa1bcb.js');
require('./getCache-901b0f67.js');

const appJobListCss = "app-job-list fireenjin-map{background:var(--ion-color-light-shade);border-radius:15px;display:block;margin:10px auto 0;overflow:hidden;max-width:calc(100% - 30px)}app-job-list #pin-bar .pins{top:112px !important}";

let AppJobList = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.user = {};
    this.jobs = [];
    this.selectedIds = [];
    this.selectedJobs = [];
    this.selectAll = false;
    this.fetchData = {};
    this.showMap = false;
  }
  onSearchInput(event) {
    this.query = event.target.value;
  }
  async onSuccess(event) {
    var _a, _b;
    if (["addJob", "editJob"].includes((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint))
      setTimeout(() => this.paginationEl.getResults(), 200);
    if (((_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.endpoint) !== "listJobs")
      return;
    setTimeout(() => {
      var _a;
      this.jobs = ((_a = this.paginationEl) === null || _a === void 0 ? void 0 : _a.results) || [];
    }, 200);
  }
  toggleSelect(event, job) {
    event.stopPropagation();
    event.preventDefault();
    this.selectedJobs = this.selectedJobs.includes(job)
      ? this.selectedJobs.filter((selectedJob) => job.id !== selectedJob.id)
      : [...new Set([...this.selectedJobs, job])];
    this.selectedIds = this.selectedIds.includes(job.id)
      ? this.selectedIds.filter((selectedId) => job.id !== selectedId)
      : [...new Set([...this.selectedIds, job.id])];
  }
  toggleSelectAll() {
    var _a, _b, _c;
    if ((_a = this.selectedIds) === null || _a === void 0 ? void 0 : _a.length) {
      this.selectedJobs = [];
      this.selectedIds = [];
      this.selectAll = false;
    }
    else {
      if ((_c = (_b = this.paginationEl) === null || _b === void 0 ? void 0 : _b.results) === null || _c === void 0 ? void 0 : _c.length) {
        this.selectedJobs = this.paginationEl.results;
        this.selectedIds = this.paginationEl.results.map((result) => result.id);
      }
    }
  }
  componentWillLoad() {
    var _a, _b, _c, _d, _e;
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.fetchData = {
      status: this.userId
        ? null
        : ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.claims) === null || _a === void 0 ? void 0 : _a.tester)
          ? ["book", "evaluate", "claim", "mitigate", "monitor", "review"]
          : [
            "book",
            "evaluate",
            "claim",
            "mitigate",
            "monitor",
            "review",
            "complete",
            "lost",
          ],
      userId: this.userId ? this.userId : (_b = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _b === void 0 ? void 0 : _b.id,
      locationId: this.userId
        ? null
        : ((_c = store.state === null || store.state === void 0 ? void 0 : store.state.claims) === null || _c === void 0 ? void 0 : _c.tester) && ((_e = (_d = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _d === void 0 ? void 0 : _d.location) === null || _e === void 0 ? void 0 : _e.id)
          ? store.state.profile.location.id
          : null,
    };
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j;
    const markers = (((_a = this.jobs) === null || _a === void 0 ? void 0 : _a.length) ? this.jobs : []).map((job) => {
      var _a, _b;
      return ({
        payload: { job },
        name: job === null || job === void 0 ? void 0 : job.title,
        icon: null,
        position: {
          lat: (_a = job === null || job === void 0 ? void 0 : job.address) === null || _a === void 0 ? void 0 : _a.lat,
          lng: (_b = job === null || job === void 0 ? void 0 : job.address) === null || _b === void 0 ? void 0 : _b.lng,
        },
      });
    });
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/jobs" }, "Jobs"), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { fill: "solid", color: "primary", href: "/jobs/refer" }, "Add"), index.h("ion-button", { onClick: () => (this.showMap = !this.showMap) }, index.h("ion-icon", { slot: "icon-only", name: "map" })))), this.showMap && (index.h("fireenjin-map", { googleMapsKey: (_c = (_b = store.state === null || store.state === void 0 ? void 0 : store.state.config) === null || _b === void 0 ? void 0 : _b.firebase) === null || _c === void 0 ? void 0 : _c.apiKey, ref: (el) => (this.mapEl = el), markers: markers })), index.h("div", { class: "ion-padding" }, index.h("fireenjin-search-bar", { paginationEl: this.paginationEl, filters: [
          {
            name: "status",
            label: "Status",
            icon: "help-circle",
            multiple: true,
            options: getStatusOptions.getStatusOptions(),
            value: this.fetchData.status,
          },
          {
            name: "tags",
            label: "Tags",
            icon: "pricetags",
            multiple: true,
            options: [
              {
                label: "Imported",
                value: "imported",
              },
            ],
          },
          ...(isInternalTeam.isInternalTeam()
            ? [
              {
                name: "userId",
                label: "Tied To",
                icon: "enter",
                value: (_d = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _d === void 0 ? void 0 : _d.id,
                options: this.userId
                  ? [
                    {
                      label: "This User",
                      value: this.userId,
                    },
                  ]
                  : [
                    {
                      label: "Me",
                      value: (_e = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _e === void 0 ? void 0 : _e.id,
                    },
                    {
                      label: "My Location",
                      value: null,
                    },
                  ],
              },
            ]
            : []),
          ...(isInternalTeam.isAdmin()
            ? [
              {
                name: "locationId",
                label: "Location",
                icon: "business",
                options: ((_f = store.state === null || store.state === void 0 ? void 0 : store.state.locations) === null || _f === void 0 ? void 0 : _f.length)
                  ? store.state.locations.map((location) => ({
                    label: location.name,
                    value: location.id,
                  }))
                  : [],
                value: ((_g = store.state === null || store.state === void 0 ? void 0 : store.state.claims) === null || _g === void 0 ? void 0 : _g.tester) && ((_j = (_h = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _h === void 0 ? void 0 : _h.location) === null || _j === void 0 ? void 0 : _j.id)
                  ? store.state.profile.location.id
                  : null,
              },
            ]
            : []),
        ] })), index.h("fireenjin-pagination", { ref: (el) => (this.paginationEl = el), disableVirtualScroll: true, listEl: ({ result: job }) => (index.h("floodteam-item-job", { job: job })), endpoint: "listJobs", limit: 24, fetchParams: { withPayables: true }, fetchData: this.fetchData, resultsKey: "jobs", query: this.query, removeDuplicates: true })),
      index.h("floodteam-navigation-footer", null, isInternalTeam.isAdmin() && (index.h("fireenjin-chip-bar", null, index.h("ion-chip", { onClick: () => this.fireenjinTrigger.emit({
          name: "import",
          type: "jobs",
        }) }, index.h("ion-icon", { class: "ft-icon-style", name: "cloud-upload" }), index.h("ion-label", null, "Import from CSV")), index.h("ion-chip", { onClick: () => {
          this.fireenjinTrigger.emit({
            name: "export",
            payload: (this.jobs || []).map((job) => {
              var _a;
              return ({
                id: (job === null || job === void 0 ? void 0 : job.id) || null,
                title: (job === null || job === void 0 ? void 0 : job.title) || null,
                address: ((_a = job === null || job === void 0 ? void 0 : job.address) === null || _a === void 0 ? void 0 : _a.full) || null,
              });
            }),
          });
        } }, index.h("ion-icon", { class: "ft-icon-style", name: "cloud-download" }), index.h("ion-label", null, "Export to CSV"))))),
    ];
  }
};
AppJobList.style = appJobListCss;

exports.app_job_list = AppJobList;

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