import { Component, h, Listen, Prop, State, Watch } from "@stencil/core";
import { Error } from "gracely";
import { sort } from "@payfunc/model";
export class IntergiroLogs {
  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 is() { return "ig-logs"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "logs": {
      "type": "unknown",
      "mutable": true,
      "complexType": {
        "original": "Log[] | Promise<Log[] | Error | string>",
        "resolved": "Log[] | Promise<string | Error | Log[]> | undefined",
        "references": {
          "Log": {
            "location": "import",
            "path": "@payfunc/model-log"
          },
          "Promise": {
            "location": "global"
          },
          "Error": {
            "location": "import",
            "path": "gracely"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "merchants": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Merchant[]",
        "resolved": "Merchant[] | undefined",
        "references": {
          "Merchant": {
            "location": "import",
            "path": "@payfunc/model-acquirer"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "logsFiltered": {},
    "filter": {}
  }; }
  static get watchers() { return [{
      "propName": "merchants",
      "methodName": "logsUpdate"
    }, {
      "propName": "logs",
      "methodName": "logsUpdate"
    }]; }
  static get listeners() { return [{
      "name": "filterChanged",
      "method": "handleFilterChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "referenceFiltered",
      "method": "handleReferenceFiltered",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
