'use strict';

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

const index = require('./index-e0385008.js');
const formatUSD = require('./formatUSD-65108a08.js');

const totallerCardsCss = "floodteam-totaller-cards .flex-container{display:flex;flex-wrap:wrap}floodteam-totaller-cards ion-card{min-width:6rem;max-width:10rem;min-height:6rem;padding:0px 10px 10px 10px;flex-basis:18%}floodteam-totaller-cards h1{font-size:1rem;color:var(--ion-text-color)}floodteam-totaller-cards h2{font-size:.8rem;color:var(--ion-text-color)}floodteam-totaller-cards h3{font-size:.6rem}@media only screen and (max-width:415.9px){floodteam-totaller-cards .flex-container{justify-content:space-evenly}}";

const TotallerCards = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.totallerId = undefined;
    this.totals = undefined;
    this.totaller = undefined;
  }
  async onSuccess(event) {
    var _a, _b;
    if (event.detail.endpoint === "findTotaller") {
      this.totaller = ((_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.totaller) || null;
    }
  }
  formatValue(value, sum) {
    return (sum === null || sum === void 0 ? void 0 : sum.format) === "usd" ? formatUSD.formatUSD(value) : value;
  }
  async fetchTotaller() {
    this.fireenjinFetch.emit({
      endpoint: "findTotaller",
      params: {
        id: this.totallerId,
      },
    });
  }
  async componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.fetchTotaller();
  }
  render() {
    var _a;
    return (index.h("div", { class: "flex-container" }, Object.entries((((_a = this.totaller) === null || _a === void 0 ? void 0 : _a.sums) || {})).map(([sumName, value]) => {
      var _a;
      return (index.h("ion-card", { class: "card" }, index.h("h2", null, value === null || value === void 0 ? void 0 : value.name), index.h("h3", null, value === null || value === void 0 ? void 0 : value.description), index.h("h1", null, this.formatValue(((_a = this.totals) === null || _a === void 0 ? void 0 : _a[sumName]) || 0, value))));
    })));
  }
};
TotallerCards.style = totallerCardsCss;

exports.floodteam_totaller_cards = TotallerCards;
