import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { c as cls } from './helpers.js';
import { d as defineCustomElement$1 } from './component.js';

const styleCss = "x-collapse{display:block;position:relative;-webkit-transition:0.3s;transition:0.3s}.is-dark-mode x-collapse{color:var(--color-text-light, #FEFEFE)}x-collapse .collapse-header{position:relative;padding:0.5rem 0;line-height:1em;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}x-collapse .collapse-header:hover:after{-webkit-animation:0.75s fadeBreathe infinite;animation:0.75s fadeBreathe infinite}x-collapse .collapse-header h4{margin:0}x-collapse .collapse-header .collapse-action{position:absolute;top:calc(50% - 0.5rem);right:0.75rem}x-collapse .collapse-container{overflow:hidden;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;max-height:0;opacity:0;-webkit-transition:max-height 0.2s ease-out, opacity 0.2s;transition:max-height 0.2s ease-out, opacity 0.2s}x-collapse.collapse-expanded .collapse-container{opacity:1}";
const XCollapseStyle0 = styleCss;

const XCollapse = /*@__PURE__*/ proxyCustomElement(class XCollapse extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.header = undefined;
        this.show = false;
        this.expanded = false;
    }
    /**
     * Element toggle state
     */
    async toggle() {
        this.toggleCollapse();
    }
    /**
     * Watch expanded state changes
     */
    watchExpanded() {
        this.updateCollapse();
    }
    /**
     * On component will load action
     */
    componentWillLoad() {
        if (this.show) {
            this.expanded = true;
        }
    }
    /**
     * On component loaded action
     */
    componentDidLoad() {
        this.updateCollapse();
    }
    /**
     * Toggle the visibility of content
     */
    toggleCollapse() {
        this.expanded = !this.expanded;
    }
    /**
     * On update the colapse state
     */
    updateCollapse() {
        if (!this.container) {
            return;
        }
        this.expanded ?
            this.showCollapseContainer() :
            this.hideCollapseContainer();
    }
    /**
     * Hide the collapse container
     */
    hideCollapseContainer() {
        this.container.style.maxHeight = null;
        this.container.style.overflow = 'hidden';
    }
    /**
     * Show the collapse container
     */
    showCollapseContainer() {
        this.container.style.maxHeight = `${this.container.scrollHeight}px`;
        setTimeout(() => {
            this.container.style.overflow = 'initial';
        }, 200);
    }
    /**
     * On keyboard action triggers the collapse
     */
    onCollapseKeyDown(e) {
        if (e.key === ' ' || e.key === 'Enter') {
            e.preventDefault();
            this.toggleCollapse();
        }
    }
    /**
     * Render component
     */
    render() {
        var _a;
        return h(Host, { key: '19ed85314812bb8f7b1ab9ae498c4ad871969afe', class: cls({ 'collapse-expanded': this.expanded }) }, h("div", { key: '97da921d56604e13a04899d015d88efae06e9640', role: "switch", class: "collapse-header", tabIndex: 0, "aria-checked": this.expanded, onClick: () => this.toggleCollapse(), onKeyDown: (e) => this.onCollapseKeyDown(e) }, ((_a = this.header) === null || _a === void 0 ? void 0 : _a.length) ? h("h4", null, this.header) : h("slot", { name: "header" }), h("span", { key: 'f7a9656eda86cebadba55449332987910a1d810e', class: "collapse-action" }, h("x-icon", { key: '8e6c592bf22f6f6973f3f1fe5dca549e1db08c4f', name: this.expanded ? 'minus' : 'dropdown' }))), h("div", { key: '86302a74f164e24c118d7b51e42f5228448e24cb', class: "collapse-container", ref: el => this.container = el }, h("slot", { key: '47edb1b312d7c0a15d9c82f1b4cc61664b89bba9' })));
    }
    get el() { return this; }
    static get watchers() { return {
        "expanded": ["watchExpanded"]
    }; }
    static get style() { return XCollapseStyle0; }
}, [4, "x-collapse", {
        "header": [1],
        "show": [4],
        "expanded": [32],
        "toggle": [64]
    }, undefined, {
        "expanded": ["watchExpanded"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["x-collapse", "x-icon"];
    components.forEach(tagName => { switch (tagName) {
        case "x-collapse":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, XCollapse);
            }
            break;
        case "x-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { XCollapse as X, defineCustomElement as d };
