import { jsx as _jsx } from "react/jsx-runtime";
import { useContext, useEffect, useRef } from "react";
import { Slot } from "@radix-ui/react-slot";
import { LayoutContext } from "./layoutContext";
import { useTradingPageContext } from "../page/trading/context/tradingPageContext";
import { TradingFeatures } from "..";
export const Header = (props)=>{
    const ref = useRef(null);
    const { asChild, ...rest } = props;
    const { setHeaderHeight, isTopLevel } = useContext(LayoutContext);
    const { disableFeatures } = useTradingPageContext();
    if (!isTopLevel) {
        throw new Error("Header component must be in top layout component.");
    }
    useEffect(()=>{
        setTimeout(()=>{
            const boundingClientRect = ref.current?.getBoundingClientRect();
            if (boundingClientRect && boundingClientRect.height) {
                // console.log(boundingClientRect);
                setHeaderHeight(boundingClientRect.height);
            }
        }, 50);
    }, []);
    /**
   * if disableFeatures includes TradingFeatures.Header, then return null
   */ if (disableFeatures?.includes(TradingFeatures.Header)) {
        return null;
    }
    const Comp = asChild ? Slot : "div";
    return /*#__PURE__*/ _jsx(Comp, {
        ...rest,
        ref: ref
    });
};
Header.displayName = "Header";

//# sourceMappingURL=header.js.map