import { createContext, FC, PropsWithChildren, useContext, useMemo } from "react";

interface DataSetContext {
    dataSets: DOMStringMap | undefined;
}

const dataSetContextDefaultState: DataSetContext = {
    dataSets: undefined,
};

const DataSetContext = createContext<DataSetContext>(dataSetContextDefaultState);

export const useDataSet = () => useContext(DataSetContext);

const DataSetContextProvider: FC<PropsWithChildren<DataSetContext>> = ({ dataSets, children }) => {
    const value = useMemo(() => ({ dataSets }), [dataSets]);
    return <DataSetContext.Provider value={value}>{children}</DataSetContext.Provider>;
};

export default DataSetContextProvider;
