import { r as registerInstance, h, H as Host, g as getElement, c as createEvent } from './core-15e24a78.js';

const Accordion = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.animating = false;
    }
    async componentWillLoad() {
        return this.toggle(this.expanded);
    }
    disconnectedCallback() {
        window.clearTimeout(this.timer);
    }
    async toggle(event) {
        if (this.animating)
            return;
        const toggle = event instanceof CustomEvent ? event.target : this.getToggle();
        toggle.expanded = event instanceof CustomEvent ? !this.expanded : event;
        return this.slide(toggle.expanded);
    }
    async slide(expanding) {
        const wrapper = this.getWrapper();
        if (!wrapper)
            return;
        this.animating = true;
        if (!expanding) {
            wrapper.style.height = this.getContentHeight();
        }
        return new Promise((resolve) => {
            window.setTimeout(() => {
                wrapper.style.height = expanding ? this.getContentHeight() : '0';
                this.timer = window.setTimeout(() => {
                    this.expanded = expanding;
                    this.animating = false;
                    wrapper.style.height = null;
                    resolve();
                }, 500);
            }, 50);
        });
    }
    getToggle() {
        return this.element.querySelector('anj-accordion-toggle');
    }
    getWrapper() {
        return this.element.querySelector('.anj-accordion-wrapper');
    }
    getContentHeight() {
        return `${this.element.querySelector('.anj-accordion-content').offsetHeight}px`;
    }
    render() {
        return (h(Host, { class: { 'anj-animate': this.animating } }, h("div", { class: "anj-accordion-header" }, h("slot", { name: "header" })), h("div", { class: "anj-accordion-wrapper" }, h("div", { class: "anj-accordion-content" }, h("slot", null)))));
    }
    get element() { return getElement(this); }
    static get style() { return ".sc-anj-accordion-h{display:block;font-size:.875rem;font-family:var(--anj-font-family);font-weight:400;line-height:1.5;outline:none;-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,.14),0 2px 1px -1px rgba(0,0,0,.12),0 1px 3px 0 rgba(0,0,0,.2);box-shadow:0 1px 1px 0 rgba(0,0,0,.14),0 2px 1px -1px rgba(0,0,0,.12),0 1px 3px 0 rgba(0,0,0,.2);border-radius:.25rem;background-clip:border-box;background-color:var(--anj-light)}.sc-anj-accordion-h, .sc-anj-accordion-h:after, .sc-anj-accordion-h:before{-webkit-box-sizing:border-box;box-sizing:border-box;outline:none}.sc-anj-accordion-h:active, .sc-anj-accordion-h .sc-anj-accordion:active, .sc-anj-accordion-h:focus, .sc-anj-accordion-h .sc-anj-accordion:focus{outline:none}.anj-animate.sc-anj-accordion-h .anj-accordion-header.sc-anj-accordion, [expanded].sc-anj-accordion-h .anj-accordion-header.sc-anj-accordion{border-bottom:1px solid var(--anj-border)}.anj-animate.sc-anj-accordion-h .anj-accordion-wrapper.sc-anj-accordion, [expanded].sc-anj-accordion-h .anj-accordion-wrapper.sc-anj-accordion{display:block}[expanded].sc-anj-accordion-h .anj-accordion-wrapper.sc-anj-accordion{height:auto}.anj-animate.sc-anj-accordion-h{overflow:hidden}.anj-accordion-header.sc-anj-accordion{border-radius:.25rem .25rem 0 0;margin-bottom:0;padding:.75rem 1.25rem}.anj-accordion-wrapper.sc-anj-accordion{display:none;height:0;-webkit-transition:height .5s ease;transition:height .5s ease}"; }
};

const AccordionBody = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
    }
    static get style() { return "anj-accordion-body{display:block;padding:1.25rem}"; }
};

const AccordionFooter = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
    }
    static get style() { return "anj-accordion-footer{border-radius:0 0 .25rem .25rem;background-color:var(--anj-light);border-top:1px solid var(--anj-border);display:block;padding:.75rem 1.25rem}"; }
};

const AccordionToggle = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.anjAccordionToggle = createEvent(this, "anjAccordionToggle", 7);
    }
    render() {
        const label = this.expanded ? `Expand` : `Collapse`;
        const path = this.expanded
            ? 'M7.41 18.59L8.83 20 12 16.83 15.17 20l1.41-1.41L12 14l-4.59 4.59zm9.18-13.18L15.17 4 12 7.17 8.83 4 7.41 5.41 12 10l4.59-4.59z'
            : 'M12 5.83L15.17 9l1.41-1.41L12 3 7.41 7.59 8.83 9 12 5.83zm0 12.34L8.83 15l-1.41 1.41L12 21l4.59-4.59L15.17 15 12 18.17z';
        return (h("anj-button", { ariaLabel: label, disabled: this.disabled, context: "icon", onClick: () => this.anjAccordionToggle.emit() }, h("svg", { slot: "icon-only", width: "24", height: "24", viewBox: "0 0 24 24" }, h("path", { d: path }))));
    }
};

export { Accordion as anj_accordion, AccordionBody as anj_accordion_body, AccordionFooter as anj_accordion_footer, AccordionToggle as anj_accordion_toggle };
