var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
  if (kind === "m")
    throw new TypeError("Private method is not writable");
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a setter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
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 _KlevuSearchLandingPage_instances, _KlevuSearchLandingPage_noResultsOptions, _KlevuSearchLandingPage_resultObject, _KlevuSearchLandingPage_imagePickerPopupRef, _KlevuSearchLandingPage_viewportUtil, _KlevuSearchLandingPage_layoutElement, _KlevuSearchLandingPage_facetListElement, _KlevuSearchLandingPage_fetchData, _KlevuSearchLandingPage_handleNoResults, _KlevuSearchLandingPage_sizeChange, _KlevuSearchLandingPage_emitChanges, _KlevuSearchLandingPage_sortChanged, _KlevuSearchLandingPage_applyFilters, _KlevuSearchLandingPage_isMobile, _KlevuSearchLandingPage_mobileDrawerOpened, _KlevuSearchLandingPage_handlePopularKeywordClick, _KlevuSearchLandingPage_handleImageSelection, _KlevuSearchLandingPage_renderNoResultBanners;
import { applyFilterWithManager, FilterManager, KlevuFetch, listFilters, personalisation, search, sendSearchEvent, trendingProducts, imageSearch, KlevuUploadImageForSearch, klaviyo, } from "@klevu/core";
import { h, Host, Fragment } from "@stencil/core";
import { parts } from "../../utils/parts";
import { KlevuInit } from "../klevu-init/klevu-init";
import { getTranslation } from "../../utils/getTranslation";
import { stringConcat } from "../../utils/stringConcat";
import { getKMCSettings } from "../../utils/getKMCSettings";
/**
 * Full app component for search landing page
 *
 * @slot header - Header container
 * @slot footer - Footer container
 * @slot content - Product grid items including the grid container
 * @slot facets - Sidebar of facets content
 * @slot noResults - Show message when no results found
 * @slot topbanners - Top banner content
 * @slot bottombanners - Bottom banner content
 */
export class KlevuSearchLandingPage {
  constructor() {
    _KlevuSearchLandingPage_instances.add(this);
    _KlevuSearchLandingPage_noResultsOptions.set(this, void 0);
    _KlevuSearchLandingPage_resultObject.set(this, void 0);
    _KlevuSearchLandingPage_imagePickerPopupRef.set(this, void 0);
    _KlevuSearchLandingPage_viewportUtil.set(this, void 0);
    _KlevuSearchLandingPage_layoutElement.set(this, void 0);
    _KlevuSearchLandingPage_facetListElement.set(this, void 0);
    this.limit = 24;
    this.term = undefined;
    this.sort = undefined;
    this.filterCount = undefined;
    this.filterCustomOrder = undefined;
    this.usePagination = undefined;
    this.useInfiniteScroll = undefined;
    this.showRatings = undefined;
    this.showRatingsCount = undefined;
    this.tSearchTitle = getTranslation("searchLandingPage.tSearchTitle");
    this.tLoadMore = getTranslation("searchLandingPage.tLoadMore");
    this.usePersonalisation = undefined;
    this.popularProductsResultCount = 3;
    this.showSearch = undefined;
    this.hideFilters = undefined;
    this.useMultiSelectFilters = undefined;
    this.useKlaviyo = undefined;
    this.showPriceAsSlider = undefined;
    this.priceInterval = 500;
    this.hidePrice = undefined;
    this.imageUrlForSearch = "";
    this.results = [];
    this.manager = new FilterManager();
    this.currentViewPortSize = undefined;
    this.infiniteScrollingPaused = false;
    this.loading = false;
    this.noResultsMessage = "";
    this.trendingProducts = [];
    this.noResultsBannerDetails = [];
    this.searchResultTopBanners = [];
    this.searchResultBottomBanners = [];
    this.isUploadingImage = false;
  }
  async connectedCallback() {
    var _a, _b, _c, _d;
    await KlevuInit.ready();
    const settings = getKMCSettings();
    if (settings) {
      __classPrivateFieldSet(this, _KlevuSearchLandingPage_noResultsOptions, (_a = settings.klevu_uc_userOptions) === null || _a === void 0 ? void 0 : _a.noResultsOptions, "f");
      if (this.showRatings === undefined) {
        this.showRatings = ((_b = settings.klevu_uc_userOptions) === null || _b === void 0 ? void 0 : _b.showRatingsOnSearchResultsLandingPage) || false;
      }
      if (this.showRatingsCount === undefined) {
        this.showRatingsCount = ((_c = settings.klevu_uc_userOptions) === null || _c === void 0 ? void 0 : _c.showRatingsCountOnSearchResultsLandingPage) || false;
      }
      if (this.usePersonalisation === undefined && (settings === null || settings === void 0 ? void 0 : settings.klevu_uc_userOptions.enablePersonalisationInSearch)) {
        this.usePersonalisation = true;
      }
      if (this.showSearch === undefined) {
        this.showSearch = settings.klevu_uc_userOptions.showSearchBoxOnLandingPage;
      }
      if (this.hideFilters === undefined) {
        this.hideFilters = !settings.klevu_filtersEnabled;
      }
      if (this.useMultiSelectFilters === undefined) {
        this.useMultiSelectFilters = settings.klevu_multiSelectFilters;
        this.showSearch = settings === null || settings === void 0 ? void 0 : settings.klevu_uc_userOptions.showSearchBoxOnLandingPage;
      }
      if (this.showPriceAsSlider === undefined) {
        this.showPriceAsSlider = settings.klevu_showPriceSlider;
      }
      if (this.priceInterval === undefined) {
        this.priceInterval = parseInt(settings.klevu_uc_userOptions.priceInterval, 10);
      }
      if (this.hidePrice === undefined) {
        this.hidePrice = !settings.klevu_showPrices;
      }
    }
    const showPopularProducts = (_d = settings === null || settings === void 0 ? void 0 : settings.klevu_uc_userOptions) === null || _d === void 0 ? void 0 : _d.noResultsOptions.showPopularProducts;
    if (showPopularProducts) {
      const trendingProductsQuery = await KlevuFetch(trendingProducts({
        limit: this.popularProductsResultCount,
      }));
      const resultObject = trendingProductsQuery.queriesById("trendingProducts");
      if (resultObject) {
        this.trendingProducts = resultObject.records;
      }
    }
    await __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_fetchData).call(this);
  }
  termChanged(oldValue, newValue) {
    __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_fetchData).call(this);
  }
  async loadMore() {
    var _a, _b, _c;
    this.loading = true;
    if (!((_a = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.getPage)) {
      return;
    }
    const nextResultObject = await __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f").getPage();
    __classPrivateFieldSet(this, _KlevuSearchLandingPage_resultObject, nextResultObject === null || nextResultObject === void 0 ? void 0 : nextResultObject.queriesById("search"), "f");
    this.results = [...this.results, ...((_c = (_b = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : [])];
    __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_emitChanges).call(this);
    this.loading = false;
  }
  async paginationChange(event) {
    var _a, _b, _c;
    if (!((_a = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.getPage)) {
      return;
    }
    this.loading = true;
    const nextResultObject = await __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f").getPage({ pageIndex: event.detail - 1 });
    __classPrivateFieldSet(this, _KlevuSearchLandingPage_resultObject, nextResultObject === null || nextResultObject === void 0 ? void 0 : nextResultObject.queriesById("search"), "f");
    this.results = (_c = (_b = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : [];
    __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_emitChanges).call(this);
    this.loading = false;
  }
  productClickHandler(event) {
    var _a;
    if (((_a = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.searchClickEvent) && event.detail.product.id) {
      __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f").searchClickEvent({
        productId: event.detail.product.id,
        variantId: event.detail.product.itemGroupId || event.detail.product.id,
      });
    }
  }
  filterManagerFiltersUpdated() {
    if (__classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_isMobile).call(this)) {
      return;
    }
    __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_fetchData).call(this);
  }
  async componentDidLoad() {
    this.currentViewPortSize = await __classPrivateFieldGet(this, _KlevuSearchLandingPage_viewportUtil, "f").getCurrentSize();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
    const isMobile = ((_a = this.currentViewPortSize) === null || _a === void 0 ? void 0 : _a.name) === "xs" || ((_b = this.currentViewPortSize) === null || _b === void 0 ? void 0 : _b.name) === "sm";
    const showInfiniteScroll = this.useInfiniteScroll && !this.infiniteScrollingPaused && this.results.length > 0;
    return (h(Host, null, h("klevu-util-viewport", { onKlevuSizeChanged: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_sizeChange).bind(this), ref: (el) => (__classPrivateFieldSet(this, _KlevuSearchLandingPage_viewportUtil, el, "f")) }), h("klevu-layout-results", { onKlevuDrawerOpened: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_mobileDrawerOpened).bind(this), ref: (el) => (__classPrivateFieldSet(this, _KlevuSearchLandingPage_layoutElement, el, "f")) }, h("slot", { name: "facets", slot: "sidebar" }, !this.hideFilters && (h("klevu-facet-list", { ref: (el) => (__classPrivateFieldSet(this, _KlevuSearchLandingPage_facetListElement, el, "f")), customOrder: this.filterCustomOrder, manager: this.manager, useApplyButton: isMobile, onKlevuApplyFilters: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_applyFilters).bind(this), mode: this.useMultiSelectFilters ? "checkbox" : "radio" }))), h("div", { slot: "header", class: "header" }, this.showSearch && h("klevu-quicksearch", null), h("div", { class: "info" }, this.imageUrlForSearch ? (__classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f") && (h("div", { class: "imageSearchResults" }, h("div", { class: "image" }, h("img", { src: this.imageUrlForSearch, alt: "" })), h("klevu-typography", { slot: "header", variant: "h1" }, "We found ", (_c = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _c === void 0 ? void 0 :
      _c.meta.totalResultsFound, " matches to your uploaded photo"), h("klevu-popup", { ref: (el) => (__classPrivateFieldSet(this, _KlevuSearchLandingPage_imagePickerPopupRef, el, "f")), popupWidth: 400, anchor: "bottom-end" }, h("div", { class: "image-picker", slot: "content" }, h("klevu-image-picker", { isLoading: this.isUploadingImage, onKlevuImageSelected: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_handleImageSelection).bind(this) })), h("label", { slot: "origin" }, h("klevu-icon", { name: "upload" }), h("span", null, "Try another photo")))))) : (h("klevu-typography", { slot: "header", variant: "h1" }, stringConcat(this.tSearchTitle, [this.term]))), ((_d = this.results) === null || _d === void 0 ? void 0 : _d.length) > 0 && (h("klevu-sort", { variant: "inline", onKlevuSortChanged: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_sortChanged).bind(this) })))), h("slot", { name: "content", slot: "content" }, h("slot", { name: "topbanners" }, this.searchResultTopBanners.map((b) => (h("klevu-banner", { imageUrl: b.bannerImg, linkUrl: b.redirectUrl, altText: b.bannerAltTag })))), ((_e = this.results) === null || _e === void 0 ? void 0 : _e.length) > 0 ? (h("klevu-product-grid", { slot: "content" }, (_f = this.results) === null || _f === void 0 ? void 0 : _f.map((p) => (h("klevu-product", { hidePrice: this.hidePrice, product: p, fixedWidth: true, exportparts: parts["klevu-product"], showRatings: this.showRatings, showRatingsCount: this.showRatingsCount }))))) : (h("slot", { name: "noResults" }, this.noResultsMessage ? (h("p", { class: "noResultsMessage" }, h("klevu-typography", { variant: "body-s" }, this.noResultsMessage))) : null, h(Fragment, null, h("slot", { name: "trending-products" }, this.trendingProducts.length > 0 && (h(Fragment, null, h("klevu-typography", { variant: "body-s" }, ((_g = __classPrivateFieldGet(this, _KlevuSearchLandingPage_noResultsOptions, "f")) === null || _g === void 0 ? void 0 : _g.productsHeading) || ""), (_h = this.trendingProducts) === null || _h === void 0 ? void 0 :
      _h.map((p) => (h("klevu-product", { hidePrice: this.hidePrice, product: p, variant: "line", exportparts: parts["klevu-product"] }))))))), __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_renderNoResultBanners).call(this), ((_j = __classPrivateFieldGet(this, _KlevuSearchLandingPage_noResultsOptions, "f")) === null || _j === void 0 ? void 0 : _j.showPopularKeywords) && (h("klevu-popular-searches", { onKlevuPopularSearchClicked: (event) => __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_handlePopularKeywordClick).call(this, event.detail) })))), this.loading && !this.infiniteScrollingPaused && h("klevu-loading-indicator", null), h("slot", { name: "bottombanners" }, this.searchResultBottomBanners.map((b) => (h("klevu-banner", { imageUrl: b.bannerImg, linkUrl: b.redirectUrl, altText: b.bannerAltTag }))))), h("div", { slot: "footer", class: "footer" }, showInfiniteScroll ? (h("klevu-util-infinite-scroll", { onKlevuLoadMore: () => {
        this.loadMore();
      }, onKlevuInfiniteScrollingPaused: () => {
        this.infiniteScrollingPaused = true;
      }, infiniteScrollPauseThreshold: 3, enabled: !!((_k = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _k === void 0 ? void 0 : _k.hasNextPage()) && !this.loading })) : this.usePagination && __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f") ? (h("klevu-pagination", { queryResult: __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f"), onKlevuPaginationChange: this.paginationChange.bind(this) })) : ((_l = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _l === void 0 ? void 0 : _l.hasNextPage()) ? (h("klevu-button", { onClick: this.loadMore.bind(this) }, this.tLoadMore)) : null))));
  }
  static get is() { return "klevu-search-landing-page"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-search-landing-page.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-search-landing-page.css"]
    };
  }
  static get properties() {
    return {
      "limit": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "How many results to display on a page"
        },
        "attribute": "limit",
        "reflect": false,
        "defaultValue": "24"
      },
      "term": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": true,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "What term was used for search"
        },
        "attribute": "term",
        "reflect": false
      },
      "sort": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "KlevuSearchSorting",
          "resolved": "KlevuSearchSorting.AdvancedSorting | KlevuSearchSorting.NameAsc | KlevuSearchSorting.NameDesc | KlevuSearchSorting.NewArrivalAsc | KlevuSearchSorting.NewArrivalDesc | KlevuSearchSorting.PriceAsc | KlevuSearchSorting.PriceDesc | KlevuSearchSorting.RatingAsc | KlevuSearchSorting.RatingDesc | KlevuSearchSorting.Relevance | undefined",
          "references": {
            "KlevuSearchSorting": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::KlevuSearchSorting"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "In which order to set the products"
        },
        "attribute": "sort",
        "reflect": false
      },
      "filterCount": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "How many products to display in filters"
        },
        "attribute": "filter-count",
        "reflect": false
      },
      "filterCustomOrder": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "{ [key: string]: string[] }",
          "resolved": "undefined | { [key: string]: string[]; }",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Order filters in a customer order"
        }
      },
      "usePagination": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Use pagination instead of loading more"
        },
        "attribute": "use-pagination",
        "reflect": false
      },
      "useInfiniteScroll": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Should use infinite scroll component to trigger load next"
        },
        "attribute": "use-infinite-scroll",
        "reflect": false
      },
      "showRatings": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Show ratings"
        },
        "attribute": "show-ratings",
        "reflect": false
      },
      "showRatingsCount": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Show ratings count"
        },
        "attribute": "show-ratings-count",
        "reflect": false
      },
      "tSearchTitle": {
        "type": "any",
        "mutable": false,
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "The title of the page"
        },
        "attribute": "t-search-title",
        "reflect": false,
        "defaultValue": "getTranslation(\"searchLandingPage.tSearchTitle\")"
      },
      "tLoadMore": {
        "type": "any",
        "mutable": false,
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Text of load more button"
        },
        "attribute": "t-load-more",
        "reflect": false,
        "defaultValue": "getTranslation(\"searchLandingPage.tLoadMore\")"
      },
      "usePersonalisation": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Enable personalization"
        },
        "attribute": "use-personalisation",
        "reflect": false
      },
      "popularProductsResultCount": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "How many products to show in popular products"
        },
        "attribute": "popular-products-result-count",
        "reflect": false,
        "defaultValue": "3"
      },
      "showSearch": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Show the quick search box at the top of the page"
        },
        "attribute": "show-search",
        "reflect": false
      },
      "hideFilters": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hide filters on results page"
        },
        "attribute": "hide-filters",
        "reflect": false
      },
      "useMultiSelectFilters": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Specify whether to show checkboxes or radio buttons for filters"
        },
        "attribute": "use-multi-select-filters",
        "reflect": false
      },
      "useKlaviyo": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Enable Klaviyo integration"
        },
        "attribute": "use-klaviyo",
        "reflect": false
      },
      "showPriceAsSlider": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Show price as options"
        },
        "attribute": "show-price-as-slider",
        "reflect": false
      },
      "priceInterval": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "The factor to use to generate the ranges"
        },
        "attribute": "price-interval",
        "reflect": false,
        "defaultValue": "500"
      },
      "hidePrice": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hides price from search results"
        },
        "attribute": "hide-price",
        "reflect": false
      },
      "imageUrlForSearch": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Pass image url if performing image search"
        },
        "attribute": "image-url-for-search",
        "reflect": false,
        "defaultValue": "\"\""
      }
    };
  }
  static get states() {
    return {
      "results": {},
      "manager": {},
      "currentViewPortSize": {},
      "infiniteScrollingPaused": {},
      "loading": {},
      "noResultsMessage": {},
      "trendingProducts": {},
      "noResultsBannerDetails": {},
      "searchResultTopBanners": {},
      "searchResultBottomBanners": {},
      "isUploadingImage": {}
    };
  }
  static get events() {
    return [{
        "method": "klevuData",
        "name": "klevuData",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "{ resultObject: KlevuResponseQueryObject; records: KlevuRecord[]; manager: FilterManager }",
          "resolved": "{ resultObject: KlevuResponseQueryObject; records: KlevuRecord[]; manager: FilterManager; }",
          "references": {
            "KlevuResponseQueryObject": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::KlevuResponseQueryObject"
            },
            "KlevuRecord": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::KlevuRecord"
            },
            "FilterManager": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::FilterManager"
            }
          }
        }
      }];
  }
  static get watchers() {
    return [{
        "propName": "term",
        "methodName": "termChanged"
      }];
  }
  static get listeners() {
    return [{
        "name": "klevuProductClick",
        "method": "productClickHandler",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "klevu-filter-selection-updates",
        "method": "filterManagerFiltersUpdated",
        "target": "document",
        "capture": false,
        "passive": false
      }];
  }
}
_KlevuSearchLandingPage_noResultsOptions = new WeakMap(), _KlevuSearchLandingPage_resultObject = new WeakMap(), _KlevuSearchLandingPage_imagePickerPopupRef = new WeakMap(), _KlevuSearchLandingPage_viewportUtil = new WeakMap(), _KlevuSearchLandingPage_layoutElement = new WeakMap(), _KlevuSearchLandingPage_facetListElement = new WeakMap(), _KlevuSearchLandingPage_instances = new WeakSet(), _KlevuSearchLandingPage_fetchData = async function _KlevuSearchLandingPage_fetchData() {
  var _a, _b, _c;
  this.loading = true;
  const rangeFilterSetting = this.showPriceAsSlider
    ? {
      key: "klevu_price",
      minMax: true,
    }
    : {
      key: "klevu_price",
      rangeInterval: this.priceInterval,
      minMax: false,
    };
  const modifiers = [
    sendSearchEvent(),
    listFilters({
      filterManager: this.manager,
      limit: this.filterCount,
      rangeFilterSettings: [rangeFilterSetting],
    }),
    applyFilterWithManager(this.manager),
  ];
  if (this.usePersonalisation && !this.imageUrlForSearch) {
    modifiers.push(personalisation());
  }
  if (this.useKlaviyo) {
    modifiers.push(klaviyo());
  }
  const result = await KlevuFetch(this.imageUrlForSearch
    ? imageSearch(this.imageUrlForSearch, { limit: this.limit, sort: this.sort }, ...modifiers)
    : search(this.term, { limit: this.limit, sort: this.sort }, ...modifiers));
  __classPrivateFieldSet(this, _KlevuSearchLandingPage_resultObject, result.queriesById("search"), "f");
  this.results = (_b = (_a = __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.records) !== null && _b !== void 0 ? _b : [];
  __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_emitChanges).call(this);
  this.loading = false;
  const allBanners = (_c = (await __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f").getBanners({ searchType: "quicksearch" }))) !== null && _c !== void 0 ? _c : [];
  this.searchResultTopBanners = allBanners.filter((b) => b.position === "top");
  this.searchResultBottomBanners = allBanners.filter((b) => b.position === "bottom");
  this.noResultsMessage = "";
  this.noResultsBannerDetails = [];
  if (this.results.length === 0) {
    __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_handleNoResults).call(this);
  }
}, _KlevuSearchLandingPage_handleNoResults = function _KlevuSearchLandingPage_handleNoResults() {
  var _a, _b, _c, _d, _e;
  this.noResultsMessage = ((_b = (_a = __classPrivateFieldGet(this, _KlevuSearchLandingPage_noResultsOptions, "f")) === null || _a === void 0 ? void 0 : _a.messages.find((m) => m.showForTerms === null)) === null || _b === void 0 ? void 0 : _b.message) || "";
  this.noResultsBannerDetails =
    ((_c = __classPrivateFieldGet(this, _KlevuSearchLandingPage_noResultsOptions, "f")) === null || _c === void 0 ? void 0 : _c.banners.filter((m) => m.showOnLandingPage && m.showForTerms === null)) || [];
  if (this.term) {
    const searchTermSpecificMessage = (_d = __classPrivateFieldGet(this, _KlevuSearchLandingPage_noResultsOptions, "f")) === null || _d === void 0 ? void 0 : _d.messages.find((m) => m.showForTerms && m.showForTerms.includes(this.term));
    if (searchTermSpecificMessage)
      this.noResultsMessage = searchTermSpecificMessage === null || searchTermSpecificMessage === void 0 ? void 0 : searchTermSpecificMessage.message;
    const searchTermSpecificBanner = ((_e = __classPrivateFieldGet(this, _KlevuSearchLandingPage_noResultsOptions, "f")) === null || _e === void 0 ? void 0 : _e.banners.filter((m) => m.showOnLandingPage && m.showForTerms && m.showForTerms.includes(this.term))) || [];
    if (searchTermSpecificBanner.length > 0)
      this.noResultsBannerDetails.unshift(...searchTermSpecificBanner);
  }
}, _KlevuSearchLandingPage_sizeChange = function _KlevuSearchLandingPage_sizeChange(event) {
  this.currentViewPortSize = event.detail;
}, _KlevuSearchLandingPage_emitChanges = function _KlevuSearchLandingPage_emitChanges() {
  if (!__classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f")) {
    return;
  }
  this.klevuData.emit({
    resultObject: __classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f"),
    records: this.results,
    manager: this.manager,
  });
  this.infiniteScrollingPaused = false;
}, _KlevuSearchLandingPage_sortChanged = async function _KlevuSearchLandingPage_sortChanged(event) {
  this.sort = event.detail;
  await __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_fetchData).call(this);
}, _KlevuSearchLandingPage_applyFilters = function _KlevuSearchLandingPage_applyFilters() {
  __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_fetchData).call(this);
  __classPrivateFieldGet(this, _KlevuSearchLandingPage_layoutElement, "f").closeDrawer();
}, _KlevuSearchLandingPage_isMobile = function _KlevuSearchLandingPage_isMobile() {
  var _a, _b;
  return ((_a = this.currentViewPortSize) === null || _a === void 0 ? void 0 : _a.name) === "xs" || ((_b = this.currentViewPortSize) === null || _b === void 0 ? void 0 : _b.name) === "sm";
}, _KlevuSearchLandingPage_mobileDrawerOpened = function _KlevuSearchLandingPage_mobileDrawerOpened() {
  __classPrivateFieldGet(this, _KlevuSearchLandingPage_facetListElement, "f").updateApplyFilterState();
}, _KlevuSearchLandingPage_handlePopularKeywordClick = function _KlevuSearchLandingPage_handlePopularKeywordClick(keyword) {
  this.term = keyword;
}, _KlevuSearchLandingPage_handleImageSelection = async function _KlevuSearchLandingPage_handleImageSelection(event) {
  var _a;
  this.isUploadingImage = true;
  const imageUrl = await KlevuUploadImageForSearch(event.detail.image);
  this.imageUrlForSearch = imageUrl;
  __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_fetchData).call(this);
  (_a = __classPrivateFieldGet(this, _KlevuSearchLandingPage_imagePickerPopupRef, "f")) === null || _a === void 0 ? void 0 : _a.closeModal();
  this.isUploadingImage = false;
}, _KlevuSearchLandingPage_renderNoResultBanners = function _KlevuSearchLandingPage_renderNoResultBanners() {
  return this.noResultsBannerDetails.map((banner) => (h("a", { href: banner.redirectUrl }, h("img", { class: "noResultsBannerImage", src: banner.bannerImageUrl, alt: banner.bannerAltTag, title: banner.bannerAltTag }))));
};
//# sourceMappingURL=klevu-search-landing-page.js.map
