import { r as registerInstance, d as createEvent, B as Build, h } from './index-33e43734.js';
import { s as state } from './store-d3327c94.js';
import { g as getStatusOptions } from './getStatusOptions-bebaf81a.js';
import { a as isInternalTeam, i as isAdmin } from './isInternalTeam-18a7b452.js';
import './index-91eb4513.js';
import './getCache-f7c123d8.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) {
    registerInstance(this, hostRef);
    this.fireenjinTrigger = 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 (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    this.fetchData = {
      status: this.userId
        ? null
        : ((_a = state === null || state === void 0 ? void 0 : 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 = state === null || state === void 0 ? void 0 : state.profile) === null || _b === void 0 ? void 0 : _b.id,
      locationId: this.userId
        ? null
        : ((_c = state === null || state === void 0 ? void 0 : state.claims) === null || _c === void 0 ? void 0 : _c.tester) && ((_e = (_d = state === null || state === void 0 ? void 0 : state.profile) === null || _d === void 0 ? void 0 : _d.location) === null || _e === void 0 ? void 0 : _e.id)
          ? state.profile.location.id
          : null,
    };
  }
  componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : 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 [
      h("ion-content", { class: "ion-padding" }, h("floodteam-title-bar", null, h("ion-router-link", { href: "/jobs" }, "Jobs"), h("ion-buttons", { slot: "end" }, h("ion-button", { fill: "solid", color: "primary", href: "/jobs/refer" }, "Add"), h("ion-button", { onClick: () => (this.showMap = !this.showMap) }, h("ion-icon", { slot: "icon-only", name: "map" })))), this.showMap && (h("fireenjin-map", { googleMapsKey: (_c = (_b = state === null || state === void 0 ? void 0 : 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 })), h("div", { class: "ion-padding" }, h("fireenjin-search-bar", { paginationEl: this.paginationEl, filters: [
          {
            name: "status",
            label: "Status",
            icon: "help-circle",
            multiple: true,
            options: getStatusOptions(),
            value: this.fetchData.status,
          },
          {
            name: "tags",
            label: "Tags",
            icon: "pricetags",
            multiple: true,
            options: [
              {
                label: "Imported",
                value: "imported",
              },
            ],
          },
          ...(isInternalTeam()
            ? [
              {
                name: "userId",
                label: "Tied To",
                icon: "enter",
                value: (_d = state === null || state === void 0 ? void 0 : state.profile) === null || _d === void 0 ? void 0 : _d.id,
                options: this.userId
                  ? [
                    {
                      label: "This User",
                      value: this.userId,
                    },
                  ]
                  : [
                    {
                      label: "Me",
                      value: (_e = state === null || state === void 0 ? void 0 : state.profile) === null || _e === void 0 ? void 0 : _e.id,
                    },
                    {
                      label: "My Location",
                      value: null,
                    },
                  ],
              },
            ]
            : []),
          ...(isAdmin()
            ? [
              {
                name: "locationId",
                label: "Location",
                icon: "business",
                options: ((_f = state === null || state === void 0 ? void 0 : state.locations) === null || _f === void 0 ? void 0 : _f.length)
                  ? state.locations.map((location) => ({
                    label: location.name,
                    value: location.id,
                  }))
                  : [],
                value: ((_g = state === null || state === void 0 ? void 0 : state.claims) === null || _g === void 0 ? void 0 : _g.tester) && ((_j = (_h = state === null || state === void 0 ? void 0 : state.profile) === null || _h === void 0 ? void 0 : _h.location) === null || _j === void 0 ? void 0 : _j.id)
                  ? state.profile.location.id
                  : null,
              },
            ]
            : []),
        ] })), h("fireenjin-pagination", { ref: (el) => (this.paginationEl = el), disableVirtualScroll: true, listEl: ({ result: job }) => (h("floodteam-item-job", { job: job })), endpoint: "listJobs", limit: 24, fetchParams: { withPayables: true }, fetchData: this.fetchData, resultsKey: "jobs", query: this.query, removeDuplicates: true })),
      h("floodteam-navigation-footer", null, isAdmin() && (h("fireenjin-chip-bar", null, h("ion-chip", { onClick: () => this.fireenjinTrigger.emit({
          name: "import",
          type: "jobs",
        }) }, h("ion-icon", { class: "ft-icon-style", name: "cloud-upload" }), h("ion-label", null, "Import from CSV")), 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,
              });
            }),
          });
        } }, h("ion-icon", { class: "ft-icon-style", name: "cloud-download" }), h("ion-label", null, "Export to CSV"))))),
    ];
  }
};
AppJobList.style = appJobListCss;

export { AppJobList as app_job_list };

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