import { Component, Listen, Prop, h } from "@stencil/core";
import { toastController } from "@ionic/core";
import state from "../../../store";
export class ModalEditUsers {
  constructor() {
    this.users = [];
  }
  onReset(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "bulkUpdateUsers") {
      const sendEmailModalEl = document.querySelector("ion-modal.modal-edit-users");
      if (sendEmailModalEl === null || sendEmailModalEl === void 0 ? void 0 : sendEmailModalEl.dismiss) {
        sendEmailModalEl.dismiss();
      }
    }
  }
  async onSuccess(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "bulkUpdateUsers") {
      const sendEmailModalEl = document.querySelector("ion-modal.modal-edit-users");
      if (sendEmailModalEl === null || sendEmailModalEl === void 0 ? void 0 : sendEmailModalEl.dismiss) {
        await sendEmailModalEl.dismiss();
        this.presentToast();
      }
    }
  }
  async presentToast() {
    var _a;
    const toast = await toastController.create({
      message: `Updated ${(_a = this.users) === null || _a === void 0 ? void 0 : _a.length} users.`,
      duration: 2000,
    });
    toast.present();
  }
  render() {
    return (h("ion-content", null,
      h("fireenjin-form", { class: "ion-padding", endpoint: "bulkUpdateUsers", beforeSubmit: async (data) => ({
          data,
          userIds: this.users.map((user) => user.id),
        }), disableLoader: true, resetButtonColor: "medium" },
        h("fireenjin-select", { name: "companyId", label: "Company", labelPosition: "stacked", endpoint: "listCompanies", limit: 100, dataPropsMap: {
            companies: "results",
          } }),
        h("fireenjin-select", { label: "Location", name: "locationId", options: ((state === null || state === void 0 ? void 0 : state.locations) || []).map((location) => ({
            label: (location === null || location === void 0 ? void 0 : location.name) || "No Location Name",
            value: location === null || location === void 0 ? void 0 : location.id,
          })) }),
        h("fireenjin-select-tags", { name: "tags", label: "Tags", labelPosition: "stacked", allowAdding: true, options: [
            {
              label: "Important",
              value: "important",
            },
          ] }))));
  }
  static get is() { return "modal-edit-users"; }
  static get originalStyleUrls() { return {
    "$": ["modal-edit-users.css"]
  }; }
  static get styleUrls() { return {
    "$": ["modal-edit-users.css"]
  }; }
  static get properties() { return {
    "users": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Partial<User>[]",
        "resolved": "Partial<User>[]",
        "references": {
          "Partial": {
            "location": "global"
          },
          "User": {
            "location": "import",
            "path": "../../../sdk"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "[]"
    }
  }; }
  static get listeners() { return [{
      "name": "fireenjinReset",
      "method": "onReset",
      "target": "body",
      "capture": false,
      "passive": false
    }, {
      "name": "fireenjinSuccess",
      "method": "onSuccess",
      "target": "body",
      "capture": false,
      "passive": false
    }]; }
}
