import { Component, Element, h, Listen, Prop, State } from "@stencil/core";
import * as translation from "../translation";
export class IntergiroLogTable {
  constructor() {
    this.hideMerchant = false;
    this.abbreviated = false;
    this.opened = {};
    this.count = 100;
  }
  componentWillLoad() {
    this.t = translation.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.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."))),
    ];
  }
  static get is() { return "ig-log-table"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "hideMerchant": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "hide-merchant",
      "reflect": false,
      "defaultValue": "false"
    },
    "logs": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Log[]",
        "resolved": "Log[] | undefined",
        "references": {
          "Log": {
            "location": "import",
            "path": "@payfunc/model-log"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "abbreviated": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "abbreviated",
      "reflect": false,
      "defaultValue": "false"
    }
  }; }
  static get states() { return {
    "t": {},
    "opened": {},
    "count": {}
  }; }
  static get elementRef() { return "element"; }
  static get listeners() { return [{
      "name": "columnClicked",
      "method": "toggleColumn",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
