import { r as registerInstance, h, H as Host, g as getElement } from './index-aed5ae27.js';
import { c as cls } from './helpers-ea9d01ce.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;-webkit-transition:0.3s;transition:0.3s;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 = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        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: '7f82133dbd9c70004069c1f6e503ee4d6a788f19', class: cls({ 'collapse-expanded': this.expanded }) }, h("div", { key: '1ceb013efd40159150183b40893504a264f17bf2', 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: '32242dc53d6781dd69aff01377cc41304c784100', class: "collapse-action" }, h("x-icon", { key: 'ffd81c8f6ce3bf39a0ca1e5906bbe5b0894e6d0b', name: this.expanded ? 'minus' : 'dropdown' }))), h("div", { key: '9ac6e4dbaef9f2b84bbeaaa5fc237757dcdc9d77', class: "collapse-container" }, h("slot", { key: '7e1f59ac30e5bfb50c335f5bdf1fff5bf94b3db4' })));
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "expanded": ["onExpandedChange"]
    }; }
};
XCollapse.style = XCollapseStyle0;

export { XCollapse as x_collapse };
