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 _KlevuPopularSearches_instances, _KlevuPopularSearches_popularSearchClick;
import { KlevuKMCSettings } from "@klevu/core";
import { h, Host } from "@stencil/core";
import { KlevuInit } from "../klevu-init/klevu-init";
import { getTranslation } from "../../utils/getTranslation";
/**
 * Fetches and displays most popular searches from Klevu Merchant center
 */
export class KlevuPopularSearches {
  constructor() {
    _KlevuPopularSearches_instances.add(this);
    this.tCaption = getTranslation("popularSearches.tCaption");
    this.popularSearches = [];
  }
  async connectedCallback() {
    var _a, _b;
    await KlevuInit.ready();
    try {
      const settings = await KlevuKMCSettings();
      this.popularSearches = (_b = (_a = settings.root) === null || _a === void 0 ? void 0 : _a.klevu_webstorePopularTerms) !== null && _b !== void 0 ? _b : [];
    }
    catch (_c) { }
  }
  render() {
    if (this.popularSearches.length == 0) {
      return null;
    }
    return (h(Host, null, h("klevu-typography", { class: "caption", variant: "h3" }, this.tCaption), this.popularSearches.map((s) => (h("klevu-list", { condensed: true, noXPadding: true, onClick: () => __classPrivateFieldGet(this, _KlevuPopularSearches_instances, "m", _KlevuPopularSearches_popularSearchClick).call(this, s) }, h("span", { slot: "primary" }, s))))));
  }
  static get is() { return "klevu-popular-searches"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-popular-searches.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-popular-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(\"popularSearches.tCaption\")"
      }
    };
  }
  static get states() {
    return {
      "popularSearches": {}
    };
  }
  static get events() {
    return [{
        "method": "klevuPopularSearchClicked",
        "name": "klevuPopularSearchClicked",
        "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": {}
        }
      }];
  }
}
_KlevuPopularSearches_instances = new WeakSet(), _KlevuPopularSearches_popularSearchClick = function _KlevuPopularSearches_popularSearchClick(suggestion) {
  this.klevuPopularSearchClicked.emit(suggestion);
};
//# sourceMappingURL=klevu-popular-searches.js.map
