import { Component, Element, h, Prop, State } from "@stencil/core";
import { DateTime } from "isoly";
import { Status } from "@payfunc/model";
import * as translation from "./translation";
export class IntergiroPortalSettlementOrders {
  constructor() {
    this.opened = false;
  }
  componentWillLoad() {
    this.t = translation.create(this.element);
  }
  render() {
    return [
      h("td", { colSpan: 8 + (this.interchange ? 1 : 0) },
        h("table", null,
          h("thead", null,
            h("tr", null,
              h("th", { color: "light" }, this.t("Order number")),
              h("th", { color: "light" }, this.t("Created")),
              h("th", { color: "light", class: "right" }, this.t("Gross")),
              h("th", { color: "light", class: "right" }, this.t("Fee")),
              this.interchange && (h("th", { color: "light", class: "right" }, this.t("Interchange"))),
              h("th", { color: "light", class: "right" }, this.t("Net")),
              h("th", { color: "light" }, this.t("Status")))),
          this.settlement.orders.map(order => {
            var _a, _b, _c;
            return (h("tbody", null,
              h("td", null,
                h("a", { href: "/order#" + ((_a = order.number) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, "").toLowerCase()) }, order.number)),
              h("td", null, DateTime.localize(DateTime.parse(order.created))),
              h("td", { class: "right" },
                h("smoothly-display-amount", { amount: order.gross, currency: this.settlement.currency })),
              h("td", { class: "right" },
                h("smoothly-display-amount", { amount: typeof order.fee == "object" ? order.fee.total : order.fee, currency: this.settlement.currency })),
              this.interchange && (h("td", { class: "right" },
                h("smoothly-display-amount", { amount: typeof order.fee == "object" ? order.fee.scheme : 0, currency: this.settlement.currency }))),
              h("td", { class: "right" },
                h("smoothly-display-amount", { amount: order.net, currency: this.settlement.currency })),
              h("td", null, order.status
                ? Array.isArray(order.status)
                  ? (_b = order.status.map((status) => h("ig-status", { status: status }))) !== null && _b !== void 0 ? _b : []
                  : (_c = Object.entries(order.status).map(status => Status.is(status[0]) && h("ig-status", { status: status[0] }))) !== null && _c !== void 0 ? _c : []
                : [])));
          }))),
    ];
  }
  static get is() { return "ig-portal-settlement-orders"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "settlement": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Settlement",
        "resolved": "Settlement",
        "references": {
          "Settlement": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "opened": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "opened",
      "reflect": false,
      "defaultValue": "false"
    },
    "server": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "server",
      "reflect": false
    },
    "interchange": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "interchange",
      "reflect": false
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get elementRef() { return "element"; }
}
