'use strict';

var index = require('./index-pX0sBY0-.js');

// utils.ts
function getInitiallySelectedItems(el) {
    return Array.from(el.querySelectorAll("ifx-list-entry"))
        .filter((entry) => entry.getAttribute("value") === "true")
        .map((entry) => {
        return {
            label: entry.getAttribute("label"),
            value: entry.getAttribute("value"),
            type: entry.getAttribute("type"),
        };
    });
}

const filterAccordionCss = () => `.header{display:flex;align-items:flex-start;align-self:stretch;cursor:pointer;border-left:3px solid transparent}.text-and-icon{display:flex;padding:12px 16px 12px 20px;align-items:center;gap:16px;flex:1 0 0}.header.expanded{border-left:3px solid #0A8276}.text{display:flex;align-items:center;gap:8px;flex:1 0 0;color:#1D1D1D;font-size:16px;font-style:normal;font-weight:600;line-height:24px}.hidden{display:none}.accordion{border-bottom:1px solid #EEEDED}.filter-accordion-container{display:flex;padding:8px 16px 16px 20px;flex-direction:column;align-items:flex-start;gap:12px;align-self:stretch;border-left:3px solid #0A8276}::slotted(ifx-filter-entry:nth-child(n+7)){display:none}.link{display:flex;align-items:center;gap:8px}.show-more ::slotted(ifx-filter-entry:nth-child(n+7)){display:block}.show-more .show-more-link{display:none}`;

const FilterAccordion = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.ifxFilterAccordionChange = index.createEvent(this, "ifxFilterAccordionChange", 7);
    }
    initialized = false;
    get el() { return index.getElement(this); }
    expanded = false;
    /** Max number of items to display before truncating/collapsing the list */
    maxVisibleItems;
    count = 0;
    totalItems = 0;
    /** Identifier/label for the filter group */
    filterGroupName = "";
    /** Emitted when the filter accordion`s state or selection changes */
    ifxFilterAccordionChange;
    componentWillLoad() {
        this.el.addEventListener("ifxListUpdate", this.handleCheckedChange);
    }
    componentDidLoad() {
        if (!this.initialized) {
            const selectedItems = getInitiallySelectedItems(this.el);
            this.count = selectedItems.length;
            this.initialized = true; // Prevent further execution in future calls
        }
    }
    handleCheckedChange = (event) => {
        const selectedItems = event.detail.selectedItems;
        this.count = selectedItems.length;
        this.ifxFilterAccordionChange.emit({
            filterGroupName: this.filterGroupName,
            selectedItems,
        });
    };
    disconnectedCallback() {
        this.el.removeEventListener("ifxListUpdate", this.handleCheckedChange);
    }
    toggleAccordion = (event) => {
        event.stopPropagation();
        this.expanded = !this.expanded;
    };
    render() {
        return (index.h("div", { key: '0740d98898997013417cf38f39e63a301be16dfd', class: `accordion ${this.expanded ? "expanded" : ""}` }, index.h("div", { key: 'b44e498b3bff48715af1c2c6bdcf314762713618', class: `header ${this.expanded ? "expanded" : ""}`, onClick: this.toggleAccordion }, index.h("div", { key: '88c0a5831935c7e651970ce44b24c09de3a0b149', class: `text-and-icon ${this.expanded ? "expanded" : ""}` }, index.h("div", { key: '9b45de6f6d50f5bc5486212c389e7b1bf01d89f4', class: "text" }, index.h("span", { key: '8864f251b18fd6e95ded2c562b2f9a18aaed1747' }, this.filterGroupName), index.h("ifx-indicator", { key: '525a7f528a09e9a2e45a2f55f9b38a5df02e436c', variant: "number", number: this.count })), index.h("ifx-icon", { key: 'dac4cfdfd877430b37aa263acf66f4b3b1bb3669', class: this.expanded ? "" : "hidden", icon: "minus-16", onClick: this.toggleAccordion }), index.h("ifx-icon", { key: '676d3c7356ef81a4d6e353226ba67fed173e2bb0', class: this.expanded ? "hidden" : "", icon: "plus-16", onClick: this.toggleAccordion }))), this.expanded && (index.h("div", { key: '516286fe33b675b737d0eb832f7d280a619ca254', class: "filter-accordion-container" }, index.h("slot", { key: '3031b8ad0800d733eb5262bc5b4b5ac90b293667', name: "list" })))));
    }
};
FilterAccordion.style = filterAccordionCss();

exports.ifx_filter_accordion = FilterAccordion;
