'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-cba1c3ae.js');
const hardwareBackButton = require('./overlays-7ec575fc.js');
require('./ionic-global-01cd0200.js');
require('./helpers-c2496722.js');

const appPaymodelCss = "";

const AppPayModel = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    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 hardwareBackButton.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 (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    if (this.payModelId && (index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser)) {
      this.fetchData();
    }
  }
  render() {
    var _a, _b, _c;
    return [
      index.h("ion-content", { scrollEvents: true, class: "ion-padding" }, index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/paymodels" }, "Pay Models")), index.h("ion-card", { class: "ion-padding" }, index.h("fireenjin-form", { endpoint: this.payModelId === "new" ? "addPayModel" : "editPayModel", documentId: this.payModelId === "new" ? null : this.payModelId, resetButton: null }, index.h("ion-list", null, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "firstName", label: "First Name", value: (_a = this.payModel) === null || _a === void 0 ? void 0 : _a.name })), index.h("ion-col", null, index.h("h2", null, "Payout Roles"), index.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 (index.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)))))))),
      index.h("floodteam-navigation-footer", null),
    ];
  }
};
AppPayModel.style = appPaymodelCss;

exports.app_paymodel = AppPayModel;
