import { Component, Event, h, Listen, Prop, State, Watch } from "@stencil/core";
import * as selectively from "selectively";
import { Account } from "@payfunc/model";
export class IntergiroAccounts {
  constructor() {
    this.selected = {};
  }
  componentWillLoad() {
    if (!this.accountsFiltered)
      this.filterAccounts();
  }
  handleFilterChanged(event) {
    this.filter = event.detail;
    event.stopPropagation();
  }
  filterAccounts() {
    const result = this.accounts && (this.filter ? selectively.filter(this.filter, this.accounts) : [...this.accounts]);
    this.accountsFiltered = result;
  }
  handleSelectedChanged(event) {
    this.selected = event.detail;
  }
  onCreate(e) {
    this.updateAccounts.emit(e.detail);
  }
  render() {
    return [
      h("ig-filter", { template: Account.template, filter: this.filter }),
      h("ig-accounts-actions", { whitelist: this.whitelist, selected: this.selected }),
      h("ig-accounts-table", { accounts: this.accountsFiltered, orders: this.orders, selected: this.selected, whitelist: this.whitelist }),
      h("ig-account-create-popup", { hidden: true, onCreate: (e) => this.onCreate(e) }),
      h("ig-accounts-footer", { accounts: this.accountsFiltered }),
    ];
  }
  static get is() { return "ig-accounts"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "accounts": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Account[]",
        "resolved": "Account[] | undefined",
        "references": {
          "Account": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "orders": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "{ [id: string]: Order[] | undefined }",
        "resolved": "undefined | { [id: string]: Order[] | undefined; }",
        "references": {
          "Order": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "filter": {
      "type": "any",
      "mutable": true,
      "complexType": {
        "original": "Criteria",
        "resolved": "Helper[] | Rule | number | string | undefined | { [property: string]: Helper | Helper[]; }",
        "references": {
          "Criteria": {
            "location": "import",
            "path": "selectively"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "filter",
      "reflect": false
    },
    "whitelist": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean | undefined",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "whitelist",
      "reflect": false
    }
  }; }
  static get states() { return {
    "accountsFiltered": {},
    "selected": {}
  }; }
  static get events() { return [{
      "method": "updateAccounts",
      "name": "updateAccounts",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get watchers() { return [{
      "propName": "accounts",
      "methodName": "filterAccounts"
    }, {
      "propName": "filter",
      "methodName": "filterAccounts"
    }]; }
  static get listeners() { return [{
      "name": "filterChanged",
      "method": "handleFilterChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "selectedChanged",
      "method": "handleSelectedChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
