var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a getter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _KlevuLatestSearches_instances, _KlevuLatestSearches_lastSearchClick;
import { KlevuLastSearches } from "@klevu/core";
import { h, Host } from "@stencil/core";
import { getTranslation } from "../../utils/getTranslation";
/**
 * Lists latest searches user has made on the site
 */
export class KlevuLatestSearches {
  constructor() {
    _KlevuLatestSearches_instances.add(this);
    this.tCaption = getTranslation("latestSearches.tCaption");
    this.lastSearches = [];
  }
  async connectedCallback() {
    this.lastSearches = KlevuLastSearches.get().map((s) => s.term);
  }
  render() {
    if (this.lastSearches.length === 0) {
      return null;
    }
    return (h(Host, null, h("klevu-typography", { variant: "h3", class: "caption" }, this.tCaption), this.lastSearches.map((ls) => (h("klevu-list", { condensed: true, noXPadding: true, onClick: () => __classPrivateFieldGet(this, _KlevuLatestSearches_instances, "m", _KlevuLatestSearches_lastSearchClick).call(this, ls) }, h("span", { slot: "primary" }, ls))))));
  }
  static get is() { return "klevu-latest-searches"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-latest-searches.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-latest-searches.css"]
    };
  }
  static get properties() {
    return {
      "tCaption": {
        "type": "any",
        "mutable": false,
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Caption of the list"
        },
        "attribute": "t-caption",
        "reflect": false,
        "defaultValue": "getTranslation(\"latestSearches.tCaption\")"
      }
    };
  }
  static get states() {
    return {
      "lastSearches": {}
    };
  }
  static get events() {
    return [{
        "method": "klevuLastSearchClicked",
        "name": "klevuLastSearchClicked",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Event that is emitted when a popular search is clicked"
        },
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        }
      }];
  }
}
_KlevuLatestSearches_instances = new WeakSet(), _KlevuLatestSearches_lastSearchClick = function _KlevuLatestSearches_lastSearchClick(suggestion) {
  this.klevuLastSearchClicked.emit(suggestion);
};
//# sourceMappingURL=klevu-latest-searches.js.map
