import {lazy, Suspense} from "react";
import {FallingLines} from "react-loader-spinner";
import {useLoadingSwitcher} from "../../hooks/useLoading.jsx";
import {useFetch} from "../../hooks/useFetch.js";
import {AxiosError} from "../../components/AxiosError.jsx";

export function StatsPage() {
    const StatsLazy = lazy(() => import('./StatsLazy.jsx'))
    const setLoading = useLoadingSwitcher()
    const {data, error} = useFetch(`/stats`, setLoading, 1)

    return <div>
        <h2>Statistiques</h2>
        <Suspense fallback={<FallingLines/>}>
            {data
                ? <>
                    <StatsLazy data={data}/>
                </>
                : error && <AxiosError error={error}/>
            }
        </Suspense>
    </div>
}