import { Component, h, Listen, Prop, State, Watch } from "@stencil/core";
import { sort } from "@payfunc/model";
export class PayfuncOrders {
  constructor() {
    this.selected = {};
    this.display = false;
  }
  componentWillLoad() {
    if (!this.ordersFiltered)
      this.updateOrders();
  }
  updateOrders(orders) {
    var _a;
    this.ordersFiltered = sort((_a = orders !== null && orders !== void 0 ? orders : this.orders) !== null && _a !== void 0 ? _a : [], "created");
  }
  handleFilterChanged(event) {
    this.updateOrders(event.detail);
    event.stopPropagation();
  }
  handleSelectedChanged(event) {
    this.selected = event.detail;
    event.stopPropagation();
  }
  render() {
    return (h("div", null,
      h("payfunc-filter", { filter: this.filter, value: this.orders }),
      h("payfunc-orders-actions", { selected: this.selected }),
      h("payfunc-orders-table", { display: this.display, orders: this.ordersFiltered, selected: this.selected, receipt: this.receipt }),
      h("payfunc-orders-footer", { orders: this.ordersFiltered, selected: this.selected })));
  }
  static get is() { return "payfunc-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]: string | number | Rule | any | 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
    }
  }; }
  static get states() { return {
    "ordersFiltered": {},
    "selected": {}
  }; }
  static get watchers() { return [{
      "propName": "orders",
      "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
    }]; }
}
