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 _KlevuFacetList_instances, _KlevuFacetList_applyManager, _KlevuFacetList_applySettings, _KlevuFacetList_clear;
import { FilterManager, } from "@klevu/core";
import { h, Host } from "@stencil/core";
/**
 * Render all facets of filter manager
 *
 * @cssprop --klevu-face-list-width 200px Width of the facet listing
 */
export class KlevuFacetList {
  constructor() {
    _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));
  }
  static get is() { return "klevu-facet-list"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-facet-list.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-facet-list.css"]
    };
  }
  static get properties() {
    return {
      "manager": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "FilterManager",
          "resolved": "FilterManager",
          "references": {
            "FilterManager": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::FilterManager"
            }
          }
        },
        "required": true,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Filter managet from which the list is built from"
        }
      },
      "mode": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "KlevuFacetMode | { [key: string]: KlevuFacetMode }",
          "resolved": "\"checkbox\" | \"radio\" | undefined | { [key: string]: KlevuFacetMode; }",
          "references": {
            "KlevuFacetMode": {
              "location": "import",
              "path": "../klevu-facet/klevu-facet",
              "id": "src/components/klevu-facet/klevu-facet.tsx::KlevuFacetMode"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Set mode for facets or if object is passed then define per key"
        },
        "attribute": "mode",
        "reflect": false
      },
      "customOrder": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "{ [key: string]: string[] }",
          "resolved": "undefined | { [key: string]: string[]; }",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Custom order keys for every facet"
        }
      },
      "accordion": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Should use accordions to for facets"
        },
        "attribute": "accordion",
        "reflect": false
      },
      "useApplyButton": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Display \"apply filters\" button in the end. And do not apply filters until this button is pressed"
        },
        "attribute": "use-apply-button",
        "reflect": false
      },
      "applyButtonText": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Button text for Apply button when using `useApplyButton`"
        },
        "attribute": "apply-button-text",
        "reflect": false,
        "defaultValue": "\"Apply\""
      },
      "clearButtonText": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Button text for Clear button when using `useApplyButton`"
        },
        "attribute": "clear-button-text",
        "reflect": false,
        "defaultValue": "\"Clear\""
      },
      "defaultPriceLabel": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Default price label for sliders"
        },
        "attribute": "default-price-label",
        "reflect": false,
        "defaultValue": "\"Price\""
      }
    };
  }
  static get states() {
    return {
      "filters": {}
    };
  }
  static get events() {
    return [{
        "method": "klevuApplyFilters",
        "name": "klevuApplyFilters",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "When filters are applied"
        },
        "complexType": {
          "original": "void",
          "resolved": "void",
          "references": {}
        }
      }];
  }
  static get elementRef() { return "el"; }
  static get listeners() {
    return [{
        "name": "klevu-filters-applied",
        "method": "filtersApplied",
        "target": "document",
        "capture": false,
        "passive": false
      }, {
        "name": "klevu-filter-selection-updates",
        "method": "filterSelectionUpdate",
        "target": "document",
        "capture": false,
        "passive": false
      }];
  }
}
_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;
};
//# sourceMappingURL=klevu-facet-list.js.map
