import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2025-2026 GoodData Corporation
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
const defaultState = {
    //main items
    definition: null,
    toValue: undefined,
    fromValue: undefined,
    definitionStatus: "pending",
    isMinimized: true,
    items: [],
    itemsStatus: "pending",
    itemsError: undefined,
    //states
    attributesDropdownOpen: false,
    addFilterDropdownOpen: false,
    trendDropdownOpen: false,
    //selected
    selectedTrend: "all",
    selectedItem: "summary",
    selectedStatus: "pending",
    selectedError: undefined,
    //root data
    attributeFilters: [],
    measureValueFilters: [],
    //attributes data
    selectedAttributes: [],
    selectedUpdated: 0,
    relevantAttributes: [],
    relevantStatus: "pending",
    includeTags: undefined,
    excludeTags: undefined,
};
const KdaStateContext = createContext({
    state: defaultState,
    setState: () => undefined,
});
export function KdaStateProvider({ children, value }) {
    const [state, setStateInternal] = useState({ ...defaultState, ...value });
    useEffect(() => {
        setStateInternal({ ...defaultState, ...value });
    }, [value]);
    const setState = useCallback((newState) => {
        setStateInternal((prevState) => ({ ...prevState, ...newState }));
    }, []);
    const providerValue = useMemo(() => {
        return { state, setState };
    }, [state, setState]);
    return _jsx(KdaStateContext.Provider, { value: providerValue, children: children });
}
export function useKdaState() {
    return useContext(KdaStateContext);
}
