'use strict';

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

const index = require('./index-7a477838.js');
const expandableFaqVariation_enum = require('./expandable-faq-variation.enum-af923f49.js');
const logger_util = require('./logger.util-fdafc086.js');

const expandableFaqCss = ".sc-digi-expandable-faq-h{display:block}";
const DigiExpandableFaqStyle0 = expandableFaqCss;

const ExpandableFaq = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.isExpanded = undefined;
        this.afHeading = undefined;
        this.afHeadingLevel = expandableFaqVariation_enum.ExpandableFaqHeadingLevel.H2;
        this.afVariation = expandableFaqVariation_enum.ExpandableFaqVariation.PRIMARY;
        this.listItems = [];
    }
    componentWillLoad() {
        this.getListItems();
        this.setFaqItemProps();
    }
    componentWillUpdate() {
        this.getListItems();
        this.setFaqItemProps();
    }
    getListItems() {
        const menuItems = this.hostElement.querySelectorAll('digi-expandable-faq-item');
        if (!menuItems || menuItems.length <= 0) {
            logger_util.logger.warn(`The slot contains no children elements.`, this.hostElement);
            return;
        }
        this.listItems = [...Array.from(menuItems)].map((faqItem) => {
            return {
                outerHTML: faqItem.outerHTML,
                ref: faqItem
            };
        });
    }
    setFaqItemProps() {
        this.listItems &&
            this.listItems.forEach((faqItem) => {
                faqItem.ref.afVariation = this.afVariation;
                try {
                    const topLevel = Number.parseInt(this.afHeadingLevel.split('h')[1]);
                    faqItem.ref.afHeadingLevel = 'h' + (topLevel + 1);
                }
                catch (e) {
                    // Nothing
                }
            });
    }
    render() {
        return (index.h("div", { key: 'd84ec6e500c1b68e97f3d603bed1ff7d3ffeefab', class: {
                'digi-expandable-faq': true
            } }, index.h(this.afHeadingLevel, { key: '1a71cdaa1d07a35e95a89d2bf4fd058a09971c7a' }, this.afHeading), index.h("slot", { key: '97c1cd09ad0d655fc6f10355c2370f3f880e901c' })));
    }
    get hostElement() { return index.getElement(this); }
};
ExpandableFaq.style = DigiExpandableFaqStyle0;

exports.digi_expandable_faq = ExpandableFaq;
