import { __decorate, __metadata } from "tslib";
import { Host, h } from "@stencil/core";
import { BEM } from "../../../utils/bem";
import { balBrowser } from "../../../utils/browser";
import { Logger } from "../../../utils/log";
export class NavMetaBar {
    constructor() {
        this.navMetaBarId = `bal-nav-meta-bar-${NavMetaBarIds++}`;
        this.previousY = 0;
        this.isHidden = false;
        /**
         * PUBLIC PROPERTY API
         * ------------------------------------------------------
         */
        /**
         * Defines if the bar should stay on top of the backdrop
         */
        this.stayOnTopOfBackdrop = false;
        /**
         * Defines the color variant
         */
        this.variant = 'primary';
        /**
         * Defines the height of the bar
         */
        this.size = 'normal';
        /**
         * Tells when to hide the bar
         */
        this.invisible = 'none';
        /**
         * Defines the position of the bar
         */
        this.position = 'none';
    }
    createLogger(log) {
        this.log = log;
    }
    /**
     * LISTENERS
     * ------------------------------------------------------
     */
    handleScroll() {
        if (balBrowser.hasWindow && balBrowser.hasDocument && this.position === 'sticky-top') {
            const maxScrollHeight = document.body.scrollHeight - document.body.clientHeight;
            const isOnTop = 0 >= window.scrollY;
            const isOverViewportTop = 0 > window.scrollY;
            const isOverViewportBottom = maxScrollHeight <= window.scrollY;
            const didMoveDownwards = window.scrollY > this.previousY;
            this.isHidden = !isOnTop && (didMoveDownwards || isOverViewportBottom || isOverViewportTop);
            this.previousY = window.scrollY;
            const transformElements = Array.from(document.querySelectorAll('.bal-nav-meta-bar-transform'));
            if (transformElements.length > 0) {
                for (let index = 0; index < transformElements.length; index++) {
                    const transformElement = transformElements[index];
                    if (this.isHidden) {
                        if (this.size === 'small') {
                            transformElement.classList.remove(`bal-nav-meta-bar-transform-normal`);
                            transformElement.classList.add(`bal-nav-meta-bar-transform-small`);
                        }
                        else {
                            transformElement.classList.remove(`bal-nav-meta-bar-transform-small`);
                            transformElement.classList.add(`bal-nav-meta-bar-transform-normal`);
                        }
                    }
                    else {
                        transformElement.classList.remove(`bal-nav-meta-bar-transform-small`);
                        transformElement.classList.remove(`bal-nav-meta-bar-transform-normal`);
                    }
                }
            }
        }
    }
    /**
     * RENDER
     * ------------------------------------------------------
     */
    render() {
        const block = BEM.block('nav-meta-bar');
        return (h(Host, { key: '9d2cee16f0b6f542d42085aca4e263d727707849', id: this.navMetaBarId, class: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, block.class()), block.modifier(`variant-${this.variant}`).class()), block.modifier(`size-${this.size}`).class()), block.modifier(`position-${this.position}`).class(this.position !== 'none')), block.modifier(`hidden-mobile`).class(this.invisible === 'mobile')), block.modifier(`hidden-tablet`).class(this.invisible === 'tablet')), block.modifier(`stay-on-top`).class(this.stayOnTopOfBackdrop)) }, h("div", { key: '6b581e5abc62a58085a57cdf74346290130fe807', class: Object.assign({}, block.element('container').class()) }, h("slot", { key: '75bdbcc78e502814264e1548697a987df10af720' }))));
    }
    static get is() { return "bal-nav-meta-bar"; }
    static get originalStyleUrls() {
        return {
            "$": ["bal-nav-meta-bar.sass"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bal-nav-meta-bar.css"]
        };
    }
    static get properties() {
        return {
            "stayOnTopOfBackdrop": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Defines if the bar should stay on top of the backdrop"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "stay-on-top-of-backdrop",
                "defaultValue": "false"
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalNavMetaBarVariant",
                    "resolved": "\"grey\" | \"primary\" | \"white\"",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Defines the color variant"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "variant",
                "defaultValue": "'primary'"
            },
            "size": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalNavMetaBarSize",
                    "resolved": "\"normal\" | \"small\"",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Defines the height of the bar"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "size",
                "defaultValue": "'normal'"
            },
            "invisible": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalNavMetaBarInvisible",
                    "resolved": "\"mobile\" | \"none\" | \"tablet\"",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Tells when to hide the bar"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "invisible",
                "defaultValue": "'none'"
            },
            "position": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalNavMetaBarPosition",
                    "resolved": "\"fixed-bottom\" | \"fixed-top\" | \"none\" | \"sticky-top\"",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Defines the position of the bar"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "position",
                "defaultValue": "'none'"
            }
        };
    }
    static get states() {
        return {
            "isHidden": {}
        };
    }
    static get elementRef() { return "el"; }
    static get listeners() {
        return [{
                "name": "scroll",
                "method": "handleScroll",
                "target": "window",
                "capture": false,
                "passive": true
            }];
    }
}
__decorate([
    Logger('bal-meta-bar'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function]),
    __metadata("design:returntype", void 0)
], NavMetaBar.prototype, "createLogger", null);
let NavMetaBarIds = 0;
