import { h } from "@stencil/core";
import { ExpandableFaqHeadingLevel } from "./expandable-faq-heading-level.enum";
import { ExpandableFaqVariation } from "./expandable-faq-variation.enum";
import { logger } from "../../../global/utils/logger";
/**
 * @enums ExpandableFaqHeadingLevel- expandable-faq-heading-level.enum.ts
 * @enums ExpandableFaqVariation - expandable-faq-variation.enum.ts
 * @swedishName FAQ
 */
export class ExpandableFaq {
    constructor() {
        this.isExpanded = undefined;
        this.afHeading = undefined;
        this.afHeadingLevel = ExpandableFaqHeadingLevel.H2;
        this.afVariation = 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.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 (h("div", { key: 'fde7684ab703ddbe07b156035ba37050ed3dda1b', class: {
                'digi-expandable-faq': true
            } }, h(this.afHeadingLevel, { key: 'f2e2dfac429cdfed99c9f71071770918cf38df70' }, this.afHeading), h("slot", { key: 'a9289be94c96e969748c8bc76a701efb2e2b56d7' })));
    }
    static get is() { return "digi-expandable-faq"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "$": ["expandable-faq.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["expandable-faq.css"]
        };
    }
    static get properties() {
        return {
            "afHeading": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "The heading of FAQ text"
                        }],
                    "text": "Rubrikens vanliga fr\u00E5gor"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-heading",
                "reflect": false
            },
            "afHeadingLevel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "ExpandableFaqHeadingLevel",
                    "resolved": "ExpandableFaqHeadingLevel.H1 | ExpandableFaqHeadingLevel.H2 | ExpandableFaqHeadingLevel.H3 | ExpandableFaqHeadingLevel.H4 | ExpandableFaqHeadingLevel.H5 | ExpandableFaqHeadingLevel.H6",
                    "references": {
                        "ExpandableFaqHeadingLevel": {
                            "location": "import",
                            "path": "./expandable-faq-heading-level.enum",
                            "id": "src/components/_expandable/expandable-faq/expandable-faq-heading-level.enum.ts::ExpandableFaqHeadingLevel"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set heading level. Default is 'h2'"
                        }],
                    "text": "S\u00E4tter rubrikniv\u00E5. 'h2' \u00E4r f\u00F6rvalt."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-heading-level",
                "reflect": false,
                "defaultValue": "ExpandableFaqHeadingLevel.H2"
            },
            "afVariation": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "ExpandableFaqVariation",
                    "resolved": "ExpandableFaqVariation.PRIMARY | ExpandableFaqVariation.SECONDARY | ExpandableFaqVariation.TERTIARY",
                    "references": {
                        "ExpandableFaqVariation": {
                            "location": "import",
                            "path": "./expandable-faq-variation.enum",
                            "id": "src/components/_expandable/expandable-faq/expandable-faq-variation.enum.ts::ExpandableFaqVariation"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set variation. Can be 'Primary' or 'Secondary'"
                        }],
                    "text": "S\u00E4tter variant. Kan vara 'Primary' eller 'Secondary'"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-variation",
                "reflect": false,
                "defaultValue": "ExpandableFaqVariation.PRIMARY"
            }
        };
    }
    static get states() {
        return {
            "isExpanded": {},
            "listItems": {}
        };
    }
    static get elementRef() { return "hostElement"; }
}
