import { Component, Host, h, Prop, Watch, State } from '@stencil/core';
export class ScPriceRange {
  handlePricesChange() {
    var _a;
    let min, max;
    (_a = this.prices) === null || _a === void 0 ? void 0 : _a.forEach(price => {
      if (!max || price.amount > max.amount) {
        max = price;
      }
      if (!min || price.amount < min.amount) {
        min = price;
      }
    });
    this.minPrice = min;
    this.maxPrice = max;
  }
  componentWillLoad() {
    this.handlePricesChange();
  }
  render() {
    if (!this.maxPrice || !this.minPrice) {
      return h(Host, null);
    }
    return (h(Host, null, this.maxPrice.amount == this.minPrice.amount ? (h("span", { class: "price-range-display" },
      h("sc-format-number", { type: "currency", currency: this.maxPrice.currency, value: this.maxPrice.amount }))) : (h("span", { class: "price-range-display" },
      h("sc-format-number", { type: "currency", currency: this.minPrice.currency, value: this.minPrice.amount }),
      "-",
      h("sc-format-number", { type: "currency", currency: this.maxPrice.currency, value: this.maxPrice.amount })))));
  }
  static get is() { return "sc-price-range"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["sc-price-range.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-price-range.css"]
  }; }
  static get properties() { return {
    "prices": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Price[]",
        "resolved": "Price[]",
        "references": {
          "Price": {
            "location": "import",
            "path": "../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The array of price objects"
      }
    }
  }; }
  static get states() { return {
    "minPrice": {},
    "maxPrice": {}
  }; }
  static get watchers() { return [{
      "propName": "prices",
      "methodName": "handlePricesChange"
    }]; }
}
