import { Component, Element, h, Prop, State, Watch } from "@stencil/core";
import { CountryCode } from "isoly";
import * as langly from "langly";
import * as translation from "../../../../translation";
export class IntergiroMerchantFeeTable {
  componentWillLoad() {
    this.t = translation.create(this.element);
    this.batchFees();
  }
  getCountryName(value) {
    var _a;
    return value == "eea"
      ? this.t("european economic area")
      : CountryCode.Alpha2.is(value)
        ? CountryCode.Name.from((_a = langly.getLanguage(this.element)) !== null && _a !== void 0 ? _a : "en", value)
        : this.t("default");
  }
  batchFees() {
    var _a, _b, _c, _d, _e, _f;
    const fees = this.fees.filter(f => f[0] == "eea" || f[0] == "other" || CountryCode.Alpha2.is(f[0]));
    this.values = [];
    for (const fee of fees) {
      const schemes = typeof fee[1] == "object" ? Object.entries(fee[1]) : [];
      for (const scheme of schemes) {
        const fees = scheme[1] && Object.entries(scheme[1]);
        const debitFee = fees && fees.find(s => s[0] == "debit");
        const debit = debitFee && Object.values(debitFee[1]);
        const creditFee = fees && fees.find(s => s[0] == "credit");
        const credit = creditFee && Object.values(creditFee[1]);
        const percentage = fees && ((_a = fees.find(s => s[0] == "percentage")) === null || _a === void 0 ? void 0 : _a[1]);
        const minimum = fees && ((_b = fees.find(s => s[0] == "minimum")) === null || _b === void 0 ? void 0 : _b[1]);
        const value = {
          country: this.getCountryName(fee[0]),
          scheme: [scheme[0]],
          debit: { percentage: (_c = debit === null || debit === void 0 ? void 0 : debit[0]) !== null && _c !== void 0 ? _c : percentage, minimum: (_d = debit === null || debit === void 0 ? void 0 : debit[1]) !== null && _d !== void 0 ? _d : minimum },
          credit: { percentage: (_e = credit === null || credit === void 0 ? void 0 : credit[0]) !== null && _e !== void 0 ? _e : percentage, minimum: (_f = credit === null || credit === void 0 ? void 0 : credit[1]) !== null && _f !== void 0 ? _f : minimum },
        };
        let existingFee;
        if ((existingFee = this.values.find(v => v.country == value.country &&
          JSON.stringify(v.credit) == JSON.stringify(value.credit) &&
          JSON.stringify(v.debit) == JSON.stringify(value.debit))))
          existingFee.scheme = existingFee.scheme.concat(value.scheme);
        else
          this.values.push(value);
      }
    }
  }
  render() {
    return [
      this.values.length > 0 && (h("table", null,
        h("th", { color: "light" }, this.t("Country")),
        h("th", { color: "light" }, this.t("Scheme")),
        h("th", { color: "light" }, this.t("Debit")),
        h("th", { color: "light" }, this.t("Credit")),
        this.values.map(f => (h("tr", null,
          h("td", null, f.country),
          h("td", null, f.scheme.map((s, i) => s + (i != f.scheme.length - 1 ? ", " : ""))),
          h("td", null,
            f.debit.percentage + " %",
            f.debit.minimum ? " Min " + f.debit.minimum + " " + this.currency : ""),
          h("td", null,
            f.credit.percentage + " %",
            f.credit.minimum ? " Min " + f.credit.minimum + " " + this.currency : "")))))),
    ];
  }
  static get is() { return "ig-merchant-fee-table"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "currency": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "Currency",
        "resolved": "\"AED\" | \"AFN\" | \"ALL\" | \"AMD\" | \"ANG\" | \"AOA\" | \"ARS\" | \"AUD\" | \"AWG\" | \"AZN\" | \"BAM\" | \"BBD\" | \"BDT\" | \"BGN\" | \"BHD\" | \"BIF\" | \"BMD\" | \"BND\" | \"BOB\" | \"BOV\" | \"BRL\" | \"BSD\" | \"BTN\" | \"BWP\" | \"BYN\" | \"BZD\" | \"CAD\" | \"CDF\" | \"CHE\" | \"CHF\" | \"CHW\" | \"CLF\" | \"CLP\" | \"CNY\" | \"COP\" | \"COU\" | \"CRC\" | \"CUC\" | \"CUP\" | \"CVE\" | \"CZK\" | \"DJF\" | \"DKK\" | \"DOP\" | \"DZD\" | \"EGP\" | \"ERN\" | \"ETB\" | \"EUR\" | \"FJD\" | \"FKP\" | \"GBP\" | \"GEL\" | \"GHS\" | \"GIP\" | \"GMD\" | \"GNF\" | \"GTQ\" | \"GYD\" | \"HKD\" | \"HNL\" | \"HRK\" | \"HTG\" | \"HUF\" | \"IDR\" | \"ILS\" | \"INR\" | \"IQD\" | \"IRR\" | \"ISK\" | \"JMD\" | \"JOD\" | \"JPY\" | \"KES\" | \"KGS\" | \"KHR\" | \"KMF\" | \"KPW\" | \"KRW\" | \"KWD\" | \"KYD\" | \"KZT\" | \"LAK\" | \"LBP\" | \"LKR\" | \"LRD\" | \"LSL\" | \"LYD\" | \"MAD\" | \"MDL\" | \"MGA\" | \"MKD\" | \"MMK\" | \"MNT\" | \"MOP\" | \"MRU\" | \"MUR\" | \"MVR\" | \"MWK\" | \"MXN\" | \"MXV\" | \"MYR\" | \"MZN\" | \"NAD\" | \"NGN\" | \"NIO\" | \"NOK\" | \"NPR\" | \"NZD\" | \"OMR\" | \"PAB\" | \"PEN\" | \"PGK\" | \"PHP\" | \"PKR\" | \"PLN\" | \"PYG\" | \"QAR\" | \"RON\" | \"RSD\" | \"RUB\" | \"RWF\" | \"SAR\" | \"SBD\" | \"SCR\" | \"SDG\" | \"SEK\" | \"SGD\" | \"SHP\" | \"SLL\" | \"SOS\" | \"SRD\" | \"SSP\" | \"STN\" | \"SVC\" | \"SYP\" | \"SZL\" | \"THB\" | \"TJS\" | \"TMT\" | \"TND\" | \"TOP\" | \"TRY\" | \"TTD\" | \"TWD\" | \"TZS\" | \"UAH\" | \"UGX\" | \"USD\" | \"USN\" | \"UYI\" | \"UYU\" | \"UYW\" | \"UZS\" | \"VES\" | \"VND\" | \"VUV\" | \"WST\" | \"XAF\" | \"XAG\" | \"XAU\" | \"XBA\" | \"XBB\" | \"XBC\" | \"XBD\" | \"XCD\" | \"XDR\" | \"XOF\" | \"XPD\" | \"XPF\" | \"XPT\" | \"XSU\" | \"XTS\" | \"XUA\" | \"XXX\" | \"YER\" | \"ZAR\" | \"ZMW\" | \"ZWL\"",
        "references": {
          "Currency": {
            "location": "import",
            "path": "isoly"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "currency",
      "reflect": false
    },
    "fees": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "[string, number | Merchant.Fee.Transaction | undefined][]",
        "resolved": "[string, number | Transaction | undefined][]",
        "references": {
          "Merchant": {
            "location": "import",
            "path": "@payfunc/model-acquirer"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "t": {},
    "values": {}
  }; }
  static get elementRef() { return "element"; }
  static get watchers() { return [{
      "propName": "fees",
      "methodName": "batchFees"
    }]; }
}
