import { Component, h, Listen, Prop, State, Watch } from "@stencil/core";
import { filter } from "selectively";
import { Order, sort } from "@payfunc/model";
export class IntergiroOrders {
  constructor() {
    this.selected = {};
    this.display = false;
  }
  componentWillLoad() {
    if (!this.ordersFiltered)
      this.updateOrders();
  }
  handleFilterChanged(event) {
    this.filter = event.detail;
    event.stopPropagation();
  }
  updateOrders() {
    const result = this.orders && (this.filter ? filter(this.filter, this.orders) : [...this.orders]);
    this.ordersFiltered = result && sort(result, "created");
  }
  handleSelectedChanged(event) {
    this.selected = event.detail;
    event.stopPropagation();
  }
  render() {
    return (h("div", null,
      h("ig-filter", { template: Order.template, filter: this.filter }),
      h("ig-orders-actions", { selected: this.selected }),
      h("ig-orders-table", { display: this.display, orders: this.ordersFiltered, selected: this.selected, receipt: this.receipt, embedded: this.embedded }),
      h("ig-orders-footer", { orders: this.ordersFiltered, selected: this.selected })));
  }
  static get is() { return "ig-orders"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "orders": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Order[]",
        "resolved": "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
    },
    "display": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "display",
      "reflect": false,
      "defaultValue": "false"
    },
    "receipt": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean | undefined",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "receipt",
      "reflect": false
    },
    "embedded": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "\"app\" | string",
        "resolved": "string | undefined",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "embedded",
      "reflect": true
    }
  }; }
  static get states() { return {
    "ordersFiltered": {},
    "selected": {}
  }; }
  static get watchers() { return [{
      "propName": "orders",
      "methodName": "updateOrders"
    }, {
      "propName": "filter",
      "methodName": "updateOrders"
    }]; }
  static get listeners() { return [{
      "name": "filterChanged",
      "method": "handleFilterChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "selectedChanged",
      "method": "handleSelectedChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
