'use strict';

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

const index = require('./index-e0385008.js');
const store = require('./store-8d1de66f.js');
const getStatusOptions = require('./getStatusOptions-64f3eefc.js');
const isInternalTeam = require('./isInternalTeam-f0d17c4a.js');
const isAdmin = require('./isAdmin-536e5c3e.js');
require('./index-37fc02d8.js');
require('./getHandlebarsHelpers-1b368c8a.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-ba857994.js');
require('./localforage-af1b8c0e.js');

const appDashboardCss = "app-dashboard floodteam-activity-feed .feed-header h3{color:#fff}app-dashboard fireenjin-map{background:var(--ion-color-light-shade);border-radius:15px;display:block;margin:20px auto 0;overflow:hidden;max-width:calc(100% - 30px)}app-dashboard h1 a{padding:0}app-dashboard ion-grid{margin-top:0;padding-top:0}app-dashboard .title-divider{display:flex;justify-content:space-between;align-items:baseline}app-dashboard .title-divider>span{display:flex;align-items:baseline;padding-inline-end:5px;margin-top:auto}app-dashboard .title-divider>span>ion-button{margin-right:5px}";

const AppDashboard = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.db = undefined;
    this.groupBy = "week";
    this.unreadCount = 0;
    this.selectedStatuses = ["book", "evaluate", "claim", "mitigate", "monitor", "review"];
    this.totals = {};
    this.options = undefined;
    this.timeframe = undefined;
    this.showMap = false;
  }
  async onTrigger(event) {
    var _a, _b, _c, _d, _e;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.name) === "set" &&
      ((_c = (_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.payload) === null || _c === void 0 ? void 0 : _c.name) === "status") {
      this.selectedStatuses = ((_e = (_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.value) || [];
      try {
        await this.mapEl.clearMarkers();
      }
      catch (e) {
        console.log("Error clearing marker");
      }
    }
  }
  async onChange(event) {
    var _a, _b, _c, _d;
    console.log(event);
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "groupBy") {
      this.groupBy = (_b = event === null || event === void 0 ? void 0 : event.target) === null || _b === void 0 ? void 0 : _b.value;
    }
    else if (((_c = event === null || event === void 0 ? void 0 : event.target) === null || _c === void 0 ? void 0 : _c.name) === "timeframe") {
      this.timeframe = (_d = event === null || event === void 0 ? void 0 : event.target) === null || _d === void 0 ? void 0 : _d.value;
    }
  }
  filterJobsByStatus(jobs, statuses) {
    return jobs.filter((job) => statuses.includes(job === null || job === void 0 ? void 0 : job.status));
  }
  getActivityFeed() {
    var _a;
    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,
    };
  }
  async componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.options = await this.db.list("/totals/1mFFMb6HglD2asYliHDm/jobs", null);
    this.getActivityFeed();
  }
  render() {
    var _a, _b;
    const myJobs = this.filterJobsByStatus(Object.values((store.state === null || store.state === void 0 ? void 0 : store.state.jobs) || {}).filter((job) => { var _a, _b, _c; return (_b = (_a = job === null || job === void 0 ? void 0 : job.userIds) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _c === void 0 ? void 0 : _c.uid); }), this.selectedStatuses);
    return [
      index.h("ion-content", { class: "truck-background ion-padding" }, isInternalTeam.isInternalTeam() && isAdmin.isAdmin() && (index.h("div", { id: "performance" }, index.h("floodteam-total-graph", { groupBy: this.groupBy, totallerId: "1mFFMb6HglD2asYliHDm" }), index.h("floodteam-totaller-card-list", { groupBy: this.groupBy, totallerIds: ["1mFFMb6HglD2asYliHDm"] }))), index.h("article", { id: "myjobs" }, this.showMap && (index.h("fireenjin-map", { googleMapsKey: (_b = (_a = store.state === null || store.state === void 0 ? void 0 : store.state.config) === null || _a === void 0 ? void 0 : _a.firebase) === null || _b === void 0 ? void 0 : _b.apiKey, ref: (el) => (this.mapEl = el), markers: myJobs.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,
            },
          });
        }) })), index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/jobs" }, "My Jobs", " ", index.h("ion-badge", { style: { borderRadius: "15px" } }, index.h("small", null, myJobs.length || 0))), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { onClick: () => (this.showMap = !this.showMap), style: {
          "--color": "rgba(var(--ion-text-color-rgb), 0.5)",
        }, fill: "outline", size: "small" }, "Map", index.h("ion-icon", { slot: "end", name: "map" })), index.h("ion-button", { style: {
          "--color": "rgba(var(--ion-text-color-rgb), 0.5)",
        }, onClick: (event) => this.fireenjinTrigger.emit({
          event,
          name: "filter",
          type: "status",
          payload: {
            control: {
              name: "status",
              label: "Status",
              icon: "help-circle",
              multiple: true,
              options: getStatusOptions.getStatusOptions(),
              value: this.selectedStatuses,
            },
          },
        }), fill: "outline", size: "small" }, "Filter", index.h("ion-icon", { slot: "end", name: "funnel" })))), index.h("ion-card", { class: "list-card" }, index.h("ion-list", null, myJobs.map((job) => (index.h("floodteam-item-job", { job: job }))))))),
      index.h("floodteam-navigation-footer", null),
    ];
  }
};
AppDashboard.style = appDashboardCss;

exports.app_dashboard = AppDashboard;
