import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useState } from 'react';
const ChartRendererStateContext = createContext({});
export function ChartRendererStateProvider({ children, }) {
    const [chartRendererState, setChartRendererStateMap] = useState({});
    const [queryStatus, setQueryStatus] = useState({});
    const [resultSetExists, setResultSetExists] = useState({});
    const [isQueryLoading, setQueryLoading] = useState({});
    const [queryError, setQueryError] = useState({});
    const [isBuildInProgress, setBuildInProgress] = useState({});
    const [slowQuery, setSlowQuery] = useState({});
    const [slowQueryFromCache, setSlowQueryFromCache] = useState({});
    const [queryRequestId, setQueryRequestId] = useState({});
    return (_jsx(ChartRendererStateContext.Provider, { value: {
            chartRendererState,
            setChartRendererReady(queryId, isReady) {
                setChartRendererStateMap((prev) => ({
                    ...prev,
                    [queryId]: isReady,
                }));
            },
            queryStatus,
            setQueryStatus(queryId, status) {
                setQueryStatus((prev) => ({
                    ...prev,
                    [queryId]: status,
                }));
            },
            resultSetExists,
            setResultSetExists(queryId, exists) {
                setResultSetExists((prev) => ({
                    ...prev,
                    [queryId]: exists,
                }));
            },
            isQueryLoading,
            setQueryLoading(queryId, exists) {
                setQueryLoading((prev) => ({
                    ...prev,
                    [queryId]: exists,
                }));
            },
            queryError,
            setQueryError(queryId, error) {
                setQueryError((prev) => ({
                    ...prev,
                    [queryId]: error,
                }));
            },
            isBuildInProgress,
            setBuildInProgress(queryId, inProgress) {
                setBuildInProgress((prev) => ({
                    ...prev,
                    [queryId]: inProgress,
                }));
            },
            slowQuery,
            setSlowQuery(queryId, isSlow) {
                setSlowQuery((prev) => ({
                    ...prev,
                    [queryId]: isSlow,
                }));
            },
            slowQueryFromCache,
            setSlowQueryFromCache(queryId, isSlow) {
                setSlowQueryFromCache((prev) => ({
                    ...prev,
                    [queryId]: isSlow,
                }));
            },
            queryRequestId,
            setQueryRequestId(queryId, requestId) {
                setQueryRequestId((prev) => ({
                    ...prev,
                    [queryId]: requestId,
                }));
            },
        }, children: children }));
}
export function useChartRendererState(queryId) {
    const { chartRendererState, queryStatus, resultSetExists, isQueryLoading, queryError, isBuildInProgress, slowQuery, slowQueryFromCache, queryRequestId, } = useContext(ChartRendererStateContext);
    return {
        isChartRendererReady: Boolean(chartRendererState[queryId]),
        queryStatus: queryStatus[queryId],
        resultSetExists: resultSetExists[queryId],
        isQueryLoading: Boolean(isQueryLoading[queryId]),
        queryError: queryError[queryId] || null,
        isBuildInProgress: Boolean(isBuildInProgress[queryId]),
        slowQuery: Boolean(slowQuery[queryId]),
        slowQueryFromCache: Boolean(slowQueryFromCache[queryId]),
        queryRequestId: queryRequestId[queryId],
    };
}
export function useChartRendererStateMethods() {
    const { setChartRendererReady, setQueryStatus, setResultSetExists, setQueryLoading, setQueryError, setBuildInProgress, setSlowQuery, setSlowQueryFromCache, setQueryRequestId, } = useContext(ChartRendererStateContext);
    return {
        setChartRendererReady,
        setQueryStatus,
        setResultSetExists,
        setQueryLoading,
        setQueryError,
        setBuildInProgress,
        setSlowQuery,
        setSlowQueryFromCache,
        setQueryRequestId,
    };
}
//# sourceMappingURL=ChartRendererStateProvider.js.map