import { Host, h } from "@stencil/core";
import { cls } from "../../utils/helpers";
export class XCollapse {
    constructor() {
        this.header = undefined;
        this.show = false;
        this.expanded = false;
    }
    /**
     * Element toggle state
     */
    async toggle() {
        this.toggleCollapse();
    }
    /**
     * Watch expanded state changes
     */
    onExpandedChange() {
        this.updateCollapse();
    }
    /**
     * On component loaded action
     */
    componentDidLoad() {
        this.container = this.el.querySelector('.collapse-container');
        if (this.show) {
            this.expanded = true;
        }
    }
    /**
     * Toggle the visibility of content
     */
    toggleCollapse() {
        this.expanded = !this.expanded;
    }
    updateCollapse() {
        const container = this.el.querySelector('.collapse-container');
        if (container.style.maxHeight) {
            this.hideCollapseContainer();
        }
        else {
            this.showCollapseContainer();
        }
    }
    hideCollapseContainer() {
        this.container.style.maxHeight = null;
        this.container.style.overflow = 'hidden';
    }
    showCollapseContainer() {
        this.container.style.maxHeight = `${this.container.scrollHeight}px`;
        setTimeout(() => {
            this.container.style.overflow = 'auto';
        }, 200);
    }
    /**
     * Render component
     */
    render() {
        var _a;
        return h(Host, { key: '9ed3bd4c972558ad23875a1ccf3fd6491e683006', class: cls({ 'collapse-expanded': this.expanded }) }, h("div", { key: '0b5781b9394ca980fe37d5d60fa7ef4d69cc3d91', class: "collapse-header", onClick: () => this.toggleCollapse() }, ((_a = this.header) === null || _a === void 0 ? void 0 : _a.length) ? h("h4", null, this.header) : h("slot", { name: "header" }), h("span", { key: 'f331b0fb71b476c7dd1a196577c9b6d930245719', class: "collapse-action" }, h("x-icon", { key: '263e701340a1149f3b0c85bd440a5071281596b8', name: this.expanded ? 'minus' : 'dropdown' }))), h("div", { key: '33cac6ebf7f23451d7e9ef24622f387023568325', class: "collapse-container" }, h("slot", { key: 'ba3dfe9f1a5237ffb93d5bc6596d4c5d5ca26406' })));
    }
    static get is() { return "x-collapse"; }
    static get originalStyleUrls() {
        return {
            "$": ["./style.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["style.css"]
        };
    }
    static get properties() {
        return {
            "header": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Element title header text"
                },
                "attribute": "header",
                "reflect": false
            },
            "show": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Element show content"
                },
                "attribute": "show",
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
    static get states() {
        return {
            "expanded": {}
        };
    }
    static get methods() {
        return {
            "toggle": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Element toggle state",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "expanded",
                "methodName": "onExpandedChange"
            }];
    }
}
