import { Component, Element, h, Prop, State } from "@stencil/core";
import * as gracely from "gracely";
import { DateTime } from "isoly";
import { Event, Item } from "@payfunc/model";
import * as translation from "./translation";
export class IntergiroOrderEvents {
  componentWillLoad() {
    this.t = translation.create(this.element);
  }
  render() {
    return (h("ul", null, this.event.map(e => (h("li", null, e.type == "fail" && e.items != undefined
      ? [
        h("details", null,
          h("summary", null,
            DateTime.localize(DateTime.parse(e.date)),
            h("b", null,
              " ",
              this.t(e.original)),
            " ",
            this.t(" (failed)"),
            "\u2003",
            Item.amount(e.items),
            " ",
            this.currency),
          this.renderEvent(e)),
      ]
      : e.type == "fail" && e.items == undefined
        ? [
          h("details", null,
            h("summary", null,
              DateTime.localize(DateTime.parse(e.date)),
              h("b", null,
                " ",
                this.t(e.original)),
              " ",
              this.t(" (failed)")),
            this.renderEvent(e)),
        ]
        : e.type == "settle"
          ? [
            h("summary", null,
              "\u2003",
              DateTime.localize(DateTime.parse(e.date)),
              h("b", null,
                " ",
                this.t(e.type)),
              "\u2003 ",
              this.t("gross: "),
              " ",
              e.gross,
              " ",
              this.currency,
              "\u2003",
              this.t("fee: "),
              " ",
              e.fee,
              " ",
              this.currency,
              "\u2003",
              this.t("net: "),
              " ",
              e.net,
              " ",
              this.currency),
          ]
          : e.type != "fail" && e.items == undefined
            ? [
              h("summary", null,
                "\u2003",
                DateTime.localize(DateTime.parse(e.date)),
                h("b", null,
                  " ",
                  this.t(e.type))),
            ]
            : e.type != "fail" && e.items != undefined
              ? [
                h("summary", null,
                  "\u2003",
                  DateTime.localize(DateTime.parse(e.date)),
                  h("b", null,
                    " ",
                    this.t(e.type)),
                  "\u2003",
                  Item.amount(e.items),
                  " ",
                  this.currency),
              ]
              : "Error")))));
  }
  renderEvent(event) {
    var _a, _b;
    let result;
    switch (event.type) {
      case "defer":
      case "deny":
      case "cancel":
      case "charge":
      case "order":
      case "pay":
      case "pend":
      case "refund":
      case "settle":
      case "synchronize":
        result = (h("dl", null, event.items
          ? [
            h("dt", null, this.t("Amount")),
            h("dd", null,
              Item.amount(event.items),
              " ",
              this.currency),
          ]
          : ""));
        break;
      case "fail":
        result = (h("dl", null,
          event.items
            ? [
              h("dt", null, this.t("Amount")),
              h("dd", null,
                Item.amount(event.items),
                " ",
                this.currency),
            ]
            : "",
          event.original ? [h("dt", null, this.t("Reason")), h("dd", null, this.t(event.original))] : "",
          event.error ? [h("dt", null, this.t("Error")), h("dd", null, event.error)] : "",
          ((_a = event.error) === null || _a === void 0 ? void 0 : _a.status) ? [h("dt", null, this.t("Status")), h("dd", null, event.error.status)] : "",
          ((_b = event.error) === null || _b === void 0 ? void 0 : _b.type) ? [h("dt", null, this.t("Type")), h("dd", null, event.error.type)] : "",
          Event.Fail.is(event) && gracely.server.backendFailure.is(event.error)
            ? [h("dt", null, this.t("Details")), h("dd", null, event.error.details.body.status.message)]
            : ""));
        break;
      default:
        result = h("dl", null);
    }
    return result;
  }
  static get is() { return "ig-order-events"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "event": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Event[]",
        "resolved": "Event[]",
        "references": {
          "Event": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "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
    },
    "payment": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Payment",
        "resolved": "Card | Customer | Defer | Installment | Invoice | Swish",
        "references": {
          "Payment": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get elementRef() { return "element"; }
}
