import { Component, Event, h, Listen, Prop, State, Watch } from "@stencil/core";
import * as selectively from "selectively";
import { Customer } from "@payfunc/model";
export class IntergiroCustomers {
  constructor() {
    this.selected = {};
  }
  componentWillLoad() {
    if (!this.customersFiltered)
      this.filterCustomers();
  }
  handleFilterChanged(event) {
    this.filter = event.detail;
    event.stopPropagation();
  }
  filterCustomers() {
    const result = this.customers && (this.filter ? selectively.filter(this.filter, this.customers) : [...this.customers]);
    this.customersFiltered = result;
  }
  handleSelectedChanged(event) {
    this.selected = event.detail;
  }
  onCreate(e) {
    this.updateCustomers.emit(e.detail);
  }
  render() {
    return [
      h("ig-filter", { template: Customer.template, filter: this.filter }),
      h("ig-customer-actions", { whitelist: this.whitelist, selected: this.selected }),
      h("ig-customers-table", { customers: this.customersFiltered, orders: this.orders, selected: this.selected, whitelist: this.whitelist }),
      h("ig-customer-create-popup", { hidden: true, onCreate: (e) => this.onCreate(e) }),
      h("ig-customers-footer", { customers: this.customersFiltered }),
    ];
  }
  static get is() { return "ig-customers"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "customers": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Customer[]",
        "resolved": "Customer[] | undefined",
        "references": {
          "Customer": {
            "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 {
    "customersFiltered": {},
    "selected": {}
  }; }
  static get events() { return [{
      "method": "updateCustomers",
      "name": "updateCustomers",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get watchers() { return [{
      "propName": "customers",
      "methodName": "filterCustomers"
    }, {
      "propName": "filter",
      "methodName": "filterCustomers"
    }]; }
  static get listeners() { return [{
      "name": "filterChanged",
      "method": "handleFilterChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "selectedChanged",
      "method": "handleSelectedChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
