import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2007-2026 GoodData Corporation
import { useMemo } from "react";
import cx from "classnames";
import { useScreenSize } from "../../dashboard/components/DashboardScreenSizeContext.js";
import { GridLayoutElement } from "./GridLayoutElement.js";
const isHiddenStyle = { height: 0, width: 0, overflow: "hidden", flex: 0 };
export function DashboardLayoutItemViewRenderer({ item, children, className, minHeight = 0, isHidden, }) {
    const screen = useScreenSize();
    const { ratio, height } = getSizeForItem(item, screen);
    const style = useMemo(() => {
        let computedStyle = {};
        // Only set minHeight if not zero
        if (minHeight && minHeight > 0) {
            computedStyle.minHeight = minHeight;
        }
        if (isHidden) {
            computedStyle = {
                ...computedStyle,
                ...isHiddenStyle,
            };
        }
        return computedStyle;
    }, [minHeight, isHidden]);
    return (_jsx(GridLayoutElement, { type: item.isLayoutItem() ? "item" : "leaf-item", layoutItemSize: item.size(), className: cx({
            [`s-fluid-layout-column-ratio-${ratio}`]: !(ratio === null || ratio === undefined),
            [`s-fluid-layout-column-height-${height}`]: !(height === null || height === undefined),
        }, className), style: style, children: children }));
}
function getSizeForItem(item, screen) {
    const size = item.size();
    const currentScreenSizeConfiguration = item.sizeForScreen(screen);
    const ratio = currentScreenSizeConfiguration?.heightAsRatio;
    const height = currentScreenSizeConfiguration?.gridHeight;
    const width = currentScreenSizeConfiguration?.gridWidth;
    return {
        height,
        width,
        ratio,
        size,
    };
}
//# sourceMappingURL=DashboardLayoutItemViewRenderer.js.map