import * as jsonLogic from "json-logic-js";
import { Component, Event, h, Listen, Prop, } from "@stencil/core";
import state from "../../../store";
export class PopoverSiteService {
  constructor() {
    this.service = {};
    this.scopeToServiceMap = {};
    this.sites = [];
  }
  async onSuccess(event) {
    var _a;
    if (["editScopeService", "addScopeService", "deleteScopeService"].includes((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint)) {
      this.accordionEl.requestAccordionToggle(null, false);
    }
  }
  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;
    const isGeneral = ((_c = (_b = (_a = this.service) === null || _a === void 0 ? void 0 : _a.tab) === null || _b === void 0 ? void 0 : _b.toLowerCase) === null || _c === void 0 ? void 0 : _c.call(_b)) === "general";
    return [
      h("ion-content", null,
        h("ion-item-divider", null, ((_d = this.service) === null || _d === void 0 ? void 0 : _d.name) || "No Name Given"),
        h("ion-accordion-group", { ref: (el) => (this.accordionEl = el), value: this.currentExpanded }, isGeneral ? (h("floodteam-form-site-service", { isGeneral: true, serviceId: (_e = this.service) === null || _e === void 0 ? void 0 : _e.id, jobId: this.jobId, siteServiceId: ((_h = (_f = this.scopeToServiceMap) === null || _f === void 0 ? void 0 : _f[`${this.jobId}-${(_g = this.service) === null || _g === void 0 ? void 0 : _g.id}`]) === null || _h === void 0 ? void 0 : _h.id) || null, amount: ((_l = (_j = this.scopeToServiceMap) === null || _j === void 0 ? void 0 : _j[`${this.jobId}-${(_k = this.service) === null || _k === void 0 ? void 0 : _k.id}`]) === null || _l === void 0 ? void 0 : _l.amount) ||
            ((_p = (_m = jsonLogic === null || jsonLogic === void 0 ? void 0 : jsonLogic.apply) === null || _m === void 0 ? void 0 : _m.call(jsonLogic, (_o = this.service) === null || _o === void 0 ? void 0 : _o.autofill, {
              service: this.service,
              job: state === null || state === void 0 ? void 0 : state.job,
            })) === null || _p === void 0 ? void 0 : _p.amount) ||
            0, price: ((_s = (_q = this.scopeToServiceMap) === null || _q === void 0 ? void 0 : _q[`${this.jobId}-${(_r = this.service) === null || _r === void 0 ? void 0 : _r.id}`]) === null || _s === void 0 ? void 0 : _s.price) ||
            ((_v = (_t = jsonLogic === null || jsonLogic === void 0 ? void 0 : jsonLogic.apply) === null || _t === void 0 ? void 0 : _t.call(jsonLogic, (_u = this.service) === null || _u === void 0 ? void 0 : _u.autofill, {
              service: this.service,
              job: state === null || state === void 0 ? void 0 : state.job,
            })) === null || _v === void 0 ? void 0 : _v.price) ||
            ((_x = (_w = this.service) === null || _w === void 0 ? void 0 : _w.prices) === null || _x === void 0 ? void 0 : _x.default), quantity: ((_0 = (_y = this.scopeToServiceMap) === null || _y === void 0 ? void 0 : _y[`${this.jobId}-${(_z = this.service) === null || _z === void 0 ? void 0 : _z.id}`]) === null || _0 === void 0 ? void 0 : _0.quantity) ||
            ((_3 = (_1 = jsonLogic === null || jsonLogic === void 0 ? void 0 : jsonLogic.apply) === null || _1 === void 0 ? void 0 : _1.call(jsonLogic, (_2 = this.service) === null || _2 === void 0 ? void 0 : _2.autofill, {
              service: this.service,
              job: state === null || state === void 0 ? void 0 : state.job,
            })) === null || _3 === void 0 ? void 0 : _3.quantity) ||
            1, unit: (_4 = this.service) === null || _4 === void 0 ? void 0 : _4.unit })) : ((this.sites || [])
          .sort((a, b) => ((a === null || a === void 0 ? void 0 : a.name) > (b === null || b === void 0 ? void 0 : b.name) ? 1 : -1))
          .map((site) => {
          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;
          return (h("floodteam-form-site-service", { siteId: site === null || site === void 0 ? void 0 : site.id, jobId: this.jobId, serviceId: (_a = this.service) === null || _a === void 0 ? void 0 : _a.id, siteServiceId: ((_d = (_b = this.scopeToServiceMap) === null || _b === void 0 ? void 0 : _b[`${site === null || site === void 0 ? void 0 : site.id}-${(_c = this.service) === null || _c === void 0 ? void 0 : _c.id}`]) === null || _d === void 0 ? void 0 : _d.id) || null, amount: ((_g = (_e = this.scopeToServiceMap) === null || _e === void 0 ? void 0 : _e[`${site === null || site === void 0 ? void 0 : site.id}-${(_f = this.service) === null || _f === void 0 ? void 0 : _f.id}`]) === null || _g === void 0 ? void 0 : _g.amount) ||
              ((_k = (_h = jsonLogic === null || jsonLogic === void 0 ? void 0 : jsonLogic.apply) === null || _h === void 0 ? void 0 : _h.call(jsonLogic, (_j = this.service) === null || _j === void 0 ? void 0 : _j.autofill, {
                service: this.service,
                job: state === null || state === void 0 ? void 0 : state.job,
              })) === null || _k === void 0 ? void 0 : _k.amount) ||
              0, price: ((_o = (_l = this.scopeToServiceMap) === null || _l === void 0 ? void 0 : _l[`${site === null || site === void 0 ? void 0 : site.id}-${(_m = this.service) === null || _m === void 0 ? void 0 : _m.id}`]) === null || _o === void 0 ? void 0 : _o.price) ||
              ((_r = (_p = jsonLogic === null || jsonLogic === void 0 ? void 0 : jsonLogic.apply) === null || _p === void 0 ? void 0 : _p.call(jsonLogic, (_q = this.service) === null || _q === void 0 ? void 0 : _q.autofill, {
                service: this.service,
                job: state === null || state === void 0 ? void 0 : state.job,
              })) === null || _r === void 0 ? void 0 : _r.price) ||
              ((_t = (_s = this.service) === null || _s === void 0 ? void 0 : _s.prices) === null || _t === void 0 ? void 0 : _t.default), quantity: ((_w = (_u = this.scopeToServiceMap) === null || _u === void 0 ? void 0 : _u[`${site === null || site === void 0 ? void 0 : site.id}-${(_v = this.service) === null || _v === void 0 ? void 0 : _v.id}`]) === null || _w === void 0 ? void 0 : _w.quantity) ||
              ((_z = (_x = jsonLogic === null || jsonLogic === void 0 ? void 0 : jsonLogic.apply) === null || _x === void 0 ? void 0 : _x.call(jsonLogic, (_y = this.service) === null || _y === void 0 ? void 0 : _y.autofill, {
                service: this.service,
                job: state === null || state === void 0 ? void 0 : state.job,
              })) === null || _z === void 0 ? void 0 : _z.quantity) ||
              1, name: site === null || site === void 0 ? void 0 : site.name, unit: (_0 = this.service) === null || _0 === void 0 ? void 0 : _0.unit }));
        })))),
    ];
  }
  static get is() { return "popover-site-service"; }
  static get originalStyleUrls() { return {
    "$": ["popover-site-service.css"]
  }; }
  static get styleUrls() { return {
    "$": ["popover-site-service.css"]
  }; }
  static get properties() { return {
    "service": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Service",
        "resolved": "{ __typename?: \"Service\"; autofill?: any; category?: string; code?: string; costs?: any; createdAt?: string; createdBy?: User; description?: string; group?: string; id?: string; name?: string; prices?: any; referencePage?: string; rental?: string; smartScoping?: any; tab?: string; type?: string; unit?: string; updatedAt?: string; updatedBy?: User; }",
        "references": {
          "Service": {
            "location": "import",
            "path": "../../../sdk"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "{}"
    },
    "scopeToServiceMap": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "{\n    [parentIdServiceId: string]: ScopeService;\n  }",
        "resolved": "{ [parentIdServiceId: string]: ScopeService; }",
        "references": {
          "ScopeService": {
            "location": "import",
            "path": "../../../sdk"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "{}"
    },
    "sites": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Site[]",
        "resolved": "Site[]",
        "references": {
          "Site": {
            "location": "import",
            "path": "../../../sdk"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "[]"
    },
    "jobId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "job-id",
      "reflect": false
    },
    "currentExpanded": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "current-expanded",
      "reflect": false
    }
  }; }
  static get events() { return [{
      "method": "fireenjinFetch",
      "name": "fireenjinFetch",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get listeners() { return [{
      "name": "fireenjinSuccess",
      "method": "onSuccess",
      "target": "body",
      "capture": false,
      "passive": false
    }]; }
}
//# sourceMappingURL=popover-site-service.js.map