import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { d as defineCustomElement$7 } from './klevu-accordion2.js';
import { d as defineCustomElement$6 } from './klevu-button2.js';
import { d as defineCustomElement$5 } from './klevu-checkbox2.js';
import { d as defineCustomElement$4 } from './klevu-facet2.js';
import { d as defineCustomElement$3 } from './klevu-icon2.js';
import { d as defineCustomElement$2 } from './klevu-slider2.js';
import { d as defineCustomElement$1 } from './klevu-typography2.js';
import { F as FilterManager } from './filterManager.js';

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 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
  if (kind === "m")
    throw new TypeError("Private method is not writable");
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a setter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a getter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _KlevuFacetList_instances, _KlevuFacetList_applyManager, _KlevuFacetList_applySettings, _KlevuFacetList_clear;
const KlevuFacetList = /*@__PURE__*/ proxyCustomElement(class KlevuFacetList extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    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.accordion = undefined;
    this.useApplyButton = undefined;
    this.applyButtonText = "Apply";
    this.clearButtonText = "Clear";
    this.defaultPriceLabel = "Price";
    this.filters = [];
  }
  connectedCallback() {
    if (!this.manager) {
      return;
    }
    __classPrivateFieldSet(this, _KlevuFacetList_applyManager, new FilterManager(), "f");
    __classPrivateFieldGet(this, _KlevuFacetList_applyManager, "f").setState(this.manager.getCurrentState());
    if (this.useApplyButton) {
      this.filters = __classPrivateFieldGet(this, _KlevuFacetList_applyManager, "f").filters;
    }
    else {
      this.filters = this.manager.filters;
    }
  }
  filtersApplied() {
    __classPrivateFieldGet(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 (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", { accordion: this.accordion, accordionStartOpen: index === 0, customOrder: (_a = this.customOrder) === null || _a === void 0 ? void 0 : _a[f.key], manager: this.useApplyButton ? __classPrivateFieldGet(this, _KlevuFacetList_applyManager, "f") : this.manager, option: f, mode: mode }));
      }
      else if (FilterManager.isKlevuFilterResultSlider(f)) {
        return (h("klevu-facet", { accordion: this.accordion, manager: this.useApplyButton ? __classPrivateFieldGet(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(this, _KlevuFacetList_instances, "m", _KlevuFacetList_clear).call(this) }, this.clearButtonText), h("klevu-button", { fullWidth: true, class: "apply", onClick: () => __classPrivateFieldGet(this, _KlevuFacetList_instances, "m", _KlevuFacetList_applySettings).call(this) }, this.applyButtonText))) : null));
  }
  get el() { return this; }
  static get style() { return klevuFacetListCss; }
}, [1, "klevu-facet-list", {
    "manager": [16],
    "mode": [1],
    "customOrder": [16],
    "accordion": [4],
    "useApplyButton": [4, "use-apply-button"],
    "applyButtonText": [1, "apply-button-text"],
    "clearButtonText": [1, "clear-button-text"],
    "defaultPriceLabel": [1, "default-price-label"],
    "filters": [32]
  }, [[4, "klevu-filters-applied", "filtersApplied"], [4, "klevu-filter-selection-updates", "filterSelectionUpdate"]]]);
_KlevuFacetList_applyManager = new WeakMap(), _KlevuFacetList_instances = new WeakSet(), _KlevuFacetList_applySettings = function _KlevuFacetList_applySettings() {
  this.manager.setState(__classPrivateFieldGet(this, _KlevuFacetList_applyManager, "f").getCurrentState());
  this.klevuApplyFilters.emit();
}, _KlevuFacetList_clear = function _KlevuFacetList_clear() {
  __classPrivateFieldGet(this, _KlevuFacetList_applyManager, "f").clearOptionSelections();
  this.filters = __classPrivateFieldGet(this, _KlevuFacetList_applyManager, "f").filters;
};
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["klevu-facet-list", "klevu-accordion", "klevu-button", "klevu-checkbox", "klevu-facet", "klevu-icon", "klevu-slider", "klevu-typography"];
  components.forEach(tagName => { switch (tagName) {
    case "klevu-facet-list":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, KlevuFacetList);
      }
      break;
    case "klevu-accordion":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "klevu-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "klevu-checkbox":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "klevu-facet":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "klevu-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "klevu-slider":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
    case "klevu-typography":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}
defineCustomElement();

export { KlevuFacetList as K, defineCustomElement as d };

//# sourceMappingURL=klevu-facet-list2.js.map