import { proxyCustomElement, HTMLElement, createEvent, h, Host, Fragment } from '@stencil/core/internal/client';
import { p as parts, d as defineCustomElement$g } from './klevu-product2.js';
import { K as KlevuInit } from './klevu-init2.js';
import { g as getTranslation } from './getTranslation.js';
import { a as KlevuUploadImageForSearch, t as trendingProducts, s as stringConcat, d as defineCustomElement$e } from './klevu-quicksearch2.js';
import { g as getKMCSettings } from './getKMCSettings.js';
import { d as defineCustomElement$E } from './klevu-accordion2.js';
import { d as defineCustomElement$D } from './klevu-banner2.js';
import { d as defineCustomElement$C } from './klevu-button2.js';
import { d as defineCustomElement$B } from './klevu-chat-bubble2.js';
import { d as defineCustomElement$A } from './klevu-chat-layout2.js';
import { d as defineCustomElement$z } from './klevu-chat-messages2.js';
import { d as defineCustomElement$y } from './klevu-checkbox2.js';
import { d as defineCustomElement$x } from './klevu-cms-list2.js';
import { d as defineCustomElement$w } from './klevu-color-swatch2.js';
import { d as defineCustomElement$v } from './klevu-drawer2.js';
import { d as defineCustomElement$u } from './klevu-dropdown2.js';
import { d as defineCustomElement$t } from './klevu-facet2.js';
import { d as defineCustomElement$s } from './klevu-facet-list2.js';
import { d as defineCustomElement$r } from './klevu-icon2.js';
import { d as defineCustomElement$q } from './klevu-image-picker2.js';
import { d as defineCustomElement$p } from './klevu-latest-searches2.js';
import { d as defineCustomElement$o } from './klevu-layout-results2.js';
import { d as defineCustomElement$n } from './klevu-list2.js';
import { d as defineCustomElement$m } from './klevu-loading-indicator2.js';
import { d as defineCustomElement$l } from './klevu-modal2.js';
import { d as defineCustomElement$k } from './klevu-moi2.js';
import { d as defineCustomElement$j } from './klevu-pagination2.js';
import { d as defineCustomElement$i } from './klevu-popular-searches2.js';
import { d as defineCustomElement$h } from './klevu-popup2.js';
import { d as defineCustomElement$f } from './klevu-product-grid2.js';
import { d as defineCustomElement$d } from './klevu-rating2.js';
import { k as klaviyo, d as defineCustomElement$c } from './klevu-search-field2.js';
import { d as defineCustomElement$b } from './klevu-slider2.js';
import { d as defineCustomElement$a } from './klevu-slides2.js';
import { d as defineCustomElement$9 } from './klevu-sort2.js';
import { d as defineCustomElement$8 } from './klevu-suggestions-list2.js';
import { d as defineCustomElement$7 } from './klevu-tab2.js';
import { d as defineCustomElement$6 } from './klevu-textfield2.js';
import { d as defineCustomElement$5 } from './klevu-typography2.js';
import { d as defineCustomElement$4 } from './klevu-util-infinite-scroll2.js';
import { d as defineCustomElement$3 } from './klevu-util-scrollbars2.js';
import { d as defineCustomElement$2 } from './klevu-util-viewport2.js';
import { F as FilterManager } from './filterManager.js';
import { f as KlevuTypeOfRecord, b as KlevuFetch, a as applyFilterWithManager, p as personalisation } from './klevuFetch.js';
import { s as search, b as sendSearchEvent } from './suggestions.js';
import { l as listFilters } from './listFilters.js';
import './KlevuApiRawResponse.js';
import './KlevuSearchSorting.js';
import './kmcRecommendation.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 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: KlevuTypeOfRecord.Image,
                    records: [
                        {
                            url,
                        },
                    ],
                },
            ],
        };
        if (options) {
            options.context = context;
        }
        else {
            options = { context };
        }
        return search("*", options, ...modifiers);
    });
}

const klevuSearchLandingPageCss = ":host{display:block}.header{width:100%}.header .info{display:flex;justify-content:space-between;width:100%;margin-top:var(--klevu-spacing-04)}.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)}";

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_handlePopularKeywordClick, _KlevuSearchLandingPage_handleImageSelection, _KlevuSearchLandingPage_renderNoResultBanners;
const KlevuSearchLandingPage$1 = /*@__PURE__*/ proxyCustomElement(class KlevuSearchLandingPage extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    this.klevuData = 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("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 watchers() { return {
    "term": ["termChanged"]
  }; }
  static get style() { return klevuSearchLandingPageCss; }
}, [1, "klevu-search-landing-page", {
    "limit": [2],
    "term": [1],
    "sort": [1],
    "filterCount": [2, "filter-count"],
    "filterCustomOrder": [16],
    "usePagination": [4, "use-pagination"],
    "useInfiniteScroll": [4, "use-infinite-scroll"],
    "showRatings": [4, "show-ratings"],
    "showRatingsCount": [4, "show-ratings-count"],
    "tSearchTitle": [8, "t-search-title"],
    "tLoadMore": [8, "t-load-more"],
    "usePersonalisation": [4, "use-personalisation"],
    "popularProductsResultCount": [2, "popular-products-result-count"],
    "showSearch": [4, "show-search"],
    "hideFilters": [4, "hide-filters"],
    "useMultiSelectFilters": [4, "use-multi-select-filters"],
    "useKlaviyo": [4, "use-klaviyo"],
    "showPriceAsSlider": [4, "show-price-as-slider"],
    "priceInterval": [2, "price-interval"],
    "hidePrice": [4, "hide-price"],
    "imageUrlForSearch": [1, "image-url-for-search"],
    "results": [32],
    "manager": [32],
    "currentViewPortSize": [32],
    "infiniteScrollingPaused": [32],
    "loading": [32],
    "noResultsMessage": [32],
    "trendingProducts": [32],
    "noResultsBannerDetails": [32],
    "searchResultTopBanners": [32],
    "searchResultBottomBanners": [32],
    "isUploadingImage": [32]
  }, [[0, "klevuProductClick", "productClickHandler"], [4, "klevu-filter-selection-updates", "filterManagerFiltersUpdated"]], {
    "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(),
    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 }))));
};
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["klevu-search-landing-page", "klevu-accordion", "klevu-banner", "klevu-button", "klevu-chat-bubble", "klevu-chat-layout", "klevu-chat-messages", "klevu-checkbox", "klevu-cms-list", "klevu-color-swatch", "klevu-drawer", "klevu-dropdown", "klevu-facet", "klevu-facet-list", "klevu-icon", "klevu-image-picker", "klevu-latest-searches", "klevu-layout-results", "klevu-list", "klevu-loading-indicator", "klevu-modal", "klevu-moi", "klevu-pagination", "klevu-popular-searches", "klevu-popup", "klevu-product", "klevu-product-grid", "klevu-quicksearch", "klevu-rating", "klevu-search-field", "klevu-slider", "klevu-slides", "klevu-sort", "klevu-suggestions-list", "klevu-tab", "klevu-textfield", "klevu-typography", "klevu-util-infinite-scroll", "klevu-util-scrollbars", "klevu-util-viewport"];
  components.forEach(tagName => { switch (tagName) {
    case "klevu-search-landing-page":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, KlevuSearchLandingPage$1);
      }
      break;
    case "klevu-accordion":
      if (!customElements.get(tagName)) {
        defineCustomElement$E();
      }
      break;
    case "klevu-banner":
      if (!customElements.get(tagName)) {
        defineCustomElement$D();
      }
      break;
    case "klevu-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$C();
      }
      break;
    case "klevu-chat-bubble":
      if (!customElements.get(tagName)) {
        defineCustomElement$B();
      }
      break;
    case "klevu-chat-layout":
      if (!customElements.get(tagName)) {
        defineCustomElement$A();
      }
      break;
    case "klevu-chat-messages":
      if (!customElements.get(tagName)) {
        defineCustomElement$z();
      }
      break;
    case "klevu-checkbox":
      if (!customElements.get(tagName)) {
        defineCustomElement$y();
      }
      break;
    case "klevu-cms-list":
      if (!customElements.get(tagName)) {
        defineCustomElement$x();
      }
      break;
    case "klevu-color-swatch":
      if (!customElements.get(tagName)) {
        defineCustomElement$w();
      }
      break;
    case "klevu-drawer":
      if (!customElements.get(tagName)) {
        defineCustomElement$v();
      }
      break;
    case "klevu-dropdown":
      if (!customElements.get(tagName)) {
        defineCustomElement$u();
      }
      break;
    case "klevu-facet":
      if (!customElements.get(tagName)) {
        defineCustomElement$t();
      }
      break;
    case "klevu-facet-list":
      if (!customElements.get(tagName)) {
        defineCustomElement$s();
      }
      break;
    case "klevu-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$r();
      }
      break;
    case "klevu-image-picker":
      if (!customElements.get(tagName)) {
        defineCustomElement$q();
      }
      break;
    case "klevu-latest-searches":
      if (!customElements.get(tagName)) {
        defineCustomElement$p();
      }
      break;
    case "klevu-layout-results":
      if (!customElements.get(tagName)) {
        defineCustomElement$o();
      }
      break;
    case "klevu-list":
      if (!customElements.get(tagName)) {
        defineCustomElement$n();
      }
      break;
    case "klevu-loading-indicator":
      if (!customElements.get(tagName)) {
        defineCustomElement$m();
      }
      break;
    case "klevu-modal":
      if (!customElements.get(tagName)) {
        defineCustomElement$l();
      }
      break;
    case "klevu-moi":
      if (!customElements.get(tagName)) {
        defineCustomElement$k();
      }
      break;
    case "klevu-pagination":
      if (!customElements.get(tagName)) {
        defineCustomElement$j();
      }
      break;
    case "klevu-popular-searches":
      if (!customElements.get(tagName)) {
        defineCustomElement$i();
      }
      break;
    case "klevu-popup":
      if (!customElements.get(tagName)) {
        defineCustomElement$h();
      }
      break;
    case "klevu-product":
      if (!customElements.get(tagName)) {
        defineCustomElement$g();
      }
      break;
    case "klevu-product-grid":
      if (!customElements.get(tagName)) {
        defineCustomElement$f();
      }
      break;
    case "klevu-quicksearch":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "klevu-rating":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "klevu-search-field":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "klevu-slider":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "klevu-slides":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "klevu-sort":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "klevu-suggestions-list":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "klevu-tab":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "klevu-textfield":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "klevu-typography":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "klevu-util-infinite-scroll":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "klevu-util-scrollbars":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "klevu-util-viewport":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const KlevuSearchLandingPage = KlevuSearchLandingPage$1;
const defineCustomElement = defineCustomElement$1;

export { KlevuSearchLandingPage, defineCustomElement };

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