import {BrowserRouter as Router} from "react-router-dom";
import AppRouter from "./AppRouter.jsx";
import "/src/Styles/app.css";
import {useDispatch, useSelector} from "react-redux";
import dayjs from "dayjs";
import locale from 'antd/locale/ru_RU';
import {ConfigProvider} from "antd";
import {useEffect} from "react";
import {checkAuth} from "../Redux/Slices/authSlice.js";
import LoadingIndicator from "../Components/Widgets/LoadingIndicator/LoadingIndicator.jsx";
import ErrorBoundary from "./ErrorBoundary.jsx";

dayjs.locale('ru');

const App = () => {
    const dispatch = useDispatch();
    const {isLoading} = useSelector((state) => state.auth);

    useEffect(() => {
        dispatch(checkAuth());
    }, [dispatch]);

    if (isLoading) {
        return <LoadingIndicator/>;
    }

    return (
        <Router>
            <ConfigProvider locale={locale}>
                <ErrorBoundary>
                    <AppRouter/>
                </ErrorBoundary>
            </ConfigProvider>
        </Router>
    );
};

export default App;
