import { Component, Element, h, Prop, State } from "@stencil/core";
import * as isoly from "isoly";
import { DateTime } from "isoly";
import { Key } from "@payfunc/model";
import * as translation from "../../../../translation";
export class IntergiroEntryDetails {
  async componentWillLoad() {
    this.t = translation.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: " + DateTime.localize(isoly.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))))));
  }
  static get is() { return "ig-entry-details"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "entry": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Log.Entry",
        "resolved": "Entry",
        "references": {
          "Log": {
            "location": "import",
            "path": "@payfunc/model-log"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "opened": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "opened",
      "reflect": false
    }
  }; }
  static get states() { return {
    "t": {},
    "key": {}
  }; }
  static get elementRef() { return "element"; }
}
