import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useMemo, useState, useCallback } from "react";
const KEY = "MARIN_MODULE_PLACE";
export const LayoutContext = /*#__PURE__*/ createContext({});
export const LayoutProvider = (props)=>{
    const context = useContext(LayoutContext);
    const [position, setPosition] = useState(()=>{
        const oldPlace = localStorage.getItem(KEY);
        if (!oldPlace) {
            return "top";
        }
        if (![
            "top",
            "bottom"
        ].includes(oldPlace)) {
            localStorage.setItem(KEY, "top");
            return "top";
        }
        return oldPlace;
    });
    const isTopLevel = useMemo(()=>!context.isTopLevel, []);
    const [siderWidth, setSiderWidth] = useState(0);
    const [headerHeight, setHeaderHeight] = useState(0);
    const [footerHeight, setFooterHeight] = useState(0);
    const [pageHeaderHeight, setPageHeaderHeight] = useState(0);
    const [pageFooterHeight, setPageFooterHeight] = useState(0);
    const changePosition = useCallback((newPosition)=>{
        localStorage.setItem(KEY, newPosition);
        setPosition(newPosition);
    }, [
        setPosition
    ]);
    return /*#__PURE__*/ _jsx(LayoutContext.Provider, {
        value: {
            siderWidth,
            headerHeight: isTopLevel ? headerHeight : context.headerHeight,
            footerHeight: isTopLevel ? footerHeight : context.footerHeight,
            setSiderWidth,
            setHeaderHeight,
            setFooterHeight,
            pageHeaderHeight,
            pageFooterHeight,
            setPageHeaderHeight,
            setPageFooterHeight,
            isTopLevel,
            marginModulePosition: position,
            setMarginModulePosition: changePosition
        },
        children: props.children
    });
};

//# sourceMappingURL=layoutContext.js.map