'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-6b50a234.js');
const klevuInit = require('./klevu-init-0ddd3486.js');
const getTranslation = require('./getTranslation-2fac1f2e.js');
const stringConcat = require('./stringConcat-49750485.js');
const getKMCSettings = require('./getKMCSettings-7c5e857d.js');
const partsExports = require('./partsExports-67956c7b.js');
const filterManager = require('./filterManager-31f4956d.js');
const klevuFetch = require('./klevuFetch-cb6905ea.js');
const sendSearchEvent = require('./sendSearchEvent-09b80a2e.js');
const listFilters = require('./listFilters-cd8c83a9.js');
const personalisation = require('./personalisation-2ed36bb0.js');
const klaviyo = require('./klaviyo-a0602f33.js');
require('./KlevuApiRawResponse-7801506a.js');
const search = require('./search-27082c77.js');
require('./kmcRecommendation-7a1d804c.js');
require('./isBrowser-e8e10249.js');
require('./KlevuDomEvents-f5b92150.js');

var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
/**
 * Uploads the image if blob passed or uses url to perform search
 *
 * @param image Pass a url or the image blob for search
 * @param options {@link KlevuSearchOptions}
 * @returns
 * @throws Error when image upload fails or when no url/blob is passed
 */
function imageSearch(image, options, ...modifiers) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!image) {
            throw new Error("Image url or blob are required.");
        }
        let url = "";
        if (typeof image === "string") {
            url = image;
        }
        else {
            url = yield stringConcat.KlevuUploadImageForSearch(image);
        }
        if (!url) {
            throw new Error("Image url is required.");
        }
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        const context = {
            sourceObjects: [
                {
                    typeOfRecord: klevuFetch.KlevuTypeOfRecord.Image,
                    records: [
                        {
                            url,
                        },
                    ],
                },
            ],
        };
        if (options) {
            options.context = context;
        }
        else {
            options = { context };
        }
        return search.search("*", options, ...modifiers);
    });
}

const klevuSearchLandingPageCss = ":host{display:block}.header{width:100%}.header .info{display:flex;justify-content:space-between;width:100%;align-items:center}.footer{display:flex;justify-content:center}@media (max-width: 511px){.header{display:block}}.noResultsMessage{text-align:center}.noResultsBannerImage{max-width:100%;margin-top:var(--klevu-spacing-04)}.imageSearchResults{display:flex;gap:var(--klevu-spacing-04);justify-content:center;align-items:center;width:100%}.imageSearchResults img{height:auto;width:auto;max-width:200px;max-height:200px}.imageSearchResults label{background-color:var(--klevu-color-neutral-7);color:white;font-size:var(--klevu-body-xs-size);padding:0.5rem;border-radius:0.3rem;cursor:pointer;margin-top:1rem;display:flex;align-items:center;width:max-content;gap:var(--klevu-spacing-02)}klevu-popup.imagesearch{--klevu-popup-width:400px}";

var __classPrivateFieldSet = (undefined && undefined.__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 = (undefined && undefined.__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_updateTerm, _KlevuSearchLandingPage_handleImageSelection, _KlevuSearchLandingPage_renderNoResultBanners;
const KlevuSearchLandingPage = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.klevuData = index.createEvent(this, "klevuData", 7);
    _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.getTranslation("searchLandingPage.tSearchTitle");
    this.tLoadMore = getTranslation.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.showVariantsCount = false;
    this.results = [];
    this.manager = new filterManager.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.KlevuInit.ready();
    const settings = getKMCSettings.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.KlevuFetch(stringConcat.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.variantId || 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;
    let facetMode = "checkbox";
    if (this.useMultiSelectFilters === false) {
      facetMode = "radio";
    }
    return (index.h(index.Host, null, index.h("klevu-util-viewport", { onKlevuSizeChanged: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_sizeChange).bind(this), ref: (el) => (__classPrivateFieldSet(this, _KlevuSearchLandingPage_viewportUtil, el, "f")) }), index.h("klevu-layout-results", { onKlevuDrawerOpened: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_mobileDrawerOpened).bind(this), ref: (el) => (__classPrivateFieldSet(this, _KlevuSearchLandingPage_layoutElement, el, "f")) }, index.h("slot", { name: "facets", slot: "sidebar" }, index.h("div", { part: "search-landing-page-sidebar" }, !this.hideFilters && (index.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: facetMode })))), index.h("div", { slot: "header", class: "header", part: "search-landing-page-header" }, this.showSearch && (index.h("klevu-quicksearch", { term: this.term, onKlevuSearch: (event) => __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_updateTerm).call(this, event.detail) })), index.h("div", { class: "info" }, this.imageUrlForSearch ? (__classPrivateFieldGet(this, _KlevuSearchLandingPage_resultObject, "f") && (index.h("div", { class: "imageSearchResults" }, index.h("div", { class: "image" }, index.h("img", { src: this.imageUrlForSearch, alt: "" })), index.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"), index.h("klevu-popup", { class: "imagesearch", exportparts: partsExports.partsExports("klevu-popup"), ref: (el) => (__classPrivateFieldSet(this, _KlevuSearchLandingPage_imagePickerPopupRef, el, "f")), anchor: "bottom-end" }, index.h("div", { class: "image-picker", slot: "content" }, index.h("klevu-image-picker", { isLoading: this.isUploadingImage, onKlevuImageSelected: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_handleImageSelection).bind(this) })), index.h("label", { slot: "origin" }, index.h("klevu-icon", { name: "upload" }), index.h("span", null, "Try another photo")))))) : (index.h("klevu-typography", { slot: "header", variant: "h1" }, stringConcat.stringConcat(this.tSearchTitle, [this.term]))), ((_d = this.results) === null || _d === void 0 ? void 0 : _d.length) > 0 && (index.h("klevu-sort", { variant: "inline", onKlevuSortChanged: __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_sortChanged).bind(this) })))), index.h("slot", { name: "content", slot: "content" }, index.h("div", { part: "search-landing-page-content" }, index.h("slot", { name: "topbanners" }, this.searchResultTopBanners.map((b) => (index.h("klevu-banner", { imageUrl: b.bannerImg, linkUrl: b.redirectUrl, altText: b.bannerAltTag })))), ((_e = this.results) === null || _e === void 0 ? void 0 : _e.length) > 0 ? (index.h("klevu-product-grid", { slot: "content" }, (_f = this.results) === null || _f === void 0 ? void 0 : _f.map((p) => (index.h("klevu-product", { hidePrice: this.hidePrice, product: p, fixedWidth: true, exportparts: partsExports.partsExports("klevu-product"), showRatings: this.showRatings, showRatingsCount: this.showRatingsCount, showVariantsCount: this.showVariantsCount }))))) : (index.h("slot", { name: "noResults" }, !this.loading && this.noResultsMessage ? (index.h("p", { class: "noResultsMessage" }, index.h("klevu-typography", { variant: "body-s" }, this.noResultsMessage))) : null, index.h(index.Fragment, null, index.h("slot", { name: "trending-products" }, this.trendingProducts.length > 0 && (index.h(index.Fragment, null, index.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) => (index.h("klevu-product", { hidePrice: this.hidePrice, product: p, variant: "line", exportparts: partsExports.partsExports("klevu-product") }))))))), !this.loading && __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_renderNoResultBanners).call(this), ((_j = __classPrivateFieldGet(this, _KlevuSearchLandingPage_noResultsOptions, "f")) === null || _j === void 0 ? void 0 : _j.showPopularKeywords) && (index.h("klevu-popular-searches", { exportparts: partsExports.partsExports("klevu-popular-searches"), onKlevuPopularSearchClicked: (event) => __classPrivateFieldGet(this, _KlevuSearchLandingPage_instances, "m", _KlevuSearchLandingPage_updateTerm).call(this, event.detail) })))), this.loading && !this.infiniteScrollingPaused && (index.h("klevu-loading-indicator", { exportparts: partsExports.partsExports("klevu-loading-indicator") })), index.h("slot", { name: "bottombanners" }, this.searchResultBottomBanners.map((b) => (index.h("klevu-banner", { imageUrl: b.bannerImg, linkUrl: b.redirectUrl, altText: b.bannerAltTag })))))), index.h("div", { slot: "footer", class: "footer", part: "search-landing-page-footer" }, showInfiniteScroll ? (index.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") ? (index.h("klevu-pagination", { exportparts: partsExports.partsExports("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()) ? (index.h("klevu-button", { onClick: this.loadMore.bind(this) }, this.tLoadMore)) : null))));
  }
  static get watchers() { return {
    "term": ["termChanged"]
  }; }
};
_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.sendSearchEvent(),
    listFilters.listFilters({
      filterManager: this.manager,
      limit: this.filterCount,
      rangeFilterSettings: [rangeFilterSetting],
    }),
    klevuFetch.applyFilterWithManager(this.manager),
  ];
  if (this.usePersonalisation && !this.imageUrlForSearch) {
    modifiers.push(personalisation.personalisation());
  }
  if (this.useKlaviyo) {
    modifiers.push(klaviyo.klaviyo());
  }
  const result = await klevuFetch.KlevuFetch(this.imageUrlForSearch
    ? imageSearch(this.imageUrlForSearch, { limit: this.limit, sort: this.sort }, ...modifiers)
    : search.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) ||
      getTranslation.getTranslation("searchLandingPage.tNoResultsFound");
  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_updateTerm = function _KlevuSearchLandingPage_updateTerm(term) {
  this.term = term;
}, _KlevuSearchLandingPage_handleImageSelection = async function _KlevuSearchLandingPage_handleImageSelection(event) {
  var _a;
  this.isUploadingImage = true;
  const imageUrl = await stringConcat.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) => (index.h("a", { href: banner.redirectUrl }, index.h("img", { class: "noResultsBannerImage", src: banner.bannerImageUrl, alt: banner.bannerAltTag, title: banner.bannerAltTag }))));
};
KlevuSearchLandingPage.style = klevuSearchLandingPageCss;

exports.klevu_search_landing_page = KlevuSearchLandingPage;

//# sourceMappingURL=klevu-search-landing-page.cjs.entry.js.map