import { Build, h, } from "@stencil/core";
import formatUSD from "../../../helpers/formatUSD";
export class TotallerCards {
  constructor() {
    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(value) : value;
  }
  async fetchTotaller() {
    this.fireenjinFetch.emit({
      endpoint: "findTotaller",
      params: {
        id: this.totallerId,
      },
    });
  }
  async componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    this.fetchTotaller();
  }
  render() {
    var _a;
    return (h("div", { class: "flex-container" }, Object.entries((((_a = this.totaller) === null || _a === void 0 ? void 0 : _a.sums) || {})).map(([sumName, value]) => {
      var _a;
      return (h("ion-card", { class: "card" }, h("h2", null, value === null || value === void 0 ? void 0 : value.name), h("h3", null, value === null || value === void 0 ? void 0 : value.description), h("h1", null, this.formatValue(((_a = this.totals) === null || _a === void 0 ? void 0 : _a[sumName]) || 0, value))));
    })));
  }
  static get is() { return "floodteam-totaller-cards"; }
  static get originalStyleUrls() {
    return {
      "$": ["totaller-cards.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["totaller-cards.css"]
    };
  }
  static get properties() {
    return {
      "totallerId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "totaller-id",
        "reflect": false
      },
      "totals": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "{ [sumName: string]: any }",
          "resolved": "{ [sumName: string]: any; }",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        }
      }
    };
  }
  static get states() {
    return {
      "totaller": {}
    };
  }
  static get events() {
    return [{
        "method": "fireenjinFetch",
        "name": "fireenjinFetch",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "FireEnjinFetchEvent",
          "resolved": "FireEnjinFetchEvent",
          "references": {
            "FireEnjinFetchEvent": {
              "location": "import",
              "path": "@fireenjin/sdk"
            }
          }
        }
      }];
  }
  static get listeners() {
    return [{
        "name": "fireenjinSuccess",
        "method": "onSuccess",
        "target": undefined,
        "capture": false,
        "passive": false
      }];
  }
}
