import { Component, h, Listen, Prop, State, Watch } from "@stencil/core";
import { Merchant } from "@payfunc/model-acquirer";
import { ModelState } from "../model";
export class IntergiroMerchants {
  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: ModelState.Authorization.template, value: this.merchants }),
      h("ig-merchant-table", { merchants: this.merchantsFiltered }),
      h("ig-merchant-footer", { merchants: this.merchantsFiltered, merchantsSelected: this.merchantsSelected }),
    ]);
  }
  static get is() { return "ig-merchants"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "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": ""
      }
    },
    "audience": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "\"private\" | \"agent\"",
        "resolved": "\"agent\" | \"private\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "audience",
      "reflect": false
    }
  }; }
  static get states() { return {
    "merchantsFiltered": {},
    "merchantsSelected": {}
  }; }
  static get watchers() { return [{
      "propName": "merchants",
      "methodName": "merchantsChanged"
    }]; }
  static get listeners() { return [{
      "name": "filterChanged",
      "method": "handleFilterChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "selectedChanged",
      "method": "handleSelectedChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
