import { r as registerInstance, h, g as getElement, c as createEvent, H as Host } from './index-08b73e9e.js';
import { d as dist } from './index-3cf720d3.js';
import { I as IntergiroMonitor, c as create$3 } from './index-9dc0f0c2.js';
import { a as Connection } from './Item-f4cbd6f4.js';
import { U as User, M as Merchant$1, K as Key } from './index-945f930d.js';
import './Credentials-b84c0c5f.js';
import './Token-ba2c5d5c.js';
import './index-a0a71287.js';
import { A as Authorization, F as FailedAuthorization } from './index-2d6441ea.js';
import './ok-c9833bf3.js';
import { M as Merchant } from './index-c2c33860.js';
import { S as Settlement } from './index-8e333ab5.js';
import './index-f77ff597.js';
import { c as create } from './index-30b826ad.js';
import { c as create$1 } from './index-371eae24.js';
import { E as Error } from './unknown-97022c22.js';
import { s as sort } from './sort-0b97b2f1.js';
import { c as create$2 } from './index-f9034522.js';
import './App-364e27cc.js';
import { N as Notice } from './Notice-668f9bc7.js';
import { c as create$4 } from './index-fb900aec.js';
import { H as Handler } from './Handler-40406565.js';
import './_commonjsHelpers-9943807e.js';
import './index-ff7475d6.js';
import './index-1f953d81.js';
import './TextDecoder-357ac2ce.js';
import './index-714bb39b.js';
import './index-063af7ee.js';

const styleCss$b = ".sc-ig-authorization-footer-h{display:-ms-flexbox;display:flex;margin:auto;border:1px solid rgb(var(--smoothly-medium-color));width:100%;max-width:90em;z-index:1;position:-webkit-sticky;position:sticky;bottom:0;color:rgb(var(--smoothly-light-contrast));background-color:rgb(var(--smoothly-light-color));height:2em;-ms-flex-align:center;align-items:center}.sc-ig-authorization-footer-h>*.sc-ig-authorization-footer::first-letter{text-transform:uppercase;padding-left:.5em}.sc-ig-authorization-footer-h>smoothly-display.sc-ig-authorization-footer:nth-child(odd):not(:first-of-type){padding-left:5em}.sc-ig-authorization-footer-h>smoothly-icon.sc-ig-authorization-footer:last-of-type{position:absolute;right:0.3em;cursor:pointer}";

const IntergiroAuthorizationFooter = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  async componentWillLoad() {
    this.t = create(this.element);
  }
  downloadCsv() {
    var _a, _b;
    const user = (_a = IntergiroMonitor.client) === null || _a === void 0 ? void 0 : _a.me.user;
    const merchant = user && !Array.isArray(user === null || user === void 0 ? void 0 : user.merchant) ? user.merchant : undefined;
    const filename = (merchant ? merchant.name + " " : "") + "authorizations " + dist.DateTime.now().substring(0, 10) + ".csv";
    const file = Authorization.toCsv(this.authorizationsSelected && this.authorizationsSelected.length != 0
      ? this.authorizationsSelected
      : ((_b = this.authorizations) !== null && _b !== void 0 ? _b : []).filter(Authorization.is));
    const link = document.createElement("a");
    link.setAttribute("href", "data:text/csv;charset=utf-8," + encodeURIComponent(file));
    link.setAttribute("download", filename);
    link.style.display = "none";
    document.body.appendChild(link);
    link.click();
    link.remove();
  }
  render() {
    var _a;
    const hasSelection = this.authorizationsSelected && this.authorizationsSelected.length != 0;
    const authorizations = hasSelection ? this.authorizationsSelected : (_a = this.authorizations) !== null && _a !== void 0 ? _a : [];
    const [amountSEK, amountEUR, failedSEK, failedEUR] = authorizations
      ? authorizations.reduce(([s, e, fs, fe], a) => {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        if (Authorization.is(a)) {
          s += ((_b = (_a = this.conversion) === null || _a === void 0 ? void 0 : _a["SEK"][a.authorization.currency]) !== null && _b !== void 0 ? _b : 1) * a.authorization.amount;
          e += ((_d = (_c = this.conversion) === null || _c === void 0 ? void 0 : _c["EUR"][a.authorization.currency]) !== null && _d !== void 0 ? _d : 1) * a.authorization.amount;
        }
        if (FailedAuthorization.is(a) && a.authorization.amount && a.authorization.currency) {
          fs += ((_f = (_e = this.conversion) === null || _e === void 0 ? void 0 : _e["SEK"][a.authorization.currency]) !== null && _f !== void 0 ? _f : 1) * a.authorization.amount;
          fe += ((_h = (_g = this.conversion) === null || _g === void 0 ? void 0 : _g["EUR"][a.authorization.currency]) !== null && _h !== void 0 ? _h : 1) * a.authorization.amount;
        }
        return [s, e, fs, fe];
      }, [0, 0, 0, 0])
      : [0, 0, 0, 0];
    return (this.authorizations && [
      h("smoothly-display", null, hasSelection ? this.t("selected amount:") : this.t("total count:")),
      h("smoothly-display", null, authorizations === null || authorizations === void 0 ? void 0 : authorizations.length),
      this.conversion && [
        h("smoothly-display", null, hasSelection ? this.t("selected authorized amount:") : this.t("total authorized amount:")),
        h("smoothly-display-amount", { amount: amountSEK !== null && amountSEK !== void 0 ? amountSEK : 0, currency: "SEK" }),
        h("span", null, " / "),
        h("smoothly-display-amount", { amount: amountEUR, currency: "EUR" }),
        h("smoothly-display", null, hasSelection ? this.t("selected failed amount:") : this.t("total failed amount:")),
        h("smoothly-display-amount", { amount: failedSEK !== null && failedSEK !== void 0 ? failedSEK : 0, currency: "SEK" }),
        h("span", null, " / "),
        h("smoothly-display-amount", { amount: failedEUR, currency: "EUR" }),
      ],
      h("smoothly-icon", { onClick: () => this.downloadCsv(), color: "light", toolTip: this.t("Download authorization report"), name: "cloud-download" }),
    ]);
  }
  get element() { return getElement(this); }
};
IntergiroAuthorizationFooter.style = styleCss$b;

const styleCss$a = "";

const IntergiroAuthorizations = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    if (!this.authorizationsFiltered)
      this.authorizationsUpdate();
  }
  authorizationsUpdate() {
    var _a;
    this.authorizationsFiltered = (_a = this.authorizations) === null || _a === void 0 ? void 0 : _a.sort((a, b) => a.authorization.created < b.authorization.created ? 1 : -1);
  }
  handleFilterChanged(event) {
    this.authorizationsFiltered = event.detail;
    event.stopPropagation();
  }
  handleSelectedChanged(event) {
    this.authorizationsSelected = Object.values(event.detail).filter(Authorization.is);
  }
  render() {
    var _a;
    return [
      this.authorizations && (h("ig-filter", { template: Authorization.template, value: this.authorizations })),
      h("ig-authorization-table", { abbreviated: ((_a = this.merchants) === null || _a === void 0 ? void 0 : _a.length) == 1, authorizations: this.authorizationsFiltered, merchants: this.merchants, "cost-plus": this.costPlus }),
      h("ig-authorization-footer", { authorizations: this.authorizationsFiltered, authorizationsSelected: this.authorizationsSelected, conversion: this.conversion }),
    ];
  }
  static get watchers() { return {
    "authorizations": ["authorizationsUpdate"]
  }; }
};
IntergiroAuthorizations.style = styleCss$a;

const styleCss$9 = ".sc-ig-log-footer-h{display:-ms-flexbox;display:flex;margin:auto;border:1px solid rgb(var(--smoothly-medium-color));width:100%;max-width:90em;z-index:1;position:-webkit-sticky;position:sticky;bottom:0;color:rgb(var(--smoothly-light-contrast));background-color:rgb(var(--smoothly-light-color));height:2em;-ms-flex-align:center;align-items:center}.sc-ig-log-footer-h>*.sc-ig-log-footer::first-letter{text-transform:uppercase;padding-left:.5em}";

const IntergiroLogFooter = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  render() {
    var _a, _b;
    return [
      h("smoothly-display", null, this.t("total count:")),
      h("smoothly-display", null, (_b = (_a = this.logs) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroLogFooter.style = styleCss$9;

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

const IntergiroLogTable = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.hideMerchant = false;
    this.abbreviated = false;
    this.opened = {};
    this.count = 100;
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  toggleColumn(e) {
    const opened = Object.assign({}, this.opened);
    if (opened[e.detail.index] == e.detail.column)
      delete opened[e.detail.index];
    else
      opened[e.detail.index] = e.detail.column;
    this.opened = opened;
    e.stopPropagation();
  }
  render() {
    return [
      !this.logs ? (h("p", null, this.t("Loading logs from server..."))) : this.logs.length > 0 ? ([
        h("table", null, h("thead", null, h("tr", null, !(this.abbreviated || this.hideMerchant) && h("th", { color: "light" }, this.t("merchant")), !this.abbreviated && h("th", { color: "light" }, this.t("reference")), h("th", { color: "light" }, this.t("resource")), h("th", { color: "light" }, this.t("entries")), h("th", { color: "light" }, this.t("created")))), this.logs.slice(0, this.count).map(log => {
          var _a, _b;
          const index = (_b = (_a = this.logs) === null || _a === void 0 ? void 0 : _a.indexOf(log)) !== null && _b !== void 0 ? _b : 0;
          return [
            h("ig-log-table-row", { log: log, opened: this.opened[index], index: index, hideMerchant: this.hideMerchant, abbreviated: this.abbreviated }),
            h("ig-log-details", { log: log, opened: this.opened[index] }),
          ];
        }), this.count < this.logs.length && (h("td", { colSpan: this.abbreviated ? 3 : this.hideMerchant ? 4 : 5 }, h("button", null, h("smoothly-icon", { onClick: () => (this.count += 100), name: "chevron-down-circle", size: "large", toolTip: this.t("Load more logs") }))))),
      ]) : (h("p", null, this.t("There are no logs to display."))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroLogTable.style = styleCss$8;

const styleCss$7 = "";

const IntergiroLogs = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.logsUpdate();
  }
  async logsUpdate() {
    let logs = await Promise.resolve(this.logs);
    logs =
      Error.is(logs) || typeof logs == "string" || !logs
        ? undefined
        : this.merchants && this.merchants.length > 0
          ? logs.filter(log => { var _a; return (_a = this.merchants) === null || _a === void 0 ? void 0 : _a.find(m => m.id == log.merchant); })
          : logs;
    this.logsFiltered = logs ? sort(logs, "created") : undefined;
  }
  handleFilterChanged(event) {
    this.logsFiltered = event.detail;
    event.stopPropagation();
  }
  handleReferenceFiltered(event) {
    this.filter = event.detail;
    event.stopPropagation();
  }
  render() {
    var _a;
    return [
      this.logs && (h("ig-filter", { "criteria-string": this.filter, value: Array.isArray(this.logs) ? this.logs : [] })),
      h("ig-log-table", { logs: this.logsFiltered, hideMerchant: ((_a = this.merchants) === null || _a === void 0 ? void 0 : _a.length) == 1 }),
      h("ig-log-footer", { logs: this.logsFiltered }),
    ];
  }
  static get watchers() { return {
    "merchants": ["logsUpdate"],
    "logs": ["logsUpdate"]
  }; }
};
IntergiroLogs.style = styleCss$7;

const styleCss$6 = ".sc-ig-merchant-footer-h{display:-ms-flexbox;display:flex;margin:auto;border:1px solid rgb(var(--smoothly-medium-color));width:100%;max-width:90em;z-index:1;position:-webkit-sticky;position:sticky;bottom:0;color:rgb(var(--smoothly-light-contrast));background-color:rgb(var(--smoothly-light-color));height:2em;-ms-flex-align:center;align-items:center}.sc-ig-merchant-footer-h>smoothly-icon.sc-ig-merchant-footer{position:absolute;right:0;padding-right:.5em;cursor:pointer}.sc-ig-merchant-footer-h>*.sc-ig-merchant-footer::first-letter{text-transform:uppercase;padding-left:.5em}";

const IntergiroMerchantFooter = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.t = create$2(this.element);
  }
  downloadCsv() {
    const file = this.merchants
      ? Merchant.toCsv(this.merchantsSelected && this.merchantsSelected.length != 0 ? this.merchantsSelected : this.merchants)
      : "";
    const link = document.createElement("a");
    link.setAttribute("href", "data:text/csv;charset=utf-8," + encodeURIComponent(file));
    link.setAttribute("download", "merchants.csv");
    link.style.display = "none";
    document.body.appendChild(link);
    link.click();
    link.remove();
  }
  render() {
    var _a, _b, _c, _d, _e;
    return [
      h("smoothly-display", null, this.t(this.merchantsSelected && ((_a = this.merchantsSelected) === null || _a === void 0 ? void 0 : _a.length) != 0 ? "selected count:" : "total count:")),
      h("smoothly-display", null, this.merchantsSelected && ((_b = this.merchantsSelected) === null || _b === void 0 ? void 0 : _b.length) != 0
        ? (_c = this.merchantsSelected) === null || _c === void 0 ? void 0 : _c.length
        : (_e = (_d = this.merchants) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0),
      h("smoothly-icon", { hidden: this.merchants == undefined, onClick: () => this.downloadCsv(), color: "light", toolTip: this.t("Download merchant details"), name: "cloud-download" }),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroMerchantFooter.style = styleCss$6;

const styleCss$5 = "";

const IntergiroMerchants = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.merchantsChanged();
  }
  merchantsChanged() {
    this.merchantsFiltered = this.merchants;
  }
  handleFilterChanged(event) {
    this.merchantsFiltered = event.detail;
    event.stopPropagation();
  }
  handleSelectedChanged(event) {
    this.merchantsSelected = Object.values(event.detail).filter(Merchant.is);
  }
  render() {
    var _a;
    return ((_a = this.merchants) === null || _a === void 0 ? void 0 : _a.length) == 1 ? (h("ig-single-merchant", { merchant: this.merchants[0], audience: this.audience })) : ([
      this.merchants && h("ig-filter", { template: Authorization.template, value: this.merchants }),
      h("ig-merchant-table", { merchants: this.merchantsFiltered }),
      h("ig-merchant-footer", { merchants: this.merchantsFiltered, merchantsSelected: this.merchantsSelected }),
    ]);
  }
  static get watchers() { return {
    "merchants": ["merchantsChanged"]
  }; }
};
IntergiroMerchants.style = styleCss$5;

const styleCss$4 = ".sc-ig-monitor-login-h{display:block}[hidden].sc-ig-monitor-login-h{display:none}.sc-ig-monitor-login-h>smoothly-dialog.sc-ig-monitor-login{top:60px;z-index:2}*.sc-ig-monitor-login{z-index:0}smoothly-input.sc-ig-monitor-login{border:1px solid rgb(var(--smoothly-medium-color))}smoothly-submit.sc-ig-monitor-login{margin-top:0.4em}.sc-ig-monitor-login-h>smoothly-dialog.sc-ig-monitor-login smoothly-input.sc-ig-monitor-login:first-of-type{border-bottom:none}";

const MonitorLogin = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.notice = createEvent(this, "notice", 7);
    this.userChanged = createEvent(this, "userChanged", 7);
  }
  componentWillLoad() {
    var _a;
    this.t = create$3(this.element);
    this.done = !!((_a = IntergiroMonitor.client) === null || _a === void 0 ? void 0 : _a.me.user);
  }
  async attemptLogin(e) {
    var _a, _b, _c, _d, _e;
    if (IntergiroMonitor.client) {
      const user = await ((_a = IntergiroMonitor.client) === null || _a === void 0 ? void 0 : _a.me.login((_b = e.detail.user) !== null && _b !== void 0 ? _b : "", (_c = e.detail.password) !== null && _c !== void 0 ? _c : ""));
      const key = User.is(user) && Merchant$1.is(user.merchant) && (await Key.unpack(user.merchant.key.private, "agent", "private"));
      if (User.is(user) && Key.is(key) && (key.aud == "agent" || ((_e = (_d = key.card) === null || _d === void 0 ? void 0 : _d.mid) === null || _e === void 0 ? void 0 : _e.startsWith("8103")))) {
        this.userChanged.emit({ user: user });
        this.done = true;
      }
      else
        this.notice.emit(Notice.failed(this.t("Login failed. Make sure email and password are correct.")));
    }
  }
  render() {
    const t = this.t;
    return [
      h("smoothly-dialog", { open: !this.done, header: "Intergiro Monitor" }, h("form", null, h("smoothly-input", { type: "email", name: "user" }, t("Email")), h("smoothly-input", { type: "password", name: "password" }, t("Password")), h("smoothly-submit", { color: "success", prevent: true, expand: "block", onSubmit: (e) => this.attemptLogin(e) }, t("Log in")))),
      h("slot", null),
    ];
  }
  get element() { return getElement(this); }
};
MonitorLogin.style = styleCss$4;

const IntergiroMonitorSettlements = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.settlementsGrouped = {};
    this.opened = {};
    this.view = "multiple";
    this.selected = {};
    this.selectedSettlements = [];
  }
  componentWillLoad() {
    this.t = create$4(this.element);
    this.settlementsChanged();
  }
  settlementsChanged() {
    var _a;
    this.settlementsFiltered = (_a = this.settlements) === null || _a === void 0 ? void 0 : _a.sort((a, b) => a.reference.slice(0.1) < b.reference.slice(0.1) ? 1 : -1);
  }
  handleFilterChanged(event) {
    this.settlementsFiltered = event.detail;
    event.stopPropagation();
  }
  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();
  }
  groupSettlements() {
    var _a;
    const registry = {};
    (_a = this.settlementsFiltered) === null || _a === void 0 ? void 0 : _a.forEach(settlement => {
      var _a;
      let date = settlement.reference.slice(0, 10);
      date = dist.Date.is(date) ? date : settlement.created;
      return (registry[date] = [...((_a = registry[date]) !== null && _a !== void 0 ? _a : []), settlement]);
    });
    this.settlementsGrouped = registry;
  }
  calculateFees(settlements) {
    const result = [];
    settlements === null || settlements === void 0 ? void 0 : settlements.map(s => s.transactions.map(t => {
      const exists = result.find(v => v.scheme == t.scheme && v.currency == s.currency);
      if (exists) {
        exists.gross += t.gross;
        exists.fee += typeof t.fee == "number" ? t.fee : t.fee.total;
        exists.net += t.net;
        exists.interchange += typeof t.fee == "number" ? 0 : t.fee.scheme;
      }
      else
        result.push({
          scheme: t.scheme,
          gross: t.gross,
          fee: typeof t.fee == "number" ? t.fee : t.fee.total,
          net: t.net,
          interchange: typeof t.fee == "number" ? 0 : t.fee.scheme,
          currency: s.currency,
        });
    }));
    return result;
  }
  handleSelectedChanged(event) {
    this.selected = event.detail["allSelected"] ? Object.assign({}, this.settlementsGrouped) : event.detail;
    this.selectedSettlements = Object.values(this.selected).reduce((s, r) => r.concat(s), []);
  }
  render() {
    var _a;
    const t = this.t;
    const isSelected = this.selectedSettlements.length > 0;
    return [
      this.settlements && h("ig-filter", { value: this.settlements }),
      h("ig-table", { selectable: true, selected: this.selected, value: this.settlements, name: t("settlements"), header: [{ name: t("date") }, { name: t("transactions") }, { name: t("total"), align: "right" }] }, (_a = Object.entries(this.settlementsGrouped)) === null || _a === void 0 ? void 0 : _a.map((s, index) => {
        const fees = this.calculateFees(s[1]);
        const fee = dist.Currency.round(fees.reduce((r, f) => { var _a, _b; return (r += ((_b = (_a = this.conversion) === null || _a === void 0 ? void 0 : _a["SEK"][f.currency]) !== null && _b !== void 0 ? _b : 1) * f.gross); }, 0), "SEK");
        return [
          h("ig-table-row", { row: [
              { column: s[0] },
              {
                column: s[1].reduce((r, s) => (r += s.transactions.length), 0) + " " + t("transactions"),
                openable: true,
              },
              {
                column: h("smoothly-display-amount", { amount: fee, currency: "SEK" }),
                openable: fees.length > 0,
                align: "right",
              },
            ], identifier: s[0], value: s[1], index: index, selected: !!this.selected[s[0]], selectable: true, opened: this.opened[index] }),
          h("ig-monitor-settlements-details", { settlement: s[1], fees: fees, opened: this.opened[index], "cost-plus": this.costPlus, view: this.view }),
        ];
      })),
      h("ig-monitor-settlements-footer", { settlements: isSelected ? this.selectedSettlements : this.settlementsFiltered, selected: isSelected, authorizations: this.authorizations, fees: this.calculateFees(isSelected ? this.selectedSettlements : this.settlementsFiltered), conversion: this.conversion }),
    ];
  }
  get element() { return getElement(this); }
  static get watchers() { return {
    "settlements": ["settlementsChanged"],
    "settlementsFiltered": ["groupSettlements"]
  }; }
};

const styleCss$3 = ".sc-ig-monitor-settlements-details-h{display:table-row}.sc-ig-monitor-settlements-details-h>td.sc-ig-monitor-settlements-details{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))}.sc-ig-monitor-settlements-details-h>td.sc-ig-monitor-settlements-details>*.sc-ig-monitor-settlements-details{display:block;margin:1em auto;background-color:rgb(var(--smoothly-default-color))}[view=single].sc-ig-monitor-settlements-details-h>td.sc-ig-monitor-settlements-details>ig-monitor-settlements-transactions.sc-ig-monitor-settlements-details{margin:1em}";

const IntergiroMonitorSettlementDetails = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    Handler.register((authorizations, _, merchants, settlements) => {
      this.authorizations = authorizations;
      this.merchants = merchants;
      this.settlements = settlements;
    });
  }
  render() {
    let result;
    switch (this.opened) {
      case "1":
        result =
          this.view == "single" ? (h("ig-monitor-settlements-transactions", { authorizations: this.authorizations, merchants: this.merchants, transactions: this.settlement.reduce((r, c) => r.concat(c.transactions), []), "cost-plus": this.costPlus })) : (h("ig-monitor-merchant-settlements", { color: "dark", settlements: this.settlement, "cost-plus": this.costPlus }));
        break;
      case "2":
        result = h("ig-monitor-settlements-fees", { fees: this.fees, "cost-plus": this.costPlus });
        break;
      default:
        return "";
    }
    return h("td", { colSpan: 4 }, result);
  }
};
IntergiroMonitorSettlementDetails.style = styleCss$3;

const styleCss$2 = ".sc-ig-monitor-settlements-footer-h{display:-ms-flexbox;display:flex;margin:auto;border:1px solid rgb(var(--smoothly-medium-color));width:100%;max-width:90em;z-index:1;position:-webkit-sticky;position:sticky;bottom:0;color:rgb(var(--smoothly-light-contrast));background-color:rgb(var(--smoothly-light-color));height:2em;-ms-flex-align:center;align-items:center}.sc-ig-monitor-settlements-footer-h>*.sc-ig-monitor-settlements-footer::first-letter{text-transform:uppercase;padding-left:.5em}.sc-ig-monitor-settlements-footer-h>smoothly-display.sc-ig-monitor-settlements-footer:nth-child(odd):not(:first-of-type){padding-left:5%}smoothly-display-amount.sc-ig-monitor-settlements-footer{padding-left:.5em}.sc-ig-monitor-settlements-footer-h>*.sc-ig-monitor-settlements-footer:not(smoothly-popup){overflow:hidden;white-space:nowrap;text-overflow:ellipsis;text-transform:capitalize}.sc-ig-monitor-settlements-footer-h>smoothly-popup.sc-ig-monitor-settlements-footer{position:absolute;right:0;padding-right:.5em;cursor:pointer}smoothly-popup.sc-ig-monitor-settlements-footer smoothly-display.sc-ig-monitor-settlements-footer{background-color:rgb(var(--smoothly-medium-contrast));color:rgb(var(--smoothly-medium-shade));padding:.4em}smoothly-popup.sc-ig-monitor-settlements-footer div.sc-ig-monitor-settlements-footer>section.sc-ig-monitor-settlements-footer{display:-ms-flexbox;display:flex}smoothly-popup.sc-ig-monitor-settlements-footer section.sc-ig-monitor-settlements-footer:first-of-type>smoothly-display.sc-ig-monitor-settlements-footer:first-of-type{border-bottom:1px solid rgb(var(--smoothly-medium-shade))}smoothly-popup.sc-ig-monitor-settlements-footer section.selected.sc-ig-monitor-settlements-footer>smoothly-display.sc-ig-monitor-settlements-footer{background-color:rgb(var(--smoothly-dark-shade))}smoothly-popup.sc-ig-monitor-settlements-footer section.sc-ig-monitor-settlements-footer:not(.selected)>smoothly-display.sc-ig-monitor-settlements-footer:last-of-type{border-left:1px solid rgb(var(--smoothly-medium-shade))}smoothly-popup.sc-ig-monitor-settlements-footer section.sc-ig-monitor-settlements-footer>smoothly-display.sc-ig-monitor-settlements-footer:last-of-type{background-color:rgb(var(--smoothly-dark-shade));width:2em}smoothly-popup.sc-ig-monitor-settlements-footer div.sc-ig-monitor-settlements-footer>section.sc-ig-monitor-settlements-footer>smoothly-display.sc-ig-monitor-settlements-footer:first-of-type{width:5em}";

const IntergiroMonitorSettlementFooter = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.notice = createEvent(this, "notice", 7);
  }
  componentWillLoad() {
    this.t = create$4(this.element);
  }
  downloadCsv() {
    const file = !this.settlements || !this.type
      ? ""
      : this.type == "summary"
        ? Settlement.toCsv(this.settlements)
        : this.authorizations
          ? Settlement.toDetailedCsv(this.settlements, this.authorizations)
          : "";
    if (file) {
      const link = document.createElement("a");
      link.setAttribute("href", "data:text/csv;charset=utf-8," + encodeURIComponent(file));
      link.setAttribute("download", "settlements.csv");
      link.style.display = "none";
      document.body.appendChild(link);
      link.click();
      link.remove();
    }
    else
      this.notice.emit(Notice.failed("Failed to download CSV."));
  }
  downloadPdf() {
    var _a;
    this.inputElement.value = JSON.stringify((_a = this.settlements) !== null && _a !== void 0 ? _a : []);
    this.submitElement.submit();
  }
  getAmount(currency, scheme) {
    var _a, _b;
    return dist.Currency.round((_b = (_a = this.fees) === null || _a === void 0 ? void 0 : _a.reduce((r, f) => (currency == f.currency && (scheme == "total" || scheme == f.scheme) ? (r += f.gross) : r), 0)) !== null && _b !== void 0 ? _b : 0, currency);
  }
  handlePopupToggle(event) {
    if (event.detail == false)
      this.type = undefined;
  }
  render() {
    var _a;
    const schemes = (_a = this.fees) === null || _a === void 0 ? void 0 : _a.reduce((r, fee) => (r.includes(fee.scheme) ? r : [...r, fee.scheme]), ["total"]);
    return [
      this.settlements &&
        (schemes === null || schemes === void 0 ? void 0 : schemes.map(scheme => [
          h("smoothly-display", null, this.t(this.selected ? "total selected" : "total") + (scheme == "total" ? "" : " " + scheme) + ":"),
          h("smoothly-display-amount", { amount: this.getAmount("SEK", scheme), currency: "SEK" }),
          h("span", null),
          h("smoothly-display-amount", { amount: this.getAmount("EUR", scheme), currency: "EUR" }),
        ])),
      h("smoothly-popup", { direction: "up" }, h("smoothly-icon", { color: "light", toolTip: this.t("Download settlement report"), name: "cloud-download" }), h("div", { class: "popup", slot: "popup" }, h("section", { class: this.type == "detailed" ? "selected" : "" }, h("smoothly-display", { onClick: () => (this.type = this.type == "detailed" ? undefined : "detailed") }, "Detailed"), h("smoothly-display", { style: { display: this.type ? "block" : "none" }, onClick: () => this.downloadCsv() }, "CSV")), h("section", { class: this.type == "summary" ? "selected" : "" }, h("smoothly-display", { onClick: () => (this.type = this.type == "summary" ? undefined : "summary") }, "Summary"), h("smoothly-display", { style: { display: this.type ? "block" : "none" }, onClick: () => this.downloadPdf() }, "PDF", h("form", { action: `${Connection.url}settlement/report?key=${Connection.key}${this.type == "detailed" ? "&detailed=true" : ""}`, target: "_blank", method: "post" }, h("input", { type: "hidden", name: "settlements", ref: (element) => (this.inputElement = element) }), h("smoothly-submit", { hidden: true, ref: (element) => (this.submitElement = element) })))))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroMonitorSettlementFooter.style = styleCss$2;

const styleCss$1 = ".sc-ig-single-merchant-h{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:center;justify-content:center;margin-top:1em}.sc-ig-single-merchant-h>*.sc-ig-single-merchant{margin-bottom:.5em;width:90em;margin:auto}";

const IntergiroMerchantSingle = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  render() {
    return [
      h("ig-merchant-single-information", { merchant: this.merchant }),
      h("ig-merchant-settlement", { merchant: this.merchant, view: "single" }),
      h("ig-merchant-rules", { merchant: this.merchant, audience: this.audience }),
    ];
  }
};
IntergiroMerchantSingle.style = styleCss$1;

const styleCss = ".sc-ig-user-menu-h{--menu-offset-top:0.3em;--menu-offset-right:0.3em;--item-padding:0.5em 1em;position:relative}.sc-ig-user-menu-h a.active.sc-ig-user-menu smoothly-icon.sc-ig-user-menu,.sc-ig-user-menu-h a.sc-ig-user-menu:hover smoothly-icon.sc-ig-user-menu{fill:rgb(var(--smoothly-default-shade))}.sc-ig-user-menu-h .background.sc-ig-user-menu{position:absolute;right:0;top:0;height:100vh;width:100vw}.sc-ig-user-menu-h>div.sc-ig-user-menu:not(.background){margin-top:var(--menu-offset-top);position:absolute;right:var(--menu-offset-right);min-width:10em;border-radius:0.2em;white-space:nowrap;background-color:rgb(var(--smoothly-default-shade));-webkit-box-shadow:var(--smoothly-shadow);box-shadow:var(--smoothly-shadow)}.sc-ig-user-menu-h>div.sc-ig-user-menu:not(.background)>div.sc-ig-user-menu{font-style:italic;padding:var(--item-padding);color:rgba(var(--smoothly-default-contrast), 0.6)}.sc-ig-user-menu-h>div.sc-ig-user-menu:not(.background) ul.sc-ig-user-menu{padding:0}.sc-ig-user-menu-h>div.sc-ig-user-menu:not(.background) ul.sc-ig-user-menu li.sc-ig-user-menu{font-weight:bold;cursor:pointer;display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;padding:var(--item-padding);-ms-flex-align:center;align-items:center}.sc-ig-user-menu-h>div.sc-ig-user-menu:not(.background) ul.sc-ig-user-menu li.sc-ig-user-menu:hover{background-color:rgb(var(--smoothly-primary-color));color:rgb(var(--smoothly-primary-contrast))}.sc-ig-user-menu-h>div.sc-ig-user-menu:not(.background) ul.sc-ig-user-menu li.sc-ig-user-menu:hover smoothly-icon.sc-ig-user-menu{fill:rgb(var(--smoothly-primary-contrast))}.sc-ig-user-menu-h:not([open])>div.sc-ig-user-menu{display:none}";

const IntergiroUserMenu = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.trigger = createEvent(this, "trigger", 7);
    this.isOpen = false;
  }
  close() {
    this.isOpen = false;
  }
  toggle() {
    this.isOpen = !this.isOpen;
  }
  logout() {
    this.trigger.emit({ name: "logout", value: undefined });
  }
  render() {
    return (h(Host, { open: this.isOpen }, h("a", { onClick: e => this.toggle(), class: { active: this.isOpen } }, h("smoothly-icon", { name: "person", size: "medium" })), h("div", { class: "background", onClick: () => this.close() }), h("div", null, h("div", null, this.userName), h("ul", null, h("li", { onClick: () => this.logout() }, h("span", null, "Logout"), h("smoothly-icon", { name: "log-out", size: "medium" }))))));
  }
};
IntergiroUserMenu.style = styleCss;

export { IntergiroAuthorizationFooter as ig_authorization_footer, IntergiroAuthorizations as ig_authorizations, IntergiroLogFooter as ig_log_footer, IntergiroLogTable as ig_log_table, IntergiroLogs as ig_logs, IntergiroMerchantFooter as ig_merchant_footer, IntergiroMerchants as ig_merchants, MonitorLogin as ig_monitor_login, IntergiroMonitorSettlements as ig_monitor_settlements, IntergiroMonitorSettlementDetails as ig_monitor_settlements_details, IntergiroMonitorSettlementFooter as ig_monitor_settlements_footer, IntergiroMerchantSingle as ig_single_merchant, IntergiroUserMenu as ig_user_menu };
