import { r as registerInstance, h } from './index-000d2977.js';
import { t as toastController } from './overlays-2be0c50d.js';
import { s as state } from './store-f6a9eb30.js';
import './ionic-global-8913b6b6.js';
import './helpers-7e937ffa.js';
import './getHandlebarsHelpers-91de4454.js';
import './_commonjsHelpers-4ed75ef8.js';
import './logic-88140d62.js';
import './index-d4e79b88.js';
import './localforage-9daa31d6.js';

const modalEditUsersCss = "modal-edit-users .banner{background-color:var(--ion-color-secondary)}modal-edit-users h1{color:#fff}modal-edit-users p{margin:0 0 15px 0;color:rgba(255, 255, 255, 0.8);font-weight:normal}.modal-edit-users{--width:700px;--max-width:700px}@media only screen and (max-width: 800px){.modal-edit-users{--width:100%;--max-width:auto}}";

const ModalEditUsers = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    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",
        },
      ] }))));
  }
};
ModalEditUsers.style = modalEditUsersCss;

export { ModalEditUsers as modal_edit_users };
