import { h, } from "@stencil/core";
import getLocationOptions from "../../../helpers/getLocationOptions";
import state from "../../../store";
export class SelectLocation {
  constructor() {
    this.name = "status";
    this.value = undefined;
    this.jobId = undefined;
    this.disabled = false;
  }
  onTrigger(event) {
    var _a, _b, _c, _d;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.name) !== "select" ||
      this.selectLocationEl !== ((_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.el))
      return;
    this.value = ((_d = (_c = event === null || event === void 0 ? void 0 : event.detail) === null || _c === void 0 ? void 0 : _c.payload) === null || _d === void 0 ? void 0 : _d.value) || null;
    this.fireenjinSubmit.emit({
      endpoint: "editJob",
      id: this.jobId,
      data: {
        locationId: this.value,
      },
    });
  }
  render() {
    var _a;
    return (h("ion-chip", { onClick: (event) => {
        if (this.disabled)
          return;
        event.preventDefault();
        event.stopPropagation();
        this.fireenjinTrigger.emit({
          event,
          name: "filter",
          type: "location",
          el: this.selectLocationEl,
          payload: {
            control: {
              name: "location",
              label: "Location",
              icon: "business",
              options: getLocationOptions(),
              value: this.value,
            },
          },
        });
      } }, h("ion-icon", { name: "business", class: "ft-icon-style" }), h("ion-label", { class: "ion-text-capitalize" }, ((_a = ((state === null || state === void 0 ? void 0 : state.locations) || []).find((location) => (location === null || location === void 0 ? void 0 : location.id) === this.value)) === null || _a === void 0 ? void 0 : _a.name) || "No Location Set")));
  }
  static get is() { return "floodteam-select-location"; }
  static get properties() {
    return {
      "name": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "name",
        "reflect": false,
        "defaultValue": "\"status\""
      },
      "value": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "value",
        "reflect": false
      },
      "jobId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "job-id",
        "reflect": false
      },
      "disabled": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "disabled",
        "reflect": false,
        "defaultValue": "false"
      }
    };
  }
  static get events() {
    return [{
        "method": "fireenjinTrigger",
        "name": "fireenjinTrigger",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "FireEnjinTriggerInput",
          "resolved": "FireEnjinTriggerInput",
          "references": {
            "FireEnjinTriggerInput": {
              "location": "import",
              "path": "@fireenjin/sdk"
            }
          }
        }
      }, {
        "method": "fireenjinSubmit",
        "name": "fireenjinSubmit",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "FireEnjinSubmitEvent",
          "resolved": "FireEnjinSubmitEvent",
          "references": {
            "FireEnjinSubmitEvent": {
              "location": "import",
              "path": "@fireenjin/sdk"
            }
          }
        }
      }];
  }
  static get elementRef() { return "selectLocationEl"; }
  static get listeners() {
    return [{
        "name": "fireenjinTrigger",
        "method": "onTrigger",
        "target": "document",
        "capture": false,
        "passive": false
      }];
  }
}
