import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
const defaultState = {
    isMenuVisible: true,
    isPopupVisible: false,
    prevScrollPos: 0,
    childrenOverride: null,
};
const Context = React.createContext({
    isMenuVisible: true,
    isPopupVisible: false,
    childrenOverride: null,
    showMenu: () => {
        throw new Error("showMenu");
    },
    hideMenu: () => {
        throw new Error("hideMenu");
    },
    showPopup: () => {
        throw new Error("showPopup");
    },
    hidePopup: () => {
        throw new Error("hidePopup");
    },
    setChildrenOverride: () => {
        throw new Error("setChildrenOverride");
    },
    clearChildrenOverride: () => {
        throw new Error("clearChildrenOverride");
    },
});
export const useMenu = () => React.useContext(Context);
export const MenuConsumer = Context.Consumer;
export class MenuProvider extends React.Component {
    state = defaultState;
    listenScrollEvent = () => {
        const height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
        const currScrollPos = window.scrollY;
        const isMenuVisible = currScrollPos < this.state.prevScrollPos || window.scrollY < height;
        this.setState({ prevScrollPos: currScrollPos });
        this.setState({ isMenuVisible });
    };
    componentDidMount() {
        window.addEventListener("scroll", this.listenScrollEvent);
    }
    componentWillUnmount() {
        window.removeEventListener("scroll", this.listenScrollEvent);
    }
    showMenu = () => {
        this.setState({ isMenuVisible: true });
    };
    hideMenu = () => {
        this.setState({ isMenuVisible: false });
    };
    showPopup = () => {
        this.setState({ isPopupVisible: true });
    };
    hidePopup = () => {
        this.setState({ isPopupVisible: false });
    };
    setChildrenOverride = (childrenOverride) => {
        this.setState({ childrenOverride });
    };
    clearChildrenOverride = () => {
        this.setState({ childrenOverride: null });
    };
    render() {
        return (_jsx(Context.Provider, { value: {
                isMenuVisible: this.state.isMenuVisible,
                isPopupVisible: this.state.isPopupVisible,
                childrenOverride: this.state.childrenOverride,
                showMenu: this.showMenu,
                hideMenu: this.hideMenu,
                showPopup: this.showPopup,
                hidePopup: this.hidePopup,
                setChildrenOverride: this.setChildrenOverride,
                clearChildrenOverride: this.clearChildrenOverride,
            }, children: this.props.children }));
    }
}
//# sourceMappingURL=context.js.map