import { r as registerInstance, h, g as getElement } from './index-aeac5cad.js';
import './_commonjsHelpers-91fffb88.js';
import { I as Item, E as Event } from './index-ec2a4942.js';
import { d as dist } from './index-fdd60c34.js';
import { d as dist$2 } from './index-909faba2.js';
import { d as dist$1 } from './index-31b724c4.js';

const sv = {
  Amount: "Belopp",
  Reason: "Anledning",
  Error: "Fel",
  Status: "Status",
  Type: "Typ",
  Details: "Detaljer",
  " (failed)": " (misslyckades)",
  defer: "skicka",
  order: "beställa",
  cancel: "avbryta",
  charge: "godkänna",
  refund: "återbetala",
  settle: "utbetala",
  fail: "misslycka",
  synchronize: "synkronisera",
  "gross: ": "brutto: ",
  "net: ": "netto: ",
  "fee: ": "avgift: ",
};

function create(language) {
  return dist.create({
    sv,
  }, language);
}

const styleCss = "*.sc-payfunc-order-events-h{display:flex}[hidden].sc-payfunc-order-events-h{display:none}.sc-payfunc-order-events-h>span.sc-payfunc-order-events{flex-grow:1;padding-left:0.6em;padding-right:0.6em}ul.sc-payfunc-order-events{width:100%;list-style-type:none;padding-inline-start:0;margin-top:0;margin-bottom:0}summary.sc-payfunc-order-events{outline:none;text-align:left}dl.sc-payfunc-order-events{margin:8px;width:100%;display:flex;flex-direction:column;flex-wrap:wrap;max-height:3em;justify-content:flex-start}dt.sc-payfunc-order-events{font-weight:bold;text-align:left}dd.sc-payfunc-order-events{text-align:left;margin:0}";

const PayfuncOrderEvents = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.t = 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, dist$1.DateTime.localize(dist$1.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, dist$1.DateTime.localize(dist$1.DateTime.parse(e.date)), h("b", null, " ", this.t(e.original)), " ", this.t(" (failed)")), this.renderEvent(e)),
        ]
        : e.type == "settle"
          ? [
            h("summary", null, "\u2003", dist$1.DateTime.localize(dist$1.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", dist$1.DateTime.localize(dist$1.DateTime.parse(e.date)), h("b", null, " ", this.t(e.type))),
            ]
            : e.type != "fail" && e.items != undefined
              ? [
                h("summary", null, "\u2003", dist$1.DateTime.localize(dist$1.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) && dist$2.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;
  }
  get element() { return getElement(this); }
};
PayfuncOrderEvents.style = styleCss;

export { PayfuncOrderEvents as payfunc_order_events };
