'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: 'fde7684ab703ddbe07b156035ba37050ed3dda1b', class: {
                'digi-expandable-faq': true
            } }, index.h(this.afHeadingLevel, { key: 'f2e2dfac429cdfed99c9f71071770918cf38df70' }, this.afHeading), index.h("slot", { key: 'a9289be94c96e969748c8bc76a701efb2e2b56d7' })));
    }
    get hostElement() { return index.getElement(this); }
};
ExpandableFaq.style = DigiExpandableFaqStyle0;

exports.digi_expandable_faq = ExpandableFaq;
