import { h } from "@stencil/core";
import { ExpandableFaqItemHeadingLevel } from "./expandable-faq-item-heading-level.enum";
import { ExpandableFaqItemVariation } from "./expandable-faq-item-variation.enum";
import { randomIdGenerator } from "../../../global/utils/randomIdGenerator";
/**
 * @enums ExpandableFaqItemHeadingLevel - expandable-faq-item-heading-level.enum.ts
 * @enums ExpandableFaqItemVariation - expandable-faq-item-variation.enum.ts
 * @swedishName FAQ - Enskild fråga
 */
export class ExpandableFaqItem {
    constructor() {
        this.afHeading = undefined;
        this.afHeadingLevel = ExpandableFaqItemHeadingLevel.H3;
        this.afFullWidth = false;
        this.afExpanded = false;
        this.afVariation = ExpandableFaqItemVariation.PRIMARY;
        this.afAnimation = true;
        this.afId = randomIdGenerator('digi-expandable-faq-item');
    }
    get cssModifiers() {
        return {
            'digi-expandable-faq-item--expanded': this.afExpanded,
            'digi-expandable-faq-item--fullwidth': this.afFullWidth,
            'digi-expandable-faq-item--primary': this.afVariation === ExpandableFaqItemVariation.PRIMARY,
            'digi-expandable-faq-item--secondary': this.afVariation === ExpandableFaqItemVariation.SECONDARY,
            'digi-expandable-faq-item--tertiary': this.afVariation === ExpandableFaqItemVariation.TERTIARY
        };
    }
    /**
     * Hämtar en höjden till innehållet i vanliga frågor och svar och animera innehållet.
     * @en Gets a height to the content for FAQ and animate the content.
     */
    componentDidLoad() {
        const content = this.hostElement.children[0].querySelector(`#${this.afId}-content`);
        if (!this.afExpanded) {
            content.setAttribute('style', 'visibility: hidden;');
        }
        else {
            content.setAttribute('style', 'height: auto;');
        }
        content.addEventListener('transitionend', () => {
            if (!this.afExpanded) {
                content.setAttribute('style', 'visibility: hidden;  height: ' + 0 + 'px');
            }
            else
                content.setAttribute('style', 'height: auto');
        });
    }
    animateContentHeight() {
        const content = this.hostElement.children[0].querySelector(`#${this.afId}-content`);
        const sectionHeight = content.firstElementChild
            .offsetHeight;
        if (!this.afExpanded && content.style.height === 'auto') {
            content.setAttribute('style', 'height: ' + sectionHeight + 'px');
            setTimeout(() => {
                content.setAttribute('style', 'height: 0');
            });
            return;
        }
        if (this.afExpanded) {
            content.setAttribute('style', 'visibility: visible; height:' + sectionHeight + 'px');
            if (!this.afAnimation) {
                setTimeout(() => {
                    content.setAttribute('style', 'height: auto');
                });
            }
        }
        else {
            content.setAttribute('style', 'height: ' + 0 + 'px');
        }
    }
    render() {
        return (h("article", { key: '7b2b0373f7f84167b89b012528e7be9ee7f70615', "aria-expanded": this.afExpanded ? 'true' : 'false', class: Object.assign({ 'digi-expandable-faq-item': true }, this.cssModifiers) }, h("header", { key: '1696540ad262246538d0c06e8c4f509d89e001fe', class: "digi-expandable-faq-item__header" }, h(this.afHeadingLevel, { key: 'e83eadc3b36841d2fcd446f47cae5b0bf6c88c0c' }, h("button", { key: 'dd702a1089e2bc936b16af5e58ca01836da1fb13', type: "button", class: "digi-expandable-faq-item__button", onClick: (e) => {
                e.preventDefault();
                this.afExpanded = !this.afExpanded;
                this.afOnClick.emit(e);
            }, "aria-expanded": this.afExpanded ? 'true' : 'false', "aria-controls": `${this.afId}-content` }, h("digi-icon-chevron-down", { key: '51cb95de4071557f33e5d8bc4183cdcae0322dd5', class: {
                'digi-expandable-faq-item__header--toggle-icon': true,
                'digi-expandable-faq-item__header--toggle-icon--expanded': this.afExpanded
            } }), h("div", { key: '0e275884fd0cf1033f2c0c3c576ba1951c6ae428', class: "digi-expandable-faq-item__header-text" }, this.afHeading)))), h("section", { key: 'a3f2864b8da871187757844f4e36da0e83d87e77', class: {
                'digi-expandable-faq-item__content': true,
                'digi-expandable-faq-item__content--animation': this.afAnimation,
                'digi-expandable-faq-item__content--hidden': !this.afExpanded
            }, id: `${this.afId}-content` }, h("div", { key: 'cf0a26beec405ea2ce63de5109531519059cf1cb' }, h("digi-typography", { key: 'f3de9345310bf8336e791c252554e26f80d337f5' }, h("slot", { key: '930caf3476eb17a28d6d220dfd5b4086d73aa988' }))))));
    }
    static get is() { return "digi-expandable-faq-item"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "$": ["expandable-faq-item.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["expandable-faq-item.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": "ExpandableFaqItemHeadingLevel",
                    "resolved": "ExpandableFaqItemHeadingLevel.H1 | ExpandableFaqItemHeadingLevel.H2 | ExpandableFaqItemHeadingLevel.H3 | ExpandableFaqItemHeadingLevel.H4 | ExpandableFaqItemHeadingLevel.H5 | ExpandableFaqItemHeadingLevel.H6",
                    "references": {
                        "ExpandableFaqItemHeadingLevel": {
                            "location": "import",
                            "path": "./expandable-faq-item-heading-level.enum",
                            "id": "src/components/_expandable/expandable-faq-item/expandable-faq-item-heading-level.enum.ts::ExpandableFaqItemHeadingLevel"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set heading level. Default is 'h3'"
                        }],
                    "text": "S\u00E4tter rubrikniv\u00E5. 'h3' \u00E4r f\u00F6rvalt."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-heading-level",
                "reflect": false,
                "defaultValue": "ExpandableFaqItemHeadingLevel.H3"
            },
            "afFullWidth": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Makes the component take up 100% of the width of the surface it is in."
                        }],
                    "text": "G\u00F6r s\u00E5 att komponenten tar upp 100% i bredd av ytan den befinner sig i."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-full-width",
                "reflect": false,
                "defaultValue": "false"
            },
            "afExpanded": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Sets the state of the FAQ item to expanded or not."
                        }],
                    "text": "S\u00E4tter l\u00E4ge p\u00E5 FAQ-fr\u00E5gan om den ska vara expanderad eller ej."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-expanded",
                "reflect": false,
                "defaultValue": "false"
            },
            "afVariation": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "ExpandableFaqItemVariation",
                    "resolved": "ExpandableFaqItemVariation.PRIMARY | ExpandableFaqItemVariation.SECONDARY | ExpandableFaqItemVariation.TERTIARY",
                    "references": {
                        "ExpandableFaqItemVariation": {
                            "location": "import",
                            "path": "./expandable-faq-item-variation.enum",
                            "id": "src/components/_expandable/expandable-faq-item/expandable-faq-item-variation.enum.ts::ExpandableFaqItemVariation"
                        }
                    }
                },
                "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": "ExpandableFaqItemVariation.PRIMARY"
            },
            "afAnimation": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Sets the state of the animation for the accordion's expanded area. Animation is on as default."
                        }],
                    "text": "St\u00E4ller in ifall komponenten ska ha en animation vid utf\u00E4llning. Animation \u00E4r p\u00E5slagen som standard."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-animation",
                "reflect": false,
                "defaultValue": "true"
            },
            "afId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set id attribute. Defaults to random string."
                        }],
                    "text": "S\u00E4tter attributet 'id'. Om inget v\u00E4ljs s\u00E5 skapas ett slumpm\u00E4ssigt id."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-id",
                "reflect": false,
                "defaultValue": "randomIdGenerator('digi-expandable-faq-item')"
            }
        };
    }
    static get events() {
        return [{
                "method": "afOnClick",
                "name": "afOnClick",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "The button element's 'onclick' event."
                        }],
                    "text": "Buttonelementets 'onclick'-event."
                },
                "complexType": {
                    "original": "MouseEvent",
                    "resolved": "MouseEvent",
                    "references": {
                        "MouseEvent": {
                            "location": "global",
                            "id": "global::MouseEvent"
                        }
                    }
                }
            }];
    }
    static get elementRef() { return "hostElement"; }
    static get watchers() {
        return [{
                "propName": "afExpanded",
                "methodName": "animateContentHeight"
            }];
    }
}
