import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { useMemo, useState } from "react";
import { isEmpty } from "lodash-es";
import { determineWidthForScreen } from "../../../_staging/layout/sizing.js";
import { useScreenSize } from "../../dashboard/components/DashboardScreenSizeContext.js";
import { useSectionDescriptionExportData } from "../../export/useExportData.js";
import { DashboardLayoutItemViewRenderer } from "./DashboardLayoutItemViewRenderer.js";
import { DashboardLayoutViewSectionHeader } from "./DashboardLayoutViewSectionHeaderRenderer.js";
import { buildEmptyItemFacadeWithSetSize } from "./utils/emptyFacade.js";
export function DashboardLayoutExportSectionHeaderRenderer(props) {
    const { section, parentLayoutItemSize } = props;
    const sectionHeader = section.header();
    const screen = useScreenSize();
    const gridWidth = determineWidthForScreen(screen, parentLayoutItemSize);
    const emptyItem = useMemo(() => {
        return buildEmptyItemFacadeWithSetSize(gridWidth, section.index());
    }, [gridWidth, section]);
    const [loading, setLoading] = useState(false);
    const [error, setError] = useState(false);
    const exportData = useSectionDescriptionExportData(props.exportData, loading, error);
    //remove empty section headers; avoid in nested containers as this would delete the first child in some cases
    if (isEmpty(sectionHeader) && !section.index()?.parent) {
        return null;
    }
    return (_jsx(DashboardLayoutItemViewRenderer, { DefaultItemRenderer: DashboardLayoutItemViewRenderer, item: emptyItem, 
        // header is always at the top, this information is not usable by it but required by
        // the shared interface with widget
        rowIndex: -1, children: isEmpty(sectionHeader) ? null : (_jsx(DashboardLayoutViewSectionHeader, { section: section, exportData: exportData, onLoadingChanged: (loading) => setLoading(loading.isLoading), onError: (error) => setError(!!error) })) }));
}
