'use strict';

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

const index = require('./index-7e93c7c3.js');
const utils = require('./utils-4717dffd.js');
const filterManager = require('./filterManager-4b52c59d.js');
const KlevuSearchSorting = require('./KlevuSearchSorting-3cce1bed.js');
require('./isBrowser-a8464358.js');

const klevuDrawerCss = ":host{display:block;--klevu-drawer-ypadding:var(--klevu-spacing-07)}.drawer{position:fixed;top:0;height:100vh;max-width:var(--klevu-drawer-max-width, max-content);z-index:1000;background:#fff;transition:left 0.4s, right 0.4s}.drawer.left{left:-100%;border-right:1px solid var(--klevu-color-border);padding-right:var(--klevu-spacing-04)}.drawer.right{right:-100%;border-left:1px solid var(--klevu-color-border);padding-left:var(--klevu-spacing-04)}.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(--klevu-drawer-background-color, rgba(0, 0, 0, 0.2));z-index:999}.background.show{display:block}.innercontainer{height:100%;width:100%;overflow-y:scroll}.insertypadding{padding:0 var(--klevu-drawer-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$5 = (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) {
    index.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$5(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$5(this, _KlevuDrawer_instances, "m", _KlevuDrawer_openEvent).bind(this));
    if (this.closeAtOutsideClick) {
      document.addEventListener("click", __classPrivateFieldGet$5(this, _KlevuDrawer_instances, "m", _KlevuDrawer_closeEvent).bind(this));
    }
  }
  detachedCallback() {
    var _a;
    document.removeEventListener("click", __classPrivateFieldGet$5(this, _KlevuDrawer_instances, "m", _KlevuDrawer_closeEvent));
    (_a = this.el) === null || _a === void 0 ? void 0 : _a.removeEventListener("click", __classPrivateFieldGet$5(this, _KlevuDrawer_instances, "m", _KlevuDrawer_openEvent));
  }
  render() {
    return (index.h(index.Host, null, index.h("slot", { name: "origin" }), index.h("div", { class: {
        drawer: true,
        show: this.open,
        left: this.anchor === "left",
        right: this.anchor === "right",
      } }, index.h("div", { class: { innercontainer: true, insertypadding: Boolean(this.insertYPadding) } }, index.h("slot", { name: "content" }))), this.background ? (index.h("div", { onClick: this.closeModal.bind(this), class: { background: true, show: this.open } })) : null));
  }
  get el() { return index.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)}";

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 _KlevuFacet_instances, _KlevuFacet_renderSlider, _KlevuFacet_renderOptions;
const KlevuFacet = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    _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.showAll = false;
  }
  filterSelectionUpdate(event) {
    index.forceUpdate(this.el);
  }
  render() {
    return (index.h(index.Host, null, this.option ? (index.h(index.Fragment, null, this.accordion ? (index.h("klevu-accordion", { exportparts: utils.globalExportedParts, startOpen: this.accordionStartOpen }, __classPrivateFieldGet$4(this, _KlevuFacet_instances, "m", _KlevuFacet_renderOptions).call(this))) : (__classPrivateFieldGet$4(this, _KlevuFacet_instances, "m", _KlevuFacet_renderOptions).call(this)))) : this.slider ? (index.h(index.Fragment, null, this.accordion ? (index.h("klevu-accordion", { exportparts: utils.globalExportedParts, startOpen: this.accordionStartOpen }, __classPrivateFieldGet$4(this, _KlevuFacet_instances, "m", _KlevuFacet_renderSlider).call(this))) : (__classPrivateFieldGet$4(this, _KlevuFacet_instances, "m", _KlevuFacet_renderSlider).call(this)))) : null));
  }
  get el() { return index.getElement(this); }
};
_KlevuFacet_instances = new WeakSet(), _KlevuFacet_renderSlider = function _KlevuFacet_renderSlider() {
  if (!this.slider) {
    return null;
  }
  return (index.h(index.Fragment, null, index.h("klevu-typography", { part: "facet-heading", class: { accordion: Boolean(this.accordion) }, variant: "body-s-bold", slot: "header" }, this.labelOverride || this.slider.label), index.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 = utils.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.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 (index.h(index.Fragment, null, index.h("klevu-typography", { part: "facet-heading", class: { accordion: Boolean(this.accordion) }, variant: "body-s-bold", slot: "header" }, this.labelOverride || this.option.label), index.h("div", { class: "options", slot: "content" }, opts.map((o) => (index.h("div", { class: "option" }, this.mode === "checkbox" ? (index.h("klevu-checkbox", { exportparts: utils.globalExportedParts, checked: o.selected, name: this.option.key, onKlevuCheckboxChange: (event) => {
      this.manager.toggleOption(this.option.key, o.value);
    } }, index.h("div", { class: "container" }, index.h("span", { class: "name" }, index.h("span", null, o.name)), index.h("span", { class: "count" }, "(", o.count, ")")))) : (index.h("div", { class: "container" }, index.h("input", { 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);
    } }), index.h("label", { htmlFor: this.option.key, class: "name" }, index.h("span", null, o.name)), index.h("span", { class: "count" }, "(", o.count, ")")))))), showAllButton ? (index.h("klevu-button", { style: { "--klevu-button-text-align": "left" }, isTertiary: true, fullWidth: true, onClick: () => (this.showAll = true) }, "More")) : 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$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 _KlevuFacetList_instances, _KlevuFacetList_applyManager, _KlevuFacetList_applySettings, _KlevuFacetList_clear;
const KlevuFacetList = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.klevuApplyFilters = index.createEvent(this, "klevuApplyFilters", 7);
    _KlevuFacetList_instances.add(this);
    _KlevuFacetList_applyManager.set(this, new filterManager.FilterManager());
    this.manager = undefined;
    this.mode = undefined;
    this.customOrder = 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.FilterManager(), "f");
    __classPrivateFieldGet$3(this, _KlevuFacetList_applyManager, "f").setState(this.manager.getCurrentState());
    if (this.useApplyButton) {
      this.filters = __classPrivateFieldGet$3(this, _KlevuFacetList_applyManager, "f").filters;
    }
    else {
      this.filters = this.manager.filters;
    }
  }
  filtersApplied() {
    __classPrivateFieldGet$3(this, _KlevuFacetList_applyManager, "f").setState(this.manager.getCurrentState());
    if (!this.useApplyButton) {
      this.filters = this.manager.filters;
    }
  }
  filterSelectionUpdate() {
    if (!this.useApplyButton) {
      this.filters = this.manager.filters;
      this.klevuApplyFilters.emit();
    }
  }
  render() {
    return (index.h(index.Host, null, this.filters.map((f, index$1) => {
      var _a;
      if (filterManager.FilterManager.isKlevuFilterResultOptions(f) || filterManager.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 (index.h("klevu-facet", { accordion: this.accordion, accordionStartOpen: index$1 === 0, customOrder: (_a = this.customOrder) === null || _a === void 0 ? void 0 : _a[f.key], exportparts: utils.globalExportedParts, manager: this.useApplyButton ? __classPrivateFieldGet$3(this, _KlevuFacetList_applyManager, "f") : this.manager, option: f, mode: mode }));
      }
      else if (filterManager.FilterManager.isKlevuFilterResultSlider(f)) {
        return (index.h("klevu-facet", { accordion: this.accordion, exportparts: utils.globalExportedParts, manager: this.useApplyButton ? __classPrivateFieldGet$3(this, _KlevuFacetList_applyManager, "f") : this.manager, slider: f, labelOverride: f.label === "klevu_price" ? this.defaultPriceLabel : undefined }));
      }
    }), this.useApplyButton ? (index.h("div", { class: "applybar" }, index.h("klevu-button", { isSecondary: true, onClick: () => __classPrivateFieldGet$3(this, _KlevuFacetList_instances, "m", _KlevuFacetList_clear).call(this) }, this.clearButtonText), index.h("klevu-button", { fullWidth: true, class: "apply", onClick: () => __classPrivateFieldGet$3(this, _KlevuFacetList_instances, "m", _KlevuFacetList_applySettings).call(this) }, this.applyButtonText))) : null));
  }
  get el() { return index.getElement(this); }
};
_KlevuFacetList_applyManager = new WeakMap(), _KlevuFacetList_instances = new WeakSet(), _KlevuFacetList_applySettings = function _KlevuFacetList_applySettings() {
  this.manager.setState(__classPrivateFieldGet$3(this, _KlevuFacetList_applyManager, "f").getCurrentState());
  this.klevuApplyFilters.emit();
}, _KlevuFacetList_clear = function _KlevuFacetList_clear() {
  __classPrivateFieldGet$3(this, _KlevuFacetList_applyManager, "f").clearOptionSelections();
  this.filters = __classPrivateFieldGet$3(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}.header slot{width:100%}.header klevu-button{margin-left:auto}.footer{margin-top:var(--klevu-spacing-04);width:100%}@media (max-width: 511px){.container{flex-direction:column;gap:0}.sidebar{width:100%}}";

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 _KlevuLayoutResults_instances, _KlevuLayoutResults_sizeChange;
const KlevuLayoutResults = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    _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 (index.h(index.Host, null, index.h("klevu-util-viewport", { onSizeChanged: __classPrivateFieldGet$2(this, _KlevuLayoutResults_instances, "m", _KlevuLayoutResults_sizeChange).bind(this), ref: (el) => (this.viewportUtil = el) }), index.h("header", { class: "header" }, index.h("slot", { name: "header" }), isMobile ? (index.h("klevu-button", { onClick: async (event) => {
        var _a;
        await ((_a = this.drawerElement) === null || _a === void 0 ? void 0 : _a.openModal());
        event.stopPropagation();
        return false;
      } }, index.h("span", { part: "material-icon" }, "menu"))) : null), index.h("div", { class: "container" }, isMobile ? (index.h("klevu-drawer", { ref: (el) => (this.drawerElement = el), insertYPadding: true, background: true }, index.h("slot", { slot: "content", name: "sidebar" }))) : (index.h("aside", { class: "sidebar" }, index.h("slot", { name: "sidebar" }))), index.h("main", null, index.h("section", { class: "content" }, index.h("slot", { name: "content" })), index.h("footer", { class: "footer" }, index.h("slot", { name: "footer" }))))));
  }
};
_KlevuLayoutResults_instances = new WeakSet(), _KlevuLayoutResults_sizeChange = function _KlevuLayoutResults_sizeChange(event) {
  this.currentViewPortSize = event.detail;
};
KlevuLayoutResults.style = klevuLayoutResultsCss;

const klevuPaginationCss = ":host{--klevu-pagination-selected-color:var(--klevu-color-primary);display:flex;gap:var(--klevu-spacing-03);justify-content:center;flex-wrap:wrap}span{display:flex;height:32px;width:32px;color:var(--klevu-color-neutral-8);border-radius:var(--klevu-border-radius-m);justify-content:center;align-items:center;font-size:var(--klevu-body-s-size);box-sizing:border-box}span.current{font-weight:bold;cursor:inherit;border:1px solid var(--klevu-pagination-selected-color);color:var(--klevu-pagination-selected-color)}span:not(.disabled):not(.current):hover{color:var(--klevu-pagination-selected-color);background-color:var(--klevu-color-neutral-2);cursor:pointer}span.disabled{opacity:var(--klevu-opacity-disabled);cursor:inherit}span.dots{width:auto}@media (max-width: 600px){:host{gap:var(--klevu-spacing-02)}}";

const KlevuPagination = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.klevuPaginationChange = index.createEvent(this, "klevuPaginationChange", 7);
    this.current = undefined;
    this.min = undefined;
    this.max = undefined;
    this.queryResult = undefined;
  }
  render() {
    let min, max, current;
    if (this.queryResult) {
      min = 1;
      max = Math.floor(this.queryResult.meta.totalResultsFound / this.queryResult.meta.noOfResults) + 1;
      current = Math.floor(this.queryResult.meta.offset / this.queryResult.meta.noOfResults) + 1;
    }
    else {
      if ([this.current, this.max, this.min].some((i) => i === undefined)) {
        throw new Error("queryResult or current, min & max needs to be defined");
      }
      min = this.min;
      max = this.max;
      current = this.current;
    }
    let pages = [];
    for (let i = min; i <= max; i++) {
      pages.push(i);
    }
    if (pages.length > 8) {
      let startIndex = min + 1;
      let endIndex = max - 1;
      let currentStartIndex = current > 3 ? current - 1 : 0;
      let currentEndIndex = current < endIndex - 1 ? currentStartIndex + 2 : endIndex - 1;
      if (currentStartIndex < startIndex) {
        currentStartIndex = startIndex + 1;
        currentEndIndex = currentStartIndex + 2;
      }
      pages = [];
      for (let i = min; i <= startIndex; i++) {
        pages.push(i);
      }
      if (startIndex + 1 < currentStartIndex) {
        pages.push(-1);
      }
      for (let i = currentStartIndex; i <= currentEndIndex; i++) {
        pages.push(i);
      }
      if (currentEndIndex + 1 < endIndex) {
        pages.push(-1);
      }
      for (let i = endIndex; i <= max; i++) {
        pages.push(i);
      }
    }
    return (index.h(index.Host, null, index.h("span", { class: {
        disabled: current === min,
      }, onClick: () => current !== min && this.klevuPaginationChange.emit(current - 1), part: "material-icon" }, "navigate_before"), pages.map((i) => {
      if (i == -1) {
        return index.h("span", { class: "disabled dots" }, "...");
      }
      return (index.h("span", { class: {
          current: current === i,
        }, onClick: () => current !== i && this.klevuPaginationChange.emit(i) }, i));
    }), index.h("span", { class: {
        disabled: current === max,
      }, onClick: () => current !== max && this.klevuPaginationChange.emit(current + 1), part: "material-icon" }, "navigate_next")));
  }
};
KlevuPagination.style = klevuPaginationCss;

const klevuProductGridCss = ".gridcontainer{display:grid;grid-gap:var(--klevu-product-grid-spacing, var(--klevu-spacing-05));grid-template-columns:repeat(auto-fill, minmax(var(--klevu-grid-product-width, 250px), 1fr))}";

const KlevuProductGrid = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.itemsPerRow = undefined;
  }
  render() {
    const style = {};
    if (this.itemsPerRow) {
      style.gridTemplateColumns = `repeat(${this.itemsPerRow}, 1fr)`;
    }
    return (index.h(index.Host, null, index.h("div", { class: "gridcontainer", style: style }, index.h("slot", null))));
  }
};
KlevuProductGrid.style = klevuProductGridCss;

const klevuSortCss = ":host{display:block}";

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$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 _KlevuSort_instances, _KlevuSort_selected, _KlevuSort_onChange;
const KlevuSort = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.klevuSortChanged = index.createEvent(this, "klevuSortChanged", 7);
    _KlevuSort_instances.add(this);
    _KlevuSort_selected.set(this, KlevuSearchSorting.KlevuSearchSorting.Relevance);
    this.variant = "default";
    this.options = [
      { value: KlevuSearchSorting.KlevuSearchSorting.Relevance, text: "Relevance" },
      { value: KlevuSearchSorting.KlevuSearchSorting.NameAsc, text: "Name ▲" },
      { value: KlevuSearchSorting.KlevuSearchSorting.NameDesc, text: "Name ▼" },
      { value: KlevuSearchSorting.KlevuSearchSorting.NewArrivalAsc, text: "New arrivals ▲" },
      { value: KlevuSearchSorting.KlevuSearchSorting.NewArrivalDesc, text: "New arrivals ▼" },
      { value: KlevuSearchSorting.KlevuSearchSorting.PriceAsc, text: "Price ▲" },
      { value: KlevuSearchSorting.KlevuSearchSorting.PriceDesc, text: "Price ▼" },
      { value: KlevuSearchSorting.KlevuSearchSorting.RatingAsc, text: "Rating ▲" },
      { value: KlevuSearchSorting.KlevuSearchSorting.RatingDesc, text: "Rating ▼" },
    ];
  }
  render() {
    return (index.h(index.Host, null, index.h("klevu-dropdown", { exportparts: utils.globalExportedParts, name: "sort", options: this.options, selected: __classPrivateFieldGet$1(this, _KlevuSort_selected, "f"), variant: this.variant, onKlevuDropdownChanged: __classPrivateFieldGet$1(this, _KlevuSort_instances, "m", _KlevuSort_onChange).bind(this) })));
  }
};
_KlevuSort_selected = new WeakMap(), _KlevuSort_instances = new WeakSet(), _KlevuSort_onChange = function _KlevuSort_onChange(event) {
  const newSort = event.detail;
  __classPrivateFieldSet(this, _KlevuSort_selected, newSort, "f");
  this.klevuSortChanged.emit(newSort);
};
KlevuSort.style = klevuSortCss;

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 _KlevuUtilViewport_instances, _KlevuUtilViewport_handleMatchMediaChange;
const KlevuUtilViewport = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.sizeChanged = index.createEvent(this, "sizeChanged", 7);
    _KlevuUtilViewport_instances.add(this);
    this.sizes = [
      { name: "xs", minWidth: 0, maxWidth: 319 },
      { name: "sm", minWidth: 320, maxWidth: 511 },
      { name: "md", minWidth: 512, maxWidth: 991 },
      { name: "lg", minWidth: 992, maxWidth: 1199 },
      { name: "xl", minWidth: 1200, maxWidth: 9999 },
    ];
  }
  connectedCallback() {
    // Add listeners for all sizes provided
    for (const size of this.sizes) {
      window
        .matchMedia(`(min-width: ${size.minWidth}px) and (max-width: ${size.maxWidth}px)`)
        .addEventListener("change", __classPrivateFieldGet(this, _KlevuUtilViewport_instances, "m", _KlevuUtilViewport_handleMatchMediaChange).bind(this));
    }
  }
  disconnectedCallback() {
    for (const size of this.sizes) {
      window
        .matchMedia(`(min-width: ${size.minWidth}px) and (max-width: ${size.maxWidth}px)`)
        .removeEventListener("change", __classPrivateFieldGet(this, _KlevuUtilViewport_instances, "m", _KlevuUtilViewport_handleMatchMediaChange).bind(this));
    }
  }
  async getCurrentSize() {
    // Iterate over all given sizes and see which one matches
    for (const size of this.sizes) {
      if (window.matchMedia(`(min-width: ${size.minWidth}px)  and (max-width: ${size.maxWidth}px)`).matches) {
        return size;
      }
    }
  }
  render() {
    return null;
  }
};
_KlevuUtilViewport_instances = new WeakSet(), _KlevuUtilViewport_handleMatchMediaChange = function _KlevuUtilViewport_handleMatchMediaChange(q) {
  if (!q.matches) {
    return;
  }
  // Find the name of the matching size and emit an event
  for (const size of this.sizes) {
    if (q.media.indexOf(`min-width: ${size.minWidth}px`) > -1) {
      this.sizeChanged.emit(size);
    }
  }
};

exports.klevu_drawer = KlevuDrawer;
exports.klevu_facet = KlevuFacet;
exports.klevu_facet_list = KlevuFacetList;
exports.klevu_layout_results = KlevuLayoutResults;
exports.klevu_pagination = KlevuPagination;
exports.klevu_product_grid = KlevuProductGrid;
exports.klevu_sort = KlevuSort;
exports.klevu_util_viewport = KlevuUtilViewport;

//# sourceMappingURL=klevu-drawer_8.cjs.entry.js.map