import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
const RangeContext = React.createContext(undefined);
export const RangeProvider = ({ children, defaultPageSize = 10 }) => {
    const [range, setRange] = React.useState([0, defaultPageSize]);
    const [numberOfResults, setNumberOfResults] = React.useState(0);
    const [actuallyPage, setActuallyPage] = React.useState(0);
    const [correction, setCorrection] = React.useState(null);
    const [overrideSearchWithCorrection, setOverrideSearchWithCorrection] = React.useState({ isAutocorrection: null, renderingCorrection: false });
    const resetPage = React.useCallback((pageSize) => {
        const size = pageSize ?? range[1] ?? defaultPageSize;
        setActuallyPage(0);
        setRange([0, size]);
    }, [range[1], defaultPageSize]);
    return (_jsx(RangeContext.Provider, { value: {
            range,
            setRange,
            numberOfResults,
            setNumberOfResults,
            actuallyPage,
            setActuallyPage,
            resetPage,
            correction,
            setCorrection,
            overrideSearchWithCorrection,
            setOverrideSearchWithCorrection,
        }, children: children }));
};
export const useRange = () => {
    const ctx = React.useContext(RangeContext);
    if (!ctx)
        throw new Error("useRange must be used within RangeProvider");
    return ctx;
};
