import { r as registerInstance, h, H as Host, g as getElement, c as createEvent, f as forceUpdate, F as Fragment } from './index-5c6903aa.js';
import { g as getGlobalSettings } from './utils-116b40b3.js';
import { g as getTranslation } from './getTranslation-a535e72f.js';
import { p as partsExports } from './partsExports-0d62f7d7.js';
import { K as KlevuFilterType } from './KlevuApiRawResponse-82e24d1e.js';
import { F as FilterManager } from './filterManager-a7b9e0c9.js';
import './KlevuDomEvents-a1ecbf7c.js';
import './isBrowser-38d37bdf.js';

const klevuDrawerCss = ":host{display:block;--ypadding:var(--klevu-drawer-y-padding, var(--klevu-spacing-04));--max-width:var(--klevu-drawer-max-width, max-content);--width:var(--klevu-drawer-width, 400px);--background-color:var(--klevu-drawer-background-color, rgba(0, 0, 0, 0.2))}.drawer{position:fixed;top:0;height:100vh;max-width:var(--max-width);z-index:1000;background:#fff;transition:left 0.4s, right 0.4s;width:var(--width)}.drawer.left{left:-100%;border-right:1px solid var(--klevu-color-neutral-3)}.drawer.right{right:-100%;border-left:1px solid var(--klevu-color-neutral-3)}.drawer.left.show{left:0}.drawer.right.show{right:0}.background{display:none;position:fixed;top:0;left:0;width:100vw;height:100vh;background:var(--background-color);z-index:999}.background.show{display:block}.innercontainer{height:100%;width:100%;box-sizing:border-box}.insertypadding{padding:0 var(--ypadding)}";

var __classPrivateFieldSet$2 = (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$4 = (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 _KlevuDrawer_instances, _KlevuDrawer_originalOverflow, _KlevuDrawer_openEvent, _KlevuDrawer_closeEvent;
const KlevuDrawer = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    _KlevuDrawer_instances.add(this);
    _KlevuDrawer_originalOverflow.set(this, void 0);
    this.startOpen = undefined;
    this.background = undefined;
    this.closeAtOutsideClick = true;
    this.insertYPadding = undefined;
    this.anchor = "right";
    this.open = false;
  }
  async openModal() {
    document.body.style.overflowX = "inherit";
    this.open = true;
    __classPrivateFieldSet$2(this, _KlevuDrawer_originalOverflow, document.body.style.overflow, "f");
    document.body.style.overflow = "hidden";
  }
  async closeModal() {
    document.body.style.overflowX = "none";
    this.open = false;
    document.body.style.overflow = __classPrivateFieldGet$4(this, _KlevuDrawer_originalOverflow, "f");
  }
  connectedCallback() {
    var _a;
    if (this.startOpen) {
      this.openModal();
    }
    (_a = this.el) === null || _a === void 0 ? void 0 : _a.addEventListener("click", __classPrivateFieldGet$4(this, _KlevuDrawer_instances, "m", _KlevuDrawer_openEvent).bind(this));
    if (this.closeAtOutsideClick) {
      document.addEventListener("click", __classPrivateFieldGet$4(this, _KlevuDrawer_instances, "m", _KlevuDrawer_closeEvent).bind(this));
    }
  }
  detachedCallback() {
    var _a;
    document.removeEventListener("click", __classPrivateFieldGet$4(this, _KlevuDrawer_instances, "m", _KlevuDrawer_closeEvent));
    (_a = this.el) === null || _a === void 0 ? void 0 : _a.removeEventListener("click", __classPrivateFieldGet$4(this, _KlevuDrawer_instances, "m", _KlevuDrawer_openEvent));
  }
  render() {
    return (h(Host, null, h("div", { part: "drawer-base" }, h("div", { part: "drawer-origin" }, h("slot", { name: "origin" })), h("div", { class: {
        drawer: true,
        show: this.open,
        left: this.anchor === "left",
        right: this.anchor === "right",
      } }, h("klevu-util-scrollbars", { overflowY: "scroll" }, h("div", { class: { innercontainer: true, insertypadding: Boolean(this.insertYPadding) }, part: "drawer-content" }, h("slot", { name: "content" })))), this.background ? (h("div", { onClick: this.closeModal.bind(this), class: { background: true, show: this.open } })) : null)));
  }
  get el() { return getElement(this); }
};
_KlevuDrawer_originalOverflow = new WeakMap(), _KlevuDrawer_instances = new WeakSet(), _KlevuDrawer_openEvent = function _KlevuDrawer_openEvent(event) {
  if (event.composedPath().some((el) => el.name === "origin")) {
    this.openModal();
  }
}, _KlevuDrawer_closeEvent = function _KlevuDrawer_closeEvent(event) {
  if (!event.composedPath().some((el) => el === this.el)) {
    this.closeModal();
  }
};
KlevuDrawer.style = klevuDrawerCss;

const klevuFacetCss = ":host{display:block}.container{display:flex;justify-content:space-between;width:100%;min-width:0}.option{margin-bottom:var(--klevu-spacing-02)}.name{display:block;flex-grow:1;min-width:0;font-size:var(--klevu-body-s-size)}.name span{display:block;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.count{flex-basis:30px;display:inline-block;margin-left:auto;text-align:right;color:var(--klevu-color-neutral-6);font-size:var(--klevu-body-xs-size)}klevu-checkbox{width:100%;min-width:0}klevu-typography{margin:var(--klevu-spacing-05) 0 var(--klevu-spacing-03)}klevu-typography.accordion{margin:inherit}input[type=\"radio\"]{margin:0;margin-right:var(--klevu-spacing-04)}.colorSwatchContainer{display:flex;flex-wrap:wrap;gap:var(--klevu-spacing-03)}";

var __classPrivateFieldGet$3 = (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 _KlevuFacet_instances, _KlevuFacet_renderSlider, _KlevuFacet_renderOptions;
const resolveFacetLabel = (option, facet) => {
  if (facet) {
    if (facet.type === KlevuFilterType.Rating) {
      return h("klevu-rating", { exportparts: partsExports("klevu-rating"), rating: parseFloat(option.name) });
    }
  }
  return option.name;
};
const KlevuFacet = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.klevuFilterSelectionUpdate = createEvent(this, "klevuFilterSelectionUpdate", 7);
    _KlevuFacet_instances.add(this);
    this.option = undefined;
    this.slider = undefined;
    this.manager = undefined;
    this.mode = "checkbox";
    this.customOrder = undefined;
    this.accordion = undefined;
    this.accordionStartOpen = undefined;
    this.labelOverride = undefined;
    this.tMore = getTranslation("facet.tMore");
    this.tAll = getTranslation("facet.tAll");
    this.useColorSwatch = false;
    this.colorSwatchOverrides = {};
    this.showAll = false;
  }
  filterSelectionUpdate(event) {
    var _a;
    if (event.detail.key !== ((_a = this.option) === null || _a === void 0 ? void 0 : _a.key)) {
      return;
    }
    forceUpdate(this.el);
    this.klevuFilterSelectionUpdate.emit({
      manager: this.manager,
      filter: event.detail,
    });
  }
  render() {
    return (h(Host, null, this.option ? (h(Fragment, null, this.accordion ? (h("klevu-accordion", { startOpen: this.accordionStartOpen, exportparts: partsExports("klevu-accordion") }, __classPrivateFieldGet$3(this, _KlevuFacet_instances, "m", _KlevuFacet_renderOptions).call(this))) : (__classPrivateFieldGet$3(this, _KlevuFacet_instances, "m", _KlevuFacet_renderOptions).call(this)))) : this.slider ? (h(Fragment, null, this.accordion ? (h("klevu-accordion", { startOpen: this.accordionStartOpen, exportparts: partsExports("klevu-accordion") }, __classPrivateFieldGet$3(this, _KlevuFacet_instances, "m", _KlevuFacet_renderSlider).call(this))) : (__classPrivateFieldGet$3(this, _KlevuFacet_instances, "m", _KlevuFacet_renderSlider).call(this)))) : null));
  }
  get el() { return getElement(this); }
};
_KlevuFacet_instances = new WeakSet(), _KlevuFacet_renderSlider = function _KlevuFacet_renderSlider() {
  if (!this.slider) {
    return null;
  }
  return (h(Fragment, null, h("span", { part: "facet-heading", slot: "header" }, h("klevu-typography", { class: { accordion: Boolean(this.accordion) }, variant: "body-s-bold" }, this.labelOverride || this.slider.label)), h("klevu-slider", { slot: "content", showTooltips: true, min: parseFloat(this.slider.min), max: parseFloat(this.slider.max), start: this.slider.start ? parseFloat(this.slider.start) : undefined, end: this.slider.end ? parseFloat(this.slider.end) : undefined, formatTooltip: (value) => { var _a, _b, _c; return ((_c = (_b = (_a = getGlobalSettings()) === null || _a === void 0 ? void 0 : _a.renderPrice) === null || _b === void 0 ? void 0 : _b.call(_a, value.toFixed(2), "EUR")) !== null && _c !== void 0 ? _c : value.toFixed(2)).toString(); }, onKlevuSliderChange: (event) => {
      this.manager.updateSlide(this.slider.key, event.detail[0], event.detail[1]);
    } })));
}, _KlevuFacet_renderOptions = function _KlevuFacet_renderOptions() {
  if (!this.option) {
    return null;
  }
  let opts = [...this.option.options];
  if (this.option.type === KlevuFilterType.Rating) {
    opts.sort((a, b) => {
      if (a.name < b.name)
        return 1;
      return -1;
    });
  }
  if (this.customOrder) {
    opts.sort((a, b) => {
      const aio = this.customOrder.indexOf(a.value);
      const bio = this.customOrder.indexOf(b.value);
      if (aio === -1 && bio !== -1) {
        return 1;
      }
      if (aio !== -1 && bio === -1) {
        return -1;
      }
      return aio - bio;
    });
  }
  let showAllButton = false;
  if (!this.showAll && opts.length > 5) {
    opts = opts.slice(0, 5);
    showAllButton = true;
  }
  return (h(Fragment, null, h("span", { part: "facet-heading", slot: "header" }, h("klevu-typography", { class: { accordion: Boolean(this.accordion) }, variant: "body-s-bold" }, this.labelOverride || this.option.label)), h("div", { class: "options", slot: "content" }, this.useColorSwatch ? (h("div", { class: "colorSwatchContainer" }, opts.map((o) => {
    let swatch = {
      name: o.name,
      color: o.value,
      selected: o.selected,
    };
    const override = this.colorSwatchOverrides ? this.colorSwatchOverrides[o.name] : undefined;
    if (override) {
      swatch.color = override.color || swatch.color;
      swatch.imageUrl = override.imageUrl;
      swatch.borderColor = override.borderColor;
    }
    return (h("klevu-color-swatch", { onKlevuSwatchClick: (event) => {
        if (this.mode !== "checkbox")
          this.manager.clearOptionSelections(this.option.key);
        this.manager.toggleOption(this.option.key, event.detail.name);
      }, name: swatch.name, color: swatch.color, imageUrl: swatch.imageUrl, selected: swatch.selected, borderColor: swatch.borderColor }));
  }))) : (h(Fragment, null, this.mode === "radio" && (h("div", { class: "container" }, h("input", { part: "facet-radio", type: "radio", id: this.option.key, name: this.option.key, value: "all", checked: this.option.options.every((opt) => !opt.selected), onClick: () => {
      var _a;
      const currentSelectedOption = (_a = this.option) === null || _a === void 0 ? void 0 : _a.options.find((opt) => opt.selected);
      if (currentSelectedOption === null || currentSelectedOption === void 0 ? void 0 : currentSelectedOption.name) {
        this.manager.toggleOption(this.option.key, currentSelectedOption.name);
      }
    } }), h("label", { htmlFor: this.option.key, class: "name" }, h("span", null, this.tAll)), h("span", { part: "facet-option-count", class: "count" }, "(", this.option.options.reduce((total, opt) => opt.count + total, 0), ")"))), opts.map((o) => (h("div", { class: "option" }, this.mode === "checkbox" ? (h("klevu-checkbox", { exportparts: partsExports("klevu-checkbox"), checked: o.selected, name: this.option.key, onKlevuCheckboxChange: (event) => {
      this.manager.toggleOption(this.option.key, o.value);
    } }, h("div", { class: "container" }, h("span", { class: "name" }, h("span", null, resolveFacetLabel(o, this.option))), h("span", { part: "facet-option-count", class: "count" }, "(", o.count, ")")))) : (h("div", { class: "container" }, h("input", { part: "facet-radio", type: "radio", id: this.option.key, name: this.option.key, value: o.value, checked: o.selected, onClick: () => {
      this.manager.clearOptionSelections(this.option.key);
      this.manager.toggleOption(this.option.key, o.value);
    } }), h("label", { htmlFor: this.option.key, class: "name" }, h("span", null, resolveFacetLabel(o, this.option))), h("span", { part: "facet-option-count", class: "count" }, "(", o.count, ")")))))))), showAllButton ? (h("klevu-button", { part: "facet-more-button", style: { "--klevu-button-text-align": "left" }, isTertiary: true, fullWidth: true, onClick: () => (this.showAll = true) }, this.tMore)) : null)));
};
KlevuFacet.style = klevuFacetCss;

const klevuFacetListCss = ":host{display:block;width:var(--klevu-facet-list-width, 200px)}.applybar{display:flex;justify-content:space-between;margin:var(--klevu-spacing-04) 0;gap:var(--klevu-spacing-05)}.applybar .apply{width:100%}klevu-facet:first-of-type::part(heading){margin-top:0}";

var __classPrivateFieldSet$1 = (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$2 = (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 _KlevuFacetList_instances, _KlevuFacetList_applyManager, _KlevuFacetList_applySettings, _KlevuFacetList_clear;
const KlevuFacetList = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.klevuApplyFilters = createEvent(this, "klevuApplyFilters", 7);
    _KlevuFacetList_instances.add(this);
    _KlevuFacetList_applyManager.set(this, new FilterManager());
    this.manager = undefined;
    this.mode = undefined;
    this.customOrder = undefined;
    this.colorSwatches = [];
    this.colorSwatchOverrides = undefined;
    this.accordion = undefined;
    this.useApplyButton = undefined;
    this.applyButtonText = "Apply";
    this.clearButtonText = "Clear";
    this.defaultPriceLabel = "Price";
    this.filters = [];
  }
  connectedCallback() {
    if (!this.manager) {
      return;
    }
    __classPrivateFieldSet$1(this, _KlevuFacetList_applyManager, new FilterManager(), "f");
    __classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f").setState(this.manager.getCurrentState());
    if (this.useApplyButton) {
      this.updateApplyFilterState();
    }
    else {
      this.filters = this.manager.filters;
    }
  }
  filterManagerAppliedFilters() {
    __classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f").setState(this.manager.getCurrentState());
    if (!this.useApplyButton) {
      this.filters = this.manager.filters;
    }
  }
  filterSelectionUpdate(e) {
    if (!this.useApplyButton) {
      this.filters = this.manager.filters;
    }
  }
  /**
   * When using `useApplyButton` then this method can be used to update current state filterManager
   * into to local state of that is displayed in the UI
   */
  async updateApplyFilterState() {
    if (!this.useApplyButton) {
      return;
    }
    this.filters = __classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f").filters;
  }
  render() {
    return (h(Host, null, this.filters.map((f, index) => {
      var _a;
      if (FilterManager.isKlevuFilterResultOptions(f) || FilterManager.isKlevuFilterResultRating(f)) {
        let mode;
        if (this.mode && typeof this.mode === "string") {
          mode = this.mode;
        }
        else if (this.mode && typeof this.mode === "object") {
          mode = this.mode[f.key];
        }
        return (h("klevu-facet", { exportparts: partsExports("klevu-facet"), accordion: this.accordion, accordionStartOpen: index === 0, customOrder: (_a = this.customOrder) === null || _a === void 0 ? void 0 : _a[f.key], manager: this.useApplyButton ? __classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f") : this.manager, option: f, useColorSwatch: this.colorSwatches && !!this.colorSwatches.includes(f.key), colorSwatchOverrides: this.colorSwatchOverrides && this.colorSwatchOverrides[f.key], mode: mode }));
      }
      else if (FilterManager.isKlevuFilterResultSlider(f)) {
        return (h("klevu-facet", { exportparts: partsExports("klevu-facet"), accordion: this.accordion, manager: this.useApplyButton ? __classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f") : this.manager, slider: f, labelOverride: f.label === "klevu_price" ? this.defaultPriceLabel : undefined }));
      }
    }), this.useApplyButton ? (h("div", { class: "applybar" }, h("klevu-button", { isSecondary: true, onClick: () => __classPrivateFieldGet$2(this, _KlevuFacetList_instances, "m", _KlevuFacetList_clear).call(this) }, this.clearButtonText), h("klevu-button", { fullWidth: true, class: "apply", onClick: () => __classPrivateFieldGet$2(this, _KlevuFacetList_instances, "m", _KlevuFacetList_applySettings).call(this) }, this.applyButtonText))) : null));
  }
  get el() { return getElement(this); }
};
_KlevuFacetList_applyManager = new WeakMap(), _KlevuFacetList_instances = new WeakSet(), _KlevuFacetList_applySettings = function _KlevuFacetList_applySettings() {
  this.manager.setState(__classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f").getCurrentState());
  this.klevuApplyFilters.emit({
    manager: this.manager,
  });
}, _KlevuFacetList_clear = function _KlevuFacetList_clear() {
  __classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f").clearOptionSelections();
  this.filters = __classPrivateFieldGet$2(this, _KlevuFacetList_applyManager, "f").filters;
};
KlevuFacetList.style = klevuFacetListCss;

const klevuLayoutResultsCss = ":host{display:block}.container{display:flex;flex-direction:row;width:100%;gap:var(--klevu-spacing-04)}.sidebar{width:300px}main{width:100%}.header{margin:var(--klevu-spacing-04) 0;display:flex;align-items:center}.header slot{width:100%}.header klevu-button{margin-left:var(--klevu-spacing-04)}.footer{margin-top:var(--klevu-spacing-04);width:100%}@media (max-width: 511px){.container{flex-direction:column;gap:0}.sidebar{width:100%}}";

var __classPrivateFieldGet$1 = (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 _KlevuLayoutResults_instances, _KlevuLayoutResults_sizeChange;
const KlevuLayoutResults = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.klevuDrawerOpened = createEvent(this, "klevuDrawerOpened", 7);
    _KlevuLayoutResults_instances.add(this);
    this.currentViewPortSize = undefined;
  }
  async componentDidLoad() {
    this.currentViewPortSize = await this.viewportUtil.getCurrentSize();
  }
  /**
   * Can be used to close the drawer programmatically
   */
  async closeDrawer() {
    var _a;
    (_a = this.drawerElement) === null || _a === void 0 ? void 0 : _a.closeModal();
  }
  render() {
    var _a, _b;
    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";
    return (h(Host, null, h("klevu-util-viewport", { onKlevuSizeChanged: __classPrivateFieldGet$1(this, _KlevuLayoutResults_instances, "m", _KlevuLayoutResults_sizeChange).bind(this), ref: (el) => (this.viewportUtil = el) }), h("header", { class: "header" }, h("slot", { name: "header" }), isMobile ? (h("klevu-button", { icon: "menu", onClick: async (event) => {
        var _a;
        await ((_a = this.drawerElement) === null || _a === void 0 ? void 0 : _a.openModal());
        this.klevuDrawerOpened.emit();
        event.stopPropagation();
        return false;
      } })) : null), h("div", { class: "container" }, isMobile ? (h("klevu-drawer", { exportparts: partsExports("klevu-drawer"), ref: (el) => (this.drawerElement = el), insertYPadding: true, background: true }, h("slot", { slot: "content", name: "sidebar" }))) : (h("aside", { class: "sidebar" }, h("slot", { name: "sidebar" }))), h("main", null, h("section", { class: "content" }, h("slot", { name: "content" })), h("footer", { class: "footer" }, h("slot", { name: "footer" }))))));
  }
};
_KlevuLayoutResults_instances = new WeakSet(), _KlevuLayoutResults_sizeChange = function _KlevuLayoutResults_sizeChange(event) {
  this.currentViewPortSize = event.detail;
};
KlevuLayoutResults.style = klevuLayoutResultsCss;

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 __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 _KlevuUtilInfiniteScroll_instances, _KlevuUtilInfiniteScroll_loadMoreCount, _KlevuUtilInfiniteScroll_observer, _KlevuUtilInfiniteScroll_loadMore, _KlevuUtilInfiniteScroll_attachIntersectionObserver, _KlevuUtilInfiniteScroll_detachIntersectionObserver;
const KlevuUtilInfiniteScroll = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.klevuLoadMore = createEvent(this, "klevuLoadMore", 7);
    this.klevuInfiniteScrollingPaused = createEvent(this, "klevuInfiniteScrollingPaused", 7);
    _KlevuUtilInfiniteScroll_instances.add(this);
    _KlevuUtilInfiniteScroll_loadMoreCount.set(this, 1);
    _KlevuUtilInfiniteScroll_observer.set(this, null);
    _KlevuUtilInfiniteScroll_loadMore.set(this, () => {
      var _a;
      if (this.infiniteScrollPauseThreshold === 0) {
        this.klevuLoadMore.emit();
        return;
      }
      if (__classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_loadMoreCount, "f") % this.infiniteScrollPauseThreshold === 0) {
        this.klevuInfiniteScrollingPaused.emit();
      }
      else {
        this.klevuLoadMore.emit();
      }
      __classPrivateFieldSet(this, _KlevuUtilInfiniteScroll_loadMoreCount, (_a = __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_loadMoreCount, "f"), _a++, _a), "f");
    });
    this.infiniteScrollPauseThreshold = 3;
    this.enabled = false;
  }
  onEnableToggled() {
    if (this.enabled) {
      __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_instances, "m", _KlevuUtilInfiniteScroll_attachIntersectionObserver).call(this);
    }
    else {
      __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_instances, "m", _KlevuUtilInfiniteScroll_detachIntersectionObserver).call(this);
    }
  }
  disconnectedCallback() {
    __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_instances, "m", _KlevuUtilInfiniteScroll_detachIntersectionObserver).call(this);
  }
  connectedCallback() {
    if (this.enabled) {
      // To avoid triggering load more immediately
      setTimeout(() => {
        __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_instances, "m", _KlevuUtilInfiniteScroll_attachIntersectionObserver).call(this);
      }, 100);
    }
  }
  render() {
    return (h(Host, null, h("div", null)));
  }
  get el() { return getElement(this); }
  static get watchers() { return {
    "enabled": ["onEnableToggled"]
  }; }
};
_KlevuUtilInfiniteScroll_loadMoreCount = new WeakMap(), _KlevuUtilInfiniteScroll_observer = new WeakMap(), _KlevuUtilInfiniteScroll_loadMore = new WeakMap(), _KlevuUtilInfiniteScroll_instances = new WeakSet(), _KlevuUtilInfiniteScroll_attachIntersectionObserver = function _KlevuUtilInfiniteScroll_attachIntersectionObserver() {
  __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_instances, "m", _KlevuUtilInfiniteScroll_detachIntersectionObserver).call(this);
  __classPrivateFieldSet(this, _KlevuUtilInfiniteScroll_observer, new IntersectionObserver((entries) => {
    if (entries[0].isIntersecting) {
      __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_loadMore, "f").call(this);
    }
  }), "f");
  if (this.el && __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_observer, "f")) {
    __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_observer, "f").observe(this.el);
  }
}, _KlevuUtilInfiniteScroll_detachIntersectionObserver = function _KlevuUtilInfiniteScroll_detachIntersectionObserver() {
  if (this.el && __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_observer, "f")) {
    __classPrivateFieldGet(this, _KlevuUtilInfiniteScroll_observer, "f").unobserve(this.el);
  }
};

export { KlevuDrawer as klevu_drawer, KlevuFacet as klevu_facet, KlevuFacetList as klevu_facet_list, KlevuLayoutResults as klevu_layout_results, KlevuUtilInfiniteScroll as klevu_util_infinite_scroll };

//# sourceMappingURL=klevu-drawer_5.entry.js.map