import { Host, h } from "@stencil/core";
export class CpslTab {
    constructor() {
        this.onTabClicked = () => {
            this.cpslTabButtonClick.emit({ tab: this.tab, selected: this.selected });
        };
        this.selected = false;
        this.tab = undefined;
    }
    onTabsChanged(ev) {
        this.setSelected(ev);
    }
    onTabsInit(ev) {
        this.setSelected(ev);
    }
    componentDidLoad() {
        new MutationObserver(() => {
            this.cpslTabButtonSizeChange.emit({ tab: this.tab });
        }).observe(this.el, {
            attributes: true,
        });
    }
    setSelected(ev) {
        const dispatchedFrom = ev.target;
        const parent = this.el.parentElement;
        if (ev.composedPath().includes(parent) || (dispatchedFrom === null || dispatchedFrom === void 0 ? void 0 : dispatchedFrom.contains(this.el))) {
            this.selected = this.tab === ev.detail.tab;
        }
    }
    render() {
        return (h(Host, { key: '6c6963acfb80e2af39004e708f8ede2aae57cbcc', class: { selected: this.selected }, onClick: this.onTabClicked }, h("div", { key: '01aad54125bcfcf49a7c938ac3922e578d67782a', class: { 'tab-container': true } }, h("slot", { key: '67d3752abebd382320be214d48869694c697afc3', name: "start" }), h("div", { key: 'a4d0616a7a24c662c2cf326166706dfe67347589', class: "content" }, h("slot", { key: '0b5c88a340039d0a045a66ddb01c605930f70fd0' })), h("slot", { key: '46ede49409b834acc7743c3c334e7f87fa25486f', name: "end" }))));
    }
    static get is() { return "cpsl-tab"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["cpsl-tab.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["cpsl-tab.css"]
        };
    }
    static get properties() {
        return {
            "selected": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The selected tab component"
                },
                "attribute": "selected",
                "reflect": false,
                "defaultValue": "false"
            },
            "tab": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "A tab id must be provided for each `cpsl-tab`. It's used internally to reference\nthe selected tab or by the router to switch between them."
                },
                "attribute": "tab",
                "reflect": false
            }
        };
    }
    static get events() {
        return [{
                "method": "cpslTabButtonClick",
                "name": "cpslTabButtonClick",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "internal",
                            "text": undefined
                        }],
                    "text": "Emitted when tabs are clicked"
                },
                "complexType": {
                    "original": "TabClickEventDetail",
                    "resolved": "TabClickEventDetail",
                    "references": {
                        "TabClickEventDetail": {
                            "location": "import",
                            "path": "./tab-interface.js",
                            "id": "src/components/cpsl-tab/tab-interface.ts::TabClickEventDetail"
                        }
                    }
                }
            }, {
                "method": "cpslTabButtonSizeChange",
                "name": "cpslTabButtonSizeChange",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "internal",
                            "text": undefined
                        }],
                    "text": "Emitted when tab size changes"
                },
                "complexType": {
                    "original": "TabSizeChangeEventDetail",
                    "resolved": "TabSizeChangeEventDetail",
                    "references": {
                        "TabSizeChangeEventDetail": {
                            "location": "import",
                            "path": "./tab-interface.js",
                            "id": "src/components/cpsl-tab/tab-interface.ts::TabSizeChangeEventDetail"
                        }
                    }
                }
            }];
    }
    static get elementRef() { return "el"; }
    static get listeners() {
        return [{
                "name": "cpslTabsChanged",
                "method": "onTabsChanged",
                "target": "window",
                "capture": false,
                "passive": false
            }, {
                "name": "cpslTabsInit",
                "method": "onTabsInit",
                "target": "window",
                "capture": false,
                "passive": false
            }];
    }
}
//# sourceMappingURL=cpsl-tab.js.map
