import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { _ as __decorate, a as __metadata } from './tslib.es6.js';
import { r as raf, l as debounce } from './helpers.js';
import { L as Logger } from './log.js';
import { b as balBreakpoints } from './breakpoints.subject.js';
import { L as ListenToResize } from './resize.decorator.js';
import { L as ListenToBreakpoints } from './breakpoints.decorator.js';

const ListItemAccordionBody = /*@__PURE__*/ proxyCustomElement(class ListItemAccordionBody extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.isMobile = balBreakpoints.isMobile;
        this.internalId = `bal-list-item-accordion-body-${ListItemAccordionBodyIds++}`;
        this.ariaState = {};
        /**
         * Sets space to content of the accordion body
         */
        this.contentSpace = 'none';
        /**
         * Sets justify-content of the items to start, center, end, or space-between. Default is start
         */
        this.contentAlignment = 'start';
        this.setMinHeightForAnimation = () => {
            if (this.currentRaf !== undefined) {
                cancelAnimationFrame(this.currentRaf);
            }
            if (this.isMobile && this.contentElWrapper) {
                this.contentElWrapper.style.removeProperty('min-height');
                return;
            }
            raf(() => {
                if (this.accordionGroup !== undefined && this.accordionGroup !== '') {
                    const allAccordionBodies = Array.from(document.body.querySelectorAll('bal-list-item-accordion-body'));
                    const groupContents = allAccordionBodies
                        .filter(el => el.accordionGroup === this.accordionGroup)
                        .map(el => el.querySelector('.bal-list__item__accordion-body__content'))
                        .filter(el => el);
                    const groupContentHeight = groupContents.reduce((acc, el) => (acc < el.offsetHeight ? el.offsetHeight : acc), 0);
                    if (this.contentElWrapper && groupContentHeight > 0 && this.el.offsetHeight !== groupContentHeight) {
                        this.contentElWrapper.style.setProperty('min-height', `${groupContentHeight}px`);
                    }
                }
            });
        };
        this.debounceSetMinHeightForAnimation = debounce(this.setMinHeightForAnimation.bind(this), 100);
    }
    createLogger(log) {
        this.log = log;
    }
    /**
     * LIFECYCLE
     * ------------------------------------------------------
     */
    connectedCallback() {
        this.setMinHeightForAnimation();
    }
    componentDidRender() {
        this.setMinHeightForAnimation();
        this.setControlIdToHead();
    }
    /**
     * LISTENERS
     * ------------------------------------------------------
     */
    resizeListener() {
    }
    breakpointListener(breakpoints) {
        this.isMobile = breakpoints.mobile;
        this.debounceSetMinHeightForAnimation();
    }
    /**
     * PUBLIC METHODS
     * ------------------------------------------------------
     */
    /**
     * @internal
     */
    async setAria(aria) {
        if (aria.labelledby && aria.labelledby !== this.ariaState.labelledby) {
            this.ariaState.labelledby = aria.labelledby;
        }
    }
    /**
     * PRIVATE METHODS
     * ------------------------------------------------------
     */
    setControlIdToHead() {
        const headEl = this.el.parentElement.querySelector('bal-list-item-accordion-head');
        if (headEl) {
            headEl.setAria({ controlId: this.internalId });
        }
    }
    /**
     * RENDER
     * ------------------------------------------------------
     */
    render() {
        return (h(Host, { key: '0d63a86061285cb7877781ed793ba47581f88421', id: this.internalId, role: 'region', "aria-labelledby": this.ariaState.labelledby, class: {
                'bal-list__item': true,
                'bal-list__item__accordion-body': true,
                'bal-list__item__accordion-body--grouped': this.accordionGroup !== undefined && this.accordionGroup !== '',
            } }, h("div", { key: 'fd39532522d0d477e222e8153eac0eeed546f4e8', class: {
                'bal-list__item__accordion-body__content': true,
                [`bal-list__item__accordion-body__content--${this.contentAlignment}`]: this.contentAlignment !== undefined,
                [`bal-list__item__accordion-body__content--space-${this.contentSpace}`]: this.contentSpace !== undefined,
            }, ref: contentElWrapper => (this.contentElWrapper = contentElWrapper) }, h("slot", { key: '067a8e5178c0396586d0491b0438ce190bd8aa85' }))));
    }
    get el() { return this; }
}, [260, "bal-list-item-accordion-body", {
        "accordionGroup": [1, "accordion-group"],
        "contentSpace": [1, "content-space"],
        "contentAlignment": [1, "content-alignment"],
        "ariaState": [32],
        "setAria": [64]
    }]);
__decorate([
    Logger('bal-list-item-accordion-body'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function]),
    __metadata("design:returntype", void 0)
], ListItemAccordionBody.prototype, "createLogger", null);
__decorate([
    ListenToResize(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ListItemAccordionBody.prototype, "resizeListener", null);
__decorate([
    ListenToBreakpoints(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], ListItemAccordionBody.prototype, "breakpointListener", null);
let ListItemAccordionBodyIds = 0;
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["bal-list-item-accordion-body"];
    components.forEach(tagName => { switch (tagName) {
        case "bal-list-item-accordion-body":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, ListItemAccordionBody);
            }
            break;
    } });
}

export { ListItemAccordionBody as L, defineCustomElement as d };
