import { r as registerInstance, h, g as getElement, c as createEvent } from './index-08b73e9e.js';
import { H as Handler } from './Handler-40406565.js';
import { i as isDefined } from './model-40d54c5a.js';
import { c as create$1 } from './index-fb900aec.js';
import { i as isDefined$1 } from './model-e84f3fd4.js';
import { d as dist } from './index-a0a71287.js';
import './unknown-97022c22.js';
import './Item-f4cbd6f4.js';
import './_commonjsHelpers-9943807e.js';
import './index-1f953d81.js';
import './index-2d6441ea.js';
import './ok-c9833bf3.js';
import './index-c2c33860.js';
import './Token-ba2c5d5c.js';
import './index-714bb39b.js';
import './index-063af7ee.js';
import './TextDecoder-357ac2ce.js';
import './index-8e333ab5.js';
import './index-945f930d.js';
import './Credentials-b84c0c5f.js';
import './index-f77ff597.js';

const styleCss$4 = ".sc-ig-monitor-merchant-settlements-h{max-width:80em}td.sc-ig-monitor-merchant-settlements{border-top:solid 1px rgb(var(--smoothly-medium-shade));border-bottom:solid 1px rgb(var(--smoothly-medium-shade));background-color:rgb(var(--smoothly-dark-shade));padding:1em}td.sc-ig-monitor-merchant-settlements>*.sc-ig-monitor-merchant-settlements{background-color:rgb(var(--smoothly-default-color));display:block}";

const IntergiroMonitorMerchantSettlements = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.opened = {};
  }
  componentWillLoad() {
    this.t = create$1(this.element);
    Handler.register((authorizations, _, merchants) => {
      this.authorizations = authorizations;
      this.merchants = merchants;
    });
  }
  toggleColumn(e) {
    const opened = Object.assign({}, this.opened);
    opened[e.detail.index] == e.detail.column
      ? delete opened[e.detail.index]
      : (opened[e.detail.index] = e.detail.column);
    this.opened = opened;
    e.stopPropagation();
  }
  render() {
    var _a;
    const t = this.t;
    const header = [
      { name: t("merchant") },
      { name: t("gross"), align: "right" },
      { name: t("fee"), align: "right" },
      this.costPlus ? { name: t("interchange"), align: "right" } : undefined,
      { name: t("net"), align: "right" },
      { name: t("transactions") },
    ];
    return (h("ig-table", { value: this.settlements, name: t("settlements"), header: header }, (_a = this.settlements) === null || _a === void 0 ? void 0 : _a.map((s, index) => {
      var _a;
      const merchant = (_a = this.merchants) === null || _a === void 0 ? void 0 : _a.find(m => m.id == s.merchant);
      return [
        h("ig-table-row", { row: [
            { column: merchant ? merchant.name : s.merchant, openable: true },
            {
              column: h("smoothly-display-amount", { amount: s.gross, currency: s.currency }),
              align: "right",
            },
            {
              column: (h("smoothly-display-amount", { amount: typeof s.fee == "object" ? s.fee.total : s.fee, currency: s.currency })),
              align: "right",
            },
            this.costPlus
              ? {
                column: (h("smoothly-display-amount", { amount: typeof s.fee == "object" ? s.fee.scheme : 0, currency: s.currency })),
                align: "right",
              }
              : undefined,
            {
              column: h("smoothly-display-amount", { amount: s.net, currency: s.currency }),
              align: "right",
            },
            { column: s.transactions.length + " " + t("transactions"), openable: true },
          ], index: index, opened: this.opened[index] }),
        this.opened[index] == (header.filter(isDefined).length - 1).toString() && (h("td", { colSpan: header.filter(isDefined).length }, h("ig-monitor-settlements-transactions", { authorizations: this.authorizations, merchants: this.merchants, transactions: s.transactions, "cost-plus": this.costPlus }))),
        this.opened[index] == "0" && (h("td", { colSpan: header.filter(isDefined).length }, h("ig-merchant-table", { abbrivated: true, merchants: merchant ? [merchant] : [] }))),
      ];
    })));
  }
  get element() { return getElement(this); }
};
IntergiroMonitorMerchantSettlements.style = styleCss$4;

const styleCss$3 = ".sc-ig-monitor-settlements-fees-h{display:inline-block;margin:auto;background-color:rgb(var(--smoothly-default-color));border:1px solid rgb(var(--smoothly-medium-color));max-width:60em}[hidden].sc-ig-monitor-settlements-fees-h{display:none}.sc-ig-monitor-settlements-fees-h>table.sc-ig-monitor-settlements-fees{text-transform:capitalize;width:100%}.sc-ig-monitor-settlements-fees-h>table.sc-ig-monitor-settlements-fees>th.sc-ig-monitor-settlements-fees,tr.sc-ig-monitor-settlements-fees>*.sc-ig-monitor-settlements-fees{display:table-cell;text-align:left;padding:0.3em .5em}tr.sc-ig-monitor-settlements-fees>*.sc-ig-monitor-settlements-fees:not(:first-child),.sc-ig-monitor-settlements-fees-h>table.sc-ig-monitor-settlements-fees>th.sc-ig-monitor-settlements-fees:not(:first-of-type){text-align:right}";

const IntergiroMonitorSettlementsFees = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fees = [];
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  render() {
    return (this.fees.length > 0 && (h("table", null, h("th", { color: "light" }, this.t("scheme")), h("th", { color: "light" }, this.t("gross")), h("th", { color: "light" }, this.t("fee")), this.costPlus && h("th", { color: "light" }, this.t("interchange")), h("th", { color: "light" }, this.t("net")), this.fees
      .sort((a, b) => (a.scheme > b.scheme ? 1 : -1))
      .map(f => (h("tr", null, h("smoothly-display", null, f.scheme), h("smoothly-display-amount", { amount: f.gross, currency: f.currency }), h("smoothly-display-amount", { amount: f.fee, currency: f.currency }), this.costPlus && (h("smoothly-display-amount", { amount: f.interchange, currency: f.currency })), h("smoothly-display-amount", { amount: f.net, currency: f.currency })))))));
  }
  get element() { return getElement(this); }
};
IntergiroMonitorSettlementsFees.style = styleCss$3;

const styleCss$2 = "td.sc-ig-monitor-settlements-transactions{border-top:solid 1px rgb(var(--smoothly-medium-shade));border-bottom:solid 1px rgb(var(--smoothly-medium-shade));background-color:rgb(var(--smoothly-dark-shade));padding:1em}td.sc-ig-monitor-settlements-transactions>*.sc-ig-monitor-settlements-transactions{background-color:rgb(var(--smoothly-default-color));max-width:70em}";

const IntergiroMonitorSettlementsTransactions = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.opened = {};
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  toggleColumn(e) {
    const opened = Object.assign({}, this.opened);
    opened[e.detail.index] == e.detail.column
      ? delete opened[e.detail.index]
      : (opened[e.detail.index] = e.detail.column);
    this.opened = opened;
    e.stopPropagation();
  }
  getFlag(country) {
    return country.toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397));
  }
  getScheme(scheme) {
    return ["mastercard", "visa"].includes(scheme) ? (h("ig-scheme-logotype", { style: { padding: "0 .3em" }, size: "small", scheme: scheme })) : (scheme);
  }
  render() {
    var _a;
    const t = this.t;
    return (h("ig-table", { value: this.transactions, name: t("transactions"), header: [
        { name: t("authorization") },
        { name: t("type") },
        { name: t("card") },
        { name: t("gross"), align: "right" },
        { name: t("fee"), align: "right" },
        this.costPlus ? { name: t("interchange"), align: "right" } : undefined,
        { name: t("net"), align: "right" },
      ] }, (_a = this.transactions) === null || _a === void 0 ? void 0 : _a.map((transaction, index) => {
      var _a;
      const authorization = (_a = this.authorizations) === null || _a === void 0 ? void 0 : _a.find(a => transaction.authorization == a.authorization.id);
      return [
        h("ig-table-row", { row: [
            { column: transaction.authorization, openable: true },
            { column: this.t(transaction.type) },
            {
              column: [
                this.getFlag(transaction.area),
                this.getScheme(transaction.scheme),
                transaction.card[0].toUpperCase() + transaction.card.slice(1),
              ],
            },
            {
              column: (h("smoothly-display-amount", { amount: transaction.gross, currency: transaction.currency })),
              align: "right",
            },
            {
              column: (h("smoothly-display-amount", { amount: typeof transaction.fee == "object" ? transaction.fee.total : transaction.fee, currency: transaction.currency })),
              align: "right",
            },
            this.costPlus
              ? {
                column: (h("smoothly-display-amount", { amount: typeof transaction.fee == "object" ? transaction.fee.scheme : 0, currency: transaction.currency })),
                align: "right",
              }
              : undefined,
            {
              column: (h("smoothly-display-amount", { amount: transaction.net, currency: transaction.currency })),
              align: "right",
            },
          ], index: index, opened: this.opened[index] }),
        this.opened[index] && (h("td", { colSpan: 6 + (this.costPlus ? 1 : 0) }, h("ig-authorization-table", { abbreviated: true, authorizations: authorization ? [authorization] : [], merchants: this.merchants, "cost-plus": this.costPlus }))),
      ];
    })));
  }
  get element() { return getElement(this); }
};
IntergiroMonitorSettlementsTransactions.style = styleCss$2;

const sv = {
  Loading: "Laddar",
  "from server...": "från servern...",
  "There are no": "Det finns inga",
  "to display.": "att visa.",
};

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

const styleCss$1 = ".sc-ig-table-h{display:block;width:100%;max-width:90em;margin:auto;border:1px solid rgb(var(--smoothly-medium-color))}[hidden].sc-ig-table-h{display:none}.sc-ig-table-h>p.sc-ig-table{padding-left:1em}.sc-ig-table-h>table.sc-ig-table{width:100%;table-layout:fixed}.sc-ig-table-h>table.sc-ig-table>thead.sc-ig-table>tr.sc-ig-table{display:table-row;font-weight:bold;height:2em}.sc-ig-table-h>table.sc-ig-table>thead.sc-ig-table>tr.sc-ig-table>th.sc-ig-table{text-transform:capitalize}.sc-ig-table-h>table.sc-ig-table>thead.sc-ig-table>tr.sc-ig-table>*.sc-ig-table{display:table-cell;padding-right:0.5em;padding-left:0.3em;vertical-align:middle;position:-webkit-sticky;position:sticky;top:1.55cm;z-index:1;text-align:left}.sc-ig-table-h>table.sc-ig-table>thead.sc-ig-table>tr.sc-ig-table>th.right.sc-ig-table{text-align:right;padding-right:5.3em}.sc-ig-table-h>table.sc-ig-table>td.sc-ig-table{text-align:center}th.checkbox.sc-ig-table{width:2em}";

const IntergiroTable = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.selectedChanged = createEvent(this, "selectedChanged", 7);
    this.selectable = false;
    this.selected = {};
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  handleToggle(event) {
    const selected = this.selected;
    if (event.detail.checked)
      selected[event.detail.id] = event.detail.value;
    else
      delete selected[event.detail.id];
    this.selectedChanged.emit((this.selected = selected));
  }
  onChecked(event) {
    this.selectedChanged.emit(event.detail.selected ? { allSelected: true } : {});
  }
  render() {
    const t = this.t;
    return [
      !this.value ? (h("p", null, t("Loading") + " " + this.name + " " + t("from server..."))) : this.value.length > 0 ? ([
        h("table", null, h("thead", null, h("tr", null, this.selectable && (h("th", { class: "checkbox", color: "light" }, h("smoothly-checkbox", { "select-all": true }))), this.header.filter(isDefined$1).map(v => (h("th", { class: v.align == "right" ? "right" : "", color: "light" }, v.name))))), h("slot", null)),
      ]) : (h("p", null, t("There are no") + " " + this.name + " " + t("to display."))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroTable.style = styleCss$1;

const styleCss = ".sc-ig-table-row-h{display:table-row;height:2.5em}[hidden].sc-ig-table-row-h{display:none}.sc-ig-table-row-h:hover{-webkit-box-shadow:var(--smoothly-shadow);box-shadow:var(--smoothly-shadow);border-top:1px solid rgb(var(--smoothly-medium-color));border-bottom:1px solid rgb(var(--smoothly-medium-color))}.sc-ig-table-row-h>td.sc-ig-table-row{vertical-align:middle}.sc-ig-table-row-h>td.right.sc-ig-table-row{text-align:right;padding-right:5em}.sc-ig-table-row-h>td.sc-ig-table-row:not(.checkbox)>*.sc-ig-table-row{padding:0.5em 0.3em;width:-webkit-max-content;width:-moz-max-content;width:max-content;min-width:3em;display:inline-block}.sc-ig-table-row-h>td.checkbox.sc-ig-table-row>*.sc-ig-table-row{padding:0em 0.3em}.sc-ig-table-row-h>td.sc-ig-table-row>.openable.sc-ig-table-row:hover{background-color:rgb(var(--smoothly-dark-shade));cursor:pointer}.opened.sc-ig-table-row{-webkit-box-sizing:border-box;box-sizing:border-box;border:solid 1px rgb(var(--smoothly-medium-shade));background-color:rgb(var(--smoothly-dark-shade));border-bottom:2.5px solid rgb(var(--smoothly-dark-shade));margin-bottom:-2.2px}.sc-ig-table-row-h>td.sc-ig-table-row:first-of-type>*.sc-ig-table-row{border-left:none}";

const IntergiroTableRow = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.columnClicked = createEvent(this, "columnClicked", 7);
    this.valueSelected = createEvent(this, "valueSelected", 7);
    this.opened = "";
    this.selected = false;
  }
  handleColumnClick(column) {
    this.opened = column;
    this.columnClicked.emit({ index: this.index, column });
  }
  handleSelected(event) {
    this.valueSelected.emit({ id: this.identifier, value: this.value, checked: event.detail.selected });
    event.stopPropagation();
  }
  render() {
    return [
      this.selectable && (h("td", { class: "checkbox" }, h("smoothly-checkbox", { selected: this.selected }))),
      this.row.filter(isDefined$1).map((v, index) => (h("td", { class: v.align == "right" ? "right" : "" }, h("section", { class: v.openable ? "openable" + (this.opened == index.toString() ? " opened" : "") : "", onClick: () => v.openable && this.handleColumnClick(index.toString()) }, v.column)))),
    ];
  }
};
IntergiroTableRow.style = styleCss;

export { IntergiroMonitorMerchantSettlements as ig_monitor_merchant_settlements, IntergiroMonitorSettlementsFees as ig_monitor_settlements_fees, IntergiroMonitorSettlementsTransactions as ig_monitor_settlements_transactions, IntergiroTable as ig_table, IntergiroTableRow as ig_table_row };
