import { h, Host } from "@stencil/core";
import { SxStyleManager } from "../../utils/sx-style-manager";
export class NdsAccordion {
    constructor() {
        this.title = '';
        this.content = '';
        this.size = 'lg';
        this.iconAlignment = 'leading';
        this.flush = false;
        this.disabled = false;
        this.defaultExpanded = false;
        this.isOpen = false;
        this.bodyElement = null;
        // Generate a unique ID if not provided
        this.componentId = `dga-button-${Math.random().toString(36).substring(2, 9)}`;
        // Computed inline styles
        this.rootStyles = {};
    }
    handleAccordionClick(e) {
        e.preventDefault();
        if (this.disabled)
            return;
        this.isOpen ? this.collapseAccordion() : this.openAccordion();
    }
    openAccordion() {
        this.isOpen = true;
        if (this.bodyElement) {
            this.bodyElement.style.maxHeight = this.bodyElement.scrollHeight + 'px';
        }
    }
    collapseAccordion() {
        this.isOpen = false;
        if (this.bodyElement) {
            this.bodyElement.style.maxHeight = null;
        }
    }
    componentDidRender() {
        if (this.isOpen && this.bodyElement) {
            this.bodyElement.style.maxHeight = this.bodyElement.scrollHeight + 24 + 'px';
        }
        else if (this.bodyElement) {
            this.bodyElement.style.maxHeight = null;
        }
        if (this.defaultExpanded) {
            this.isOpen = this.defaultExpanded;
        }
    }
    handleSxChange() {
        this.processStyling();
    }
    componentWillLoad() {
        // Initialize style manager with element reference
        this.sxStyleManager = new SxStyleManager(this.componentId, this.el);
    }
    componentDidLoad() {
        // Process styling after the component is fully loaded and shadow DOM is ready
        this.processStyling();
    }
    componentDidUpdate() {
        // Re-process styling after updates
        this.processStyling();
    }
    processStyling() {
        if (!this.sx)
            return;
        // Handle both string and object formats
        const sxValue = typeof this.sx === 'string' ? JSON.parse(this.sx) : this.sx;
        this.rootStyles = this.sxStyleManager.processSxProp(sxValue);
    }
    disconnectedCallback() {
        var _a;
        // Clean up styles when component is removed
        (_a = this.sxStyleManager) === null || _a === void 0 ? void 0 : _a.cleanup();
    }
    render() {
        return (h(Host, { key: '0fc3e73d1d925b6b390d6fce955e3ff312e59ed0', id: this.componentId, style: this.rootStyles }, h("div", { key: '10cda7dfb7c288649c9ead450556eb30501a80c9', class: `dga-accordion-item dga-accordion-item--${this.size} 
          ${this.iconAlignment === 'leading' ? 'dga-accordion-item--icon-leading' : ''}
          ${this.flush ? 'dga-accordion-item--flush' : ''} 
          ${this.disabled ? 'disabled' : ''} ${this.isOpen ? 'active' : ''}` }, h("a", { key: '2618bc041a34422a1955984fca4a6ced24c8cb35', href: "#", onClick: e => this.handleAccordionClick(e), onKeyDown: e => (e.code === 'Space' ? this.handleAccordionClick(e) : null), class: "dga-accordion-item__header" }, this.iconAlignment === 'leading' && (h("div", { key: '5b4f821fc85c5979de1d25eaa03917e714bc9f17', class: "dga-accordion-item__arrow" }, h("dga-icon-v2", { key: 'b0eaa44fbb64e65602f90dc576cb4e81e6645bbe', name: "arrow-down-01", variant: "stroke", size: 16 }))), h("div", { key: 'ff5a633cfcf375bfd90df3441d75cfa594c128b2', class: "dga-accordion-item__title" }, h("slot", { key: '12553def2becd76b904588a3e7959ece96076577', name: 'title' }, this.title)), this.iconAlignment === 'trailing' && (h("div", { key: '6d8fa7bbbda3ccb6f4aa9f22f4438906e98253a0', class: "dga-accordion-item__arrow" }, h("dga-icon-v2", { key: '7f873b6bc2197be2dbd9ebd990ae6a0bf05ce0f0', name: "arrow-down-01", variant: "stroke", size: 16 })))), h("div", { key: 'ccecf69d4b1cfc7242457237818d226895294cfc', ref: el => (this.bodyElement = el), class: "dga-accordion-item__body" }, h("slot", { key: '85036d1c48e36e081fd087211fdfaafac5607ee6', name: 'content' }, this.content)))));
    }
    static get is() { return "nds-accordion"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["nds-accordion.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["nds-accordion.css"]
        };
    }
    static get properties() {
        return {
            "title": {
                "type": "string",
                "attribute": "title",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "content": {
                "type": "string",
                "attribute": "content",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "size": {
                "type": "string",
                "attribute": "size",
                "mutable": false,
                "complexType": {
                    "original": "'lg' | 'md' | 'sm'",
                    "resolved": "\"lg\" | \"md\" | \"sm\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'lg'"
            },
            "iconAlignment": {
                "type": "string",
                "attribute": "icon-alignment",
                "mutable": false,
                "complexType": {
                    "original": "'leading' | 'trailing'",
                    "resolved": "\"leading\" | \"trailing\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'leading'"
            },
            "flush": {
                "type": "boolean",
                "attribute": "flush",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "disabled": {
                "type": "boolean",
                "attribute": "disabled",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "defaultExpanded": {
                "type": "boolean",
                "attribute": "default-expanded",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "sx": {
                "type": "string",
                "attribute": "sx",
                "mutable": false,
                "complexType": {
                    "original": "SxProps | string",
                    "resolved": "CSSProperties & NestedSelector | string",
                    "references": {
                        "SxProps": {
                            "location": "import",
                            "path": "../../utils/sx-system",
                            "id": "src/utils/sx-system.ts::SxProps"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "isOpen": {}
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "sx",
                "methodName": "handleSxChange"
            }];
    }
}
