import { r as registerInstance, h, g as getElement, c as createEvent } from './index-08b73e9e.js';
import { d as dist } from './index-3cf720d3.js';
import './Item-f4cbd6f4.js';
import { K as Key } from './index-3299c1c0.js';
import './Credentials-b84c0c5f.js';
import './Token-ba2c5d5c.js';
import './index-a0a71287.js';
import { c as create } from './index-371eae24.js';
import { g as getWarningMessage } from './model-12e84827.js';
import './_commonjsHelpers-9943807e.js';
import './index-1f953d81.js';
import './TextDecoder-357ac2ce.js';
import './index-2d6441ea.js';
import './ok-c9833bf3.js';
import './index-c2c33860.js';
import './index-714bb39b.js';
import './index-063af7ee.js';
import './index-8e333ab5.js';
import './index-f77ff597.js';

const styleCss$6 = ".sc-ig-entry-details-h{display:table-row}.sc-ig-entry-details-h>td.sc-ig-entry-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));padding:1em}.sc-ig-entry-details-h>td.sc-ig-entry-details>section.sc-ig-entry-details{display:-ms-flexbox;display:flex;-ms-flex-pack:start;justify-content:flex-start;-ms-flex-direction:column;flex-direction:column;padding-left:4.5em}.sc-ig-entry-details-h>td.sc-ig-entry-details>section.sc-ig-entry-details:not(:last-child){padding-bottom:.5em}.sc-ig-entry-details-h>td.sc-ig-entry-details>section.sc-ig-entry-details>*.sc-ig-entry-details:first-child{font-weight:bold;padding-bottom:.1em}.sc-ig-entry-details-h>td.sc-ig-entry-details>section.sc-ig-entry-details>*.sc-ig-entry-details:first-child::first-letter{text-transform:capitalize}pre.sc-ig-entry-details{max-width:40em;white-space:pre-wrap;word-wrap:break-word;margin:.1em 0}";

const IntergiroEntryDetails = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  async componentWillLoad() {
    this.t = create(this.element);
    for (const data of Object.entries(this.entry.data))
      if (data[0] == "headers" && data[1].authorization)
        this.key = await Key.unpack(data[1].authorization.replace("Bearer ", ""), "public", "private", "agent");
  }
  render() {
    const t = this.t;
    const data = this.entry.point == "response" ? this.entry.data.body : this.entry.data;
    return (this.opened == "data" && (h("td", { colSpan: 3 }, typeof data == "object" ? (Object.entries(data).map(d => this.key && d[0] == "headers" ? ([
      h("section", null, h("smoothly-display", null, t(d[0])), h("pre", null, "content type: " + d[1].contentType), h("pre", null, "accept: " + JSON.stringify(d[1].accept, null, 2))),
      h("section", null, h("smoothly-display", null, t("key")), h("pre", null, "issuer: " + this.key.iss), h("pre", null, "issued at: " + dist.DateTime.localize(dist.DateTime.create(new Date(this.key.iat * 1000)))), h("pre", null, "audience: " + this.key.aud), this.key.agent && h("pre", null, "agent: " + this.key.agent), h("pre", null, "id: " + this.key.sub), this.key.url && h("pre", null, "url: " + this.key.url), this.key.card && h("pre", null, "card: " + JSON.stringify(this.key.card, null, 2)), h("pre", null, "signature: " + this.key.token.split(".").pop())),
    ]) : (h("section", null, h("smoothly-display", null, t(d[0])), h("pre", null, typeof d[1] == "object" ? JSON.stringify(d[1], null, 2) : d[1]))))) : (h("section", null, h("smoothly-display", null, "body"), h("pre", null, data))))));
  }
  get element() { return getElement(this); }
};
IntergiroEntryDetails.style = styleCss$6;

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

const IntergiroEntryTable = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.opened = {};
  }
  componentWillLoad() {
    this.t = create(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.entries.length > 0 ? ([
        h("table", null, h("thead", null, h("tr", null, h("th", { color: "light" }, this.t("level")), h("th", { color: "light" }, this.t("point")), h("th", { color: "light" }, this.t("data")))), this.entries.map(e => {
          const index = this.entries.indexOf(e);
          return [
            h("ig-entry-table-row", { entry: e, opened: this.opened[index], index: index }),
            h("ig-entry-details", { entry: e, opened: this.opened[index] }),
          ];
        })),
      ]) : (h("p", null, this.t("There are no entries to display."))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroEntryTable.style = styleCss$5;

const styleCss$4 = ".sc-ig-entry-table-row-h{display:table-row;border-top:1px solid rgba(var(--smoothly-medium-color), 0);border-bottom:1px solid rgba(var(--smoothly-medium-color), 0)}[hidden].sc-ig-entry-table-row-h{display:none}.sc-ig-entry-table-row-h:hover{border-top:1px solid rgb(var(--smoothly-medium-color));border-bottom:1px solid rgb(var(--smoothly-medium-color));-webkit-box-shadow:var(--smoothly-shadow);box-shadow:var(--smoothly-shadow)}.sc-ig-entry-table-row-h>td.sc-ig-entry-table-row:not(:last-child){padding-left:.3em}.sc-ig-entry-table-row-h>td.sc-ig-entry-table-row>*.sc-ig-entry-table-row{padding:.5em .3em;width:-webkit-max-content;width:-moz-max-content;width:max-content;min-width:3em;display:inline-block}.sc-ig-entry-table-row-h>td.sc-ig-entry-table-row>*.sc-ig-entry-table-row:hover{background-color:rgb(var(--smoothly-dark-shade));cursor:pointer}.opened.sc-ig-entry-table-row{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:-2px;margin-top:-1px}";

const IntergiroLogTableRow$1 = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.columnClicked = createEvent(this, "columnClicked", 7);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  handleColumnClick(column) {
    this.columnClicked.emit({ index: this.index, column });
  }
  render() {
    const t = this.t;
    return [
      h("td", null, t(this.entry.level)),
      h("td", null, t(this.entry.point)),
      h("td", null, h("section", { class: "openable" + (this.opened == "data" ? " opened" : ""), onClick: () => this.handleColumnClick("data") }, t(this.entry.level == "warning" ? getWarningMessage(this.entry) : "details"))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroLogTableRow$1.style = styleCss$4;

const styleCss$3 = ".sc-ig-log-details-h{display:table-row}.sc-ig-log-details-h>td.sc-ig-log-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));padding:1em}smoothly-display.sc-ig-log-details{overflow:visible;word-wrap:break-word;max-width:80em;padding:.5em;padding-left:4.5em}";

const IntergiroLogDetails = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  render() {
    let result;
    switch (this.opened) {
      case "merchant":
        result = h("ig-log-merchant", { log: this.log });
        break;
      case "reference":
        result = h("ig-log-reference", { reference: this.log.reference });
        break;
      case "entries":
        result = h("ig-entry-table", { entries: this.log.entries });
        break;
      case "resource":
        result = h("smoothly-display", null, this.log.resource.method + " " + this.log.resource.location);
        break;
      default:
        return "";
    }
    return h("td", { colSpan: 5 }, result);
  }
};
IntergiroLogDetails.style = styleCss$3;

const styleCss$2 = ".sc-ig-log-merchant-h{display:-ms-flexbox;display:flex;-ms-flex-pack:start;justify-content:flex-start;padding-left:4.5em}.sc-ig-log-merchant-h>section.sc-ig-log-merchant>*.sc-ig-log-merchant:first-child{font-weight:bold}.sc-ig-log-merchant-h>section.sc-ig-log-merchant>*.sc-ig-log-merchant:first-child::first-letter{text-transform:capitalize}section.sc-ig-log-merchant{width:50%}smoothly-display.sc-ig-log-merchant,ig-display-edit.sc-ig-log-merchant{text-align:left;margin:0;width:35%}";

const IntergiroLogMerchant = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  render() {
    return [
      h("section", null, h("smoothly-display", null, this.t("agent")), h("smoothly-display", null, this.log.agent)),
      this.log.merchant && (h("section", null, h("smoothly-display", null, this.t("merchant")), h("smoothly-display", null, this.t(this.log.merchant)))),
      this.log.client && (h("section", null, h("smoothly-display", null, this.t("client")), h("smoothly-display", null, this.log.client))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroLogMerchant.style = styleCss$2;

const styleCss$1 = ".sc-ig-log-reference-h{display:-ms-flexbox;display:flex;-ms-flex-pack:start;justify-content:flex-start;padding-left:4.5em}.sc-ig-log-reference-h>section.sc-ig-log-reference{width:50%}.sc-ig-log-reference-h>section.sc-ig-log-reference>*.sc-ig-log-reference{text-align:left;margin:0;width:35%}.sc-ig-log-reference-h>section.sc-ig-log-reference>*.sc-ig-log-reference:first-child{font-weight:bold}.sc-ig-log-reference-h>section.sc-ig-log-reference>*.sc-ig-log-reference:first-child::first-letter{text-transform:capitalize}.sc-ig-log-reference-h>section.sc-ig-log-reference>*.sc-ig-log-reference:last-child{cursor:pointer}";

const IntergiroLogReference = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.referenceFiltered = createEvent(this, "referenceFiltered", 7);
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  render() {
    return [
      h("section", null, h("smoothly-display", null, this.t("type")), h("smoothly-display", { onClick: () => this.referenceFiltered.emit(this.reference.type) }, this.t(this.reference.type))),
      this.reference.id && (h("section", null, h("smoothly-display", null, "ID"), h("smoothly-display", { onClick: () => this.referenceFiltered.emit(this.reference.id) }, this.reference.id))),
      this.reference.number && (h("section", null, h("smoothly-display", null, this.t("number")), h("smoothly-display", { onClick: () => this.referenceFiltered.emit(this.reference.number) }, this.reference.number))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroLogReference.style = styleCss$1;

const styleCss = ".sc-ig-log-table-row-h{display:table-row;border-top:1px solid rgba(var(--smoothly-medium-color), 0);border-bottom:1px solid rgba(var(--smoothly-medium-color), 0)}[hidden].sc-ig-log-table-row-h{display:none}.sc-ig-log-table-row-h:hover{border-top-color:rgb(var(--smoothly-medium-color));border-bottom-color:rgb(var(--smoothly-medium-color));-webkit-box-shadow:var(--smoothly-shadow);box-shadow:var(--smoothly-shadow)}.sc-ig-log-table-row-h>td.sc-ig-log-table-row:nth-child(5){max-width:18em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sc-ig-log-table-row-h>td.sc-ig-log-table-row>*.sc-ig-log-table-row{padding:.5em .3em;width:-webkit-max-content;width:-moz-max-content;width:max-content;min-width:3em;display:inline-block}.sc-ig-log-table-row-h>td.sc-ig-log-table-row>.openable.sc-ig-log-table-row:hover{background-color:rgb(var(--smoothly-dark-shade));cursor:pointer}.opened.sc-ig-log-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;margin-top:-1px}.sc-ig-log-table-row-h>td.sc-ig-log-table-row:first-of-type>.opened.sc-ig-log-table-row{border-left:none}";

const resources = [
  (l, m, t, s) => l.match(/authorization\/?$/g) && m == "POST"
    ? `${t("authorization") + (s ? " " + s.amount + " " + s.currency : "")}`
    : undefined,
  (l, m, t, s) => l.match(/refund\/?$/g) && m == "POST" ? `${t("refund") + (s ? " " + s.amount + " " + s.currency : "")}` : undefined,
  (l, m, t, s) => l.match(/capture\/?$/g) && m == "POST"
    ? `${t("capture") + (s ? " " + s.amount + " " + s.currency : "")}`
    : undefined,
  (l, m, t) => (l.match(/authorization/g) && m == "DELETE" ? t("cancelled") : undefined),
  (l, m, t) => (l.match(/ch3d1.*check\/?$/g) && m == "POST" ? t("ch3d1 check") : undefined),
  (l, m, t) => (l.match(/ch3d1.*enrolled\/?$/g) && m == "POST" ? t("ch3d1 enrolled") : undefined),
  (l, m, t) => (l.match(/authorization\/merchant\/?$/g) && m == "POST" ? t("create merchant") : undefined),
  (l, m, t) => (l.match(/rule\/?$/g) && (m == "PUT" || m == "PATCH") ? t("change rule") : undefined),
  (l, m, t) => l.match(/authorization\/merchant\/?/g) && (m == "PUT" || m == "PATCH") ? t("change merchant") : undefined,
  (l, m, t) => (l.match(/card\/?$/g) && m == "POST" ? t("create card") : undefined),
  (l, m, t) => (l.match(/card\/secret\/?$/g) && m == "DELETE" ? t("regenerate secrets") : undefined),
  (l, m, t) => (l.match(/settlement\/?/g) && m == "POST" ? t("manually create settlements") : undefined),
  (l, m, t) => (l.match("Settlement") && m == "SCHEDULE" ? t("scheduled generation of settlements") : undefined),
  (l, m, t) => (l.match(/preauth\/?/g) && m == "POST" ? t("3d2 preauthorization step") : undefined),
  (l, m, t) => (l.match(/postauth\/?/g) && m == "POST" ? t("3d2 postauthorization step") : undefined),
  (l, m, t) => (l.match(/auth\/?/g) && m == "POST" ? t("3d2 authorization step") : undefined),
  (l, m, t) => l.match("Currency Conversion") && m == "SCHEDULE"
    ? t("scheduled updating of currency conversion rates")
    : undefined,
];
const IntergiroLogTableRow = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.columnClicked = createEvent(this, "columnClicked", 7);
    this.opened = "";
    this.abbreviated = false;
    this.hideMerchant = false;
  }
  componentWillLoad() {
    this.t = create(this.element);
    this.getResource();
  }
  handleColumnClick(column) {
    this.opened = column;
    this.columnClicked.emit({ index: this.index, column });
  }
  getResource() {
    var _a, _b, _c;
    const t = this.t;
    const search = (_b = (_a = this.log.entries.find(e => e.point == "PreAuthorization State")) === null || _a === void 0 ? void 0 : _a.data.state) !== null && _b !== void 0 ? _b : (_c = this.log.entries.find(e => e.point == "PostAuthorization State")) === null || _c === void 0 ? void 0 : _c.data.state;
    const level = this.log.entries[this.log.entries.length - 1].level;
    let resource;
    for (const check of resources)
      if ((resource = check(this.log.resource.location, this.log.resource.method, this.t, search === null || search === void 0 ? void 0 : search.authorization)))
        break;
    this.resource = resource
      ? resource + t(level == "warning" || level == "error" || level == "exception" ? " failed" : "")
      : this.log.resource.method + " " + this.log.resource.location;
  }
  render() {
    const t = this.t;
    const entry = this.log.entries[this.log.entries.length - 1];
    return [
      !(this.abbreviated || this.hideMerchant) && [
        h("td", null, h("section", { class: "openable" + (this.opened == "merchant" ? " opened" : ""), onClick: () => this.handleColumnClick("merchant") }, t(this.log.merchant))),
      ],
      !this.abbreviated && [
        h("td", null, h("section", { class: this.log.reference ? "openable" + (this.opened == "reference" ? " opened" : "") : "", onClick: () => this.log.reference && this.handleColumnClick("reference") }, this.log.reference ? t(this.log.reference.type) : t("none"))),
      ],
      h("td", null, h("section", { class: "openable" + (this.opened == "resource" ? " opened" : ""), onClick: () => this.handleColumnClick("resource") }, this.resource)),
      h("td", null, h("section", { class: "openable" + (this.opened == "entries" ? " opened" : ""), onClick: () => this.handleColumnClick("entries") }, t(entry.level == "warning" ? getWarningMessage(entry) : entry.level))),
      h("td", null, h("smoothly-display-date-time", { datetime: dist.DateTime.localize(this.log.created) })),
    ];
  }
  get element() { return getElement(this); }
  static get watchers() { return {
    "log": ["getResource"]
  }; }
};
IntergiroLogTableRow.style = styleCss;

export { IntergiroEntryDetails as ig_entry_details, IntergiroEntryTable as ig_entry_table, IntergiroLogTableRow$1 as ig_entry_table_row, IntergiroLogDetails as ig_log_details, IntergiroLogMerchant as ig_log_merchant, IntergiroLogReference as ig_log_reference, IntergiroLogTableRow as ig_log_table_row };
