import { h, Host } from "@stencil/core";
import { state, onChange } from "./pn-sidenav-store";
export class PnSidenavLevel {
    constructor() {
        this.level = 1;
        this.levelId = '';
        this.isOpen = false;
        this.parentName = '';
        this.parentHref = '';
        this.parentLinkId = '';
        this.alignment = 'right';
    }
    hostElement;
    async componentWillLoad() {
        const parent = this.hostElement.parentElement;
        if (parent.tagName.toLowerCase() !== 'nav') {
            this.level = 2;
        }
        if (parent.tagName.toLowerCase() === 'pn-sidenav-link') {
            this.parentName = parent.getAttribute('name') + '';
            this.parentHref = parent.getAttribute('href') + '';
            this.parentLinkId = parent.getAttribute('linkid') + '';
            const parentLinkName = this.parentName.toLowerCase().replace(/\W/gi, '_');
            this.levelId = `sidenav-lvl${this.level}-${parentLinkName}`;
            if (parent.getAttribute('current') + '' === 'true') {
                state.openLevel = this.levelId;
                this.onChangeOpenLevel();
            }
        }
        onChange('openLevel', () => {
            this.onChangeOpenLevel();
        });
    }
    onOpen() { }
    onChangeOpenLevel() {
        this.isOpen = state.openLevel === this.levelId;
    }
    render() {
        const attributes = {
            'aria-hidden': this.level > 1 ? !this.isOpen + '' : null,
            'data-level': this.level + '',
            'id': this.levelId ?? '',
        };
        return (h(Host, { key: '49181ad9c3005878ceb520b87ac1721f86f9d220', ...attributes, "data-asdfasdf": this.isOpen }, h("slot", { key: '43331c462c778d7dfaf5830bb7d4acccb4b9d3e6' })));
    }
    static get is() { return "pn-sidenav-level"; }
    static get originalStyleUrls() {
        return {
            "$": ["pn-sidenav-level.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["pn-sidenav-level.css"]
        };
    }
    static get states() {
        return {
            "level": {},
            "levelId": {},
            "isOpen": {},
            "parentName": {},
            "parentHref": {},
            "parentLinkId": {},
            "alignment": {}
        };
    }
    static get elementRef() { return "hostElement"; }
    static get watchers() {
        return [{
                "propName": "isOpen",
                "methodName": "onOpen"
            }];
    }
}
//# sourceMappingURL=pn-sidenav-level.js.map
