import { r as registerInstance, h, H as Host, g as getElement } from './index-ClISz4NF.js';
import { p as pick } from './utils-CQvUntGY.js';
import { S as Sizes } from './sizes-BcQO4NH2.js';
import { g as govHost, b as booleanString } from './template-CoD1xawt.js';
import { v as validateProp } from './props-CJZgTDla.js';
import { A as AttributeObserver, a as ariaAttributes } from './attribute-Bz_RzYFb.js';
import { c as createID } from './string.utils-vN03FcXN.js';
import { i as inheritAriaAttributes } from './accessibility-wqNV8djF.js';
import './gov.log-BtqD9K8d.js';

const CollapsibleSizes = pick(Sizes, ['_XS', '_S', '_M', '_L', '_XL']);
var CollapsibleDirection;
(function (CollapsibleDirection) {
    CollapsibleDirection["DOWN"] = "down";
    CollapsibleDirection["UP"] = "up";
})(CollapsibleDirection || (CollapsibleDirection = {}));
const CollapsibleClass = {
    root: 'gov-collapsible',
    content: 'gov-collapsible__content',
    disabled: 'gov-collapsible--disabled',
};

const GovCollapsible = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.hydrated = false;
        /**
         * Element size.
         */
        this.size = 'm';
        /**
         * Makes component disabled.
         */
        this.disabled = false;
        /**
         * Defines whether the collapsible is open or closed
         */
        this.open = false;
        this.inheritedAttributes = {};
        this.h = govHost(this.host);
        this.triggerId = createID("GovCollapsibleControl");
        this.contentId = createID("GovCollapsibleContent");
    }
    validateSize(newValue) {
        validateProp(CollapsibleSizes, newValue, CollapsibleClass.root);
    }
    componentDidLoad() {
        this.attributeObserver = new AttributeObserver(this.host, (attributeName, newValue) => {
            this.onAriaAttributeChange(attributeName, newValue);
        });
        this.attributeObserver.startObserving(ariaAttributes);
    }
    componentWillLoad() {
        this.validateSize(this.size);
        this.inheritedAttributes = inheritAriaAttributes(this.host);
    }
    onAriaAttributeChange(attributeName, newValue) {
        this.host.removeAttribute(attributeName);
        this.inheritedAttributes = Object.assign(Object.assign({}, this.inheritedAttributes), { [attributeName]: newValue });
    }
    disconnectedCallback() {
        var _a;
        (_a = this.attributeObserver) === null || _a === void 0 ? void 0 : _a.stopObserving();
    }
    connectedCallback() {
        this.hydrated = true;
    }
    render() {
        return (h(Host, { key: '3c9284a4fdbf445f402693b15c5269c8e5b98372', hydrated: this.hydrated, class: this.h.classes([CollapsibleClass.root, this.disabled && CollapsibleClass.disabled]), size: this.size }, h("gov-button", Object.assign({ key: 'db793476b0b8ed5ecc44dd2191b3cf26c0a97e86', color: 'primary', size: this.size, type: 'link', disabled: this.disabled, "onGov-click": (e) => {
                e.stopPropagation();
                e.preventDefault();
                this.open = !this.open;
            } }, this.inheritedAttributes, { identifier: this.triggerId, "aria-controls": this.contentId, "aria-expanded": booleanString(this.open), "aria-haspopup": "true" }), this.label, h("gov-icon", { key: 'c230a7d2553c0858ddf24c6f9c7afbc249cd7f8e', slot: 'icon-end', name: this.open ? 'chevron-up' : 'chevron-down', type: "components" })), h("div", { key: '64e787e14f8773dae11f0e54658984f3622b8b47', class: CollapsibleClass.content, hidden: !this.open, id: this.contentId, "aria-labelledby": this.triggerId, "aria-hidden": booleanString(!this.open) }, h("slot", { key: '1e09e5a7242946af30012b68beb38119865003ec' }))));
    }
    get host() { return getElement(this); }
    static get watchers() { return {
        "size": ["validateSize"]
    }; }
};

export { GovCollapsible as gov_collapsible };
//# sourceMappingURL=gov-collapsible.entry.js.map

//# sourceMappingURL=gov-collapsible.entry.js.map