import { r as registerInstance, d as createEvent, B as Build, h } from './index-31949dc5.js';
import { t as toastController } from './overlays-291bc7b7.js';
import './ionic-global-70d3ca26.js';
import './helpers-06537f39.js';

const appPaymodelCss = "";

const AppPayModel = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fireenjinFetch = createEvent(this, "fireenjinFetch", 7);
    this.payModelId = undefined;
    this.payModel = {};
  }
  async onSuccess(event) {
    var _a, _b, _c, _d, _e, _f;
    if (event.detail.endpoint === "addPayModel") {
      const routerEl = document.querySelector("ion-router");
      if (!routerEl || !((_c = (_b = (_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.addPayModel) === null || _c === void 0 ? void 0 : _c.id))
        return;
      routerEl.push(`/paymodels/${event.detail.data.addPayModel.id}`);
    }
    else if (event.detail.endpoint === "editPayModel") {
      this.presentToast();
    }
    else if (event.detail.endpoint === "findPayModel") {
      this.payModel = ((_f = (_e = (_d = event === null || event === void 0 ? void 0 : event.detail) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.findPayModel) === null || _f === void 0 ? void 0 : _f.payModel) || {};
    }
  }
  async presentToast() {
    const toast = await toastController.create({
      message: "The pay model has been updated.",
      duration: 2000,
    });
    toast.present();
  }
  async fetchData() {
    this.fireenjinFetch.emit({
      endpoint: "findPayModel",
      id: this.payModelId,
    });
  }
  async componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    if (this.payModelId && (Build === null || Build === void 0 ? void 0 : Build.isBrowser)) {
      this.fetchData();
    }
  }
  render() {
    var _a, _b, _c;
    return [
      h("ion-content", { scrollEvents: true, class: "ion-padding" }, h("floodteam-title-bar", null, h("ion-router-link", { href: "/paymodels" }, "Pay Models")), h("ion-card", { class: "ion-padding" }, h("fireenjin-form", { endpoint: this.payModelId === "new" ? "addPayModel" : "editPayModel", documentId: this.payModelId === "new" ? null : this.payModelId, resetButton: null }, h("ion-list", null, h("ion-grid", null, h("ion-row", null, h("ion-col", null, h("fireenjin-input", { name: "firstName", label: "First Name", value: (_a = this.payModel) === null || _a === void 0 ? void 0 : _a.name })), h("ion-col", null, h("h2", null, "Payout Roles"), h("ion-list", null, ((_c = (_b = this.payModel) === null || _b === void 0 ? void 0 : _b.payouts) === null || _c === void 0 ? void 0 : _c.length)
        ? this.payModel.payouts.map((payout) => {
          var _a, _b;
          return (h("ion-item", null, ((_a = payout === null || payout === void 0 ? void 0 : payout.role) === null || _a === void 0 ? void 0 : _a.name)
            ? (_b = payout === null || payout === void 0 ? void 0 : payout.role) === null || _b === void 0 ? void 0 : _b.name
            : "No Role Name"));
        })
        : null)))))))),
      h("floodteam-navigation-footer", null),
    ];
  }
};
AppPayModel.style = appPaymodelCss;

export { AppPayModel as app_paymodel };
