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 _KlevuMerchandising_instances, _KlevuMerchandising_viewportUtil, _KlevuMerchandising_layoutElement, _KlevuMerchandising_facetListElement, _KlevuMerchandising_resultObject, _KlevuMerchandising_currency, _KlevuMerchandising_buildQuery, _KlevuMerchandising_fetchData, _KlevuMerchandising_buildAfterResults, _KlevuMerchandising_loadMore, _KlevuMerchandising_paginationChange, _KlevuMerchandising_emitChanges, _KlevuMerchandising_sortChanged, _KlevuMerchandising_sizeChange, _KlevuMerchandising_applyFilters, _KlevuMerchandising_isMobile, _KlevuMerchandising_mobileDrawerOpened;
import { abTest, applyFilterWithManager, categoryMerchandising, FilterManager, KlevuFetch, KlevuSSRFetch, KlevuSSRHydrate, listFilters, personalisation, sendMerchandisingViewEvent, } from "@klevu/core";
import { h, Host } from "@stencil/core";
import { KlevuInit } from "../klevu-init/klevu-init";
import { getTranslation } from "../../utils/getTranslation";
import { getKMCSettings } from "../../utils/getKMCSettings";
import { partsExports } from "../../utils/partsExports";
/**
 * Full merchandising app to power up your product grid pages
 *
 * @slot header - Header container
 * @slot footer - Footer container
 * @slot content - Product grid items including the grid container
 * @slot facets - Sidebar of facets content
 * @slot topbanners - Top banner content
 * @slot bottombanners - Bottom banner content
 *
 * @csspart merchandising-sidebar - Sidebar container
 * @csspart merchandising-header - Header container
 * @csspart merchandising-content - Content container
 * @csspart merchandising-footer - Footer container
 */
export class KlevuMerchandising {
  constructor() {
    _KlevuMerchandising_instances.add(this);
    _KlevuMerchandising_viewportUtil.set(this, void 0);
    _KlevuMerchandising_layoutElement.set(this, void 0);
    _KlevuMerchandising_facetListElement.set(this, void 0);
    _KlevuMerchandising_resultObject.set(this, void 0);
    _KlevuMerchandising_currency.set(this, "");
    this.usePagination = undefined;
    this.useInfiniteScroll = undefined;
    this.limit = 24;
    this.category = undefined;
    this.categoryTitle = undefined;
    this.tLoadMore = getTranslation("merchandising.tLoadMore");
    this.sort = undefined;
    this.filterCount = undefined;
    this.options = undefined;
    this.filterCustomOrder = undefined;
    this.sortOptions = undefined;
    this.showRatings = undefined;
    this.showRatingsCount = undefined;
    this.usePersonalisation = undefined;
    this.autoUpdateUrl = undefined;
    this.useABTest = undefined;
    this.useLoadingIndicator = false;
    this.hidePrice = undefined;
    this.showVariantsCount = false;
    this.hideBrand = undefined;
    this.hideDescription = undefined;
    this.hideHoverImage = undefined;
    this.hideImage = undefined;
    this.hideName = undefined;
    this.hideSwatches = undefined;
    this.outOfStockCaption = undefined;
    this.showAddToCart = undefined;
    this.showProductCode = undefined;
    this.tAddToCart = undefined;
    this.vatCaption = undefined;
    this.currentViewPortSize = undefined;
    this.results = [];
    this.manager = new FilterManager();
    this.loading = false;
    this.infiniteScrollingPaused = false;
    this.searchResultTopBanners = [];
    this.searchResultBottomBanners = [];
  }
  async connectedCallback() {
    await KlevuInit.ready();
  }
  async componentWillLoad() {
    var _a, _b, _c;
    const settings = getKMCSettings();
    if (settings) {
      if (this.showRatings === undefined) {
        this.showRatings = ((_a = settings.klevu_uc_userOptions) === null || _a === void 0 ? void 0 : _a.showRatingsOnCategoryPage) || false;
      }
      if (this.showRatingsCount === undefined) {
        this.showRatingsCount = ((_b = settings.klevu_uc_userOptions) === null || _b === void 0 ? void 0 : _b.showRatingsCountOnCategoryPage) || false;
      }
      if (this.usePersonalisation === undefined && (settings === null || settings === void 0 ? void 0 : settings.klevu_uc_userOptions.enablePersonalisationInCatNav)) {
        this.usePersonalisation = true;
      }
      if (this.useABTest === undefined) {
        this.useABTest = settings.klevu_abTestActive;
      }
      __classPrivateFieldSet(this, _KlevuMerchandising_currency, ((_c = settings.klevu_uc_userOptions.priceFormatter) === null || _c === void 0 ? void 0 : _c.currencySymbol) || "", "f");
    }
    const SSR = this.el.closest("klevu-util-ssr-provider");
    if (SSR && SSR.packed && SSR.identifier) {
      const packed = await SSR.getPacked();
      const res = await KlevuSSRHydrate(packed, __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_buildQuery).call(this), SSR.identifier);
      __classPrivateFieldSet(this, _KlevuMerchandising_resultObject, res.queriesById("categoryMerchandising"), "f");
      await __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_buildAfterResults).call(this);
    }
    else {
      await __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_fetchData).call(this);
    }
  }
  async watchPropHandler(newValue, oldValue) {
    if (newValue !== oldValue) {
      this.manager.clear();
      await __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_fetchData).call(this);
    }
  }
  infiniteScrollLoadMoreHandler() {
    __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_loadMore).call(this);
  }
  infiniteLoadPausedHandler() {
    this.infiniteScrollingPaused = true;
  }
  productClickHandler(event) {
    var _a, _b;
    if (!event.detail.product.id) {
      return;
    }
    if ((_a = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.categoryMerchandisingClickEvent) {
      (_b = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _b === void 0 ? void 0 : _b.categoryMerchandisingClickEvent({
        productId: event.detail.product.id,
        variantId: event.detail.product.variantId,
        categoryTitle: this.categoryTitle,
      });
    }
  }
  async componentDidLoad() {
    this.currentViewPortSize = await __classPrivateFieldGet(this, _KlevuMerchandising_viewportUtil, "f").getCurrentSize();
  }
  filterManagerFiltersUpdated() {
    if (__classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_isMobile).call(this)) {
      return;
    }
    __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_fetchData).call(this);
  }
  render() {
    var _a, _b, _c;
    const showInfiniteScroll = this.useInfiniteScroll &&
      !this.infiniteScrollingPaused &&
      this.results.length > 0 &&
      ((_a = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.hasNextPage());
    return (h(Host, null, h("klevu-util-viewport", { onKlevuSizeChanged: __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_sizeChange).bind(this), ref: (el) => (__classPrivateFieldSet(this, _KlevuMerchandising_viewportUtil, el, "f")) }), h("klevu-layout-results", { onKlevuDrawerOpened: __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_mobileDrawerOpened).bind(this), ref: (el) => (__classPrivateFieldSet(this, _KlevuMerchandising_layoutElement, el, "f")), exportparts: partsExports("klevu-layout-results") }, h("slot", { name: "facets", slot: "sidebar" }, h("div", { part: "merchandising-sidebar" }, h("klevu-facet-list", { priceSliderCurrency: __classPrivateFieldGet(this, _KlevuMerchandising_currency, "f"), ref: (el) => (__classPrivateFieldSet(this, _KlevuMerchandising_facetListElement, el, "f")), accordion: true, customOrder: this.filterCustomOrder, manager: this.manager, useApplyButton: __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_isMobile).call(this), onKlevuApplyFilters: __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_applyFilters).bind(this), exportparts: partsExports("klevu-facet-list"), shouldUpdateUrlForFacets: this.autoUpdateUrl }))), h("div", { slot: "header", class: "header", part: "merchandising-header" }, h("klevu-typography", { variant: "h1" }, this.categoryTitle), h("klevu-sort", { variant: "inline", onKlevuSortChanged: __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_sortChanged).bind(this), options: this.sortOptions, exportparts: partsExports("klevu-sort") })), h("slot", { name: "content", slot: "content" }, h("div", { part: "merchandising-content" }, h("slot", { name: "topbanners" }, this.searchResultTopBanners.map((b) => (h("klevu-banner", { exportparts: partsExports("klevu-banner"), imageUrl: b.bannerImg, linkUrl: b.redirectUrl, altText: b.bannerAltTag })))), h("klevu-product-grid", null, this.results.map((p) => (h("klevu-product", { product: p, fixedWidth: true, exportparts: partsExports("klevu-product"), showRatings: this.showRatings, showRatingsCount: this.showRatingsCount, hidePrice: this.hidePrice, showVariantsCount: this.showVariantsCount, hideBrand: this.hideBrand, hideDescription: this.hideDescription, hideHoverImage: this.hideHoverImage, hideImage: this.hideImage, hideName: this.hideName, hideSwatches: this.hideSwatches, outOfStockCaption: this.outOfStockCaption, showAddToCart: this.showAddToCart, showProductCode: this.showProductCode, tAddToCart: this.tAddToCart, vatCaption: this.vatCaption })))), this.useLoadingIndicator && this.loading && !this.infiniteScrollingPaused && (h("klevu-loading-indicator", { exportparts: partsExports("klevu-loading-indicator") })), h("slot", { name: "bottombanners" }, this.searchResultBottomBanners.map((b) => (h("klevu-banner", { exportparts: partsExports("klevu-banner"), imageUrl: b.bannerImg, linkUrl: b.redirectUrl, altText: b.bannerAltTag })))))), h("div", { slot: "footer", class: "footer", part: "merchandising-footer" }, showInfiniteScroll ? (h("klevu-util-infinite-scroll", { infiniteScrollPauseThreshold: 3, enabled: !!((_b = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _b === void 0 ? void 0 : _b.hasNextPage()) && !this.loading })) : this.usePagination && __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f") ? (h("klevu-pagination", { exportparts: partsExports("klevu-pagination"), queryResult: __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f"), onKlevuPaginationChange: __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_paginationChange).bind(this), shouldUpdateUrlForPage: this.autoUpdateUrl })) : ((_c = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _c === void 0 ? void 0 : _c.hasNextPage()) ? (h("klevu-button", { exportparts: partsExports("klevu-button"), onClick: __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_loadMore).bind(this) }, this.tLoadMore)) : null))));
  }
  static get is() { return "klevu-merchandising"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-merchandising.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-merchandising.css"]
    };
  }
  static get properties() {
    return {
      "usePagination": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Should display pagination instead of load next"
        },
        "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
      },
      "limit": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Count of products for page"
        },
        "attribute": "limit",
        "reflect": false,
        "defaultValue": "24"
      },
      "category": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": true,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Which category products"
        },
        "attribute": "category",
        "reflect": false
      },
      "categoryTitle": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": true,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Category title"
        },
        "attribute": "category-title",
        "reflect": false
      },
      "tLoadMore": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Text for load more button"
        },
        "attribute": "t-load-more",
        "reflect": false,
        "defaultValue": "getTranslation(\"merchandising.tLoadMore\")"
      },
      "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": "Order of results"
        },
        "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 filters per facet to show"
        },
        "attribute": "filter-count",
        "reflect": false
      },
      "options": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "KlevuMerchandisingOptions",
          "resolved": "undefined | { id: string; searchTerm: string; } & Omit<KlevuBaseQuerySettings, \"query\">",
          "references": {
            "KlevuMerchandisingOptions": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::KlevuMerchandisingOptions"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Object to override and settings on search options"
        }
      },
      "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 given order"
        }
      },
      "sortOptions": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "Array<{ value: KlevuSearchSorting; text: string }>",
          "resolved": "undefined | { value: KlevuSearchSorting; text: string; }[]",
          "references": {
            "Array": {
              "location": "global",
              "id": "global::Array"
            },
            "KlevuSearchSorting": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::KlevuSearchSorting"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Pass custom options for the sort dropdown"
        }
      },
      "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
      },
      "usePersonalisation": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Enable personalisation"
        },
        "attribute": "use-personalisation",
        "reflect": false
      },
      "autoUpdateUrl": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "To update the pagination and filters to the url automatically"
        },
        "attribute": "auto-update-url",
        "reflect": false
      },
      "useABTest": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Overrides KMC setting to use ABtest for results"
        },
        "attribute": "use-a-b-test",
        "reflect": false
      },
      "useLoadingIndicator": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Used to enable loading indicator"
        },
        "attribute": "use-loading-indicator",
        "reflect": false,
        "defaultValue": "false"
      },
      "hidePrice": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hides price from merchandising"
        },
        "attribute": "hide-price",
        "reflect": false
      },
      "showVariantsCount": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Show variants count in merchandising"
        },
        "attribute": "show-variants-count",
        "reflect": false,
        "defaultValue": "false"
      },
      "hideBrand": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hides brand from merchandising"
        },
        "attribute": "hide-brand",
        "reflect": false
      },
      "hideDescription": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hides description from merchandising"
        },
        "attribute": "hide-description",
        "reflect": false
      },
      "hideHoverImage": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hides hover image from merchandising"
        },
        "attribute": "hide-hover-image",
        "reflect": false
      },
      "hideImage": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hides image from merchandising"
        },
        "attribute": "hide-image",
        "reflect": false
      },
      "hideName": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Hides name from merchandising"
        },
        "attribute": "hide-name",
        "reflect": false
      },
      "hideSwatches": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Do not show swatches in products in merchandising"
        },
        "attribute": "hide-swatches",
        "reflect": false
      },
      "outOfStockCaption": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Caption to show if product is out of stock in products in merchandising"
        },
        "attribute": "out-of-stock-caption",
        "reflect": false
      },
      "showAddToCart": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Show add to cart button in products in merchandising"
        },
        "attribute": "show-add-to-cart",
        "reflect": false
      },
      "showProductCode": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "To show the product code next to product name in merchandising"
        },
        "attribute": "show-product-code",
        "reflect": false
      },
      "tAddToCart": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Text for add to cart button in merchandising"
        },
        "attribute": "t-add-to-cart",
        "reflect": false
      },
      "vatCaption": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Text to be added after the price. Usually used to indicate that does the price include VAT or not in merchandising."
        },
        "attribute": "vat-caption",
        "reflect": false
      }
    };
  }
  static get states() {
    return {
      "currentViewPortSize": {},
      "results": {},
      "manager": {},
      "loading": {},
      "infiniteScrollingPaused": {},
      "searchResultTopBanners": {},
      "searchResultBottomBanners": {}
    };
  }
  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 elementRef() { return "el"; }
  static get watchers() {
    return [{
        "propName": "category",
        "methodName": "watchPropHandler"
      }];
  }
  static get listeners() {
    return [{
        "name": "klevuLoadMore",
        "method": "infiniteScrollLoadMoreHandler",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "klevuInfiniteScrollingPaused",
        "method": "infiniteLoadPausedHandler",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "klevuProductClick",
        "method": "productClickHandler",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "klevu-filter-selection-updates",
        "method": "filterManagerFiltersUpdated",
        "target": "document",
        "capture": false,
        "passive": false
      }];
  }
}
_KlevuMerchandising_viewportUtil = new WeakMap(), _KlevuMerchandising_layoutElement = new WeakMap(), _KlevuMerchandising_facetListElement = new WeakMap(), _KlevuMerchandising_resultObject = new WeakMap(), _KlevuMerchandising_currency = new WeakMap(), _KlevuMerchandising_instances = new WeakSet(), _KlevuMerchandising_buildQuery = function _KlevuMerchandising_buildQuery() {
  const modifiers = [
    sendMerchandisingViewEvent(this.categoryTitle),
    listFilters({
      filterManager: this.manager,
      limit: this.filterCount,
      rangeFilterSettings: [
        {
          key: "klevu_price",
          minMax: true,
        },
      ],
    }),
    applyFilterWithManager(this.manager),
  ];
  if (this.usePersonalisation) {
    modifiers.push(personalisation());
  }
  if (this.useABTest) {
    modifiers.push(abTest());
  }
  return [categoryMerchandising(this.category, Object.assign({ limit: this.limit, sort: this.sort }, this.options), ...modifiers)];
}, _KlevuMerchandising_fetchData = async function _KlevuMerchandising_fetchData() {
  this.loading = true;
  const SSR = this.el.closest("klevu-util-ssr-provider");
  if (SSR) {
    const { result, identifier, packed } = await KlevuSSRFetch(__classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_buildQuery).call(this));
    SSR.identifier = identifier;
    SSR.setPacked(packed);
    __classPrivateFieldSet(this, _KlevuMerchandising_resultObject, result.queriesById("categoryMerchandising"), "f");
  }
  else {
    const result = await KlevuFetch(...__classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_buildQuery).call(this));
    __classPrivateFieldSet(this, _KlevuMerchandising_resultObject, result.queriesById("categoryMerchandising"), "f");
  }
  await __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_buildAfterResults).call(this);
  this.loading = false;
}, _KlevuMerchandising_buildAfterResults = async function _KlevuMerchandising_buildAfterResults() {
  var _a, _b;
  if (!__classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) {
    return;
  }
  this.results = (_b = (_a = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.records) !== null && _b !== void 0 ? _b : [];
  if (this.results.length > 0 && !__classPrivateFieldGet(this, _KlevuMerchandising_currency, "f")) {
    __classPrivateFieldSet(this, _KlevuMerchandising_currency, this.results[0].currency, "f");
  }
  const INIT = this.el.closest("klevu-init");
  if (INIT === null || INIT === void 0 ? void 0 : INIT.kmcLoadDefaults) {
    const allBanners = await __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f").getBanners();
    this.searchResultTopBanners = allBanners.filter((b) => b.position === "top");
    this.searchResultBottomBanners = allBanners.filter((b) => b.position === "bottom");
  }
  __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_emitChanges).call(this);
}, _KlevuMerchandising_loadMore = async function _KlevuMerchandising_loadMore() {
  var _a, _b, _c;
  if (!((_a = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.getPage)) {
    return;
  }
  this.loading = true;
  const nextResultObject = await __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f").getPage();
  __classPrivateFieldSet(this, _KlevuMerchandising_resultObject, nextResultObject === null || nextResultObject === void 0 ? void 0 : nextResultObject.queriesById("categoryMerchandising"), "f");
  this.results = [...this.results, ...((_c = (_b = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : [])];
  __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_emitChanges).call(this);
  this.loading = false;
}, _KlevuMerchandising_paginationChange = async function _KlevuMerchandising_paginationChange(event) {
  var _a, _b, _c;
  if (!((_a = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _a === void 0 ? void 0 : _a.getPage)) {
    return;
  }
  this.loading = true;
  const nextResultObject = await __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f").getPage({ pageIndex: event.detail - 1 });
  __classPrivateFieldSet(this, _KlevuMerchandising_resultObject, nextResultObject === null || nextResultObject === void 0 ? void 0 : nextResultObject.queriesById("categoryMerchandising"), "f");
  this.results = (_c = (_b = __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : [];
  __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_emitChanges).call(this);
  this.loading = false;
}, _KlevuMerchandising_emitChanges = function _KlevuMerchandising_emitChanges() {
  if (!__classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f")) {
    return;
  }
  this.klevuData.emit({
    resultObject: __classPrivateFieldGet(this, _KlevuMerchandising_resultObject, "f"),
    records: this.results,
    manager: this.manager,
  });
  this.infiniteScrollingPaused = false;
}, _KlevuMerchandising_sortChanged = async function _KlevuMerchandising_sortChanged(event) {
  this.sort = event.detail;
  await __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_fetchData).call(this);
}, _KlevuMerchandising_sizeChange = function _KlevuMerchandising_sizeChange(event) {
  this.currentViewPortSize = event.detail;
}, _KlevuMerchandising_applyFilters = function _KlevuMerchandising_applyFilters() {
  __classPrivateFieldGet(this, _KlevuMerchandising_instances, "m", _KlevuMerchandising_fetchData).call(this);
  __classPrivateFieldGet(this, _KlevuMerchandising_layoutElement, "f").closeDrawer();
}, _KlevuMerchandising_isMobile = function _KlevuMerchandising_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";
}, _KlevuMerchandising_mobileDrawerOpened = function _KlevuMerchandising_mobileDrawerOpened() {
  __classPrivateFieldGet(this, _KlevuMerchandising_facetListElement, "f").updateApplyFilterState();
};
//# sourceMappingURL=klevu-merchandising.js.map
